← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16329: Options / OrganisationUnitControlller, raised the abstraction level and cetnralized some code

 

------------------------------------------------------------
revno: 16329
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-08-06 13:11:12 +0200
message:
  Options / OrganisationUnitControlller, raised the abstraction level and cetnralized some code
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.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-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-06-06 07:40:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java	2014-08-06 11:11:12 +0000
@@ -34,6 +34,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.hisp.dhis.system.util.TextUtils;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -141,7 +143,7 @@
         return defaultValue;
     }
 
-    protected static boolean isTrue( String str )
+    protected static boolean stringIsTrue( String str )
     {
         return stringAsBoolean( str );
     }
@@ -176,7 +178,7 @@
     {
         String enabled = options.get( type );
 
-        return isTrue( enabled ) || enabled == null && assumeTrue;
+        return stringIsTrue( enabled ) || ( enabled == null && assumeTrue );
     }
 
     public boolean isDisabled( String type )
@@ -199,6 +201,21 @@
     {
         return stringAsDate( options.get( key ) );
     }
+    
+    public boolean contains( String type )
+    {
+        return options.containsKey( type );
+    }
+    
+    public String get( String type )
+    {
+        return options.get( type );
+    }
+    
+    public boolean isTrue( String type )
+    {
+        return options.containsKey( type ) && TextUtils.TRUE.equalsIgnoreCase( options.get( type ) );
+    }
 
     //--------------------------------------------------------------------------
     // Getters and Setters
@@ -246,5 +263,4 @@
     {
         options.putAll( options );
     }
-
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2014-04-10 14:52:30 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2014-08-06 11:11:12 +0000
@@ -45,6 +45,7 @@
     public static final TextUtils INSTANCE = new TextUtils();
     public static final String EMPTY = "";
     public static final String SPACE = "";
+    public static final String TRUE = "true";
     public static final String LN = System.getProperty( "line.separator" );
     
     private static final Pattern LINK_PATTERN = Pattern.compile( "((http://|https://|www\\.).+?)($|\\n|\\r|\\r\\n| )" );

=== 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-06-11 20:27:54 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/organisationunit/OrganisationUnitController.java	2014-08-06 11:11:12 +0000
@@ -66,20 +66,20 @@
     {
         List<OrganisationUnit> entityList;
 
-        boolean levelSorted = options.getOptions().containsKey( "levelSorted" ) && Boolean.parseBoolean( options.getOptions().get( "levelSorted" ) );
+        boolean levelSorted = options.contains( "levelSorted" ) && Boolean.parseBoolean( options.get( "levelSorted" ) );
 
         Integer level = null;
 
         Integer maxLevel = null;
 
-        if ( options.getOptions().containsKey( "level" ) )
+        if ( options.contains( "level" ) )
         {
-            level = Integer.parseInt( options.getOptions().get( "level" ) );
+            level = Integer.parseInt( options.get( "level" ) );
         }
 
-        if ( options.getOptions().containsKey( "maxLevel" ) )
+        if ( options.contains( "maxLevel" ) )
         {
-            maxLevel = Integer.parseInt( options.getOptions().get( "maxLevel" ) );
+            maxLevel = Integer.parseInt( options.get( "maxLevel" ) );
 
             if ( organisationUnitService.getOrganisationUnitLevelByLevel( maxLevel ) == null )
             {
@@ -92,15 +92,15 @@
             }
         }
 
-        if ( "true".equals( options.getOptions().get( "userOnly" ) ) )
+        if ( options.isTrue( "userOnly" ) )
         {
             entityList = new ArrayList<>( currentUserService.getCurrentUser().getOrganisationUnits() );
         }
-        else if ( "true".equals( options.getOptions().get( "userDataViewOnly" ) ) )
+        else if ( options.isTrue( "userDataViewOnly" ) )
         {
             entityList = new ArrayList<>( currentUserService.getCurrentUser().getDataViewOrganisationUnits() );
         }
-        else if ( "true".equals( options.getOptions().get( "userDataViewFallback" ) ) )
+        else if ( options.isTrue( "userDataViewFallback" ) )
         {
             User user = currentUserService.getCurrentUser();
 
@@ -113,9 +113,9 @@
                 entityList = new ArrayList<>( organisationUnitService.getOrganisationUnitsAtLevel( 1 ) );
             }
         }
-        else if ( options.getOptions().containsKey( "query" ) )
+        else if ( options.contains( "query" ) )
         {
-            entityList = new ArrayList<>( manager.filter( getEntityClass(), options.getOptions().get( "query" ) ) );
+            entityList = new ArrayList<>( manager.filter( getEntityClass(), options.get( "query" ) ) );
 
             if ( levelSorted )
             {