← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19003: add href to Property class

 

------------------------------------------------------------
revno: 19003
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-24 13:42:41 +0700
message:
  add href to Property class
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.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/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2015-03-31 15:04:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2015-04-24 06:42:41 +0000
@@ -227,6 +227,11 @@
      */
     private List<String> constants;
 
+    /**
+     * Used by LinkService to link to the Schema describing this type (if reference).
+     */
+    private String href;
+
     public Property()
     {
     }
@@ -639,6 +644,18 @@
         this.constants = constants;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getHref()
+    {
+        return href;
+    }
+
+    public void setHref( String href )
+    {
+        this.href = href;
+    }
+
     public String key()
     {
         return isCollection() ? collectionName : name;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java	2015-03-24 03:01:32 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchemaController.java	2015-04-24 06:42:41 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.schema.Schemas;
+import org.hisp.dhis.webapi.service.LinkService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
@@ -67,10 +68,16 @@
     @Autowired
     private RenderService renderService;
 
+    @Autowired
+    private LinkService linkService;
+
     @RequestMapping
     public @ResponseBody Schemas getSchemas()
     {
-        return new Schemas( schemaService.getSortedSchemas() );
+        Schemas schemas = new Schemas( schemaService.getSortedSchemas() );
+        linkService.generateSchemaLinks( schemas.getSchemas() );
+
+        return schemas;
     }
 
     @RequestMapping( value = "/{type}", method = RequestMethod.GET )
@@ -80,6 +87,7 @@
 
         if ( schema != null )
         {
+            linkService.generateSchemaLinks( schema );
             return schema;
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/DefaultLinkService.java	2015-04-24 06:42:41 +0000
@@ -34,6 +34,7 @@
 import org.hibernate.collection.spi.PersistentCollection;
 import org.hisp.dhis.common.Pager;
 import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.PropertyType;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,6 +43,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Collection;
+import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -123,6 +125,35 @@
         }
     }
 
+    @Override
+    public void generateSchemaLinks( List<Schema> schemas )
+    {
+        for ( Schema schema : schemas )
+        {
+            generateSchemaLinks( schema );
+        }
+    }
+
+    @Override
+    public void generateSchemaLinks( Schema schema )
+    {
+        generateSchemaLinks( schema, contextService.getServletPath() );
+    }
+
+    @Override
+    public void generateSchemaLinks( Schema schema, String hrefBase )
+    {
+        for ( Property property : schema.getProperties() )
+        {
+            Schema klassSchema = schemaService.getDynamicSchema( property.getKlass() );
+
+            if ( property.is( PropertyType.REFERENCE ) )
+            {
+                property.setHref( hrefBase + "/schemas/" + klassSchema.getSingular() );
+            }
+        }
+    }
+
     private <T> void generateLink( T object, String hrefBase, boolean deepScan )
     {
         Schema schema = schemaService.getDynamicSchema( object.getClass() );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/LinkService.java	2015-04-24 06:42:41 +0000
@@ -29,6 +29,9 @@
  */
 
 import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.schema.Schema;
+
+import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -50,7 +53,7 @@
      * <p/>
      * Uses hrefBase from ContextService.getServletPath().
      *
-     * @param object Object (can be collection) to set HREFs on
+     * @param object   Object (can be collection) to set HREFs on
      * @param deepScan Generate links also on deeper levels (only one level down)
      * @see javax.servlet.http.HttpServletRequest
      * @see ContextService
@@ -66,4 +69,10 @@
      * @see javax.servlet.http.HttpServletRequest
      */
     <T> void generateLinks( T object, String hrefBase, boolean deepScan );
+
+    void generateSchemaLinks( List<Schema> schemas );
+
+    void generateSchemaLinks( Schema schema );
+
+    void generateSchemaLinks( Schema schema, String hrefBase );
 }