← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12299: Made EventQueryParams extend DataQueryParams to promote code reuse

 

------------------------------------------------------------
revno: 12299
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-29 17:48:42 +0200
message:
  Made EventQueryParams extend DataQueryParams to promote code reuse
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-09-29 15:24:12 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-09-29 15:48:42 +0000
@@ -103,11 +103,11 @@
     private static final DimensionItem[] DIM_OPT_ARR = new DimensionItem[0];
     private static final DimensionItem[][] DIM_OPT_2D_ARR = new DimensionItem[0][];
     
-    private List<DimensionalObject> dimensions = new ArrayList<DimensionalObject>();
+    protected List<DimensionalObject> dimensions = new ArrayList<DimensionalObject>();
     
-    private List<DimensionalObject> filters = new ArrayList<DimensionalObject>();
+    protected List<DimensionalObject> filters = new ArrayList<DimensionalObject>();
 
-    private AggregationType aggregationType;
+    protected AggregationType aggregationType;
     
     private Map<MeasureFilter, Double> measureCriteria = new HashMap<MeasureFilter, Double>();
     
@@ -119,9 +119,9 @@
     // Transient properties
     // -------------------------------------------------------------------------
     
-    private transient Partitions partitions;
+    protected transient Partitions partitions;
 
-    private transient String periodType;
+    protected transient String periodType;
         
     private transient PeriodType dataPeriodType;
     

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2013-09-29 15:30:34 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2013-09-29 15:48:42 +0000
@@ -34,13 +34,10 @@
 import java.util.List;
 import java.util.Set;
 
-import org.hisp.dhis.common.BaseDimensionalObject;
-import org.hisp.dhis.common.DimensionType;
+import org.hisp.dhis.analytics.DataQueryParams;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.common.NameableObjectUtils;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
 
@@ -48,6 +45,7 @@
  * @author Lars Helge Overland
  */
 public class EventQueryParams
+    extends DataQueryParams
 {
     public static final String OU_MODE_SELECTED = "selected";
     public static final String OU_MODE_CHILDREN = "children";
@@ -63,8 +61,6 @@
     
     private List<QueryItem> items = new ArrayList<QueryItem>();
 
-    private List<DimensionalObject> dimensions = new ArrayList<DimensionalObject>();
-    
     private List<String> asc = new ArrayList<String>();
     
     private List<String> desc = new ArrayList<String>();
@@ -93,16 +89,23 @@
     {
     }
     
+    @Override
     public EventQueryParams instance()
     {
         EventQueryParams params = new EventQueryParams();
+
+        params.dimensions = new ArrayList<DimensionalObject>( this.dimensions );
+        params.filters = new ArrayList<DimensionalObject>( this.filters );
+        params.aggregationType = this.aggregationType;
+
+        params.partitions = this.partitions;
+        params.periodType = this.periodType;
         
         params.program = this.program;
         params.programStage = this.programStage;
         params.startDate = this.startDate;
         params.endDate = this.endDate;
         params.items = new ArrayList<QueryItem>( this.items );
-        params.dimensions = new ArrayList<DimensionalObject>( this.dimensions );            
         params.asc = new ArrayList<String>( this.asc );
         params.desc = new ArrayList<String>( this.desc );
         params.organisationUnitMode = this.organisationUnitMode;
@@ -123,56 +126,19 @@
     {
         return organisationUnitMode != null && organisationUnitMode.equalsIgnoreCase( mode );
     }
-
-    public List<OrganisationUnit> getOrganisationUnits()
-    {
-        int index = dimensions.indexOf( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID ) );
-        return index != -1 ? NameableObjectUtils.asTypedList( dimensions.get( index ).getItems(), OrganisationUnit.class ) : null;
-    }
-
-    public void setOrganisationUnits( List<OrganisationUnit> organisationUnits )
-    {
-        setDimensionOptions( DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATIONUNIT, null, organisationUnits );
-    }
-    
-    public List<Period> getPeriods()
-    {
-        int index = dimensions.indexOf( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID ) );
-        return index != -1 ? NameableObjectUtils.asTypedList( dimensions.get( index ).getItems(), Period.class ) : null;
-    }
-    
-    public void setPeriods( List<Period> periods )
-    {
-        setDimensionOptions( DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, null, periods );
-    }
     
     public boolean hasStartEndDate()
     {
         return startDate != null && endDate != null;
     }
-    
-    private EventQueryParams setDimensionOptions( String dimension, DimensionType type, String dimensionName, List<? extends NameableObject> options )
-    {
-        int index = dimensions.indexOf( new BaseDimensionalObject( dimension ) );
-        
-        if ( index != -1 )
-        {
-            dimensions.set( index, new BaseDimensionalObject( dimension, type, dimensionName, options ) );
-        }
-        else
-        {
-            dimensions.add( new BaseDimensionalObject( dimension, type, dimensionName, options ) );
-        }
-        
-        return this;
-    }
-    
+        
     public Set<OrganisationUnit> getOrganisationUnitChildren()
     {
         Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
         
-        for ( OrganisationUnit unit : getOrganisationUnits() )
+        for ( NameableObject object : getOrganisationUnits() )
         {
+            OrganisationUnit unit = (OrganisationUnit) object;            
             children.addAll( unit.getChildren() );
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2013-09-29 15:41:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2013-09-29 15:48:42 +0000
@@ -50,6 +50,7 @@
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -294,8 +295,9 @@
             }
         }
         
-        for ( OrganisationUnit unit : params.getOrganisationUnits() )
+        for ( NameableObject object : params.getOrganisationUnits() )
         {
+            OrganisationUnit unit = (OrganisationUnit) object;
             unit.setLevel( organisationUnitService.getLevelOfOrganisationUnit( unit.getUid() ) );
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2013-09-29 15:41:22 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2013-09-29 15:48:42 +0000
@@ -38,8 +38,10 @@
 import org.hisp.dhis.analytics.event.EventQueryParams;
 import org.hisp.dhis.analytics.event.EventQueryPlanner;
 import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.Program;
 
 /**
@@ -141,8 +143,9 @@
         else
         {
             //TODO implement properly 
-            params.setTableName( TABLE_BASE_NAME + year( params.getPeriods().get( 0 ).getStartDate() ) + "_" + program.getUid() );
-            params.setPeriodType( params.getPeriods().get( 0 ).getPeriodType().getName() );
+            Period period = (Period) params.getPeriods().get( 0 );
+            params.setTableName( TABLE_BASE_NAME + year( period.getStartDate() ) + "_" + program.getUid() );
+            params.setPeriodType( period.getPeriodType().getName() );
             list.add( params );
         }
         
@@ -153,8 +156,9 @@
     {
         ListMap<Integer, OrganisationUnit> levelOrgUnitMap = new ListMap<Integer, OrganisationUnit>();
         
-        for ( OrganisationUnit unit : params.getOrganisationUnits() )
+        for ( NameableObject object : params.getOrganisationUnits() )
         {
+            OrganisationUnit unit = (OrganisationUnit) object;
             levelOrgUnitMap.putValue( unit.getLevel(), unit );
         }
         

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2013-09-28 16:27:09 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2013-09-29 15:48:42 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.analytics.event.QueryItem;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.system.util.TextUtils;
@@ -241,8 +242,9 @@
         {
             sql += "and (";
             
-            for ( OrganisationUnit unit : params.getOrganisationUnits() )
+            for ( NameableObject object : params.getOrganisationUnits() )
             {
+                OrganisationUnit unit = (OrganisationUnit) object;
                 sql += "uidlevel" + unit.getLevel() + " = '" + unit.getUid() + "' or ";
             }