← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16132: Event charts, impl pretty print of filters for use in titles

 

------------------------------------------------------------
revno: 16132
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-07-15 15:54:20 +0200
message:
  Event charts, impl pretty print of filters for use in titles
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryOperator.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AccountController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.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/chart/BaseChart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java	2014-07-15 13:54:20 +0000
@@ -28,13 +28,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.apache.commons.lang.StringUtils.join;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.AnalyticsType;
 import org.hisp.dhis.common.BaseAnalyticalObject;
 import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.DimensionalObjectUtils;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -73,7 +75,7 @@
     public static final String TYPE_AREA = "area";
     public static final String TYPE_PIE = "pie";
     public static final String TYPE_RADAR = "radar";
-
+    
     protected String domainAxisLabel;
 
     protected String rangeAxisLabel;
@@ -161,10 +163,10 @@
         return baseLineValue != null;
     }
 
-    public List<NameableObject> getFilterItems()
+    public String generateTitle()
     {
-        List<NameableObject> filterItems = new ArrayList<NameableObject>();
-
+        List<String> titleItems = new ArrayList<>();
+        
         for ( String filter : filterDimensions )
         {
             DimensionalObject object = getDimensionalObject( filter, relativePeriodDate, user, true,
@@ -172,16 +174,22 @@
 
             if ( object != null )
             {
-                filterItems.addAll( object.getItems() );
+                String item = IdentifiableObjectUtils.join( object.getItems() );
+                String filt = DimensionalObjectUtils.getPrettyFilter( object.getFilter() );
+                
+                if ( item != null )
+                {
+                    titleItems.add( item );
+                }
+                
+                if ( filt != null )
+                {
+                    titleItems.add( filt );
+                }
             }
         }
-
-        return filterItems;
-    }
-
-    public String generateTitle()
-    {
-        return StringUtils.defaultIfBlank( IdentifiableObjectUtils.join( getFilterItems() ), StringUtils.EMPTY );
+        
+        return join( titleItems, DimensionalObjectUtils.TITLE_ITEM_SEP );
     }
     
     public boolean isAnalyticsType( AnalyticsType type )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2014-07-13 13:53:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionalObjectUtils.java	2014-07-15 13:54:20 +0000
@@ -40,6 +40,8 @@
 import java.util.Set;
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang.StringUtils;
+
 /**
  * @author Lars Helge Overland
  */
@@ -50,6 +52,8 @@
     public static final String ITEM_SEP = "-";
     
     private static final Pattern INT_PATTERN = Pattern.compile( "^(0|-?[1-9]\\d*)$" );
+
+    public static final String TITLE_ITEM_SEP = ", ";
     
     /**
      * Converts a concrete dimensional class identifier to a dimension identifier.
@@ -294,4 +298,45 @@
         List<NameableObject> items = NameableObjectUtils.getNameableObjects( values );
         dim.setItems( items );
     }
+    
+    /**
+     * Accepts filter strings on the format:
+     * </p>
+     * <code>operator:filter:operator:filter</code>
+     * </p>
+     * and returns a pretty print version on the format:
+     * </p>
+     * <code>operator filter, operator filter</code>
+     * 
+     * @param filter the filter.
+     * @return a pretty print version of the filter.
+     */
+    public static String getPrettyFilter( String filter )
+    {
+        if ( filter == null || !filter.contains( DIMENSION_NAME_SEP ) )
+        {
+            return null;
+        }
+        
+        List<String> filterItems = new ArrayList<>();
+        
+        String[] split = filter.split( DIMENSION_NAME_SEP );
+
+        for ( int i = 0; i < split.length; i += 2 )
+        {
+            QueryOperator operator = QueryOperator.fromString( split[i] );
+            String value = split[i+1];
+            
+            if ( operator != null )
+            {
+                boolean ignoreOperator = ( QueryOperator.LIKE.equals( operator ) || QueryOperator.IN.equals( operator ) );
+                
+                value = value.replaceAll( QueryFilter.OPTION_SEP, TITLE_ITEM_SEP );
+                
+                filterItems.add( ( ignoreOperator ? StringUtils.EMPTY : ( operator.getValue() + " " ) ) + value );
+            }
+        }
+        
+        return StringUtils.join( filterItems, TITLE_ITEM_SEP );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IllegalQueryException.java	2014-07-15 13:54:20 +0000
@@ -38,4 +38,9 @@
     {
         super( message );
     }
+    
+    public IllegalQueryException( String message, Throwable throwable) 
+    {
+        super( message, throwable );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java	2014-06-14 17:58:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryFilter.java	2014-07-15 13:54:20 +0000
@@ -118,7 +118,7 @@
         
         return "'" + encodedFilter + "'";
     }
-
+    
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryOperator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryOperator.java	2014-06-27 10:12:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/QueryOperator.java	2014-07-15 13:54:20 +0000
@@ -33,7 +33,14 @@
  */
 public enum QueryOperator
 {
-    EQ, GT, GE, LT, LE, NE, LIKE, IN;
+    EQ( "=" ), GT( ">" ), GE( ">=" ), LT( "<" ), LE( "<=" ), NE( "!=" ), LIKE( "like" ), IN( "in" );
+    
+    private final String value;
+    
+    private QueryOperator( String value )
+    {
+        this.value = value;
+    }    
     
     public static final QueryOperator fromString( String string )
     {
@@ -44,4 +51,9 @@
         
         return valueOf( string.toUpperCase() );
     }
+    
+    public String getValue()
+    {
+        return value;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AccountController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AccountController.java	2014-05-22 12:40:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AccountController.java	2014-07-15 13:54:20 +0000
@@ -217,8 +217,6 @@
 
         boolean invitedByEmail = ( inviteUsername != null && !inviteUsername.isEmpty() );
 
-        log.info( "AccountController: inviteUsername = " + inviteUsername );
-
         boolean canChooseUsername = true;
 
         if ( invitedByEmail )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2014-07-10 10:27:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2014-07-15 13:54:20 +0000
@@ -81,8 +81,14 @@
         return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
     }
 
-    @ExceptionHandler( { IllegalQueryException.class, IllegalArgumentException.class } )
-    public ResponseEntity<String> illegalQueryArgumentExceptionHandler( IllegalQueryException ex )
+    @ExceptionHandler( IllegalQueryException.class )
+    public ResponseEntity<String> illegalQueryExceptionHandler( IllegalQueryException ex )
+    {
+        return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
+    }
+
+    @ExceptionHandler( IllegalArgumentException.class )
+    public ResponseEntity<String> illegalArgumentExceptionHandler( IllegalArgumentException ex )
     {
         return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
     }