← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21820: move node metadata generator to export service, also adds support for field filtering pr class (d...

 

------------------------------------------------------------
revno: 21820
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-27 16:06:30 +0700
message:
  move node metadata generator to export service, also adds support for field filtering pr class (default is still :owner)
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
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataExportController.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-01-27 07:34:02 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-01-27 09:06:30 +0000
@@ -31,6 +31,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.fieldfilter.FieldFilterService;
+import org.hisp.dhis.node.NodeUtils;
+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.QueryService;
 import org.hisp.dhis.schema.Schema;
@@ -60,6 +64,9 @@
     private QueryService queryService;
 
     @Autowired
+    private FieldFilterService fieldFilterService;
+
+    @Autowired
     private CurrentUserService currentUserService;
 
     @Override
@@ -82,7 +89,7 @@
         {
             Query query;
 
-            if ( params.hasQuery( klass ) )
+            if ( params.getQuery( klass ) != null )
             {
                 query = params.getQuery( klass );
             }
@@ -108,6 +115,22 @@
     }
 
     @Override
+    public RootNode getMetadataAsNode( MetadataExportParams params )
+    {
+        RootNode rootNode = NodeUtils.createMetadata();
+        rootNode.addChild( new SimpleNode( "date", new Date(), true ) );
+
+        Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = getMetadata( params );
+
+        for ( Class<? extends IdentifiableObject> klass : metadata.keySet() )
+        {
+            rootNode.addChild( fieldFilterService.filter( klass, metadata.get( klass ), params.getFields( klass ) ) );
+        }
+
+        return rootNode;
+    }
+
+    @Override
     public void validate( MetadataExportParams params ) throws MetadataExportException
     {
 

=== 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-01-27 03:17:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportParams.java	2016-01-27 09:06:30 +0000
@@ -28,11 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.query.Query;
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -45,6 +47,10 @@
 
     private Map<Class<? extends IdentifiableObject>, Query> queries = new HashMap<>();
 
+    private Map<Class<? extends IdentifiableObject>, List<String>> fields = new HashMap<>();
+
+    private static final List<String> defaultFields = Lists.newArrayList( ":owner" );
+
     public MetadataExportParams()
     {
     }
@@ -80,13 +86,25 @@
         return this;
     }
 
-    public boolean hasQuery( Class<? extends IdentifiableObject> klass )
-    {
-        return queries.containsKey( klass );
-    }
-
     public Query getQuery( Class<? extends IdentifiableObject> klass )
     {
-        return queries.containsKey( klass ) ? queries.get( klass ) : null;
+        return queries.get( klass );
+    }
+
+    public MetadataExportParams addFields( Class<? extends IdentifiableObject> klass, List<String> classFields )
+    {
+        if ( !fields.containsKey( klass ) )
+        {
+            fields.put( klass, classFields );
+        }
+
+        fields.get( klass ).addAll( classFields );
+        return this;
+    }
+
+    public List<String> getFields( Class<? extends IdentifiableObject> klass )
+    {
+        List<String> strings = fields.get( klass );
+        return strings != null ? strings : defaultFields;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportService.java	2016-01-27 07:18:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportService.java	2016-01-27 09:06:30 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.node.types.RootNode;
 
 import java.util.List;
 import java.util.Map;
@@ -40,6 +41,8 @@
 {
     Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> getMetadata( MetadataExportParams params );
 
+    RootNode getMetadataAsNode( MetadataExportParams params );
+
     void validate( MetadataExportParams params ) throws MetadataExportException;
 
     MetadataExportParams getParamsFromMap( Map<String, String> parameters );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataExportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataExportController.java	2016-01-27 07:18:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetadataExportController.java	2016-01-27 09:06:30 +0000
@@ -28,17 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.collect.Lists;
-import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dxf2.metadata2.MetadataExportParams;
 import org.hisp.dhis.dxf2.metadata2.MetadataExportService;
-import org.hisp.dhis.fieldfilter.DefaultFieldFilterService;
-import org.hisp.dhis.node.NodeUtils;
-import org.hisp.dhis.node.types.CollectionNode;
 import org.hisp.dhis.node.types.RootNode;
-import org.hisp.dhis.node.types.SimpleNode;
-import org.hisp.dhis.schema.Schema;
-import org.hisp.dhis.schema.SchemaService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -46,8 +38,6 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.util.Date;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -60,29 +50,10 @@
     @Autowired
     private MetadataExportService metadataExportService;
 
-    @Autowired
-    private SchemaService schemaService;
-
-    @Autowired
-    private DefaultFieldFilterService fieldFilterService;
-
     @RequestMapping( value = "", method = RequestMethod.GET )
     public @ResponseBody RootNode getMetadata( @RequestParam Map<String, String> rpParameters )
     {
-        RootNode rootNode = NodeUtils.createMetadata();
-        rootNode.addChild( new SimpleNode( "date", new Date(), true ) );
-
         MetadataExportParams params = metadataExportService.getParamsFromMap( rpParameters );
-
-        Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata( params );
-
-        for ( Class<? extends IdentifiableObject> klass : metadata.keySet() )
-        {
-            Schema schema = schemaService.getDynamicSchema( klass );
-            CollectionNode collectionNode = fieldFilterService.filter( klass, metadata.get( klass ), Lists.newArrayList( ":owner" ) );
-            rootNode.addChild( collectionNode );
-        }
-
-        return rootNode;
+        return metadataExportService.getMetadataAsNode( params );
     }
 }