← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21818: Support enable/disable of metadata export type in /api/metadata/export

 

------------------------------------------------------------
revno: 21818
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-27 14:18:12 +0700
message:
  Support enable/disable of metadata export type in /api/metadata/export
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java
  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/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-api/src/main/java/org/hisp/dhis/schema/SchemaService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaService.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaService.java	2016-01-27 07:18:12 +0000
@@ -65,6 +65,15 @@
     Schema getSchemaBySingularName( String name );
 
     /**
+     * Get schema which has been generated by a SchemaDescriptor by singular name.
+     *
+     * @param name Name to get Schema for, will be matched against Schema.getSingular().
+     * @return Schema for class, or null
+     * @see org.hisp.dhis.schema.SchemaDescriptor
+     */
+    Schema getSchemaByPluralName( String name );
+
+    /**
      * Get all available schemas (which are generated with a schema descriptor).
      *
      * @return List of all available schemas

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2016-01-27 07:18:12 +0000
@@ -56,6 +56,8 @@
 
     private Map<String, Schema> singularSchemaMap = new HashMap<>();
 
+    private Map<String, Schema> pluralSchemaMap = new HashMap<>();
+
     private Map<Class<?>, Schema> dynamicClassSchemaMap = new HashMap<>();
 
     @Autowired
@@ -92,6 +94,7 @@
 
             classSchemaMap.put( schema.getKlass(), schema );
             singularSchemaMap.put( schema.getSingular(), schema );
+            pluralSchemaMap.put( schema.getPlural(), schema );
 
             updateSelf( schema );
         }
@@ -173,6 +176,12 @@
     }
 
     @Override
+    public Schema getSchemaByPluralName( String name )
+    {
+        return pluralSchemaMap.get( name );
+    }
+
+    @Override
     public List<Schema> getSchemas()
     {
         return Lists.newArrayList( classSchemaMap.values() );

=== 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 03:17:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/DefaultMetadataExportService.java	2016-01-27 07:18:12 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.query.Query;
 import org.hisp.dhis.query.QueryService;
@@ -36,6 +38,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +49,8 @@
 @Component
 public class DefaultMetadataExportService implements MetadataExportService
 {
+    private static final Log log = LogFactory.getLog( MetadataExportService.class );
+
     @Autowired
     private SchemaService schemaService;
 
@@ -64,6 +69,8 @@
                 .forEach( schema -> params.getClasses().add( (Class<? extends IdentifiableObject>) schema.getKlass() ) );
         }
 
+        log.info( "Export started at " + new Date() );
+
         for ( Class<? extends IdentifiableObject> klass : params.getClasses() )
         {
             Query query;
@@ -79,9 +86,12 @@
             }
 
             List<? extends IdentifiableObject> objects = queryService.query( query );
+            log.info( "Exported " + objects.size() + " objects of type " + klass.getSimpleName() );
             metadata.put( klass, objects );
         }
 
+        log.info( "Export done at " + new Date() );
+
         return metadata;
     }
 
@@ -90,4 +100,23 @@
     {
 
     }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public MetadataExportParams getParamsFromMap( Map<String, String> parameters )
+    {
+        MetadataExportParams params = new MetadataExportParams();
+
+        for ( String p : parameters.keySet() )
+        {
+            Schema schema = schemaService.getSchemaByPluralName( p );
+
+            if ( schema != null && schema.isIdentifiableObject() && "true".equalsIgnoreCase( parameters.get( p ) ) )
+            {
+                params.addClass( (Class<? extends IdentifiableObject>) schema.getKlass() );
+            }
+        }
+
+        return params;
+    }
 }

=== 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-25 08:31:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/MetadataExportService.java	2016-01-27 07:18:12 +0000
@@ -41,4 +41,6 @@
     Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> getMetadata( 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-25 08:31:37 +0000
+++ 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
@@ -43,6 +43,7 @@
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import java.util.Date;
@@ -66,12 +67,13 @@
     private DefaultFieldFilterService fieldFilterService;
 
     @RequestMapping( value = "", method = RequestMethod.GET )
-    public @ResponseBody RootNode getMetadata()
+    public @ResponseBody RootNode getMetadata( @RequestParam Map<String, String> rpParameters )
     {
         RootNode rootNode = NodeUtils.createMetadata();
         rootNode.addChild( new SimpleNode( "date", new Date(), true ) );
 
-        MetadataExportParams params = new MetadataExportParams();
+        MetadataExportParams params = metadataExportService.getParamsFromMap( rpParameters );
+
         Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata( params );
 
         for ( Class<? extends IdentifiableObject> klass : metadata.keySet() )