dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22700
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10997: PDF import, added some nullpointer checks, removed some comments, fixed codestyle
------------------------------------------------------------
revno: 10997
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-05-25 13:38:41 +0200
message:
PDF import, added some nullpointer checks, removed some comments, fixed codestyle
modified:
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/PdfDataEntryFormService.java
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/PdfFieldCell.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFormFontSettings.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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-05-25 06:27:02 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java 2013-05-25 11:38:41 +0000
@@ -74,12 +74,10 @@
public class DefaultPdfDataEntryFormService
implements PdfDataEntryFormService
{
-
private static final Color COLOR_BACKGROUDTEXTBOX = Color.LIGHT_GRAY;
private static final String TEXT_BLANK = " ";
- // --- All the Settings Related
private static final int TEXTBOXWIDTH_NUMBERTYPE = 20;
private static final int TEXTBOXWIDTH = 200;
@@ -92,8 +90,6 @@
private static Integer PROGRAM_FORM_ROW_NUMBER = 10;
- // Variables
-
private PdfFormFontSettings pdfFormFontSettings;
private I18nFormat format;
@@ -121,18 +117,13 @@
{
try
{
-
- // STEP 1. Assign the parameters to the global variable
this.pdfFormFontSettings = pdfFormFontSettings;
this.format = format;
-
- // STEP 2. Set Page Size
+
document.setPageSize( pageSize );
- // STEP 3. PDF Document Open
document.open();
- // STEP 3. Generate the PDF Form
if ( typeId == PdfDataEntryFormUtil.DATATYPE_DATASET )
{
setDataSet_DocumentContent( document, writer, inputUid );
@@ -142,7 +133,6 @@
setProgramStage_DocumentContent( document, writer, inputUid );
}
- // STEP 4. Close the PDF Document
document.close();
}
@@ -150,16 +140,11 @@
{
ex.printStackTrace();
}
-
}
- // -----------------------------------------------------------------------------
- // --- Retrieve Document Content - DataSet [START]
-
private void setDataSet_DocumentContent( Document document, PdfWriter writer, String dataSetUid )
throws IOException, DocumentException, ParseException, Exception
{
-
DataSet dataSet = dataSetService.getDataSet( dataSetUid );
if ( dataSet == null )
@@ -168,33 +153,24 @@
}
else
{
- // Step 1. Set DataSet Name/Description
setDataSet_DocumentTopSection( document, dataSet );
- // Add a line space
document.add( Chunk.NEWLINE );
- // Step 2. Generate period listings
List<Period> periods = getPeriods_DataSet( dataSet.getPeriodType() );
- // Step 3. 'Main Table' Create and Set
- // The 'Main Table' is used to hold the layout of the page content.
PdfPTable mainTable = new PdfPTable( 1 ); // Table with 1 cell.
setMainTable( mainTable );
- // Step 4. Add Organisation & Period input textfield
insertTable_OrgAndPeriod( mainTable, writer, periods );
- // Step 5. Insert DataSet Info - [The MAIN Section]
insertTable_DataSet( mainTable, writer, dataSet );
- // Step 6. Add the mainTable with content in it to the document.
document.add( mainTable );
document.add( Chunk.NEWLINE );
document.add( Chunk.NEWLINE );
- // Step. 7 - Add 'Save As' Button
insertSaveAsButton( document, writer, PdfDataEntryFormUtil.LABELCODE_BUTTON_SAVEAS );
}
}
@@ -219,8 +195,7 @@
private void setMainTable( PdfPTable mainTable )
{
- mainTable.setWidthPercentage( 90.0f ); // Use 90% of space for Main
- // Table Width.
+ mainTable.setWidthPercentage( 90.0f );
mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );
}
@@ -231,27 +206,22 @@
if ( dataSet.getSections().size() > 0 )
{
- // Sectioned Ones
for ( Section section : dataSet.getSections() )
{
insertTable_DataSetSections( mainTable, writer, rectangle, section.getDataElements(),
section.getDisplayName() );
}
-
}
else
{
- // Default one
insertTable_DataSetSections( mainTable, writer, rectangle, dataSet.getDataElements(), "" );
}
-
}
private void insertTable_DataSetSections( PdfPTable mainTable, PdfWriter writer, Rectangle rectangle,
Collection<DataElement> dataElements, String sectionName )
throws IOException, DocumentException
{
-
// Add Section Name and Section Spacing
insertTable_TextRow( writer, mainTable, rectangle, TEXT_BLANK );
@@ -262,7 +232,7 @@
}
// Create A Table To Add For Each Section
- PdfPTable table = new PdfPTable( 2 ); // Code 1
+ PdfPTable table = new PdfPTable( 2 );
for ( DataElement dataElement : dataElements )
{
@@ -274,7 +244,7 @@
String dataElementTextType = dataElement.getType();
- // Yes Only case - render as Checkbox
+ // Yes Only case - render as check-box
if ( dataElementTextType.equals( DataElement.VALUE_TYPE_TRUE_ONLY ) )
{
addCell_WithCheckBox( table, writer, strFieldLabel );
@@ -294,36 +264,23 @@
addCell_WithTextField( table, rectangle, writer, strFieldLabel, PdfFieldCell.TYPE_TEXT_NUMBER );
}
- // if(dataElementTextType.equals(DataElement.VALUE_TYPE_DATE))
- else
+ else //DataElement.VALUE_TYPE_DATE
{
- // NOTE: When Rendering for DataSet, DataElement's OptionSet
- // does not get rendered.
- // Only for events, it gets rendered as dropdown list.
+ // NOTE: When Rendering for DataSet, DataElement's OptionSet does not get rendered.
+ // Only for events, it gets rendered as drop-down list.
addCell_WithTextField( table, rectangle, writer, strFieldLabel );
-
}
-
}
PdfPCell cell_withInnerTable = new PdfPCell( table );
cell_withInnerTable.setBorder( Rectangle.NO_BORDER );
mainTable.addCell( cell_withInnerTable );
-
}
- // --- Retrieve Document Content - DataSet [END]
- // -----------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------
- // --- Retrieve Document Content - ProgramStage [START]
-
private void setProgramStage_DocumentContent( Document document, PdfWriter writer, String programStageUid )
throws IOException, DocumentException, ParseException, Exception
{
-
- // Get ProgramStage
ProgramStage programStage = programStageService.getProgramStage( programStageUid );
if ( programStage == null )
@@ -332,18 +289,16 @@
}
else
{
-
- // STEP 1. Get Rectangle with TextBox Width to be used
+ // 1. Get Rectangle with TextBox Width to be used
Rectangle rectangle = new Rectangle( 0, 0, TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );
- // STEP 2. Create Main Layout table and set the properties
+ // 2. Create Main Layout table and set the properties
PdfPTable mainTable = getProgramStageMainTable();
- // STEP 3. Generate Period List for ProgramStage
+ // 3. Generate Period List for ProgramStage
List<Period> periods = getProgramStagePeriodList();
- // STEP 4. Add Org Unit, Period, Hidden ProgramStageID Field
- // Add Organisation & Period input textfield
+ // 4. Add Org Unit, Period, Hidden ProgramStageID Field
insertTable_OrgAndPeriod( mainTable, writer, periods );
insertTable_TextRow( writer, mainTable, rectangle, TEXT_BLANK );
@@ -352,14 +307,12 @@
insertTable_HiddenValue( mainTable, rectangle, writer,
PdfDataEntryFormUtil.LABELCODE_PROGRAMSTAGEIDTEXTBOX, String.valueOf( programStage.getId() ) );
- // STEP 5. Add ProgramStage Content to PDF - [The Main Section]
+ // 5. Add ProgramStage Content to PDF - [The Main Section]
insertTable_ProgramStage( mainTable, writer, programStage );
- // STEP 6. Add the mainTable to document
+ // 6. Add the mainTable to document
document.add( mainTable );
-
}
-
}
private void insertTable_ProgramStage( PdfPTable mainTable, PdfWriter writer, ProgramStage programStage )
@@ -375,23 +328,19 @@
{
insertTable_ProgramStageSections( mainTable, rectangle, writer, section.getProgramStageDataElements() );
}
-
}
else
{
// Default one
insertTable_ProgramStageSections( mainTable, rectangle, writer, programStage.getProgramStageDataElements() );
}
-
}
private void insertTable_ProgramStageSections( PdfPTable mainTable, Rectangle rectangle, PdfWriter writer,
Collection<ProgramStageDataElement> programStageDataElements )
throws IOException, DocumentException
{
-
- // Add one to column count due to date entry + one hidden height set
- // field.
+ // Add one to column count due to date entry + one hidden height set field.
int colCount = programStageDataElements.size() + 1 + 1;
PdfPTable table = new PdfPTable( colCount ); // Code 1
@@ -399,13 +348,11 @@
float totalWidth = 800f;
float firstCellWidth_dateEntry = PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 3;
float lastCellWidth_hidden = PdfDataEntryFormUtil.UNITSIZE_DEFAULT;
- // float dataElementCell_offset = 4f;
float dataElementCellWidth = (totalWidth - firstCellWidth_dateEntry - lastCellWidth_hidden)
/ programStageDataElements.size();
// Create 2 types of Rectangles, one for Date field, one for data
- // elements
- // - to be used when rendering them.
+ // elements - to be used when rendering them.
Rectangle rectangleDate = new Rectangle( 0, 0, PdfDataEntryFormUtil.UNITSIZE_DEFAULT * 2,
PdfDataEntryFormUtil.UNITSIZE_DEFAULT );
Rectangle rectangleDataElement = new Rectangle( 0, 0, dataElementCellWidth,
@@ -444,7 +391,6 @@
for ( int rowNo = 1; rowNo <= PROGRAM_FORM_ROW_NUMBER; rowNo++ )
{
-
// Add Date Column
String strFieldDateLabel = PdfDataEntryFormUtil.LABELCODE_DATADATETEXTFIELD + Integer.toString( rowNo );
@@ -472,13 +418,12 @@
String query = ""; // Get All Option
- // TODO: This gets repeated <-- Create an array of the
+ // TODO: This gets repeated <- Create an array of the
// options. and apply only once.
List<String> options = optionService.getOptions( optionSet.getId(), query, MAX_OPTIONS_DISPLAYED );
addCell_WithDropDownListField( table, strFieldLabel, options.toArray( new String[0] ),
options.toArray( new String[0] ), rectangleDataElement, writer );
- // (int)(rectangleDataElement.getWidth())
}
else
{
@@ -490,7 +435,6 @@
}
addCell_Text( table, TEXT_BLANK, Element.ALIGN_LEFT );
-
}
PdfPCell cell_withInnerTable = new PdfPCell( table );
@@ -521,12 +465,6 @@
return mainTable;
}
- // --- Retrieve Document Content - ProgramStage [END]
- // -----------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------
- // ------------ Insert Section/Item Related Methods [START] ------------
-
private void insertTable_OrgAndPeriod( PdfPTable mainTable, PdfWriter writer, List<Period> periods )
throws IOException, DocumentException
{
@@ -562,7 +500,6 @@
String value )
throws IOException, DocumentException
{
-
// Add Organization ID/Period textfield
// Create A table to add for each group AT HERE
PdfPTable table = new PdfPTable( 1 ); // Code 1
@@ -577,16 +514,13 @@
}
private void insertTable_TextRow( PdfWriter writer, PdfPTable mainTable, Rectangle rectangle, String text )
- throws IOException, DocumentException
{
insertTable_TextRow( writer, mainTable, rectangle, text,
pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ) );
}
private void insertTable_TextRow( PdfWriter writer, PdfPTable mainTable, Rectangle rectangle, String text, Font font )
- throws IOException, DocumentException
{
-
// Add Organization ID/Period textfield
// Create A table to add for each group AT HERE
PdfPTable table = new PdfPTable( 1 );
@@ -610,7 +544,7 @@
tableButton.setWidthPercentage( 20.0f );
float buttonHeight = PdfDataEntryFormUtil.UNITSIZE_DEFAULT + 5;
- tableButton.setHorizontalAlignment( PdfPTable.ALIGN_CENTER );
+ tableButton.setHorizontalAlignment( Element.ALIGN_CENTER );
String jsAction = "app.execMenuItem('SaveAs');";
@@ -619,12 +553,6 @@
document.add( tableButton );
}
- // ------------ Insert Section/Item Related Methods [END] ------------
- // -----------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------
- // ------------ Add Control To Cell Related Methods [START] ------------
-
private void addCell_Text( PdfPTable table, String text, int horizontalAlignment )
{
addCell_Text( table, text, horizontalAlignment, pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ) );
@@ -667,7 +595,6 @@
throws IOException, DocumentException
{
TextField nameField = new TextField( writer, rect, strfldName );
- // table.getc
nameField.setBorderWidth( 1 );
nameField.setBorderColor( Color.BLACK );
@@ -688,9 +615,7 @@
private void addCell_WithDropDownListField( PdfPTable table, String strfldName, String[] optionList,
String[] valueList, Rectangle rect, PdfWriter writer )
- throws IOException, DocumentException
{
-
// If there is option, then create name-value set in 2 dimension array
// and set it as dropdown option name-value list.
String[][] optionValueList = new String[optionList.length][2];
@@ -709,8 +634,6 @@
dropDown.setMKBorderColor( CMYKColor.BLACK );
- // Combine
-
PdfPCell cell = PdfDataEntryFormUtil.getPdfPCell( PdfDataEntryFormUtil.CELL_MIN_HEIGHT_DEFAULT,
PdfDataEntryFormUtil.CELL_COLUMN_TYPE_ENTRYFIELD );
cell.setCellEvent( new PdfFieldCell( dropDown, (int) (rect.getWidth()), writer ) );
@@ -760,9 +683,7 @@
}
private void addCell_WithRadioButton( PdfPTable table, PdfWriter writer, String strfldName )
- throws IOException, DocumentException
{
-
// Add to the main table
PdfPCell cell = PdfDataEntryFormUtil.getPdfPCell( PdfDataEntryFormUtil.CELL_MIN_HEIGHT_DEFAULT,
PdfDataEntryFormUtil.CELL_COLUMN_TYPE_ENTRYFIELD );
@@ -778,7 +699,6 @@
// Last - Add Annotation
writer.addAnnotation( radiogroupField );
-
}
private void addCell_WithPushButtonField( PdfPTable table, String strfldName, float buttonHeight, String jsAction,
@@ -792,12 +712,6 @@
table.addCell( cell );
}
- // ------------ Add Control To Cell Related Methods [END] ------------
- // -----------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------
- // ------------ Period Related Methods [START] ------------
-
public String[] getPeriodValues( List<Period> periods )
{
String[] periodValues = new String[periods.size()];
@@ -825,7 +739,6 @@
private Period setPeriodDateRange()
throws ParseException
{
-
Period period = new Period();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( Period.DEFAULT_DATE_FORMAT );
@@ -841,7 +754,4 @@
return period;
}
-
- // ------------ Period Related Methods [END] ------------
- // -----------------------------------------------------------------------------
}
=== 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 06:19:23 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormService.java 2013-05-25 11:38:41 +0000
@@ -36,5 +36,4 @@
{
void generatePDFDataEntryForm( Document document, PdfWriter writer, String inputUid, int typeId,
Rectangle pageSize, PdfFormFontSettings pdfFormFontSettings, I18nFormat format );
-
}
=== 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-25 06:19:23 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java 2013-05-25 11:38:41 +0000
@@ -54,51 +54,33 @@
public class PdfDataEntryFormUtil
{
-
- // public Static Values
public static final int DATATYPE_DATASET = 0;
public static final int DATATYPE_PROGRAMSTAGE = 1;
public static final float UNITSIZE_DEFAULT = 10;
// Label Names
+
public static final String LABELCODE_TEXTFIELD = "TXFD_";
-
public static final String LABELCODE_BUTTON = "BTNFD_";
-
public static final String LABELCODE_ORGID = LABELCODE_TEXTFIELD + "OrgID";
-
public static final String LABELCODE_PERIODID = LABELCODE_TEXTFIELD + "PeriodID";
-
public static final String LABELCODE_BUTTON_SAVEAS = LABELCODE_BUTTON + "SaveAs";
-
public static final String LABELCODE_DATADATETEXTFIELD = "TXFDDT_";
-
public static final String LABELCODE_DATAENTRYTEXTFIELD = "TXFDDV_";
-
public static final String LABELCODE_PROGRAMSTAGEIDTEXTBOX = "TXPSTGID_";
-
// Cell Related
public final static float CELL_MIN_HEIGHT_DEFAULT = 13;
-
public final static float CONTENT_HEIGHT_DEFAULT = 11;
-
public final static int CELL_COLUMN_TYPE_LABEL = 0;
-
public final static int CELL_COLUMN_TYPE_ENTRYFIELD = 1;
-
- // private static values
private static final String DATAVALUE_IMPORT_STOREBY = "admin";
-
private static final String DATAVALUE_IMPORT_COMMENT = "Imported by PDF Data Entry Form";
-
private static final String DATAVALUE_IMPORT_TIMESTAMP_DATEFORMAT = "yyyy-MM-dd";
-
private static final String FOOTERTEXT_DEFAULT = "PDF Template generated from DHIS %s on %s";
-
private static final String DATEFORMAT_FOOTER_DEFAULT = "MMMM dd, yyyy";
@@ -106,9 +88,6 @@
// METHODS
// -------------------------------------------------------------------------
- // -------------------------------------------------------------------------
- // --- Document Setting Related [START]
-
public static void setFooterOnDocument( Document document, String footerText, Font font )
{
boolean isNumbered = true;
@@ -117,23 +96,18 @@
footer.setBorder( Rectangle.NO_BORDER );
footer.setAlignment( Element.ALIGN_RIGHT );
document.setFooter( footer );
-
}
- // Set DefaultFooter
public static void setDefaultFooterOnDocument( Document document, String serverName, Font font )
{
- // Set Footer
String strFooterText = String.format( FOOTERTEXT_DEFAULT, serverName, (new SimpleDateFormat(
DATEFORMAT_FOOTER_DEFAULT )).format( new Date() ) );
setFooterOnDocument( document, strFooterText, font );
-
}
public static Rectangle getDefaultPageSize( int typeId )
{
-
if ( typeId == PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
{
return new Rectangle( PageSize.A4.getLeft(),
@@ -143,15 +117,8 @@
{
return PageSize.A4;
}
-
}
- // --- Document Setting Related [END]
- // -------------------------------------------------------------------------
-
- // -------------------------------------------------------------------------
- // --- PdfPCell Related [START]
-
public static PdfPCell getPdfPCell( float minHeight )
{
return getPdfPCell( minHeight, CELL_COLUMN_TYPE_LABEL );
@@ -177,12 +144,6 @@
return cell;
}
-
- // --- PdfPCell Related [END]
- // -------------------------------------------------------------------------
-
-
- // Retreive DataValue Informations from PDF inputStream.
public static DataValueSet getDataValueSet( InputStream in )
throws RuntimeException
{
@@ -194,14 +155,12 @@
try
{
-
reader = new PdfReader( in ); // new PdfReader(in, null);
AcroFields form = reader.getAcroFields();
if ( form != null )
{
-
// TODO: MOVE THESE STATIC NAME VALUES TO inside of service
// class or PDFForm Class <-- should be in PDFForm Class.
String strOrgUID = form.getField( PdfDataEntryFormUtil.LABELCODE_ORGID );
@@ -240,12 +199,10 @@
.format( new Date() ) );
dataValueList.add( dataValue );
-
}
}
dataValueSet.setDataValues( dataValueList );
-
}
else
{
@@ -259,19 +216,12 @@
}
finally
{
- reader.close();
+ if ( reader != null )
+ {
+ reader.close();
+ }
}
return dataValueSet;
}
-
-
- // -----------------------------------------------------------------------------
- // --- For Import - ProgramStage [START]
-
-
- // --- For Import - ProgramStage [END]
- // -----------------------------------------------------------------------------
-
-
}
=== 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-25 06:19:23 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java 2013-05-25 11:38:41 +0000
@@ -48,21 +48,13 @@
public class PdfFieldCell
implements PdfPCellEvent
{
-
public final static int TYPE_DEFAULT = 0;
-
public final static int TYPE_BUTTON = 1;
-
public final static int TYPE_TEXT_ORGUNIT = 2;
-
public final static int TYPE_TEXT_NUMBER = 3;
-
public final static int TYPE_CHECKBOX = 4;
-
public final static int TYPE_RADIOBUTTON = 5;
-
private final static float RADIOBUTTON_WIDTH = 10.0f;
-
private final static float RADIOBUTTON_TEXTOFFSET = 3.0f;
private PdfFormField parent;
@@ -143,18 +135,15 @@
switch ( type )
{
-
case TYPE_RADIOBUTTON:
if ( parent != null )
{
-
float leftLoc = rect.getLeft();
float rightLoc = rect.getLeft() + RADIOBUTTON_WIDTH;
try
{
-
String text;
String value;
@@ -185,9 +174,7 @@
leftLoc = rightLoc;
rightLoc += RADIOBUTTON_WIDTH;
-
}
-
}
catch ( Exception ex )
{
@@ -195,7 +182,6 @@
}
writer.addAnnotation( parent );
-
}
break;
=== 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-25 06:19:23 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFormFontSettings.java 2013-05-25 11:38:41 +0000
@@ -32,40 +32,24 @@
public class PdfFormFontSettings
{
- // Font Types
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;
- // Font Default Sizes
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;
- // Font Family Default
private final static String FONTFAMILY = "HELVETICA";
- // private variables
private Font fontBody;
-
private Font fontTitle;
-
private Font fontDescription;
-
private Font fontSectionHeader;
-
private Font fontFooter;
public PdfFormFontSettings()
@@ -79,7 +63,6 @@
public void setFont( int fontType, Font font )
{
-
switch ( fontType )
{
case FONTTYPE_BODY:
@@ -98,7 +81,6 @@
fontFooter = font;
break;
}
-
}
public Font getFont( int fontType )
=== 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-25 06:38:01 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java 2013-05-25 11:38:41 +0000
@@ -27,9 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.lowagie.text.Document;
-import com.lowagie.text.DocumentException;
-import com.lowagie.text.pdf.PdfWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.api.utils.PdfDataEntryFormImportUtil;
@@ -54,13 +59,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.ParseException;
+import com.lowagie.text.Document;
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.pdf.PdfWriter;
/**
* @author James Chang <jamesbchang@xxxxxxxxx>
@@ -100,14 +101,15 @@
@PathVariable String dataSetUid )
throws Exception
{
- // STEP 1. - Create Document and PdfWriter - with OutputStream and
- // document tie.
- Document document = new Document(); // TODO: can specify the size of
- // document - like letter or A4
+ // 1. - Create Document and PdfWriter
+
+ Document document = new Document(); // TODO: can specify the size of doc
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance( document, baos );
- // STEP 2. Generate PDF Document Contents
+ // 2. Generate PDF Document Content
+
PdfFormFontSettings pdfFormFontSettings = new PdfFormFontSettings();
PdfDataEntryFormUtil.setDefaultFooterOnDocument( document, request.getServerName(),
@@ -118,12 +120,13 @@
PdfDataEntryFormUtil.getDefaultPageSize( PdfDataEntryFormUtil.DATATYPE_DATASET ),
new PdfFormFontSettings(), i18nManager.getI18nFormat() );
- // STEP 3. - Response Header/Content Type Set
+ // 3. - Response Header/Content Type Set
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE );
response.setContentLength( baos.size() );
- // STEP 4. - Output the data into Stream and close the stream.
- // write ByteArrayOutputStream to the ServletOutputStream
+ // 4. - Output the data into Stream and close the stream.
+
writeToOutputStream( baos, response );
}
@@ -132,36 +135,36 @@
public void sendFormPDF_DataSet( HttpServletRequest request, HttpServletResponse response )
throws Exception
{
- // Step 1. Set up Import Option
+ // 1. Set up Import Option
+
ImportStrategy strategy = ImportStrategy.NEW_AND_UPDATES;
IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
boolean dryRun = false;
- boolean skipExistingCheck = false; // THIS IS THE DEFAULT CHOICE. DO WE
- // USE THIS?
-
+ boolean skipExistingCheck = false;
+
ImportOptions options = new ImportOptions( dataElementIdScheme, orgUnitIdScheme, dryRun, strategy,
skipExistingCheck );
- // Step 2. Generate Task ID
+ // 2. Generate Task ID
+
TaskId taskId = new TaskId( TaskCategory.DATAVALUE_IMPORT, currentUserService.getCurrentUser() );
notifier.clear( taskId );
- // Step 3. Input Stream Check
+ // 3. Input Stream Check
+
InputStream in = request.getInputStream();
in = StreamUtils.wrapAndCheckCompressionFormat( in );
- // No logging?
- // log.info( options );
-
- // Step 4. Save (Import) the data values.
+ // 4. Save (Import) the data values.
+
dataValueSetService.saveDataValueSetPdf( in, options, taskId );
// Step 5. Set the response - just simple OK response.
+
ContextUtils.okResponse( response, "" );
-
}
//--------------------------------------------------------------------------
@@ -171,15 +174,16 @@
@RequestMapping(value = "/programStage/{programStageUid}", method = RequestMethod.GET)
public void getFormPDF_ProgramStage( HttpServletRequest request, HttpServletResponse response,
@PathVariable String programStageUid )
- throws IOException, DocumentException, ParseException, I18nManagerException
+ throws IOException, DocumentException, I18nManagerException
{
- // STEP 1. - Create Document and PdfWriter - with OutputStream and
- // document tie.
+ // 1. - Create Document and PdfWriter
+
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance( document, baos );
- // STEP 2. Generate PDF Document Contents
+ // 2. Generate PDF Document Contents
+
PdfFormFontSettings pdfFormFontSettings = new PdfFormFontSettings();
PdfDataEntryFormUtil.setDefaultFooterOnDocument( document, request.getServerName(),
@@ -187,17 +191,16 @@
pdfDataEntryFormService.generatePDFDataEntryForm( document, writer, programStageUid,
PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE,
- PdfDataEntryFormUtil.getDefaultPageSize( PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
- // , new Rectangle( PageSize.A4.getLeft(),
- // PageSize.A4.getBottom(), PageSize.A4.getTop(),
- // PageSize.A4.getRight() )
- , new PdfFormFontSettings(), i18nManager.getI18nFormat() );
+ PdfDataEntryFormUtil.getDefaultPageSize( PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE ),
+ new PdfFormFontSettings(), i18nManager.getI18nFormat() );
- // STEP 3. - Response Header/Content Type Set
+ // 3. - Response Header/Content Type Set
+
contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, CacheStrategy.NO_CACHE );
response.setContentLength( baos.size() );
- // STEP 4. - write ByteArrayOutputStream to the ServletOutputStream
+ // 4. - write ByteArrayOutputStream to the ServletOutputStream
+
writeToOutputStream( baos, response );
}
@@ -209,11 +212,13 @@
InputStream in = request.getInputStream();
// Temporarily using Util class from same project.
+
PdfDataEntryFormImportUtil pdfDataEntryFormImportUtil = new PdfDataEntryFormImportUtil();
pdfDataEntryFormImportUtil.ImportProgramStage( in, i18nManager.getI18nFormat() );
// Step 5. Set the response - just simple OK response.
+
ContextUtils.okResponse( response, "" );
}
@@ -233,8 +238,11 @@
}
finally
{
- os.flush();
- os.close();
+ if ( os != null )
+ {
+ os.flush();
+ os.close();
+ }
}
}
}