← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10850: Modified report table to use dimensional properties from BaseAnalyticalObject

 

------------------------------------------------------------
revno: 10850
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-05-15 17:00:45 +0200
message:
  Modified report table to use dimensional properties from BaseAnalyticalObject
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/tracker/ProgramInstanceController.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-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2013-05-14 21:14:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2013-05-15 15:00:45 +0000
@@ -269,6 +269,15 @@
             organisationUnits.clear();
             organisationUnits.addAll( other.getOrganisationUnits() );
             
+            dataElementGroups.clear();
+            dataElementGroups.addAll( other.getDataElementGroups() );
+            
+            organisationUnitGroups.clear();
+            organisationUnitGroups.addAll( other.getOrganisationUnitGroups() );
+            
+            categoryDimensions.clear();
+            categoryDimensions.addAll( other.getCategoryDimensions() );
+            
             userOrganisationUnit = other.isUserOrganisationUnit();
             userOrganisationUnitChildren = other.isUserOrganisationUnitChildren();            
         }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-05-15 13:39:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-05-15 15:00:45 +0000
@@ -46,16 +46,14 @@
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.common.adapter.JacksonMapListIdentifiableObjectSerializer;
 import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.DimensionalView;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
@@ -69,7 +67,6 @@
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -279,20 +276,6 @@
     private String fontSize;
     
     // -------------------------------------------------------------------------
-    // Presentation properties
-    // -------------------------------------------------------------------------
-
-    /**
-     * Map of data element group set uids and data element groups.
-     */
-    private Map<String, List<DataElementGroup>> dataElementGroupSets = new HashMap<String, List<DataElementGroup>>();
-    
-    /**
-     * Map of organisation unit group uids and organisation unit groups.
-     */
-    private Map<String, List<OrganisationUnitGroup>> organisationUnitGroupSets = new HashMap<String, List<OrganisationUnitGroup>>();
-    
-    // -------------------------------------------------------------------------
     // Transient properties
     // -------------------------------------------------------------------------
 
@@ -576,54 +559,6 @@
     }
     
     /**
-     * Populates the presentation properties based on the persisted properties.
-     */
-    public ReportTable populatePresentationProps()
-    {
-        ListMap<String, DataElementGroup> degs = new ListMap<String, DataElementGroup>();
-        
-        for ( DataElementGroup group : dataElementGroups )
-        {
-            degs.putValue( group.getGroupSet().getUid(), group );
-        }
-        
-        ListMap<String, OrganisationUnitGroup> ougs = new ListMap<String, OrganisationUnitGroup>();
-        
-        for ( OrganisationUnitGroup group : organisationUnitGroups )
-        {
-            ougs.putValue( group.getGroupSet().getUid(), group );
-        }
-        
-        dataElementGroupSets.clear();
-        dataElementGroupSets.putAll( degs );        
-        organisationUnitGroupSets.clear();
-        organisationUnitGroupSets.putAll( ougs );
-        
-        return this;
-    }
-    
-    /**
-     * Sets the persisted properties based on the presentation properties.
-     */
-    public ReportTable readPresentationProps()
-    {
-        dataElementGroups.clear();        
-        organisationUnitGroups.clear();
-        
-        for ( String groupSet : dataElementGroupSets.keySet() )
-        {
-            dataElementGroups.addAll( dataElementGroupSets.get( groupSet ) );
-        }
-        
-        for ( String groupSet : organisationUnitGroupSets.keySet() )
-        {
-            organisationUnitGroups.addAll( organisationUnitGroupSets.get( groupSet ) );
-        }
-        
-        return this;
-    }
-    
-    /**
      * Creates a map which contains mappings between the organisation unit
      * identifier and the name of the group this organisation unit is a member
      * of in all of the given group sets for all organisation units in this
@@ -632,6 +567,7 @@
      * @param groupSets the collection of organisation unit group sets.
      * @return a map.
      */
+    @Deprecated
     public Map<String, Object> getOrganisationUnitGroupMap( Collection<OrganisationUnitGroupSet> groupSets )
     {
         Map<String, Object> organisationUnitGroupMap = new HashMap<String, Object>();
@@ -1082,7 +1018,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isRegression()
     {
@@ -1095,7 +1031,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isCumulative()
     {
@@ -1150,7 +1086,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public ReportParams getReportParams()
     {
@@ -1163,7 +1099,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public Integer getSortOrder()
     {
@@ -1176,7 +1112,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public Integer getTopLimit()
     {
@@ -1189,7 +1125,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isTotals()
     {
@@ -1202,7 +1138,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isSubtotals()
     {
@@ -1215,7 +1151,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isHideEmptyRows()
     {
@@ -1228,7 +1164,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public String getDigitGroupSeparator()
     {
@@ -1241,7 +1177,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public String getDisplayDensity()
     {
@@ -1254,7 +1190,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( {DetailedView.class, ExportView.class, DimensionalView.class} )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public String getFontSize()
     {
@@ -1267,38 +1203,6 @@
     }
 
     // -------------------------------------------------------------------------
-    // Get- and set-methods for presentation properties
-    // -------------------------------------------------------------------------
-
-    @JsonProperty
-    @JsonSerialize( using = JacksonMapListIdentifiableObjectSerializer.class )
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
-    public Map<String, List<DataElementGroup>> getDataElementGroupSets()
-    {
-        return dataElementGroupSets;
-    }
-
-    public void setDataElementGroupSets( Map<String, List<DataElementGroup>> dataElementGroupSets )
-    {
-        this.dataElementGroupSets = dataElementGroupSets;
-    }
-
-    @JsonProperty
-    @JsonSerialize( using = JacksonMapListIdentifiableObjectSerializer.class )
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
-    public Map<String, List<OrganisationUnitGroup>> getOrganisationUnitGroupSets()
-    {
-        return organisationUnitGroupSets;
-    }
-
-    public void setOrganisationUnitGroupSets( Map<String, List<OrganisationUnitGroup>> organisationUnitGroupSets )
-    {
-        this.organisationUnitGroupSets = organisationUnitGroupSets;
-    }
-
-    // -------------------------------------------------------------------------
     // Get- and set-methods for transient properties
     // -------------------------------------------------------------------------
 
@@ -1450,7 +1354,6 @@
 
             regression = reportTable.isRegression();
             cumulative = reportTable.isCumulative();
-            relatives = reportTable.getRelatives() == null ? relatives : reportTable.getRelatives();
             reportParams = reportTable.getReportParams() == null ? reportParams : reportTable.getReportParams();
             sortOrder = reportTable.getSortOrder() == null ? sortOrder : reportTable.getSortOrder();
             topLimit = reportTable.getTopLimit() == null ? topLimit : reportTable.getTopLimit();
@@ -1460,29 +1363,6 @@
             digitGroupSeparator = reportTable.getDigitGroupSeparator();
             displayDensity = reportTable.getDisplayDensity();
             fontSize = reportTable.getFontSize();
-            userOrganisationUnit = reportTable.isUserOrganisationUnit();
-            userOrganisationUnitChildren = reportTable.isUserOrganisationUnitChildren();
-
-            dataElements.clear();
-            dataElements.addAll( reportTable.getDataElements() );
-
-            indicators.clear();
-            indicators.addAll( reportTable.getIndicators() );
-
-            dataSets.clear();
-            dataSets.addAll( reportTable.getDataSets() );
-
-            organisationUnits.clear();
-            organisationUnits.addAll( reportTable.getOrganisationUnits() );
-
-            periods.clear();
-            periods.addAll( reportTable.getPeriods() );
-
-            dataElementGroups.clear();
-            dataElementGroups.addAll( reportTable.getDataElementGroups() );
-            
-            organisationUnitGroups.clear();
-            organisationUnitGroups.addAll( reportTable.getOrganisationUnitGroups() );
             
             columnDimensions.clear();
             columnDimensions.addAll( reportTable.getColumnDimensions() );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2013-05-13 11:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2013-05-15 15:00:45 +0000
@@ -232,10 +232,10 @@
 
     private void mergeChart( Chart chart )
     {
+        dimensionService.mergeAnalyticalObject( chart );
+        
         chart.getFilterDimensions().clear();
                 
-        dimensionService.mergeAnalyticalObject( chart );
-        
         chart.setSeries( toDimension( chart.getColumns().get( 0 ).getDimension() ) );
         chart.setCategory( toDimension( chart.getRows().get( 0 ).getDimension() ) );
         

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-04-24 14:11:57 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-05-15 15:00:45 +0000
@@ -27,8 +27,22 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.common.DimensionalObjectUtils.toDimension;
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.common.DimensionService;
+import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -61,17 +75,6 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
-import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  * @author Lars Helge Overland
@@ -108,6 +111,9 @@
 
     @Autowired
     private UserService userService;
+    
+    @Autowired
+    private DimensionService dimensionService;
 
     @Autowired
     private I18nManager i18nManager;
@@ -125,8 +131,6 @@
     {
         ReportTable reportTable = JacksonUtils.fromJson( input, ReportTable.class );
 
-        reportTable.readPresentationProps();
-
         mergeReportTable( reportTable );
 
         reportTableService.saveReportTable( reportTable );
@@ -149,8 +153,6 @@
 
         ReportTable newReportTable = JacksonUtils.fromJson( input, ReportTable.class );
 
-        newReportTable.readPresentationProps();
-
         mergeReportTable( newReportTable );
 
         reportTable.mergeWith( newReportTable );
@@ -177,15 +179,15 @@
     @Override
     protected void postProcessEntity( ReportTable reportTable ) throws Exception
     {
-        I18nFormat format = i18nManager.getI18nFormat();
-
-        reportTable.populatePresentationProps();
-
+        reportTable.populateAnalyticalProperties();
+        
         for ( OrganisationUnit organisationUnit : reportTable.getOrganisationUnits() )
         {
             reportTable.getParentGraphMap().put( organisationUnit.getUid(), organisationUnit.getParentGraph() );
         }
 
+        I18nFormat format = i18nManager.getI18nFormat();
+
         if ( reportTable.getPeriods() != null && !reportTable.getPeriods().isEmpty() )
         {
             for ( Period period : reportTable.getPeriods() )
@@ -475,17 +477,25 @@
 
     private void mergeReportTable( ReportTable reportTable )
     {
-        reportTable.setDataElements( dataElementService.getDataElementsByUid( getUids( reportTable.getDataElements() ) ) );
-        reportTable.setIndicators( indicatorService.getIndicatorsByUid( getUids( reportTable.getIndicators() ) ) );
-        reportTable.setDataSets( dataSetService.getDataSetsByUid( getUids( reportTable.getDataSets() ) ) );
-        reportTable.setOrganisationUnits( organisationUnitService.getOrganisationUnitsByUid( getUids( reportTable.getOrganisationUnits() ) ) );
-        reportTable.setPeriods( periodService.reloadPeriods( reportTable.getPeriods() ) );
-        reportTable.setDataElementGroups( dataElementService.getDataElementGroupsByUid( getUids( reportTable.getDataElementGroups() ) ) );
-        reportTable.setOrganisationUnitGroups( organisationUnitGroupService.getOrganisationUnitGroupsByUid( getUids( reportTable.getOrganisationUnitGroups() ) ) );
-
-        if ( reportTable.getUser() != null )
-        {
-            reportTable.setUser( userService.getUser( reportTable.getUser().getUid() ) );
+        dimensionService.mergeAnalyticalObject( reportTable );
+        
+        reportTable.getColumnDimensions().clear();
+        reportTable.getRowDimensions().clear();
+        reportTable.getFilterDimensions().clear();
+        
+        for ( DimensionalObject column : reportTable.getColumns() )
+        {
+            reportTable.getColumnDimensions().add( toDimension( column.getDimension() ) );
+        }
+        
+        for ( DimensionalObject row : reportTable.getRows() )
+        {
+            reportTable.getRowDimensions().add( toDimension( row.getDimension() ) );
+        }
+        
+        for ( DimensionalObject filter : reportTable.getFilters() )
+        {
+            reportTable.getFilterDimensions().add( toDimension( filter.getDimension() ) );
         }
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/tracker/ProgramInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/tracker/ProgramInstanceController.java	2013-05-14 09:56:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/tracker/ProgramInstanceController.java	2013-05-15 15:00:45 +0000
@@ -27,14 +27,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.programdatavalue.ProgramInstance;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.program.ProgramInstanceService;
@@ -49,10 +51,6 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -62,8 +60,6 @@
 {
     public static final String RESOURCE_PATH = "/programInstances";
 
-    private static final Log LOG = LogFactory.getLog( ProgramInstanceController.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -89,13 +85,6 @@
     @Autowired
     private PatientDataValueService patientDataValueService;
 
-    private I18nFormat format;
-
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
     // -------------------------------------------------------------------------
     // Controller
     // -------------------------------------------------------------------------