dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18338
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7692: Dynamic jasper in local/in CCEM report
------------------------------------------------------------
revno: 7692
committer: Samta <samta-bajpayee@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-07-24 13:35:33 +0100
message:
Dynamic jasper in local/in CCEM report
removed:
local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/DynamicJasperTemplate.java
modified:
local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateJRXMLReportAction.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
=== removed file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/DynamicJasperTemplate.java'
--- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/DynamicJasperTemplate.java 2012-07-24 05:31:29 +0000
+++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/DynamicJasperTemplate.java 1970-01-01 00:00:00 +0000
@@ -1,168 +0,0 @@
-/**
- *
- */
-package org.hisp.dhis.coldchain.reports.action;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-import net.sf.jasperreports.engine.JRDataSource;
-import net.sf.jasperreports.engine.JasperExportManager;
-import net.sf.jasperreports.engine.JasperFillManager;
-import net.sf.jasperreports.engine.JasperPrint;
-import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.data.JRMapCollectionDataSource;
-import ar.com.fdvs.dj.core.DynamicJasperHelper;
-import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
-import ar.com.fdvs.dj.domain.DynamicReport;
-import ar.com.fdvs.dj.domain.Style;
-import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
-import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
-import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
-import ar.com.fdvs.dj.domain.constants.Font;
-import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
-import ar.com.fdvs.dj.domain.constants.VerticalAlign;
-import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
-
-/**
- * @author Samta Bajpai
- *
- * @version DynamicJasperTemplate.java Jul 19, 2012 5:41:06 PM
- */
-public class DynamicJasperTemplate
-{
-
- protected JasperPrint jp;
-
- protected JasperReport jr;
-
- protected Map params = new HashMap();
-
- protected DynamicReport dr;
-
- public void buildReport()
- throws Exception
- {
-
- FastReportBuilder frb = new FastReportBuilder();
-
- Font font = new Font( 10, "Arial", true );
-
- Style headerStyle = new Style();
-
- headerStyle.setFont( font );
-
- headerStyle.setHorizontalAlign( HorizontalAlign.LEFT );
-
- headerStyle.setVerticalAlign( VerticalAlign.MIDDLE );
-
- font = new Font( 8, "Arial", false );
-
- Style detailStyle = new Style();
-
- detailStyle.setFont( font );
-
- detailStyle.setHorizontalAlign( HorizontalAlign.LEFT );
-
- detailStyle.setVerticalAlign( VerticalAlign.MIDDLE );
- AbstractColumn column;
- for ( int i = 1; i <= 10; i++ )
- {
- frb.addColumn("Column" + i, "Column" + i, String.class.getName(), 50,true);
- }
- frb.setColumnsPerPage(1, 10).setUseFullPageWidth(true).setColspan(1, 2, "Estimated");
- //frb.setUseFullPageWidth( true );
-
- // Pass the JasperReport Template to DynamicJasper
-
- frb.setTemplateFile( "C:/report1.jrxml" );
-
- DynamicReport dr = frb.build();
-
- List records = new ArrayList();
-
- for ( int i = 1; i < 10; i++ )
- {
-
- Map columns = new HashMap();
-
- for ( int j = 1; j <= 10; j++ )
- {
-
- // The HashMap Key must save with ColumnProperty Name
-
- columns.put( "Column" + j, "Record " + i + " Column " +j + " data." );
-
- }
-
- records.add( columns );
-
- }
-
- JRDataSource ds = new JRMapCollectionDataSource( records );
-
- jr = DynamicJasperHelper.generateJasperReport( dr, new ClassicLayoutManager(), params );
-
- if ( ds != null )
- {
-
- jp = JasperFillManager.fillReport( jr, params, ds );
-
- }
- else
- {
-
- jp = JasperFillManager.fillReport( jr, params );
-
- }
-
- JasperExportManager.exportReportToPdfFile( jp, "C:/report-out.pdf" );
-
- }
-
- protected JRDataSource getDataSource()
- {
-
- // Generate dummy data to show in the report.
-
- List records = new ArrayList();
-
- for ( int i = 1; i < 10; i++ )
- {
-
- Map columns = new HashMap();
-
- for ( int j = 1; j <= 10; j++ )
- {
-
- // The HashMap Key must save with ColumnProperty Name
-
- columns.put( "Column" + j, "Record " + i + " Column " + j + " data." );
-
- }
-
- records.add( columns );
-
- }
-
- JRDataSource ds = new JRMapCollectionDataSource( records );
-
- return ds;
-
- }
-
- public static void main( String[] args )
- throws Exception
- {
-
- DynamicJasperTemplate djt = new DynamicJasperTemplate();
-
- djt.buildReport();
-
- }
-
-}
=== modified file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateJRXMLReportAction.java'
--- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateJRXMLReportAction.java 2012-07-24 05:31:29 +0000
+++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/reports/action/GenerateJRXMLReportAction.java 2012-07-24 12:35:33 +0000
@@ -367,23 +367,21 @@
detailStyle.setFont( font );
detailStyle.setHorizontalAlign( HorizontalAlign.LEFT );
detailStyle.setVerticalAlign( VerticalAlign.MIDDLE );
- AbstractColumn column;
+
ccemReportOutput = new CCEMReportOutput();
List<String> tableHeadings = new ArrayList<String>();
List<List<String>> tableSubHeadings = new ArrayList<List<String>>();
List tableData = new ArrayList();
-
List<String> oneSubHeadingRow = new ArrayList<String>();
List<String> content= new ArrayList<String>();
- FastReportBuilder frb = new FastReportBuilder();
-
+ FastReportBuilder frb = new FastReportBuilder();
Integer periodId = 0;
Date date1 = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime( date1 );
- String periodStartDate = "";
- Map<String, Integer> dataValueCountMap = new HashMap<String, Integer>();
+ String periodStartDate = "";
+ Map<String, Integer> subHeadingNumber= new HashMap<String, Integer>();
if( periodRadio.equalsIgnoreCase( CCEMReport.CURRENT_YEAR ) )
{
periodStartDate = calendar.get( Calendar.YEAR ) + "-01-01";
@@ -416,17 +414,18 @@
hash.put( "dataElementId", dataElementId );
hash.put( "optComboId", optComboId );
List<String> distinctDataElementValues = new ArrayList<String>( ccemReportManager.getDistinctDataElementValue( dataElementId, optComboId, periodId ) );
-
+ int number=0;
for( int i = 0; i < distinctDataElementValues.size(); i++ )
- {
+ {
if( i != 0 )
{
- tableHeadings.add( " " );
-
+ tableHeadings.add( " " );
}
oneSubHeadingRow.add( distinctDataElementValues.get( i ).split( ":" )[2] );
dataElementOptions.add( distinctDataElementValues.get( i ) );
- }
+ number++;
+ }
+ subHeadingNumber.put( ccemReportDesign1.getDisplayheading(), number );
}
tableSubHeadings.add( oneSubHeadingRow );
@@ -441,7 +440,7 @@
{
if(i==0 || i==1)
{
- frb.addColumn(tableHeadings.get( i ), tableHeadings.get( i ), String.class.getName(), 100,true).build();
+ frb.addColumn(tableHeadings.get( i ), tableHeadings.get( i ), String.class.getName(), 50,true);
count++;
}
@@ -460,27 +459,30 @@
else
{
frb.addColumn(tableSubHeadings.get( j ).get( k ),
- tableSubHeadings.get( j ).get( k ), String.class.getName(), 100,false).build() ;
+ tableSubHeadings.get( j ).get( k ), String.class.getName(), 50, true);
content.add( tableSubHeadings.get( j ).get( k ) );
count++;
}
- }
-
- }
- //frb.build();
+ }
+ }
frb.setPrintColumnNames(true);
- frb.setColumnsPerPage(1, count).setUseFullPageWidth(true);
- Style colspanStyle = new Style();
- colspanStyle.setBackgroundColor(Color.GRAY);
- colspanStyle.setTransparency(Transparency.OPAQUE);
- colspanStyle.setBorder(Border.PEN_1_POINT());
-
- frb.setColspan(2, 5, "Estimated", colspanStyle);
-
- frb.setTemplateFile( path+"report1.jrxml" );
-
- //dynamicReport.getOptions().getDefaultHeaderStyle().setBorder(Border.PEN_1_POINT());
-
+ frb.setHeaderHeight( 100 );
+ frb.setColumnsPerPage(1, count).setUseFullPageWidth(true);
+
+ int start=2;
+ for(int i=2;i<=tableHeadings.size()-1;i++)
+ {
+ if(tableHeadings.get( i )== " ")
+ {
+
+ }
+ else
+ {
+ frb.setColspan(start, subHeadingNumber.get( tableHeadings.get( i ) ), tableHeadings.get( i ));
+ start=start + subHeadingNumber.get( tableHeadings.get( i ) );
+ }
+ }
+ frb.setTemplateFile( path+"ORGUNITGROUP_DATAVALUE.jrxml" );
for( Integer orgUnitGroupId : orgunitGroupList )
{
Map numberOfData=new HashMap();
@@ -493,8 +495,7 @@
{
OrganisationUnitGroup orgUnitGroup = organisationUnitGroupService.getOrganisationUnitGroup( orgUnitGroupId );
- String orgUnitIdsBycomma = getCommaDelimitedString( orgUnitIds );
- System.out.println("Organisation Group"+orgUnitGroup.getName());
+ String orgUnitIdsBycomma = getCommaDelimitedString( orgUnitIds );
numberOfData.put( "Facility Type", orgUnitGroup.getName() );
numberOfData.put( "Total Facilities", ""+orgUnitIds.size() );
Map<String, Integer> dataValueCountMap2 = new HashMap<String, Integer>( ccemReportManager.getDataValueCountforDataElements( dataElementIdsByComma, optComboIdsByComma, periodId, orgUnitIdsBycomma ) );
@@ -516,25 +517,18 @@
JRDataSource ds = new JRMapCollectionDataSource(tableData );
DynamicReport dynamicReport = frb.build();
+ dynamicReport.getOptions().getDefaultDetailStyle().setBackgroundColor( Color.BLUE );
dynamicReport.getOptions().getDefaultHeaderStyle().setBorder(Border.THIN());
+ dynamicReport.getOptions().getDefaultHeaderStyle().setHorizontalAlign(HorizontalAlign.CENTER );
dynamicReport.getOptions().getDefaultDetailStyle().setBorder(Border.THIN());
dynamicReport.getOptions().getDefaultDetailStyle().setHorizontalAlign(HorizontalAlign.CENTER );
+ dynamicReport.getOptions().getDefaultDetailStyle().setVerticalAlign( VerticalAlign.MIDDLE );
jr = DynamicJasperHelper.generateJasperReport( dynamicReport, new ClassicLayoutManager(), hash );
- jasperPrint = JasperFillManager.fillReport( jr, hash, ds );
-
-
- //JasperExportManager.exportReportToPdfFile( jasperPrint, "C:/report1.pdf" );
- //hash.put( "periodId", periodId );
- // hash.put( "tableData", tableData );
- //hash.put( "tableHeadings", tableHeadings );
- //hash.put( "tableSubHeadings",tableSubHeadings );
- //fileName = "report1.jrxml";
+ jasperPrint = JasperFillManager.fillReport( jr, hash, ds );
}
ServletOutputStream ouputStream = response.getOutputStream();
JRExporter exporter = null;
-
- System.out.println( "Type is:" + type );
if ( "pdf".equalsIgnoreCase( type ) )
{
response.setContentType( "application/pdf" );
@@ -603,8 +597,6 @@
}
}
}
-
-
return SUCCESS;
}