← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14212: add new PropertyScannerService, use SchemaService in SchemaController, extended MetaData class to...

 

------------------------------------------------------------
revno: 14212
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-03-13 16:56:48 +0100
message:
  add new PropertyScannerService, use SchemaService in SchemaController, extended MetaData class to include Schemas.
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultPropertyScannerService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/PropertyScannerService.java
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Property.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Schema.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/DataElementSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/IndicatorSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SchemaController.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/metadata/MetaData.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java	2014-02-22 16:27:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/MetaData.java	2014-03-13 15:56:48 +0000
@@ -32,6 +32,7 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.collect.Lists;
 import org.hisp.dhis.attribute.Attribute;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.DimensionalObject;
@@ -54,6 +55,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.document.Document;
+import org.hisp.dhis.dxf2.schema.Schema;
 import org.hisp.dhis.filter.MetaDataFilter;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
@@ -97,6 +99,8 @@
 {
     private Date created;
 
+    private List<Schema> schemas = Lists.newArrayList();
+
     private List<Attribute> attributeTypes = new ArrayList<Attribute>();
 
     private List<Document> documents = new ArrayList<Document>();
@@ -148,7 +152,7 @@
     private List<IndicatorGroupSet> indicatorGroupSets = new ArrayList<IndicatorGroupSet>();
 
     private List<IndicatorType> indicatorTypes = new ArrayList<IndicatorType>();
-    
+
     private List<NameableObject> items = new ArrayList<NameableObject>();
 
     private List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
@@ -216,6 +220,19 @@
     }
 
     @JsonProperty
+    @JacksonXmlElementWrapper( localName = "schemas", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "schema", namespace = DxfNamespaces.DXF_2_0 )
+    public List<Schema> getSchemas()
+    {
+        return schemas;
+    }
+
+    public void setSchemas( List<Schema> schemas )
+    {
+        this.schemas = schemas;
+    }
+
+    @JsonProperty
     @JacksonXmlElementWrapper(localName = "attributeTypes", namespace = DxfNamespaces.DXF_2_0)
     @JacksonXmlProperty(localName = "attributeType", namespace = DxfNamespaces.DXF_2_0)
     public List<Attribute> getAttributeTypes()

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultPropertyScannerService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultPropertyScannerService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultPropertyScannerService.java	2014-03-13 15:56:48 +0000
@@ -0,0 +1,74 @@
+package org.hisp.dhis.dxf2.schema;
+
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+import com.google.common.collect.Lists;
+import org.hisp.dhis.system.util.ReflectionUtils;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Default PropertyScannerService implementation that uses Reflection and Jackson annotations
+ * for reading in properties.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultPropertyScannerService implements PropertyScannerService
+{
+    @Override
+    public List<Property> getProperties( Class<?> klass )
+    {
+        return scanClass( klass );
+    }
+
+    private List<Property> scanClass( Class<?> klass )
+    {
+        List<Property> properties = Lists.newArrayList();
+
+        Map<String, ReflectionUtils.PropertyDescriptor> classMap = ReflectionUtils.getJacksonClassMap( klass );
+
+        // for now, just use the reflection utils directly
+        for ( ReflectionUtils.PropertyDescriptor descriptor : classMap.values() )
+        {
+            Property property = new Property( descriptor.getMethod() );
+            properties.add( property );
+
+            property.setKlass( descriptor.getClazz() );
+            property.setCollection( descriptor.isCollection() );
+            property.setIdentifiableObject( descriptor.isIdentifiableObject() );
+            property.setName( descriptor.getName() );
+            property.setXmlName( descriptor.getXmlName() );
+            property.setXmlCollectionName( descriptor.getXmlCollectionName() );
+            property.setDescription( descriptor.getDescription() );
+        }
+
+        return properties;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaService.java	2014-03-13 15:05:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaService.java	2014-03-13 15:56:48 +0000
@@ -43,6 +43,11 @@
 {
     private Map<Class<?>, Schema> classSchemaMap = Maps.newHashMap();
 
+    private Map<String, Schema> singularSchemaMap = Maps.newHashMap();
+
+    @Autowired
+    private PropertyScannerService propertyScannerService;
+
     @Autowired
     private List<SchemaDescriptor> descriptors = Lists.newArrayList();
 
@@ -52,7 +57,10 @@
         for ( SchemaDescriptor descriptor : descriptors )
         {
             Schema schema = descriptor.getSchema();
+            schema.setProperties( propertyScannerService.getProperties( schema.getKlass() ) );
+
             classSchemaMap.put( schema.getKlass(), schema );
+            singularSchemaMap.put( schema.getSingular(), schema );
         }
     }
 
@@ -63,6 +71,12 @@
     }
 
     @Override
+    public Schema getSchemaBySingularName( String name )
+    {
+        return singularSchemaMap.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/schema/Property.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Property.java	2014-03-13 14:30:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Property.java	2014-03-13 15:56:48 +0000
@@ -29,12 +29,16 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
 
 import java.lang.reflect.Method;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
+@JacksonXmlRootElement( localName = "property", namespace = DxfNamespaces.DXF_2_0 )
 public class Property
 {
     private String name;
@@ -47,7 +51,7 @@
 
     private String xmlCollectionName;
 
-    private Class<?> clazz;
+    private Class<?> klass;
 
     private Method method;
 
@@ -55,12 +59,13 @@
 
     private boolean identifiableObject;
 
-    private Property( Method method )
+    public Property( Method method )
     {
         this.method = method;
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getName()
     {
         return name;
@@ -72,6 +77,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getDescription()
     {
         return description;
@@ -83,6 +89,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getXmlName()
     {
         return xmlName;
@@ -94,6 +101,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isXmlAttribute()
     {
         return xmlAttribute;
@@ -105,6 +113,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getXmlCollectionName()
     {
         return xmlCollectionName;
@@ -116,14 +125,15 @@
     }
 
     @JsonProperty
-    public Class<?> getClazz()
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Class<?> getKlass()
     {
-        return clazz;
+        return klass;
     }
 
-    public void setClazz( Class<?> clazz )
+    public void setKlass( Class<?> klass )
     {
-        this.clazz = clazz;
+        this.klass = klass;
     }
 
     public Method getMethod()
@@ -137,6 +147,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isCollection()
     {
         return collection;
@@ -148,6 +159,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isIdentifiableObject()
     {
         return identifiableObject;
@@ -158,15 +170,16 @@
         this.identifiableObject = identifiableObject;
     }
 
-    @Override public String toString()
+    @Override
+    public String toString()
     {
-        return "PropertyDescriptor{" +
+        return "Property{" +
             "name='" + name + '\'' +
             ", description='" + description + '\'' +
             ", xmlName='" + xmlName + '\'' +
             ", xmlAttribute=" + xmlAttribute +
             ", xmlCollectionName='" + xmlCollectionName + '\'' +
-            ", clazz=" + clazz +
+            ", klass=" + klass +
             ", method=" + method +
             ", collection=" + collection +
             ", identifiableObject=" + identifiableObject +

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/PropertyScannerService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/PropertyScannerService.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/PropertyScannerService.java	2014-03-13 15:56:48 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.dxf2.schema;
+
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface PropertyScannerService
+{
+    List<Property> getProperties( Class<?> klass );
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Schema.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Schema.java	2014-03-13 14:30:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/Schema.java	2014-03-13 15:56:48 +0000
@@ -72,7 +72,7 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty( isAttribute = true, namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( isAttribute = true )
     public Class<?> getKlass()
     {
         return klass;
@@ -84,6 +84,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getSingular()
     {
         return singular;
@@ -95,6 +96,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getPlural()
     {
         return plural;
@@ -106,6 +108,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isImportable()
     {
         return importable;
@@ -117,6 +120,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isExportable()
     {
         return exportable;
@@ -128,6 +132,7 @@
     }
 
     @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isDeletable()
     {
         return deletable;
@@ -150,4 +155,18 @@
     {
         this.properties = properties;
     }
+
+    @Override
+    public String toString()
+    {
+        return "Schema{" +
+            "klass=" + klass +
+            ", singular='" + singular + '\'' +
+            ", plural='" + plural + '\'' +
+            ", importable=" + importable +
+            ", exportable=" + exportable +
+            ", deletable=" + deletable +
+            ", properties=" + properties +
+            '}';
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaService.java	2014-03-13 15:05:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/SchemaService.java	2014-03-13 15:56:48 +0000
@@ -37,5 +37,7 @@
 {
     Schema getSchema( Class<?> klass );
 
+    Schema getSchemaBySingularName( String name );
+
     List<Schema> getSchemas();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/DataElementSchemaDescriptor.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/DataElementSchemaDescriptor.java	2014-03-13 15:05:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/DataElementSchemaDescriptor.java	2014-03-13 15:56:48 +0000
@@ -42,8 +42,6 @@
     @Override
     public Schema getSchema()
     {
-        Schema schema = new Schema( DataElement.class, "dataElement", "dataElements", true, true, true );
-
-        return schema;
+        return new Schema( DataElement.class, "dataElement", "dataElements", true, true, true );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/IndicatorSchemaDescriptor.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/IndicatorSchemaDescriptor.java	2014-03-13 15:05:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/descriptors/IndicatorSchemaDescriptor.java	2014-03-13 15:56:48 +0000
@@ -42,8 +42,6 @@
     @Override
     public Schema getSchema()
     {
-        Schema schema = new Schema( Indicator.class, "indicator", "indicators", true, true, true );
-
-        return schema;
+        return new Schema( Indicator.class, "indicator", "indicators", true, true, true );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java	2014-01-02 13:13:21 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java	2014-03-13 15:56:48 +0000
@@ -47,6 +47,8 @@
 import org.hisp.dhis.common.view.UuidView;
 import org.hisp.dhis.common.view.WithoutOrganisationUnitsView;
 
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-03-13 15:05:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml	2014-03-13 15:56:48 +0000
@@ -8,6 +8,8 @@
 
   <bean id="org.hisp.dhis.dxf2.schema.SchemaService" class="org.hisp.dhis.dxf2.schema.DefaultSchemaService" />
 
+  <bean id="org.hisp.dhis.dxf2.schema.PropertyScannerService" class="org.hisp.dhis.dxf2.schema.DefaultPropertyScannerService" />
+
   <bean id="org.hisp.dhis.dxf2.metadata.ExportService" class="org.hisp.dhis.dxf2.metadata.DefaultExportService" scope="prototype" />
 
   <bean id="org.hisp.dhis.dxf2.metadata.ImportService" class="org.hisp.dhis.dxf2.metadata.DefaultImportService" scope="prototype" />

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SchemaController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SchemaController.java	2014-03-13 13:23:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SchemaController.java	2014-03-13 15:56:48 +0000
@@ -28,128 +28,62 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
-import com.google.common.collect.Maps;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.dxf2.metadata.ExchangeClasses;
+import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.dxf2.schema.Schema;
+import org.hisp.dhis.dxf2.schema.SchemaService;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.system.util.ReflectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
 import java.io.IOException;
-import java.util.Map;
+import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = "", method = RequestMethod.GET )
+@RequestMapping( value = "/schemas", method = RequestMethod.GET )
 public class SchemaController
 {
-    @RequestMapping( value = { "/schemas", "/schemas.json" }, method = RequestMethod.GET )
-    public void getTypesJson( HttpServletResponse response ) throws IOException
-    {
-        response.setContentType( MediaType.APPLICATION_JSON_VALUE );
-        Map<String, Map<String, ReflectionUtils.PropertyDescriptor>> output = Maps.newHashMap();
-
-        for ( Class<? extends IdentifiableObject> key : ExchangeClasses.getAllExportMap().keySet() )
-        {
-            Map<String, ReflectionUtils.PropertyDescriptor> classMap = ReflectionUtils.getJacksonClassMap( key );
-            output.put( ExchangeClasses.getAllExportMap().get( key ), classMap );
-        }
-
-        JacksonUtils.toJson( response.getOutputStream(), output );
-    }
-
-    @RequestMapping( value = { "/schemas.xml" }, method = RequestMethod.GET )
-    public void getTypesXml( HttpServletResponse response ) throws IOException
-    {
-        response.setContentType( MediaType.APPLICATION_XML_VALUE );
-        Map<String, Map<String, ReflectionUtils.PropertyDescriptor>> output = Maps.newHashMap();
-
-        for ( Class<? extends IdentifiableObject> key : ExchangeClasses.getAllExportMap().keySet() )
-        {
-            Map<String, ReflectionUtils.PropertyDescriptor> classMap = ReflectionUtils.getJacksonClassMap( key );
-            output.put( ExchangeClasses.getAllExportMap().get( key ), classMap );
-        }
-
-        try
-        {
-            ToXmlGenerator generator = (ToXmlGenerator) JacksonUtils.getXmlMapper().getJsonFactory().createJsonGenerator( response.getOutputStream() );
-            XMLStreamWriter staxWriter = generator.getStaxWriter();
-
-            staxWriter.writeStartElement( "", "schemas", DxfNamespaces.DXF_2_0 );
-
-            for ( String key : output.keySet() )
-            {
-                Map<String, ReflectionUtils.PropertyDescriptor> map = output.get( key );
-                writeClassMap( staxWriter, key, map );
-            }
-
-            staxWriter.writeEndElement();
-            staxWriter.close();
-        }
-        catch ( XMLStreamException ex )
-        {
-            ex.printStackTrace();
-        }
-    }
-
-    private void writeClassMap( XMLStreamWriter staxWriter, String type, Map<String, ReflectionUtils.PropertyDescriptor> classMap )
-    {
-        try
-        {
-            staxWriter.writeStartElement( "", "schema", DxfNamespaces.DXF_2_0 );
-            staxWriter.writeAttribute( "type", type );
-
-            for ( String field : classMap.keySet() )
-            {
-                staxWriter.writeStartElement( "", field, DxfNamespaces.DXF_2_0 );
-                ReflectionUtils.PropertyDescriptor descriptor = classMap.get( field );
-                writeDescriptor( staxWriter, descriptor );
-                staxWriter.writeEndElement();
-            }
-
-            staxWriter.writeEndElement();
-        }
-        catch ( XMLStreamException ignored )
-        {
-        }
-    }
-
-    private void writeDescriptor( XMLStreamWriter staxWriter, ReflectionUtils.PropertyDescriptor descriptor )
-    {
-        writeSimpleElement( staxWriter, "name", descriptor.getName() );
-        writeSimpleElement( staxWriter, "xmlName", descriptor.getXmlName() );
-        writeSimpleElement( staxWriter, "xmlAttribute", descriptor.isXmlAttribute() );
-        writeSimpleElement( staxWriter, "clazz", descriptor.getClazz() );
-        writeSimpleElement( staxWriter, "collection", descriptor.isCollection() );
-        writeSimpleElement( staxWriter, "identifiableObject", descriptor.isIdentifiableObject() );
-        writeSimpleElement( staxWriter, "description", descriptor.getDescription() );
-    }
-
-    private void writeSimpleElement( XMLStreamWriter staxWriter, String fieldName, Object text )
-    {
-        if ( text == null )
-        {
-            return;
-        }
-
-        try
-        {
-            staxWriter.writeStartElement( "", fieldName, DxfNamespaces.DXF_2_0 );
-            staxWriter.writeCharacters( text.toString() );
-            staxWriter.writeEndElement();
-        }
-        catch ( XMLStreamException ignored )
-        {
-        }
+    @Autowired
+    private SchemaService schemaService;
+
+    @RequestMapping( value = "", method = RequestMethod.GET, produces = { "*/*" } )
+    public void getSchemasJson( HttpServletResponse response ) throws IOException
+    {
+        List<Schema> schemas = schemaService.getSchemas();
+        MetaData metaData = new MetaData();
+        metaData.setSchemas( schemas );
+
+        JacksonUtils.toJson( response.getOutputStream(), schemas );
+    }
+
+    @RequestMapping( value = "/{type}", method = RequestMethod.GET, produces = { "*/*" } )
+    public void getSchemaJson( @PathVariable String type, HttpServletResponse response ) throws IOException
+    {
+        Schema schema = schemaService.getSchemaBySingularName( type );
+        JacksonUtils.toJson( response.getOutputStream(), schema );
+    }
+
+    @RequestMapping( value = "", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE } )
+    public void getSchemasXml( HttpServletResponse response ) throws IOException
+    {
+        List<Schema> schemas = schemaService.getSchemas();
+        MetaData metaData = new MetaData();
+        metaData.setSchemas( schemas );
+
+        JacksonUtils.toXml( response.getOutputStream(), metaData );
+    }
+
+    @RequestMapping( value = "/{type}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE } )
+    public void getSchemaXml( @PathVariable String type, HttpServletResponse response ) throws IOException
+    {
+        Schema schema = schemaService.getSchemaBySingularName( type );
+        JacksonUtils.toXml( response.getOutputStream(), schema );
     }
 }