← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6935: Impl dynamic data for report table resource in web api

 

------------------------------------------------------------
revno: 6935
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-05-14 20:21:39 +0200
message:
  Impl dynamic data for report table resource in web api
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.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/resources/templates/html/reportTable.xsl


--
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/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2012-04-23 09:35:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2012-05-14 18:21:39 +0000
@@ -118,6 +118,17 @@
     Grid getReportTableGrid( int id, I18nFormat format, Date reportingPeriod, Integer organisationUnitId );
 
     /**
+     *
+     * 
+     * @param reportTable
+     * @param format
+     * @param reportingPeriod
+     * @param organisationUnitUid
+     * @return
+     */
+    Grid getReportTableGrid( ReportTable reportTable, I18nFormat format, Date reportingPeriod, String organisationUnitUid );
+    
+    /**
      * Instantiates and populates a Grid populated with data from the ReportTable
      * with the given identifier.
      *

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2012-05-13 20:01:48 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2012-05-14 18:21:39 +0000
@@ -144,6 +144,17 @@
         return getGrid( reportTable );
     }
 
+    public Grid getReportTableGrid( ReportTable reportTable, I18nFormat format, Date reportingPeriod, String organisationUnitUid )
+    {
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
+
+        Integer organisationUnitId = organisationUnit != null ? organisationUnit.getId() : null;
+        
+        reportTable = initDynamicMetaObjects( reportTable, reportingPeriod, organisationUnitId, format );
+
+        return getGrid( reportTable );
+    }
+    
     public ReportTable getReportTable( String uid, String mode )
     {
         if ( mode.equals( MODE_REPORT_TABLE ) )

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2012-05-10 18:47:10 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2012-05-14 18:21:39 +0000
@@ -319,13 +319,16 @@
     {
         List<T> list = new ArrayList<T>();
         
-        for ( String uid : uids )
+        if ( uids != null )
         {
-            T object = getByUid( uid );
-            
-            if ( object != null )
+            for ( String uid : uids )
             {
-                list.add( object );
+                T object = getByUid( uid );
+                
+                if ( object != null )
+                {
+                    list.add( object );
+                }
             }
         }
         

=== 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	2012-05-11 19:04:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2012-05-14 18:21:39 +0000
@@ -44,9 +44,15 @@
 import org.hisp.dhis.api.utils.WebLinkPopulator;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
 import org.hisp.dhis.reporttable.ReportTables;
@@ -81,6 +87,12 @@
     private OrganisationUnitService organisationUnitService;
 
     @Autowired
+    private IndicatorService indicatorService;
+    
+    @Autowired
+    private DataElementService dataElementService;
+    
+    @Autowired
     private I18nManager i18nManager;
 
     @Autowired
@@ -140,6 +152,64 @@
         return "reportTable";
     }
 
+    @RequestMapping( value = "/data", method = RequestMethod.GET )
+    public String getReportTableDynamicData( @RequestParam(required=false, value="in") List<String> indicators,
+                                             @RequestParam(required=false, value="de") List<String> dataElements,
+                                             @RequestParam(value="ou") List<String> orgUnits,
+                                             @RequestParam(required=false) List<String> crossTab,
+                                             @RequestParam(required=false) boolean orgUnitIsParent,
+                                             RelativePeriods relatives,
+                                             Model model, 
+                                             HttpServletResponse response ) throws Exception
+    {
+        List<Indicator> indicators_ = indicatorService.getIndicatorsByUid( indicators );
+        List<DataElement> dataElements_ = dataElementService.getDataElementsByUid( dataElements );
+        List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsByUid( orgUnits );
+        
+        if ( indicators_.isEmpty() && dataElements_.isEmpty() )
+        {
+            ContextUtils.conflictResponse( response, "No indicators or data elements specified" );
+            return null;
+        }
+        
+        if ( orgUnitIsParent )
+        {
+            List<OrganisationUnit> childUnits = new ArrayList<OrganisationUnit>();
+            
+            for ( OrganisationUnit unit : organisationUnits )
+            {
+                childUnits.addAll( unit.getChildren() );
+            }
+            
+            organisationUnits = childUnits;
+        }
+        
+        if ( organisationUnits.isEmpty() )
+        {
+            ContextUtils.conflictResponse( response, "No valid organisation units specified" );
+            return null;
+        }
+        
+        ReportTable table = new ReportTable();
+        
+        table.setIndicators( indicators_ );
+        table.setDataElements( dataElements_ );
+        table.setUnits( organisationUnits );
+        
+        table.setDoIndicators( crossTab != null && crossTab.contains( "data" ) );
+        table.setDoPeriods( crossTab != null && crossTab.contains( "periods" ) );
+        table.setDoUnits( crossTab != null && crossTab.contains( "orgunits" ) );
+        
+        table.setRelatives( relatives );
+        
+        Grid grid = reportTableService.getReportTableGrid( table, i18nManager.getI18nFormat(), new Date(), null );
+
+        model.addAttribute( "model", grid );
+        model.addAttribute( "view", "detailed" );
+        
+        return "reportTableData";
+    }
+        
     @RequestMapping( value = "/{uid}/data", method = RequestMethod.GET )
     public String getReportTableData( @PathVariable( "uid" ) String uid, Model model,
                                       @RequestParam( value = "ou", required = false ) String organisationUnitUid,

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl	2012-05-11 19:04:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl	2012-05-14 18:21:39 +0000
@@ -27,7 +27,27 @@
 			<td colspan="4">period yyyy-MM-dd (opt)</td>
 		</tr>
 	  </table><br/>
-	  	  
+	  
+	  
+	  <table>
+		<tr>
+			<td>Dynamic Data</td>
+			<td><a href="data.json">json</a></td>
+		</tr>
+		<tr>
+			<td>in</td>
+			<td>indicator uids</td>
+		</tr>
+		<tr>
+			<td>de</td>
+			<td>data element uids</td>
+		</tr>
+		<tr>
+			<td>ou</td>
+			<td>org unit uids</td>
+		</tr>
+      </table></tr>
+	  
       <table>
         <tr>
           <td>ID</td>