← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 145: dhis-web-reporting: Moved the initialization of report tables from the web layer to the service l...

 

------------------------------------------------------------
revno: 145
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-04-02 14:32:16 +0200
message:
  dhis-web-reporting: Moved the initialization of report tables from the web layer to the service layer. This is better design as we want to keep the web layer minimal and it was prone to lazy-loading exceptions
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/DefaultReportTableCreator.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/DefaultReportTableCreator.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/DefaultReportTableCreator.java	2009-04-02 07:52:56 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/DefaultReportTableCreator.java	2009-04-02 12:32:16 +0000
@@ -73,13 +73,6 @@
         this.reportTableManager = reportTableManager;
     }
     
-    private ReportTableService reportTableService;
-
-    public void setReportTableService( ReportTableService reportTableService )
-    {
-        this.reportTableService = reportTableService;
-    }
-    
     private BatchHandlerFactory batchHandlerFactory;
     
     public void setBatchHandlerFactory( BatchHandlerFactory batchHandlerFactory )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableInternalProcess.java	2009-04-02 12:32:16 +0000
@@ -28,9 +28,18 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 
 import org.amplecode.cave.process.SerialToGroup;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.report.ReportStore;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.system.process.AbstractStatementInternalProcess;
 
@@ -41,34 +50,87 @@
 public abstract class ReportTableInternalProcess
     extends AbstractStatementInternalProcess implements ReportTableCreator, SerialToGroup
 {
+    private static final Log log = LogFactory.getLog( ReportTableInternalProcess.class );
+    
     public static final String ID = "internal-process-ReportTable";
     public static final String PROCESS_TYPE = "ReportTable";
 
+    private static final String MODE_REPORT = "report";
+    private static final String MODE_REPORT_TABLE = "table";
+
     private static final String PROCESS_GROUP = "DataMartProcessGroup";
-    
-    private List<ReportTable> reportTables = new ArrayList<ReportTable>();
-    
-    public void setReportTables( List<ReportTable> reportTables )
-    {
-        this.reportTables = reportTables;
-    }
-
-    private boolean doDataMart;
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    protected ReportTableService reportTableService;
+
+    public void setReportTableService( ReportTableService reportTableService )
+    {
+        this.reportTableService = reportTableService;
+    }
+
+    protected ReportStore reportStore;
+
+    public void setReportStore( ReportStore reportStore )
+    {
+        this.reportStore = reportStore;
+    }
+
+    protected OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Properties
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    private String mode;
+
+    public void setMode( String mode )
+    {
+        this.mode = mode;
+    }
+
+    private Integer reportingPeriod;
+
+    public void setReportingPeriod( Integer reportingPeriod )
+    {
+        this.reportingPeriod = reportingPeriod;
+    }
+
+    private Integer parentOrganisationUnitId;
+
+    public void setParentOrganisationUnitId( Integer parentOrganisationUnitId )
+    {
+        this.parentOrganisationUnitId = parentOrganisationUnitId;
+    }
+
+    private Integer organisationUnitId;
+
+    public void setOrganisationUnitId( Integer organisationUnitId )
+    {
+        this.organisationUnitId = organisationUnitId;
+    }
         
-    public void setDoDataMart( boolean doDataMart )
-    {
-        this.doDataMart = doDataMart;
-    }
-
-    // -------------------------------------------------------------------------
-    // Logic
-    // -------------------------------------------------------------------------
-
-    public void addReportTable( ReportTable table )
-    {
-        this.reportTables.add( table );
-    }
-
+    private I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+    
     // -------------------------------------------------------------------------
     // SerialToGroup implementation
     // -------------------------------------------------------------------------
@@ -84,9 +146,73 @@
 
     public void executeStatements()
     {
-        for ( ReportTable reportTable : reportTables )
+        for ( ReportTable reportTable : getReportTables( id, mode ) )
         {
-            createReportTable( reportTable, doDataMart );
+            // -----------------------------------------------------------------
+            // Reporting period report parameter / current reporting period
+            // -----------------------------------------------------------------
+
+            Date date = null;
+
+            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
+            {
+                reportTable.setRelativePeriods( reportTableService.getRelativePeriods( reportTable.getRelatives(), reportingPeriod ) );
+                
+                date = reportTableService.getDateFromPreviousMonth( reportingPeriod );
+                
+                log.info( "Reporting period: " + reportingPeriod );
+            }
+            else
+            {
+                reportTable.setRelativePeriods( reportTableService.getRelativePeriods( reportTable.getRelatives(), -1 ) );
+                
+                date = reportTableService.getDateFromPreviousMonth( -1 );
+            }
+
+            String reportingMonthName = format.formatPeriod( new MonthlyPeriodType().createPeriod( date ) );
+            
+            reportTable.setReportingMonthName( reportingMonthName );
+
+            // -----------------------------------------------------------------
+            // Parent organisation unit report parameter
+            // -----------------------------------------------------------------
+
+            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamParentOrganisationUnit() )
+            {
+                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
+
+                reportTable.getRelativeUnits().addAll( new ArrayList<OrganisationUnit>( organisationUnit.getChildren() ) );
+                
+                log.info( "Parent organisation unit: " + organisationUnit.getName() );
+            }
+
+            // -----------------------------------------------------------------
+            // Organisation unit report parameter
+            // -----------------------------------------------------------------
+
+            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamOrganisationUnit() )
+            {
+                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+                
+                List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
+                organisationUnits.add( organisationUnit );
+                reportTable.getRelativeUnits().addAll( organisationUnits );
+                
+                log.info( "Organisation unit: " + organisationUnit.getName() );
+            }
+
+            // -----------------------------------------------------------------
+            // Set properties and initalize
+            // -----------------------------------------------------------------
+
+            reportTable.setI18nFormat( format );
+            reportTable.init();
+
+            // -----------------------------------------------------------------
+            // Create report table
+            // -----------------------------------------------------------------
+
+            createReportTable( reportTable, true );
         }
                 
         deleteRelativePeriods();
@@ -97,4 +223,32 @@
     // -------------------------------------------------------------------------
 
     protected abstract void deleteRelativePeriods();
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    /**
+     * If report table mode, this method will return the report table with the
+     * given identifier. If report mode, this method will return the report
+     * tables associated with the report.
+     * 
+     * @param id the identifier.
+     * @param mode the mode.
+     */
+    private Collection<ReportTable> getReportTables( Integer id, String mode )
+    {
+        Collection<ReportTable> reportTables = new ArrayList<ReportTable>();
+
+        if ( mode.equals( MODE_REPORT_TABLE ) )
+        {
+            reportTables.add( reportTableService.getReportTable( id ) );
+        }
+        else if ( mode.equals( MODE_REPORT ) )
+        {
+            reportTables = reportStore.getReport( id ).getReportTables();
+        }
+
+        return reportTables;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-03-07 13:10:38 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-04-02 12:32:16 +0000
@@ -25,10 +25,14 @@
     scope="prototype">
     <property name="statementManager"
       ref="org.hisp.dhis.jdbc.StatementManager"/>
+    <property name="reportTableService"
+      ref="org.hisp.dhis.reporttable.ReportTableService"/>
+    <property name="reportStore"
+      ref="org.hisp.dhis.report.ReportStore"/>
+    <property name="organisationUnitService"
+      ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
     <property name="reportTableManager"
       ref="org.hisp.dhis.reporttable.jdbc.ReportTableManager"/>
-    <property name="reportTableService"
-      ref="org.hisp.dhis.reporttable.ReportTableService"/>
     <property name="batchHandlerFactory"
       ref="org.hisp.dhis.jdbc.BatchHandlerFactory"/>
     <property name="dataMartService"

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java	2009-04-02 07:52:56 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/CreateTableAction.java	2009-04-02 12:32:16 +0000
@@ -31,23 +31,10 @@
 import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_REPORT;
 import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
 import org.amplecode.cave.process.ProcessCoordinator;
 import org.amplecode.cave.process.ProcessExecutor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.MonthlyPeriodType;
-import org.hisp.dhis.report.ReportStore;
-import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableInternalProcess;
-import org.hisp.dhis.reporttable.ReportTableService;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork.Action;
@@ -59,12 +46,6 @@
 public class CreateTableAction
     implements Action
 {
-    private static final Log log = LogFactory.getLog( CreateTableAction.class );
-    
-    private static final String MODE_REPORT = "report";
-
-    private static final String MODE_REPORT_TABLE = "table";
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -83,27 +64,6 @@
         this.currentUserService = currentUserService;
     }
 
-    private ReportTableService reportTableService;
-
-    public void setReportTableService( ReportTableService reportTableService )
-    {
-        this.reportTableService = reportTableService;
-    }
-
-    private ReportStore reportStore;
-
-    public void setReportStore( ReportStore reportStore )
-    {
-        this.reportStore = reportStore;
-    }
-    
-    private OrganisationUnitService organisationUnitService;
-
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
-    {
-        this.organisationUnitService = organisationUnitService;
-    }
-
     private I18nFormat format;
 
     public void setFormat( I18nFormat format )
@@ -163,76 +123,12 @@
         
         ReportTableInternalProcess process = (ReportTableInternalProcess) executor.getProcess();
 
-        process.setDoDataMart( true );
-
-        // ---------------------------------------------------------------------
-        // Report parameters
-        // ---------------------------------------------------------------------
-
-        for ( ReportTable reportTable : getReportTables( id, mode ) )
-        {
-            // -----------------------------------------------------------------
-            // Reporting period report parameter / current reporting period
-            // -----------------------------------------------------------------
-
-            Date date = null;
-
-            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
-            {
-                reportTable.setRelativePeriods( reportTableService.getRelativePeriods( reportTable.getRelatives(), reportingPeriod ) );
-                
-                date = reportTableService.getDateFromPreviousMonth( reportingPeriod );
-                
-                log.info( "Reporting period: " + reportingPeriod );
-            }
-            else
-            {
-                reportTable.setRelativePeriods( reportTableService.getRelativePeriods( reportTable.getRelatives(), -1 ) );
-                
-                date = reportTableService.getDateFromPreviousMonth( -1 );
-            }
-
-            String reportingMonthName = format.formatPeriod( new MonthlyPeriodType().createPeriod( date ) );
-            
-            reportTable.setReportingMonthName( reportingMonthName );
-
-            // -----------------------------------------------------------------
-            // Parent organisation unit report parameter
-            // -----------------------------------------------------------------
-
-            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamParentOrganisationUnit() )
-            {
-                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId );
-
-                reportTable.getRelativeUnits().addAll( new ArrayList<OrganisationUnit>( organisationUnit.getChildren() ) );
-                
-                log.info( "Parent organisation unit: " + organisationUnit.getName() );
-            }
-
-            // -----------------------------------------------------------------
-            // Organisation unit report parameter
-            // -----------------------------------------------------------------
-
-            if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamOrganisationUnit() )
-            {
-                OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
-                
-                List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
-                organisationUnits.add( organisationUnit );
-                reportTable.getRelativeUnits().addAll( organisationUnits );
-                
-                log.info( "Organisation unit: " + organisationUnit.getName() );
-            }
-
-            reportTable.setI18nFormat( format );
-            reportTable.init();
-
-            process.addReportTable( reportTable );
-        }
-
-        // ---------------------------------------------------------------------
-        // Internal process execution
-        // ---------------------------------------------------------------------
+        process.setId( id );
+        process.setMode( mode );
+        process.setReportingPeriod( reportingPeriod );
+        process.setParentOrganisationUnitId( parentOrganisationUnitId );
+        process.setOrganisationUnitId( organisationUnitId );
+        process.setFormat( format );
 
         processCoordinator.requestProcessExecution( executor );
 
@@ -240,32 +136,4 @@
 
         return SUCCESS;
     }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    /**
-     * If report table mode, this method will return the report table with the
-     * given identifier. If report mode, this method will return the report
-     * tables associated with the report.
-     * 
-     * @param id the identifier.
-     * @param mode the mode.
-     */
-    private Collection<ReportTable> getReportTables( Integer id, String mode )
-    {
-        Collection<ReportTable> reportTables = new ArrayList<ReportTable>();
-
-        if ( mode.equals( MODE_REPORT_TABLE ) )
-        {
-            reportTables.add( reportTableService.getReportTable( id ) );
-        }
-        else if ( mode.equals( MODE_REPORT ) )
-        {
-            reportTables = reportStore.getReport( id ).getReportTables();
-        }
-
-        return reportTables;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-03-24 10:31:31 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-04-02 12:32:16 +0000
@@ -202,12 +202,6 @@
       ref="processCoordinator"/>
     <property name="currentUserService"
       ref="org.hisp.dhis.user.CurrentUserService"/>
-    <property name="reportTableService"
-      ref="org.hisp.dhis.reporttable.ReportTableService"/>
-    <property name="reportStore"
-      ref="org.hisp.dhis.report.ReportStore"/>
-    <property name="organisationUnitService"
-      ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
   </bean>
   
   <bean id="org.hisp.dhis.reporting.tablecreator.action.GetReportParamsAction"



--
Trunk
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.