dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22856
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11126: PDF Form minor changes on label and input check
------------------------------------------------------------
revno: 11126
committer: James Chang <jamesbchang@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-31 15:03:08 +0700
message:
PDF Form minor changes on label and input check
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/PdfDataEntryFormUtil.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-30 11:00:42 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java 2013-05-31 08:03:08 +0000
@@ -484,14 +484,14 @@
// Create A table to add for each group AT HERE
PdfPTable table = new PdfPTable( 2 ); // Code 1
- addCell_Text( table, "OrganizationID", Element.ALIGN_LEFT );
+ addCell_Text( table, "Organization unit identifier", Element.ALIGN_LEFT );
addCell_WithTextField( table, rectangle, writer, PdfDataEntryFormUtil.LABELCODE_ORGID,
PdfFieldCell.TYPE_TEXT_ORGUNIT );
String[] periodsTitle = getPeriodTitles( periods, format );
String[] periodsValue = getPeriodValues( periods );
- addCell_Text( table, "PeriodID", Element.ALIGN_LEFT );
+ addCell_Text( table, "Period", Element.ALIGN_LEFT );
addCell_WithDropDownListField( table, PdfDataEntryFormUtil.LABELCODE_PERIODID, periodsTitle, periodsValue,
rectangle, writer );
=== 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-30 11:20:45 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java 2013-05-31 08:03:08 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -98,6 +97,12 @@
private static final String DATEFORMAT_FOOTER_DEFAULT = "MMMM dd, yyyy";
+ private static final String ERROR_INVALID_PERIOD = "Invalid period: ";
+
+ private static final String ERROR_EMPTY_ORG_UNIT = "The organisation unit was not specified";
+
+ private static final String ERROR_EMPTY_PERIOD = "The period was not specified.";
+
// -------------------------------------------------------------------------
// METHODS
// -------------------------------------------------------------------------
@@ -186,10 +191,28 @@
if ( form != null )
{
- String strOrgUID = form.getField( PdfDataEntryFormUtil.LABELCODE_ORGID );
- String strPeriodID = form.getField( PdfDataEntryFormUtil.LABELCODE_PERIODID );
-
- Period period = PeriodType.createPeriodExternalId( strPeriodID );
+
+ // Process OrgUnitUID and PeriodID from the PDF Form
+
+ String orgUnitUID = form.getField( PdfDataEntryFormUtil.LABELCODE_ORGID ).trim();
+ String periodID = form.getField( PdfDataEntryFormUtil.LABELCODE_PERIODID ).trim();
+
+ if ( periodID == "" )
+ {
+ throw new IllegalArgumentException( ERROR_EMPTY_PERIOD );
+ }
+
+ if ( orgUnitUID == "" )
+ {
+ throw new IllegalArgumentException( ERROR_EMPTY_ORG_UNIT );
+ }
+
+ Period period = PeriodType.createPeriodExternalId( periodID );
+
+ if ( period == null )
+ {
+ throw new IllegalArgumentException( ERROR_INVALID_PERIOD + periodID );
+ }
// Loop Through the Fields and get data.
@@ -205,7 +228,7 @@
dataValue.setDataElement( strArrFldName[1] );
dataValue.setCategoryOptionCombo( strArrFldName[2] );
- dataValue.setOrgUnit( strOrgUID );
+ dataValue.setOrgUnit( orgUnitUID );
dataValue.setPeriod( period.getIsoDate() );
dataValue.setValue( form.getField( fldName ) );
@@ -227,7 +250,7 @@
throw new RuntimeException( "Could not generate PDF AcroFields form from input" );
}
}
- catch ( IOException ex )
+ catch ( Exception ex )
{
throw new RuntimeException( ex );
}
=== 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 11:38:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/PDFFormController.java 2013-05-31 08:03:08 +0000
@@ -35,6 +35,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.api.utils.PdfDataEntryFormImportUtil;
@@ -70,6 +72,8 @@
@RequestMapping(value = "/pdfForm")
public class PDFFormController
{
+ private static final Log log = LogFactory.getLog( PDFFormController.class );
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -103,7 +107,7 @@
{
// 1. - Create Document and PdfWriter
- Document document = new Document(); // TODO: can specify the size of doc
+ Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance( document, baos );
@@ -118,7 +122,7 @@
pdfDataEntryFormService.generatePDFDataEntryForm( document, writer, dataSetUid,
PdfDataEntryFormUtil.DATATYPE_DATASET,
PdfDataEntryFormUtil.getDefaultPageSize( PdfDataEntryFormUtil.DATATYPE_DATASET ),
- new PdfFormFontSettings(), i18nManager.getI18nFormat() );
+ pdfFormFontSettings, i18nManager.getI18nFormat() );
// 3. - Response Header/Content Type Set
@@ -145,6 +149,8 @@
ImportOptions options = new ImportOptions( dataElementIdScheme, orgUnitIdScheme, dryRun, strategy,
skipExistingCheck );
+
+ log.info( options );
// 2. Generate Task ID
@@ -192,7 +198,7 @@
pdfDataEntryFormService.generatePDFDataEntryForm( document, writer, programStageUid,
PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE,
PdfDataEntryFormUtil.getDefaultPageSize( PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE ),
- new PdfFormFontSettings(), i18nManager.getI18nFormat() );
+ pdfFormFontSettings, i18nManager.getI18nFormat() );
// 3. - Response Header/Content Type Set