=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java 2013-06-02 01:38:28 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java 2013-06-26 08:56:44 +0000 @@ -61,7 +61,6 @@ import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; -import com.lowagie.text.pdf.CMYKColor; import com.lowagie.text.pdf.PdfAnnotation; import com.lowagie.text.pdf.PdfAppearance; import com.lowagie.text.pdf.PdfBorderDictionary; @@ -73,6 +72,10 @@ import com.lowagie.text.pdf.RadioCheckField; import com.lowagie.text.pdf.TextField; +/** + * @author James Chang + */ + public class DefaultPdfDataEntryFormService implements PdfDataEntryFormService { @@ -148,13 +151,17 @@ throws IOException, DocumentException, ParseException, Exception { DataSet dataSet = dataSetService.getDataSet( dataSetUid ); - + if ( dataSet == null ) { throw new Exception( "Error - DataSet not found for UID " + dataSetUid ); } else { + + // Get I18n locale language translated version of DataSet + dataSet = dataSetService.getDataSet( dataSet.getId(), true, true, false ); + setDataSet_DocumentTopSection( document, dataSet ); document.add( Chunk.NEWLINE ); @@ -185,7 +192,7 @@ document.add( new Paragraph( dataSet.getDisplayName(), pdfFormFontSettings .getFont( PdfFormFontSettings.FONTTYPE_TITLE ) ) ); - document.add( new Paragraph( dataSet.getDescription(), pdfFormFontSettings + document.add( new Paragraph( dataSet.getDisplayDescription(), pdfFormFontSettings .getFont( PdfFormFontSettings.FONTTYPE_DESCRIPTION ) ) ); } @@ -552,6 +559,7 @@ } // Insert 'Save As' button to document. + @SuppressWarnings( "unused" ) private void insertSaveAsButton( Document document, PdfWriter writer, String name ) throws DocumentException { @@ -699,6 +707,7 @@ table.addCell( cell ); } + @SuppressWarnings( "unused" ) private void addCell_WithRadioButton( PdfPTable table, PdfWriter writer, String strfldName ) { // Add to the main table === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormService.java 2013-05-25 11:38:41 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormService.java 2013-06-26 08:56:44 +0000 @@ -32,6 +32,10 @@ import com.lowagie.text.pdf.PdfWriter; import org.hisp.dhis.i18n.I18nFormat; +/** + * @author James Chang + */ + public interface PdfDataEntryFormService { void generatePDFDataEntryForm( Document document, PdfWriter writer, String inputUid, int typeId, === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java 2013-05-31 08:03:08 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java 2013-06-26 08:56:44 +0000 @@ -49,6 +49,10 @@ import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfReader; +/** + * @author James Chang + */ + public class PdfDataEntryFormUtil { public static final int DATATYPE_DATASET = 0; @@ -216,6 +220,7 @@ // Loop Through the Fields and get data. + @SuppressWarnings( "unchecked" ) Set fldNames = form.getFields().keySet(); for ( String fldName : fldNames ) === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java 2013-05-30 10:42:28 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java 2013-06-26 08:56:44 +0000 @@ -45,6 +45,10 @@ import com.lowagie.text.pdf.PushbuttonField; import com.lowagie.text.pdf.RadioCheckField; +/** + * @author James Chang + */ + public class PdfFieldCell implements PdfPCellEvent { @@ -132,6 +136,8 @@ { PdfContentByte canvasText = canvases[PdfPTable.TEXTCANVAS]; + + // PENDING LOGIC // PdfContentByte canvasLine = canvases[PdfPTable.LINECANVAS]; // // float margin = 2; @@ -143,10 +149,8 @@ // // canvasLine.rectangle( x1, y1, x2 - x1, y2 - y1 ); - switch ( type ) + if ( type == TYPE_RADIOBUTTON ) { - case TYPE_RADIOBUTTON: - if ( parent != null ) { float leftLoc = rect.getLeft(); @@ -193,10 +197,9 @@ writer.addAnnotation( parent ); } - - break; - - case TYPE_BUTTON: + } + else if ( type == TYPE_BUTTON ) + { // Add the push button PushbuttonField button = new PushbuttonField( writer, rect, name ); button.setBackgroundColor( new GrayColor( 0.75f ) ); @@ -213,40 +216,39 @@ formField = button.getField(); formField.setAction( PdfAction.javaScript( jsAction, writer ) ); - - break; - - case TYPE_CHECKBOX: - + } + else if ( type == TYPE_CHECKBOX ) + { // Start from the middle of the cell width. float startingPoint = rect.getLeft() + ((rect.getWidth() + width) / 2.0f); formField.setWidget( new Rectangle( startingPoint, rect.getBottom(), startingPoint + width, rect.getTop() ), PdfAnnotation.HIGHLIGHT_NONE ); - - break; - - case TYPE_TEXT_ORGUNIT: - formField.setAdditionalActions( PdfName.BL, PdfAction.javaScript( - "if(event.value == '') app.alert('Warning! Please Enter The Org ID.');", writer ) ); - - case TYPE_TEXT_NUMBER: - - default: - + } + else + { + + if ( type == TYPE_TEXT_ORGUNIT ) + { + formField.setAdditionalActions( PdfName.BL, PdfAction.javaScript( + "if(event.value == '') app.alert('Warning! Please Enter The Org ID.');", writer ) ); + } + + // TYPE_TEXT_NUMBER case included as well here. + + // PENDING LOGIC // Add -1, +1 to create cellpadding effect - spacing between // rows/cells // formField.setWidget( // new Rectangle( rect.getLeft() + 1, rect.getBottom() + 1, // rect.getLeft() + width - 1, rect.getTop() - 1 ), // PdfAnnotation.HIGHLIGHT_NONE ); + formField.setWidget( new Rectangle( rect.getLeft(), rect.getBottom(), rect.getLeft() + width, rect.getTop() ), PdfAnnotation.HIGHLIGHT_NONE ); - break; - } writer.addAnnotation( formField ); === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFormFontSettings.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFormFontSettings.java 2013-05-30 11:00:42 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFormFontSettings.java 2013-06-26 08:56:44 +0000 @@ -29,86 +29,56 @@ import com.lowagie.text.Font; import java.awt.*; +import java.util.HashMap; +import java.util.Map; + +/** + * @author James Chang + */ public class PdfFormFontSettings { public final static int FONTTYPE_BODY = 0; + public final static int FONTTYPE_TITLE = 1; + public final static int FONTTYPE_DESCRIPTION = 2; + public final static int FONTTYPE_SECTIONHEADER = 3; + public final static int FONTTYPE_FOOTER = 4; private final static float FONTSIZE_BODY = 10; + private final static float FONTSIZE_TITLE = 16; + private final static float FONTSIZE_DESCRIPTION = 11; + private final static float FONTSIZE_SECTIONHEADER = 14; + private final static float FONTSIZE_FOOTER = 8; private final static String FONTFAMILY = "HELVETICA"; - private Font fontBody; - private Font fontTitle; - private Font fontDescription; - private Font fontSectionHeader; - private Font fontFooter; + private Map fontTypeMap = new HashMap(); public PdfFormFontSettings() { - fontBody = createFont( FONTTYPE_BODY ); - fontTitle = createFont( FONTTYPE_TITLE ); - fontDescription = createFont( FONTTYPE_DESCRIPTION ); - fontSectionHeader = createFont( FONTTYPE_SECTIONHEADER ); - fontFooter = createFont( FONTTYPE_FOOTER ); + fontTypeMap.put( FONTTYPE_BODY, createFont( FONTTYPE_BODY ) ); + fontTypeMap.put( FONTTYPE_TITLE, createFont( FONTTYPE_TITLE ) ); + fontTypeMap.put( FONTTYPE_DESCRIPTION, createFont( FONTTYPE_DESCRIPTION ) ); + fontTypeMap.put( FONTTYPE_SECTIONHEADER, createFont( FONTTYPE_SECTIONHEADER ) ); + fontTypeMap.put( FONTTYPE_FOOTER, createFont( FONTTYPE_FOOTER ) ); } - //TODO use map instead of fixed properties - public void setFont( int fontType, Font font ) { - switch ( fontType ) - { - case FONTTYPE_BODY: - fontBody = font; - break; - case FONTTYPE_TITLE: - fontTitle = font; - break; - case FONTTYPE_DESCRIPTION: - fontDescription = font; - break; - case FONTTYPE_SECTIONHEADER: - fontSectionHeader = font; - break; - case FONTTYPE_FOOTER: - fontFooter = font; - break; - } + fontTypeMap.put( fontType, font ); } public Font getFont( int fontType ) { - Font font = null; - - switch ( fontType ) - { - case FONTTYPE_BODY: - font = fontBody; - break; - case FONTTYPE_TITLE: - font = fontTitle; - break; - case FONTTYPE_DESCRIPTION: - font = fontDescription; - break; - case FONTTYPE_SECTIONHEADER: - font = fontSectionHeader; - break; - case FONTTYPE_FOOTER: - font = fontFooter; - break; - } - - return font; + return fontTypeMap.get( fontType ); } private Font createFont( int fontType ) @@ -118,29 +88,29 @@ switch ( fontType ) { - case FONTTYPE_BODY: - font.setSize( FONTSIZE_BODY ); - break; - case FONTTYPE_TITLE: - font.setSize( FONTSIZE_TITLE ); - font.setStyle( java.awt.Font.BOLD ); - font.setColor( new Color( 0, 0, 128 ) ); // Navy Color - break; - case FONTTYPE_DESCRIPTION: - font.setSize( FONTSIZE_DESCRIPTION ); - font.setColor( Color.DARK_GRAY ); - break; - case FONTTYPE_SECTIONHEADER: - font.setSize( FONTSIZE_SECTIONHEADER ); - font.setStyle( java.awt.Font.BOLD ); - font.setColor( new Color( 70, 130, 180 ) ); // Steel Blue Color - break; - case FONTTYPE_FOOTER: - font.setSize( FONTSIZE_FOOTER ); - break; - default: - font.setSize( FONTSIZE_BODY ); - break; + case FONTTYPE_BODY: + font.setSize( FONTSIZE_BODY ); + break; + case FONTTYPE_TITLE: + font.setSize( FONTSIZE_TITLE ); + font.setStyle( java.awt.Font.BOLD ); + font.setColor( new Color( 0, 0, 128 ) ); // Navy Color + break; + case FONTTYPE_DESCRIPTION: + font.setSize( FONTSIZE_DESCRIPTION ); + font.setColor( Color.DARK_GRAY ); + break; + case FONTTYPE_SECTIONHEADER: + font.setSize( FONTSIZE_SECTIONHEADER ); + font.setStyle( java.awt.Font.BOLD ); + font.setColor( new Color( 70, 130, 180 ) ); // Steel Blue Color + break; + case FONTTYPE_FOOTER: + font.setSize( FONTSIZE_FOOTER ); + break; + default: + font.setSize( FONTSIZE_BODY ); + break; } return font; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java 2013-05-31 08:03:08 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java 2013-06-26 08:56:44 +0000 @@ -31,6 +31,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -41,6 +43,8 @@ import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy; import org.hisp.dhis.api.utils.PdfDataEntryFormImportUtil; import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.dxf2.datavalueset.DataValueSetService; import org.hisp.dhis.dxf2.metadata.ImportOptions; import org.hisp.dhis.dxf2.pdfform.PdfDataEntryFormService; @@ -49,6 +53,9 @@ import org.hisp.dhis.i18n.I18nManager; import org.hisp.dhis.i18n.I18nManagerException; import org.hisp.dhis.importexport.ImportStrategy; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.program.ProgramStage; +import org.hisp.dhis.program.ProgramStageService; import org.hisp.dhis.scheduling.TaskCategory; import org.hisp.dhis.scheduling.TaskId; import org.hisp.dhis.system.notification.Notifier; @@ -74,6 +81,8 @@ { private static final Log log = LogFactory.getLog( PDFFormController.class ); + //private static final String DATEFORMAT_DEFAULT = "MMMM dd, yyyy"; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -88,6 +97,12 @@ private DataValueSetService dataValueSetService; @Autowired + private DataSetService dataSetService; + + @Autowired + private ProgramStageService programStageService; + + @Autowired private I18nManager i18nManager; @Autowired @@ -125,10 +140,13 @@ pdfFormFontSettings, i18nManager.getI18nFormat() ); // 3. - Response Header/Content Type Set - - contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE ); - response.setContentLength( baos.size() ); + String fileName = dataSetService.getDataSet( dataSetUid ).getName() + " " + (new SimpleDateFormat( + Period.DEFAULT_DATE_FORMAT )).format( new Date() ) ; + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE, fileName, false ); + response.setContentLength( baos.size() ); + // 4. - Output the data into Stream and close the stream. writeToOutputStream( baos, response ); @@ -202,7 +220,10 @@ // 3. - Response Header/Content Type Set - contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE ); + String fileName = programStageService.getProgramStage( programStageUid ).getName() + " " + + (new SimpleDateFormat(Period.DEFAULT_DATE_FORMAT )).format( new Date() ) ; + + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE, fileName, false ); response.setContentLength( baos.size() ); // 4. - write ByteArrayOutputStream to the ServletOutputStream