dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12379
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3795: Pushed custom data set report function to service layer
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 3795 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-05-30 21:32:45 +0200
message:
Pushed custom data set report function to service layer
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateCustomDataSetReportAction.java
dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml
--
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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2011-05-30 15:17:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java 2011-05-30 19:17:04 +0000
@@ -48,6 +48,10 @@
public class DataSet
extends AbstractNameableObject
{
+ public static final String TYPE_DEFAULT = "default";
+ public static final String TYPE_SECTION = "section";
+ public static final String TYPE_CUSTOM = "custom";
+
/**
* Determines if a de-serialized file is compatible with this class.
*/
@@ -219,6 +223,21 @@
return mobile != null && mobile;
}
+ public String getDataSetType()
+ {
+ if ( hasDataEntryForm() )
+ {
+ return TYPE_CUSTOM;
+ }
+
+ if ( hasSections() )
+ {
+ return TYPE_SECTION;
+ }
+
+ return TYPE_DEFAULT;
+ }
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java 2011-04-22 17:02:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java 2011-05-30 19:32:17 +0000
@@ -228,6 +228,4 @@
int getDataSetCount();
Collection<DataSet> getDataSetsBetween(int first, int max );
-
-
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-05-10 10:59:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-05-30 19:32:17 +0000
@@ -31,6 +31,7 @@
import java.util.Map;
import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
@@ -71,12 +72,24 @@
* Puts in aggregated datavalues in the custom dataentry form and returns
* whole report text.
*
- * @param dataEntryFormCode the data entry form HTML code.
+ * @param dataEntryForm the data entry form.
* @param a map with aggregated data values mapped to data element operands.
* @return data entry form HTML code populated with aggregated data in the
* input fields.
*/
- String prepareReportContent( String dataEntryFormCode, Map<String, String> dataValues, Map<Integer, String> indicatorValues );
+ String prepareReportContent( DataEntryForm dataEntryForm, Map<String, String> dataValues, Map<Integer, String> indicatorValues );
+
+ /**
+ * Generates html code for a custom data set report.
+ *
+ * @param dataSet the data set.
+ * @param unit the organisation unit.
+ * @param period the period.
+ * @param selectedUnitOnly indicates whether to use captured or aggregated data.
+ * @param format the i18n format.
+ * @return
+ */
+ String getCustomDataSetReport( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format );
/**
* Generates a Grid representing a data set report with all data elements
@@ -85,7 +98,7 @@
* @param dataSet the data set.
* @param unit the organisation unit.
* @param period the period.
- * @param selectedUnitOnly indicators whether to use captured or aggregated data.
+ * @param selectedUnitOnly indicates whether to use captured or aggregated data.
* @param format the i18n format.
* @param i18n the i18n object.
* @return a Grid.
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-05-29 20:11:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-05-30 19:32:17 +0000
@@ -55,6 +55,7 @@
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator;
import org.hisp.dhis.dataelement.comparator.DataElementNameComparator;
+import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.Section;
import org.hisp.dhis.dataset.comparator.SectionOrderComparator;
@@ -189,11 +190,11 @@
return map;
}
- public String prepareReportContent( String dataEntryFormCode, Map<String, String> dataValues, Map<Integer, String> indicatorValues )
+ public String prepareReportContent( DataEntryForm dataEntryForm, Map<String, String> dataValues, Map<Integer, String> indicatorValues )
{
StringBuffer buffer = new StringBuffer();
- Matcher inputMatcher = INPUT_PATTERN.matcher( dataEntryFormCode );
+ Matcher inputMatcher = INPUT_PATTERN.matcher( dataEntryForm.getHtmlCode() );
// ---------------------------------------------------------------------
// Iterate through all matching data element fields.
@@ -242,6 +243,15 @@
return buffer.toString();
}
+ public String getCustomDataSetReport( DataSet dataSet, OrganisationUnit unit, Period period, boolean selectedUnitOnly, I18nFormat format )
+ {
+ Map<String, String> aggregatedDataValueMap = getAggregatedValueMap( dataSet, unit, period, selectedUnitOnly, format );
+
+ Map<Integer, String> aggregatedIndicatorMap = getAggregatedIndicatorValueMap( dataSet, unit, period, format );
+
+ return prepareReportContent( dataSet.getDataEntryForm(), aggregatedDataValueMap, aggregatedIndicatorMap );
+ }
+
public List<Grid> getSectionDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n )
{
String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, DEFAULT_AGGREGATION_STRATEGY );
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-04-12 13:07:35 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-05-30 19:10:22 +0000
@@ -80,7 +80,7 @@
{
private static final String EMPTY = "";
- private static final String XLS_DEFAULT_SHEET_NAME = "Sheet 1";
+ private static final String XLS_SHEET_PREFIX = "Sheet ";
private static final WritableCellFormat XLS_FORMAT_TTTLE = new WritableCellFormat( new WritableFont(
WritableFont.TAHOMA, 13, WritableFont.NO_BOLD, false ) );
@@ -101,7 +101,29 @@
public static void toPdf( Grid grid, OutputStream out )
{
Document document = openDocument( out );
-
+
+ toPdfInternal( grid, document );
+
+ closeDocument( document );
+ }
+
+ /**
+ * Writes a PDF representation of the given list of Grids to the given OutputStream.
+ */
+ public static void toPdf( List<Grid> grids, OutputStream out )
+ {
+ Document document = openDocument( out );
+
+ for ( Grid grid : grids )
+ {
+ toPdfInternal( grid, document );
+ }
+
+ closeDocument( document );
+ }
+
+ private static void toPdfInternal( Grid grid, Document document )
+ {
PdfPTable table = new PdfPTable( grid.getVisibleWidth() );
table.setHeaderRows( 1 );
@@ -128,10 +150,29 @@
}
addTableToDocument( document, table );
-
- closeDocument( document );
- }
-
+ }
+
+ /**
+ * Writes a XLS (Excel workbook) representation of the given list of Grids to the given OutputStream.
+ */
+ public static void toXls( List<Grid> grids, OutputStream out )
+ throws Exception
+ {
+ WritableWorkbook workbook = Workbook.createWorkbook( out );
+
+ for ( int i = 0; i < grids.size(); i++ )
+ {
+ Grid grid = grids.get( i );
+
+ String sheetName = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), XLS_SHEET_PREFIX + ( i + 1 ) ) );
+
+ toXlsInternal( grid, workbook, sheetName, i );
+ }
+
+ workbook.write();
+ workbook.close();
+ }
+
/**
* Writes a XLS (Excel workbook) representation of the given Grid to the given OutputStream.
*/
@@ -139,10 +180,19 @@
throws Exception
{
WritableWorkbook workbook = Workbook.createWorkbook( out );
-
- String sheetName = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), XLS_DEFAULT_SHEET_NAME ) );
- WritableSheet sheet = workbook.createSheet( sheetName, 0 );
+ String sheetName = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), XLS_SHEET_PREFIX + 1 ) );
+
+ toXlsInternal( grid, workbook, sheetName, 0 );
+
+ workbook.write();
+ workbook.close();
+ }
+
+ private static void toXlsInternal( Grid grid, WritableWorkbook workbook, String sheetName, int sheetNo )
+ throws Exception
+ {
+ WritableSheet sheet = workbook.createSheet( sheetName, sheetNo );
int rowNumber = 1;
@@ -179,10 +229,6 @@
rowNumber++;
}
-
- workbook.write();
-
- workbook.close();
}
/**
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateCustomDataSetReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateCustomDataSetReportAction.java 2011-05-10 10:59:59 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateCustomDataSetReportAction.java 2011-05-30 19:32:17 +0000
@@ -27,9 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Map;
-
-import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.datasetreport.DataSetReportService;
import org.hisp.dhis.i18n.I18nFormat;
@@ -131,15 +128,7 @@
public String execute()
throws Exception
{
- Map<String, String> aggregatedDataValueMap = dataSetReportService.getAggregatedValueMap( selectedDataSet, selectedOrgunit, selectedPeriod,
- selectedUnitOnly, format );
-
- Map<Integer, String> aggregatedIndicatorMap = dataSetReportService.getAggregatedIndicatorValueMap( selectedDataSet, selectedOrgunit, selectedPeriod, format );
-
- DataEntryForm dataEntryForm = selectedDataSet.getDataEntryForm();
-
- customDataEntryFormCode = dataSetReportService.prepareReportContent( dataEntryForm.getHtmlCode(),
- aggregatedDataValueMap, aggregatedIndicatorMap );
+ customDataEntryFormCode = dataSetReportService.getCustomDataSetReport( selectedDataSet, selectedOrgunit, selectedPeriod, selectedUnitOnly, format );
reportingUnit = selectedOrgunit.getName();
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-05-17 11:26:03 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-05-30 19:10:22 +0000
@@ -115,7 +115,7 @@
<action name="addReport" class="org.hisp.dhis.reporting.reportviewer.action.AddReportAction">
<result name="success" type="redirect">displayViewReportForm.action</result>
- <result name="error" type="chain">displayAddReportForm</result>
+ <result name="error" type="redirect">displayAddReportForm.action</result>
<interceptor-ref name="fileUploadStack"/>
<param name="requiredAuthorities">F_REPORT_ADD</param>
</action>