← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10105: Analytics, impl support for specifying the authenticated users org unit or org unit children for ...

 

------------------------------------------------------------
revno: 10105
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-03-09 15:35:08 +0100
message:
  Analytics, impl support for specifying the authenticated users org unit or org unit children for ou dimension
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.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/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2013-03-09 14:12:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2013-03-09 14:35:08 +0000
@@ -76,8 +76,6 @@
     public static final String KEY_USER_ORGUNIT = "USER_ORGUNIT";
     public static final String KEY_USER_ORGUNIT_CHILDREN = "USER_ORGUNIT_CHILDREN";
     
-    public static final List<String> USER_KEYS = Arrays.asList( KEY_USER_ORGUNIT, KEY_USER_ORGUNIT_CHILDREN );
-
     private static final List<String> FEATURETYPES = Arrays.asList( FEATURETYPE_NONE, FEATURETYPE_MULTIPOLYGON, FEATURETYPE_POLYGON, FEATURETYPE_POINT );
 
     private static final Comparator<IdentifiableObject> COMPARATOR = new IdentifiableObjectNameComparator();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2013-03-09 14:12:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java	2013-03-09 14:35:08 +0000
@@ -34,7 +34,7 @@
 
 public class SMSCommand
 {
-    private int id; // id for this element
+    private int id;
 
     private String name;
 
@@ -52,8 +52,7 @@
 
     private String defaultMessage;
 
-    private boolean currentPeriodUsedForReporting = false; // default is
-                                                           // previous
+    private boolean currentPeriodUsedForReporting = false; // default is prev
 
     public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset,
         Set<SMSCode> codes, String codeSeparator, String defaultMessage )

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-03-08 10:17:23 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-03-09 14:35:08 +0000
@@ -43,6 +43,7 @@
 import static org.hisp.dhis.analytics.DataQueryParams.getDimensionItemsFromParam;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.asList;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.asTypedList;
+import static org.hisp.dhis.organisationunit.OrganisationUnit.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -83,6 +84,7 @@
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -98,6 +100,8 @@
 import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.system.util.Timer;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 
 public class DefaultAnalyticsService
@@ -142,6 +146,9 @@
     
     @Autowired
     private ConstantService constantService;
+    
+    @Autowired
+    private CurrentUserService currentUserService;
 
     // -------------------------------------------------------------------------
     // Implementation
@@ -510,9 +517,32 @@
         
         if ( ORGUNIT_DIM_ID.equals( dimension ) )
         {
-            List<IdentifiableObject> ous = asList( organisationUnitService.getOrganisationUnitsByUid( options ) );
-            
-            if ( ous == null || ous.isEmpty() )
+            User user = currentUserService.getCurrentUser();
+            
+            List<IdentifiableObject> ous = new ArrayList<IdentifiableObject>();
+            
+            for ( String ou : options )
+            {
+                if ( KEY_USER_ORGUNIT.equals( ou ) && user != null && user.getOrganisationUnit() != null )
+                {
+                    ous.add( user.getOrganisationUnit() );
+                }
+                else if ( KEY_USER_ORGUNIT_CHILDREN.equals( ou ) && user != null && user.getOrganisationUnit() != null )
+                {
+                    ous.addAll( user.getOrganisationUnit().getSortedChildren() );
+                }
+                else
+                {
+                    OrganisationUnit unit = organisationUnitService.getOrganisationUnit( ou );
+                    
+                    if ( unit != null )
+                    {
+                        ous.add( unit );
+                    }
+                }
+            }
+            
+            if ( ous.isEmpty() )
             {
                 throw new IllegalQueryException( "Dimension ou is present in query without any valid dimension options" );
             }
@@ -524,22 +554,22 @@
         {
             List<Period> periods = new ArrayList<Period>();
             
-            periods : for ( String isoPeriod : options )
+            for ( String isoPeriod : options )
             {
-                Period period = PeriodType.getPeriodFromIsoString( isoPeriod );
-                
-                if ( period != null )
-                {
-                    period.setName( format != null ? format.formatPeriod( period ) : null );
-                    periods.add( period );
-                    continue periods;
-                }
-                
                 if ( RelativePeriodEnum.contains( isoPeriod ) )
                 {
                     RelativePeriodEnum relativePeriod = RelativePeriodEnum.valueOf( isoPeriod );
                     periods.addAll( RelativePeriods.getRelativePeriodsFromEnum( relativePeriod, format, true ) );
-                    continue periods;
+                }
+                else
+                {
+                    Period period = PeriodType.getPeriodFromIsoString( isoPeriod );
+                
+                    if ( period != null )
+                    {
+                        period.setName( format != null ? format.formatPeriod( period ) : null );
+                        periods.add( period );
+                    }
                 }
             }
             

=== 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-03-08 15:40:04 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-03-09 14:35:08 +0000
@@ -49,7 +49,6 @@
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.i18n.I18nManager;
-import org.hisp.dhis.i18n.I18nManagerException;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;