← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21861: support default fields, filter, order in metadata export /api/metadata/export

 

------------------------------------------------------------
revno: 21861
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-03 14:29:14 +0700
message:
  support default fields, filter, order in metadata export /api/metadata/export
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportParams.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/metadata2/DefaultMetadataExportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-02-03 06:57:11 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-02-03 07:29:14 +0000
@@ -38,7 +38,6 @@
 import org.hisp.dhis.node.types.RootNode;
 import org.hisp.dhis.node.types.SimpleNode;
 import org.hisp.dhis.query.Query;
-import org.hisp.dhis.query.QueryParserException;
 import org.hisp.dhis.query.QueryService;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
@@ -99,8 +98,10 @@
             }
             else
             {
-                Schema schema = schemaService.getDynamicSchema( klass );
-                query = Query.from( schema );
+                OrderParams orderParams = new OrderParams();
+                orderParams.setOrder( Sets.newHashSet( params.getDefaultOrder() ) );
+                query = queryService.getQueryFromUrl( klass, params.getDefaultFilter(), orderParams.getOrders( schemaService.getDynamicSchema( klass ) ) );
+                query.setDefaultOrder();
             }
 
             if ( query.getUser() == null )
@@ -147,6 +148,24 @@
         MetadataExportParams params = new MetadataExportParams();
         Map<Class<? extends IdentifiableObject>, Map<String, List<String>>> map = new HashMap<>();
 
+        if ( parameters.containsKey( "fields" ) )
+        {
+            params.setDefaultFields( parameters.get( "fields" ) );
+            parameters.remove( "fields" );
+        }
+
+        if ( parameters.containsKey( "filter" ) )
+        {
+            params.setDefaultFilter( parameters.get( "filter" ) );
+            parameters.remove( "filter" );
+        }
+
+        if ( parameters.containsKey( "order" ) )
+        {
+            params.setDefaultOrder( parameters.get( "order" ) );
+            parameters.remove( "order" );
+        }
+
         for ( String parameterKey : parameters.keySet() )
         {
             String[] parameter = parameterKey.split( ":" );
@@ -170,22 +189,25 @@
                 continue;
             }
 
-            if ( "fields".equalsIgnoreCase( parameter[1] ) )
-            {
-                if ( !map.get( klass ).containsKey( "fields" ) ) map.get( klass ).put( "fields", new ArrayList<>() );
-                map.get( klass ).get( "fields" ).addAll( parameters.get( parameterKey ) );
-            }
-
-            if ( "filter".equalsIgnoreCase( parameter[1] ) )
-            {
-                if ( !map.get( klass ).containsKey( "filter" ) ) map.get( klass ).put( "filter", new ArrayList<>() );
-                map.get( klass ).get( "filter" ).addAll( parameters.get( parameterKey ) );
-            }
-
-            if ( "order".equalsIgnoreCase( parameter[1] ) )
-            {
-                if ( !map.get( klass ).containsKey( "order" ) ) map.get( klass ).put( "order", new ArrayList<>() );
-                map.get( klass ).get( "order" ).addAll( parameters.get( parameterKey ) );
+            if ( parameter.length > 1 )
+            {
+                if ( "fields".equalsIgnoreCase( parameter[1] ) )
+                {
+                    if ( !map.get( klass ).containsKey( "fields" ) ) map.get( klass ).put( "fields", new ArrayList<>() );
+                    map.get( klass ).get( "fields" ).addAll( parameters.get( parameterKey ) );
+                }
+
+                if ( "filter".equalsIgnoreCase( parameter[1] ) )
+                {
+                    if ( !map.get( klass ).containsKey( "filter" ) ) map.get( klass ).put( "filter", new ArrayList<>() );
+                    map.get( klass ).get( "filter" ).addAll( parameters.get( parameterKey ) );
+                }
+
+                if ( "order".equalsIgnoreCase( parameter[1] ) )
+                {
+                    if ( !map.get( klass ).containsKey( "order" ) ) map.get( klass ).put( "order", new ArrayList<>() );
+                    map.get( klass ).get( "order" ).addAll( parameters.get( parameterKey ) );
+                }
             }
         }
 
@@ -204,11 +226,13 @@
                 orderParams.setOrder( Sets.newHashSet( classMap.get( "order" ) ) );
 
                 Query query = queryService.getQueryFromUrl( klass, classMap.get( "filter" ), orderParams.getOrders( schema ) );
+                query.setDefaultOrder();
                 params.addQuery( query );
             }
             else if ( classMap.containsKey( "filter" ) )
             {
                 Query query = queryService.getQueryFromUrl( klass, classMap.get( "filter" ), new ArrayList<>() );
+                query.setDefaultOrder();
                 params.addQuery( query );
             }
             else if ( classMap.containsKey( "order" ) )
@@ -217,6 +241,7 @@
                 orderParams.setOrder( Sets.newHashSet( classMap.get( "order" ) ) );
 
                 Query query = queryService.getQueryFromUrl( klass, new ArrayList<>(), orderParams.getOrders( schema ) );
+                query.setDefaultOrder();
                 params.addQuery( query );
             }
         }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportParams.java	2016-02-03 06:57:11 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportParams.java	2016-02-03 07:29:14 +0000
@@ -53,7 +53,11 @@
 
     private Map<Class<? extends IdentifiableObject>, List<String>> fields = new HashMap<>();
 
-    private static final List<String> defaultFields = Lists.newArrayList( ":owner" );
+    private List<String> defaultFields = Lists.newArrayList( ":owner" );
+
+    private List<String> defaultFilter = new ArrayList<>();
+
+    private List<String> defaultOrder = new ArrayList<>();
 
     public MetadataExportParams()
     {
@@ -118,4 +122,34 @@
         List<String> strings = fields.get( klass );
         return strings != null ? strings : defaultFields;
     }
+
+    public List<String> getDefaultFields()
+    {
+        return defaultFields;
+    }
+
+    public void setDefaultFields( List<String> defaultFields )
+    {
+        this.defaultFields = defaultFields;
+    }
+
+    public List<String> getDefaultFilter()
+    {
+        return defaultFilter;
+    }
+
+    public void setDefaultFilter( List<String> filter )
+    {
+        this.defaultFilter = filter;
+    }
+
+    public List<String> getDefaultOrder()
+    {
+        return defaultOrder;
+    }
+
+    public void setDefaultOrder( List<String> defaultOrder )
+    {
+        this.defaultOrder = defaultOrder;
+    }
 }