← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16336: Options, javadocs. OrganisationUnitController, added method for getting org units at level relati...

 

------------------------------------------------------------
revno: 16336
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-08-07 11:15:03 +0200
message:
  Options, javadocs. OrganisationUnitController, added method for getting org units at level relative to an org unit.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js


--
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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java	2014-08-06 11:25:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java	2014-08-07 09:15:03 +0000
@@ -34,8 +34,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.hisp.dhis.system.util.TextUtils;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -98,30 +96,12 @@
 
         return null;
     }
-
-    protected static boolean stringAsBoolean( String str )
-    {
-        return stringAsBoolean( str, false );
-    }
-
+    
     protected static boolean stringAsBoolean( String str, boolean defaultValue )
     {
-        if ( str != null )
-        {
-            if ( str.equalsIgnoreCase( "true" ) )
-            {
-                return true;
-            }
-            else if ( str.equalsIgnoreCase( "false" ) )
-            {
-                return false;
-            }
-        }
-
-        return defaultValue;
+        return str != null ? Boolean.parseBoolean( str ) : defaultValue;
     }
 
-
     protected static int stringAsInt( String str )
     {
         return stringAsInt( str, 0 );
@@ -143,11 +123,6 @@
         return defaultValue;
     }
 
-    protected static boolean stringIsTrue( String str )
-    {
-        return stringAsBoolean( str );
-    }
-
     //--------------------------------------------------------------------------
     // Internal State
     //--------------------------------------------------------------------------
@@ -174,52 +149,70 @@
     // Get options for classes/strings etc
     //--------------------------------------------------------------------------
 
+    /**
+     * Indicates whether the given object type is enabled. Takes the assumeTrue 
+     * parameter into account.
+     */
     public boolean isEnabled( String type )
     {
         String enabled = options.get( type );
 
-        return stringIsTrue( enabled ) || ( enabled == null && assumeTrue );
+        return isTrue( enabled ) || ( enabled == null && assumeTrue );
     }
 
+    /**
+     * Indicates whether the given object type is disabled. Takes the assumeTrue 
+     * parameter into account.
+     */
     public boolean isDisabled( String type )
     {
         return !isEnabled( type );
     }
 
-    public boolean booleanTrue( String key )
-    {
-        return booleanTrue( key, false );
-    }
-
-    public boolean booleanTrue( String key, boolean defaultValue )
-    {
-        String value = options.get( key );
-        return stringAsBoolean( value, defaultValue );
-    }
-
     public Date getDate( String key )
     {
         return stringAsDate( options.get( key ) );
     }
     
-    public boolean contains( String type )
-    {
-        return options.containsKey( type );
-    }
-    
-    public String get( String type )
-    {
-        return options.get( type );
-    }
-    
-    public Integer getInt( String type )
-    {
-        return options.get( type ) != null ? Integer.parseInt( options.get( type ) ) : null;
-    }
-    
-    public boolean isTrue( String type )
-    {
-        return options.get( type ) != null && Boolean.parseBoolean( options.get( type ) );
+    /**
+     * Indicates whether the options contains the given parameter key.
+     */
+    public boolean contains( String key )
+    {
+        return options.containsKey( key );
+    }
+
+    /**
+     * Indicates whether the options contains a non-null option value for the given 
+     * parameter key.
+     */
+    public boolean containsValue( String key )
+    {
+        return options.get( key ) != null;
+    }
+    
+    /**
+     * Returns the option value for the given parameter key.
+     */
+    public String get( String key )
+    {
+        return options.get( key );
+    }
+
+    /**
+     * Returns the option value for the given parameter key as in Integer.
+     */
+    public Integer getInt( String key )
+    {
+        return options.get( key ) != null ? Integer.parseInt( options.get( key ) ) : null;
+    }
+    
+    /**
+     * Indicates whether the option value for the parameter key is true.
+     */
+    public boolean isTrue( String key )
+    {
+        return options.get( key ) != null && Boolean.parseBoolean( options.get( key ) );
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-07-30 09:46:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-08-07 09:15:03 +0000
@@ -295,7 +295,7 @@
 
         CollectionNode collectionNode = fieldFilterService.filter( getEntityClass(), entities, fields );
 
-        if ( options.booleanTrue( "useWrapper" ) || entities.size() > 1 )
+        if ( options.isTrue( "useWrapper" ) || entities.size() > 1 )
         {
             RootNode rootNode = new RootNode( "metadata" );
             rootNode.setDefaultNamespace( DxfNamespaces.DXF_2_0 );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2014-08-06 11:28:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2014-08-07 09:15:03 +0000
@@ -162,13 +162,13 @@
     {
         OrganisationUnit organisationUnit = manager.get( getEntityClass(), uid );
 
+        List<OrganisationUnit> organisationUnits = Lists.newArrayList();
+
         if ( organisationUnit == null )
         {
-            return Lists.newArrayList();
+            return organisationUnits;
         }
 
-        List<OrganisationUnit> organisationUnits = Lists.newArrayList();
-
         if ( options.contains( "includeChildren" ) )
         {
             options.getOptions().put( "useWrapper", "true" );
@@ -180,6 +180,14 @@
             options.getOptions().put( "useWrapper", "true" );
             organisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( uid ) );
         }
+        else if ( options.contains( "level" ) )
+        {
+            options.getOptions().put( "useWrapper", "true" );
+            int level = options.getInt( "level" );
+            int ouLevel = organisationUnitService.getLevelOfOrganisationUnit( organisationUnit.getId() );
+            int targetLevel = ouLevel + level;
+            organisationUnits.addAll( organisationUnitService.getOrganisationUnitsAtLevel( targetLevel, organisationUnit ) );
+        }
         else
         {
             organisationUnits.add( organisationUnit );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-08-06 19:15:50 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-08-07 09:15:03 +0000
@@ -100,10 +100,10 @@
 
 dhis2.de.event.formLoaded = "dhis2.de.event.formLoaded";
 dhis2.de.event.dataValuesLoaded = "dhis2.de.event.dataValuesLoaded";
+dhis2.de.event.formReady = "dhis2.de.event.formReady";
 dhis2.de.event.dataValueSaved = "dhis2.de.event.dataValueSaved";
 dhis2.de.event.completed = "dhis2.de.event.completed";
 dhis2.de.event.uncompleted = "dhis2.de.event.uncompleted";
-dhis2.de.event.formReady = "dhis2.de.event.formReady";
 
 /**
  * Convenience method to be used from inside custom forms. When a function is