← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21847: minor fixes to RenderService

 

------------------------------------------------------------
revno: 21847
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-02-02 11:06:07 +0700
message:
  minor fixes to RenderService
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderFormat.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/render/DefaultRenderService.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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderFormat.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderFormat.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderFormat.java	2016-02-02 04:06:07 +0000
@@ -0,0 +1,38 @@
+package org.hisp.dhis.render;
+
+/*
+ * Copyright (c) 2004-2016, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum RenderFormat
+{
+    JSON,
+    XML;
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderService.java	2016-02-01 07:36:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/render/RenderService.java	2016-02-02 04:06:07 +0000
@@ -28,9 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.IdentifiableObject;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -57,5 +61,16 @@
 
     <T> T fromXml( String input, Class<T> klass ) throws IOException;
 
-    boolean isValidJson(String json) throws IOException;
+    boolean isValidJson( String json ) throws IOException;
+
+    /**
+     * Parses metadata stream and automatically finds collections of id object based on root properties.
+     * <p>
+     * i.e. A property called "dataElements" would be tried to parsed as a collection of data elements.
+     *
+     * @param inputStream Stream to read from
+     * @param format      Payload format (JSON and XML is supported)
+     * @return Map of all id object types that were found
+     */
+    Map<Class<? extends IdentifiableObject>, Collection<? extends IdentifiableObject>> fromMetadata( InputStream inputStream, RenderFormat format );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/render/DefaultRenderService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/render/DefaultRenderService.java	2016-02-01 07:36:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/render/DefaultRenderService.java	2016-02-02 04:06:07 +0000
@@ -39,11 +39,18 @@
 import com.fasterxml.jackson.databind.util.JSONPObject;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.schema.SchemaService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 
+import javax.annotation.PostConstruct;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Default implementation that uses Jackson to serialize/deserialize
@@ -53,15 +60,13 @@
 public class DefaultRenderService
     implements RenderService
 {
+    @Autowired
+    private SchemaService schemaService;
+
     private final ObjectMapper jsonMapper = new ObjectMapper();
 
     private final XmlMapper xmlMapper = new XmlMapper();
 
-    public DefaultRenderService()
-    {
-        configureObjectMappers();
-    }
-
     //--------------------------------------------------------------------------
     // RenderService
     //--------------------------------------------------------------------------
@@ -162,6 +167,13 @@
         return true;
     }
 
+    @Override
+    public Map<Class<? extends IdentifiableObject>, Collection<? extends IdentifiableObject>> fromMetadata( InputStream inputStream, RenderFormat format )
+    {
+        Map<Class<? extends IdentifiableObject>, Collection<? extends IdentifiableObject>> map = new HashMap<>();
+        return map;
+    }
+
     //--------------------------------------------------------------------------
     // Helpers
     //--------------------------------------------------------------------------
@@ -176,6 +188,7 @@
         return xmlMapper;
     }
 
+    @PostConstruct
     private void configureObjectMappers()
     {
         ObjectMapper[] objectMappers = new ObjectMapper[]{ jsonMapper, xmlMapper };