=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/Catalog.java' --- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/Catalog.java 2012-05-09 07:02:15 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/Catalog.java 2012-05-30 10:46:26 +0000 @@ -1,5 +1,8 @@ package org.hisp.dhis.coldchain.catalog; +import java.io.File; +import java.sql.Blob; + import org.hisp.dhis.common.BaseNameableObject; //public class Catalog implements Serializable public class Catalog extends BaseNameableObject @@ -8,15 +11,26 @@ * Determines if a de-serialized file is compatible with this class. */ private static final long serialVersionUID = -6551567526188061690L; - + + public static final String DEFAULT_CCEMFOLDER = "CCEMIMAGES"; + private int id; private String name; private String description; + + private String catalogImage; + + //private Blob image; private CatalogType catalogType; + // private File image; + + //private byte[] image; + + // ------------------------------------------------------------------------- // Contructors // ------------------------------------------------------------------------- @@ -37,11 +51,26 @@ this.description = description; this.catalogType = catalogType; } + + /* + public Catalog( Blob image ) + { + this.image = image; + } + + + public Catalog( byte[] image ) + { + this.image = image; + } + */ // ------------------------------------------------------------------------- // hashCode and equals // ------------------------------------------------------------------------- + + @Override public int hashCode() { @@ -115,4 +144,59 @@ this.catalogType = catalogType; } + public String getCatalogImage() + { + return catalogImage; + } + + public void setCatalogImage( String catalogImage ) + { + this.catalogImage = catalogImage; + } + /* + public File getImage() + { + return image; + } + + public void setImage( File image ) + { + this.image = image; + } + + public void setBinaryStream( Blob image ) + { + this.image = image; + } + + public Blob getBinaryStream() + { + return image; + } + + public Blob getImage() + { + return image; + } + + public void setImage( Blob image ) + { + this.image = image; + } + + + public byte[] getImage() + { + return image; + } + + public void setImage( byte[] image ) + { + this.image = image; + } + */ + + + + } === modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/CatalogType.java' --- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/CatalogType.java 2012-05-14 09:25:17 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/catalog/CatalogType.java 2012-05-30 10:46:26 +0000 @@ -24,6 +24,8 @@ private DataEntryForm dataEntryForm; + private String catalogTypeImage; + // ------------------------------------------------------------------------- // Contructors // ------------------------------------------------------------------------- @@ -121,4 +123,12 @@ this.catalogTypeAttributes = catalogTypeAttributes; } + public String getCatalogTypeImage() + { + return catalogTypeImage; + } + public void setCatalogTypeImage( String catalogTypeImage ) + { + this.catalogTypeImage = catalogTypeImage; + } } === modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/Configuration_IN.java' --- local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/Configuration_IN.java 2011-06-28 10:02:15 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/config/Configuration_IN.java 2012-05-30 10:46:26 +0000 @@ -39,7 +39,7 @@ public static final String DEFAULT_REPORTFOLDER = "ra_national"; public static final String DEFAULT_TEMPFOLDER = "temp"; - + private int id; private String key; === modified file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/Catalog.hbm.xml' --- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/Catalog.hbm.xml 2012-04-17 11:59:19 +0000 +++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/Catalog.hbm.xml 2012-05-30 10:46:26 +0000 @@ -12,6 +12,15 @@ + + + + + + + + + === modified file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/CatalogType.hbm.xml' --- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/CatalogType.hbm.xml 2012-05-09 12:08:52 +0000 +++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/CatalogType.hbm.xml 2012-05-30 10:46:26 +0000 @@ -13,6 +13,7 @@ + net.sourceforge.jexcelapi === modified file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowAddCatalogFormAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowAddCatalogFormAction.java 2012-05-14 09:25:17 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowAddCatalogFormAction.java 2012-05-30 10:46:26 +0000 @@ -49,14 +49,20 @@ return catalogTypeAttributes; } + private CatalogType catalogType; + + public CatalogType getCatalogType() + { + return catalogType; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- public String execute() { - - CatalogType catalogType = catalogTypeService.getCatalogType( catalogTypeId ); + catalogType = catalogTypeService.getCatalogType( catalogTypeId ); //catalogTypeAttributes = catalogType.getCatalogTypeAttributes(); === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowCatalogTypeImageAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowCatalogTypeImageAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowCatalogTypeImageAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,109 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.coldchain.catalog.Catalog; +import org.hisp.dhis.coldchain.catalog.CatalogType; +import org.hisp.dhis.coldchain.catalog.CatalogTypeService; + +import com.opensymphony.xwork2.Action; + +public class ShowCatalogTypeImageAction implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogTypeService catalogTypeService; + + public void setCatalogTypeService( CatalogTypeService catalogTypeService ) + { + this.catalogTypeService = catalogTypeService; + } + + + + // ------------------------------------------------------------------------- + // Input/Output and Getter / Setter + // ------------------------------------------------------------------------- + + private int id; + + public void setId( int id ) + { + this.id = id; + } + + + private byte[] bimage; + + public byte[] getBimage() + { + return bimage; + } + + String cataLogImage = null; + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + + CatalogType catalogType = catalogTypeService.getCatalogType( id ); + + if ( catalogType.getCatalogTypeImage() != null ) + { + cataLogImage = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + catalogType.getCatalogTypeImage(); + } + + else + { + + } + + File file = new File( cataLogImage ); + bimage = new byte[(int) file.length()]; + + try + { + FileInputStream fileInputStream = new FileInputStream( file ); + //convert file into array of bytes + fileInputStream.read( bimage ); + fileInputStream.close(); + } + catch (Exception e) + { + //e.printStackTrace(); + } + + try + { + HttpServletResponse response = ServletActionContext.getResponse(); + response.reset(); + response.setContentType("multipart/form-data"); + + OutputStream out = response.getOutputStream(); + out.write( bimage ); + out.flush(); + out.close(); + } + + catch (IOException e) + { + //e.printStackTrace(); + } + + return SUCCESS; + } + +} + + === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowImageAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowImageAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowImageAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,131 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.coldchain.catalog.Catalog; +import org.hisp.dhis.coldchain.catalog.CatalogService; + +import com.opensymphony.xwork2.Action; + +public class ShowImageAction implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogService catalogService; + + public void setCatalogService( CatalogService catalogService ) + { + this.catalogService = catalogService; + } + + + + // ------------------------------------------------------------------------- + // Input/Output and Getter / Setter + // ------------------------------------------------------------------------- + + private int id; + + public void setId( int id ) + { + this.id = id; + } + + + private byte[] bimage; + + public byte[] getBimage() + { + return bimage; + } + + String cataLogImage = null; + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + + Catalog catalog = catalogService.getCatalog( id ); + + if ( catalog.getCatalogImage() != null ) + { + cataLogImage = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + catalog.getCatalogImage(); + } + + else if ( catalog.getCatalogType().getCatalogTypeImage() != null ) + { + cataLogImage = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + catalog.getCatalogType().getCatalogTypeImage(); + } + + else + { + + } + //System.out.println( "cataLog Image is : " + cataLogImage ); + + /* + HttpServletResponse response = ServletActionContext.getResponse(); + response.reset(); + response.setContentType("multipart/form-data"); + + bimage = catalog.getImage(); + + OutputStream out = response.getOutputStream(); + out.write( bimage ); + out.flush(); + out.close(); + */ + + + File file = new File( cataLogImage ); + bimage = new byte[(int) file.length()]; + + try + { + FileInputStream fileInputStream = new FileInputStream( file ); + //convert file into array of bytes + fileInputStream.read( bimage ); + fileInputStream.close(); + } + catch (Exception e) + { + //e.printStackTrace(); + } + + try + { + HttpServletResponse response = ServletActionContext.getResponse(); + response.reset(); + response.setContentType("multipart/form-data"); + + OutputStream out = response.getOutputStream(); + out.write( bimage ); + out.flush(); + out.close(); + } + + catch (IOException e) + { + //e.printStackTrace(); + } + + + + + + + + return SUCCESS; + } + +} === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogImageFormAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogImageFormAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogImageFormAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,56 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import org.hisp.dhis.coldchain.catalog.Catalog; +import org.hisp.dhis.coldchain.catalog.CatalogService; + +import com.opensymphony.xwork2.Action; + +public class ShowUploadCatalogImageFormAction implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogService catalogService; + + public void setCatalogService( CatalogService catalogService ) + { + this.catalogService = catalogService; + } + + + // ------------------------------------------------------------------------- + // Input/Output and Getter / Setter + // ------------------------------------------------------------------------- + + private int id; + + public void setId( int id ) + { + this.id = id; + } + + private Catalog catalog; + + public Catalog getCatalog() + { + return catalog; + } + + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + + catalog = catalogService.getCatalog( id ); + + + return SUCCESS; + + } + +} + === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogTypeImageFormAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogTypeImageFormAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/ShowUploadCatalogTypeImageFormAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,56 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import org.hisp.dhis.coldchain.catalog.CatalogType; +import org.hisp.dhis.coldchain.catalog.CatalogTypeService; + +import com.opensymphony.xwork2.Action; + +public class ShowUploadCatalogTypeImageFormAction implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogTypeService catalogTypeService; + + public void setCatalogTypeService( CatalogTypeService catalogTypeService ) + { + this.catalogTypeService = catalogTypeService; + } + + // ------------------------------------------------------------------------- + // Input/Output + // ------------------------------------------------------------------------- + + private int id; + + public int getId() + { + return id; + } + + public void setId( int id ) + { + this.id = id; + } + + private CatalogType catalogType; + + public CatalogType getCatalogType() + { + return catalogType; + } + + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + //System.out.println( id ); + catalogType = catalogTypeService.getCatalogType( id ); + + return SUCCESS; + } +} === modified file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UpdateCatalogFormAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UpdateCatalogFormAction.java 2012-05-09 12:08:52 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UpdateCatalogFormAction.java 2012-05-30 10:46:26 +0000 @@ -1,7 +1,10 @@ package org.hisp.dhis.coldchain.catalog.action; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,7 +16,6 @@ import org.hisp.dhis.coldchain.catalog.CatalogType; import org.hisp.dhis.coldchain.catalog.CatalogTypeAttribute; import org.hisp.dhis.coldchain.catalog.CatalogTypeService; -import org.hisp.dhis.coldchain.catalog.comparator.CatalogTypeAttributeComparator; import com.opensymphony.xwork2.Action; @@ -58,7 +60,6 @@ this.id = id; } - private Catalog catalog; @@ -96,10 +97,48 @@ return catalogTypeAttributes; } + private String cataLogImage; + + + private byte[] bimage; + + public byte[] getBimage() + { + return bimage; + } + + private OutputStream outPutStream; + + public OutputStream getOutPutStream() + { + return outPutStream; + } + + private BufferedImage bufferedImage; + + public BufferedImage getBufferedImage() + { + return bufferedImage; + } + + private URL url; + + public URL getUrl() + { + return url; + } + + + + public String getCataLogImage() + { + return cataLogImage; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- - + public String execute() throws Exception { @@ -107,7 +146,97 @@ catalogTypes = new ArrayList( catalogTypeService.getAllCatalogTypes()); - + + cataLogImage = catalog.getCatalogImage(); + + //String outputFilePath = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + cataLogImage; + + System.out.println( "Catalog Image Name is :" + cataLogImage ); + + cataLogImage = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + cataLogImage; + + System.out.println( "Complete Path of Image is :" + cataLogImage ); + + + /* + HttpServletResponse response = ServletActionContext.getResponse(); + response.reset(); + response.setContentType("multipart/form-data"); + + + bimage = catalog.getImage(); + + OutputStream out = response.getOutputStream(); + out.write( bimage ); + out.flush(); + out.close(); + */ + + /* + bimage = catalog.getImage(); + System.out.println( " Image is :" + bimage ); + System.out.println( " lenght is :" + bimage.length ); + System.out.println( " String is :" + bimage.toString() ); + try + { + + int len = bimage.toString().length(); + byte [] rb = new byte[len]; + //InputStream readImg = rs.getBinaryStream(1); + //int index=readImg.read(rb, 0, len); + outPutStream.write( rb,0,len ); + + + + //outPutStream + //FileOutputStream fos = new FileOutputStream("cataLogImage"); + // outPutStream = new FileOutputStream( cataLogImage ); + //outPutStream.write( bimage ); + //outPutStream.close(); + } + catch(Exception e) + { + //e.printStackTrace(); + } + + */ + + + + /* + String filePath = cataLogImage; + File f1 = new File( filePath ); + + ImageInputStream imgStream1 = ImageIO.createImageInputStream( f1 ); + long size = imgStream1.length(); + + + //bufferedImage = ImageIO.read( f1 ); + + BufferedImage bufferedImage1 = ImageIO.read( f1 ); + //boolean success = ImageIO.write( bufferedImage1,"gif",socket.getOutputStream()); + + + try + { + url = new URL( getCodeBase(), cataLogImage ); + + bufferedImage = ImageIO.read( url ); + } + catch (IOException e) + { + + } + + System.out.println( "IMAGE is :" + bufferedImage ); + System.out.println( "URL is :" + url ); + + + //outPutStream.w.write( bufferedImage1 ); + + */ + + // ------------------------------------------------------------------------- // Get catalog attribute values // ------------------------------------------------------------------------- @@ -150,6 +279,21 @@ return SUCCESS; } - +/* + private URL getCodeBase() + { + //URL url = null; + try + { + url = new URL( "catalog.getCatalogImage()" ); + } + catch (IOException e) + { + + } + System.out.println( "URL in method is :" + url ); + return url; + } +*/ } === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogImageAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogImageAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogImageAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,359 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import java.io.File; +import java.io.FileInputStream; +import java.sql.Blob; + +import org.hibernate.Hibernate; +import org.hisp.dhis.coldchain.catalog.Catalog; +import org.hisp.dhis.coldchain.catalog.CatalogService; +import org.hisp.dhis.system.util.StreamUtils; + +import com.opensymphony.xwork2.Action; + +public class UploadCatalogImageAction implements Action +{ + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogService catalogService; + + public void setCatalogService( CatalogService catalogService ) + { + this.catalogService = catalogService; + } + + // ------------------------------------------------------------------------- + // Input/Output + // ------------------------------------------------------------------------- + + private String message; + + public String getMessage() + { + return message; + } + + public void setMessage( String message ) + { + this.message = message; + } + + private int catalogID; + + public void setCatalogID( int catalogID ) + { + this.catalogID = catalogID; + } + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + + + /* + private File file; + + public File getFile() + { + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + private String fileName; + + public String getFileName() + { + return fileName; + } + + public void setFileName( String fileName ) + { + this.fileName = fileName; + } + + + private File file; + + public void setUpload( File file ) + { + this.file = file; + } + + private File upload; + + public File getUpload() + { + return upload; + } + + + private String fileName; + + public void setUploadFileName( String fileName ) + { + this.fileName = fileName; + } + /* + * + * + * + */ + /* + private String tempFileName; + + public void setTempFileName( String tempFileName ) + { + this.tempFileName = tempFileName; + } + + private File upload; + + public void setUpload( File upload ) + { + this.upload = upload; + } + + private File file; + + public void setUpload( File file ) + { + this.file = file; + } + */ + private String fileName; + + private File upload; + + public void setUploadFileName( String fileName ) + { + this.fileName = fileName; + } + + + public void setUpload( File upload ) + { + this.upload = upload; + } + + private File outputFile; + + String imageName = ""; + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + + public String execute() throws Exception + { + outputFile = null; + + Catalog catalog = catalogService.getCatalog( catalogID ); + + + //File directory = null; + + String fileType = fileName.substring(fileName.indexOf( '.' )+1, fileName.length()); + + + System.out.println( "File Name is : " + fileName +" File Type is : " + fileType ); + + System.out.println( "UPLOAD is : " + upload ); + + + + if ( ! ( fileType.equalsIgnoreCase( "jpg" ) || fileType.equalsIgnoreCase( "png" ) || fileType.equalsIgnoreCase( "gif" ) || fileType.equalsIgnoreCase( "jpeg" ) || fileType.equalsIgnoreCase( "tiff" ) || fileType.equalsIgnoreCase( "bmp" ) ) ) + //if ( !fileType.equalsIgnoreCase( "jpg" ) || !fileType.equalsIgnoreCase( "png" ) || !fileType.equalsIgnoreCase( "gif" ) || !fileType.equalsIgnoreCase( "bmp" ) ) + { + message = "The file you are trying to import is not an image file"; + + return SUCCESS; + } + + imageName = catalog.getName()+"."+ fileType; + + catalog.setCatalogImage( imageName ); + //catalog.setCatalogImage( fileName ); + catalogService.updateCatalog( catalog ); + + + + + String outputFilePath = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER; + + File newdir = new File( outputFilePath ); + if( !newdir.exists() ) + { + newdir.mkdirs(); + } + + outputFile = new File( newdir, imageName ); + try + { + StreamUtils.write( upload, outputFile ); + + message = "Image successfully uploaded"; + } + + catch( Exception e ) + { + /* + e.printStackTrace(); + message += "
Some problem occured while Importing the file : "+ upload.getName() + "
Error Message: "+e.getMessage()+"
"; + */ + } + + //String cataLogImage = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + catalog.getCatalogImage(); + + + //FileInputStream fis; + + /* + + File file = new File( cataLogImage ); + byte[] bFile = new byte[(int) file.length()]; + + + try + { + FileInputStream fileInputStream = new FileInputStream(file); + //convert file into array of bytes + fileInputStream.read(bFile); + fileInputStream.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + catalog.setImage( bFile ); + + catalogService.updateCatalog( catalog ); + + */ + + //fis = new FileInputStream(image); + + + // catalog.setImage( image ); + + /* + catalog.setBinaryStream( image ); + + catalog.setBinaryStream(InputStream)fis, (int)(image.length())); + */ + + + + + //System.out.println( "File Name is : " + upload.getName() ); + + + + //outputFile = new File( directory, (Math.random() * 1000) + fileName ); + + //String outputFilePathTest = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER + File.separator + tempFileName; + + + /* + File newdir = new File( outputFilePath ); + if( !newdir.exists() ) + { + newdir.mkdirs(); + } + */ + + //outputFile = new File( directory, (Math.random() * 1000) + fileName ); + + // file.renameTo( outputFile ); + + /* + File output = null; + output = new File( outputFilePath, outputFilePathTest ); + */ + //InputStream inputStream = null; + + //inputStream = new BufferedInputStream( new FileInputStream( file ) ); + + //outputFile = new File( newdir, (Math.random() * 1000) + fileName ); + + //outputFile = new File( newdir, fileName ); + + /* outputFile = new File( newdir, imageName );*/ + /*try + { */ + //outputFile = new File( outputFilePathTest ); + + //outputFile = new File( newdir, fileName ); + + //outputFile = new File( newdir, (Math.random() * 1000) + fileName ); + + + /* StreamUtils.write( upload, outputFile ); */ + + //System.out.println( " outputFile : " + outputFile ); + + // System.out.println( "File Name is : " + upload.getName() ); + + //StreamUtils.write( upload, outputFile ); + + + //System.out.println( "File Name is : " + file.getPath() ); + // System.out.println( "File Name is : " + fileName ); + + //System.out.println( "File Name is : " + tempFileName ); + + //String fileType = fileName.substring(fileName.indexOf( '.' )+1, fileName.length()); + + //String fileType = fileName.substring(fileName.indexOf( '.' )+1, upload.getName().length()); + + // System.out.println( "File Name is : " + fileName +" File Type is : " + fileType ); + + /* + message = "Image successfully uploaded"; + } + */ + /* + catch( Exception e ) + { + + e.printStackTrace(); + message += "
Some problem occured while Importing the file : "+ upload.getName() + "
Error Message: "+e.getMessage()+"
"; + + } + */ + + /* + String filePath = c:\images\+ "button1.gif"; + File f1 = new File(filePath); + + ImageInputStream imgStream1 = ImageIO.createImageInputStream(f1); + long size = imgStream1.length(); + + BufferedImage bufferedImage1 = ImageIO.read(f1); + boolean success = ImageIO.write(bufferedImage1,"gif",socket.getOutputStream()); + + socketWriter.close(); + socketReader.close(); + socket.close(); + socket = null; + */ + + + + + return SUCCESS; + } + + +} === added file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogTypeImageAction.java' --- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogTypeImageAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/catalog/action/UploadCatalogTypeImageAction.java 2012-05-30 10:46:26 +0000 @@ -0,0 +1,121 @@ +package org.hisp.dhis.coldchain.catalog.action; + +import java.io.File; + +import org.hisp.dhis.coldchain.catalog.Catalog; +import org.hisp.dhis.coldchain.catalog.CatalogType; +import org.hisp.dhis.coldchain.catalog.CatalogTypeService; +import org.hisp.dhis.system.util.StreamUtils; + +import com.opensymphony.xwork2.Action; + +public class UploadCatalogTypeImageAction implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private CatalogTypeService catalogTypeService; + + public void setCatalogTypeService( CatalogTypeService catalogTypeService ) + { + this.catalogTypeService = catalogTypeService; + } + + // ------------------------------------------------------------------------- + // Input/Output + // ------------------------------------------------------------------------- + + private int id; + + public void setId( int id ) + { + this.id = id; + } + + private String fileName; + + private File upload; + + public void setUploadFileName( String fileName ) + { + this.fileName = fileName; + } + + + public void setUpload( File upload ) + { + this.upload = upload; + } + + private String message; + + public String getMessage() + { + return message; + } + + public void setMessage( String message ) + { + this.message = message; + } + + String imageName = ""; + + private File outputFile; + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() throws Exception + { + outputFile = null; + + CatalogType catalogType = catalogTypeService.getCatalogType( id ); + + String fileType = fileName.substring(fileName.indexOf( '.' )+1, fileName.length()); + + if ( ! ( fileType.equalsIgnoreCase( "jpg" ) || fileType.equalsIgnoreCase( "png" ) || fileType.equalsIgnoreCase( "gif" ) || fileType.equalsIgnoreCase( "jpeg" ) || fileType.equalsIgnoreCase( "tiff" ) || fileType.equalsIgnoreCase( "bmp" ) ) ) + //if ( !fileType.equalsIgnoreCase( "jpg" ) || !fileType.equalsIgnoreCase( "png" ) || !fileType.equalsIgnoreCase( "gif" ) || !fileType.equalsIgnoreCase( "bmp" ) ) + { + message = "The file you are trying to import is not an image file"; + + return SUCCESS; + } + + imageName = catalogType.getName()+"."+ fileType; + + catalogType.setCatalogTypeImage( imageName ); + + catalogTypeService.updateCatalogType( catalogType ); + + + String outputFilePath = System.getenv( "DHIS2_HOME" ) + File.separator + Catalog.DEFAULT_CCEMFOLDER; + + File newdir = new File( outputFilePath ); + if( !newdir.exists() ) + { + newdir.mkdirs(); + } + + outputFile = new File( newdir, imageName ); + try + { + StreamUtils.write( upload, outputFile ); + + message = "Image successfully uploaded"; + } + + catch( Exception e ) + { + + e.printStackTrace(); + message += "
Some problem occured while Importing the file : "+ fileName + "
Error Message: "+e.getMessage()+"
"; + + } + + + return SUCCESS; + } +} + === modified file 'local/in/dhis-web-coldchain/src/main/resources/META-INF/dhis/beans.xml' --- local/in/dhis-web-coldchain/src/main/resources/META-INF/dhis/beans.xml 2012-05-23 06:35:17 +0000 +++ local/in/dhis-web-coldchain/src/main/resources/META-INF/dhis/beans.xml 2012-05-30 10:46:26 +0000 @@ -497,5 +497,46 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file === modified file 'local/in/dhis-web-coldchain/src/main/resources/org/hisp/dhis/coldchain/i18n_module.properties' --- local/in/dhis-web-coldchain/src/main/resources/org/hisp/dhis/coldchain/i18n_module.properties 2012-05-24 06:15:24 +0000 +++ local/in/dhis-web-coldchain/src/main/resources/org/hisp/dhis/coldchain/i18n_module.properties 2012-05-30 10:46:26 +0000 @@ -113,4 +113,6 @@ ccem_setup = CCEM Setup ccem_entry = CCEM Entry -ccem_reports = CCEM Reports \ No newline at end of file +ccem_reports = CCEM Reports +upload_image = Upload image +upload_catalog_image = Upload catalog image \ No newline at end of file === modified file 'local/in/dhis-web-coldchain/src/main/resources/struts.xml' --- local/in/dhis-web-coldchain/src/main/resources/struts.xml 2012-05-23 06:35:17 +0000 +++ local/in/dhis-web-coldchain/src/main/resources/struts.xml 2012-05-30 10:46:26 +0000 @@ -499,7 +499,50 @@ enquipmentSelect.action F_EQUIPMENT_DATAENTRY - - - + + + + + /main.vm + /dhis-web-coldchain/uploadCatalogImageForm.vm + css/style.css + F_CATALOG_UPDATE + + + + /main.vm + /dhis-web-coldchain/menu.vm + /dhis-web-coldchain/responseUplodImageStatus.vm + + + + + + + /content.vm + + + + + /main.vm + /dhis-web-coldchain/uploadCatalogTypeImageForm.vm + css/style.css + F_CATALOG_UPDATE + + + + + /main.vm + /dhis-web-coldchain/menu.vm + /dhis-web-coldchain/responseUplodCatalogTypeImageStatus.vm + + + + + + + /content.vm + + + \ No newline at end of file === modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/addCatalogForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/addCatalogForm.vm 2012-05-05 11:16:25 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/addCatalogForm.vm 2012-05-30 10:46:26 +0000 @@ -25,10 +25,10 @@ #end - +    - +
=== modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogList.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogList.vm 2012-05-09 07:02:15 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogList.vm 2012-05-30 10:46:26 +0000 @@ -32,12 +32,13 @@ + - + @@ -46,6 +47,12 @@ + + + +
$i18n.getString( "name" )$i18n.getString( "operations" )$i18n.getString( "operations" )
$encoder.htmlEncode( $catalog.name ) + $i18n.getString( 'upload_image' ) + $i18n.getString( 'edit' ) === modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogTypeList.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogTypeList.vm 2012-05-09 12:08:52 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/catalogTypeList.vm 2012-05-30 10:46:26 +0000 @@ -36,6 +36,7 @@
$encoder.htmlEncode( $catalogType.name ) + $i18n.getString( 'upload_image' ) $i18n.getString( 'edit' ) $i18n.getString( $i18n.getString( === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload.png' Binary files local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload.png 1970-01-01 00:00:00 +0000 and local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload.png 2012-05-30 10:46:26 +0000 differ === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload11111.jpg' Binary files local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload11111.jpg 1970-01-01 00:00:00 +0000 and local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/images/upload11111.jpg 2012-05-30 10:46:26 +0000 differ === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogImageForm.js' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogImageForm.js 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogImageForm.js 2012-05-30 10:46:26 +0000 @@ -0,0 +1,36 @@ +jQuery(document).ready( function(){ + + validation( 'uploadCatalogImageForm', function(form){ + //tempFileName = $('#upload').val();alert( tempFileName ); + form.submit(); + }, function(){ + isSubmit = true; + + }); + + checkValueIsExist( "name", "validateCatalog.action", {id:getFieldValue('id')}); +}); + + +/* + +*/ \ No newline at end of file === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogTypeImageForm.js' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogTypeImageForm.js 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/javascript/uploadCatalogTypeImageForm.js 2012-05-30 10:46:26 +0000 @@ -0,0 +1,11 @@ +jQuery(document).ready( function(){ + + validation( 'uploadCatalogTypeImageForm', function(form){ + form.submit(); + }, function(){ + isSubmit = true; + + }); + + checkValueIsExist( "name", "validateCatalogType.action", {id:getFieldValue('id')}); +}); === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodCatalogTypeImageStatus.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodCatalogTypeImageStatus.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodCatalogTypeImageStatus.vm 2012-05-30 10:46:26 +0000 @@ -0,0 +1,5 @@ +$encoder.xmlEncode( $message ) + +

+ + === added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodImageStatus.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodImageStatus.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/responseUplodImageStatus.vm 2012-05-30 10:46:26 +0000 @@ -0,0 +1,5 @@ +$encoder.xmlEncode( $message ) + +

+ + === modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/showAddCatalogForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/showAddCatalogForm.vm 2012-05-09 07:02:15 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/showAddCatalogForm.vm 2012-05-30 10:46:26 +0000 @@ -11,6 +11,10 @@ + + + +
+ + + #if ( $catalogTypeAttributes.size() > 0) @@ -55,4 +59,11 @@ #end #end +
 
$i18n.getString( "catalogType_details" )
+
  + +
\ No newline at end of file === modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogForm.vm 2012-05-05 11:16:25 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogForm.vm 2012-05-30 10:46:26 +0000 @@ -18,6 +18,9 @@ +
+ + + + + + +

- + + \ No newline at end of file === modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogTypeForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogTypeForm.vm 2012-04-30 11:24:11 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/updateCatalogTypeForm.vm 2012-05-30 10:46:26 +0000 @@ -4,7 +4,9 @@
- + + + + + +
+ @@ -23,7 +25,13 @@
$i18n.getString( "catalog_type_details" )
- +
  + +
=== added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogImageForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogImageForm.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogImageForm.vm 2012-05-30 10:46:26 +0000 @@ -0,0 +1,43 @@ + + + +

$i18n.getString( "upload_catalog_image" )

+

+ +

+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
  
   +
+ + + +
=== added file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogTypeImageForm.vm' --- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogTypeImageForm.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/uploadCatalogTypeImageForm.vm 2012-05-30 10:46:26 +0000 @@ -0,0 +1,38 @@ + + +

$i18n.getString( "edit_catalogType" )

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
$i18n.getString( "catalog_type_details" )
 
   +
+ +