← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15684: add owner to property class, mainly useful for relationships (many-to-many, one-to-many etc). Upd...

 

------------------------------------------------------------
revno: 15684
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-06-15 13:00:20 +0200
message:
  add owner to property class, mainly useful for relationships (many-to-many, one-to-many etc). Updated Jackson2PropertyIntrospectorService to set this property if either there is no @JsonView, or there is @JsonView and it contains ExportView.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeCollection.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeComplex.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.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/node/annotation/NodeCollection.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeCollection.java	2014-06-09 14:26:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeCollection.java	2014-06-15 11:00:20 +0000
@@ -49,7 +49,9 @@
 
     String itemNamespace() default "";
 
+    boolean useWrapping() default true;
+
+    boolean isPersisted() default true;
+
     boolean owner() default false;
-
-    boolean useWrapping() default true;
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeComplex.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeComplex.java	2014-06-09 14:26:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeComplex.java	2014-06-15 11:00:20 +0000
@@ -44,4 +44,8 @@
     String value() default "";
 
     String namespace() default "";
+
+    boolean isPersisted() default true;
+
+    boolean owner() default false;
 }

=== 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	2014-06-10 16:59:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-06-15 11:00:20 +0000
@@ -139,6 +139,13 @@
     private boolean collection;
 
     /**
+     * If this property is a complex object or a collection, is this property considered
+     * the owner of that relationship (important for imports etc).
+     */
+    @NodeSimple( isPersisted = false )
+    private boolean owner;
+
+    /**
      * Is this class a sub-class of IdentifiableObject
      *
      * @see org.hisp.dhis.common.IdentifiableObject
@@ -333,6 +340,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isOwner()
+    {
+        return owner;
+    }
+
+    public void setOwner( boolean owner )
+    {
+        this.owner = owner;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isIdentifiableObject()
     {
         return identifiableObject;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java	2014-06-11 07:43:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java	2014-06-15 11:00:20 +0000
@@ -29,6 +29,7 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@@ -37,6 +38,7 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.annotation.Description;
+import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.util.StringUtils;
 
@@ -107,13 +109,31 @@
                 name = StringUtils.uncapitalize( name );
             }
 
+            property.setName( name );
+
             if ( method.isAnnotationPresent( Description.class ) )
             {
                 Description description = method.getAnnotation( Description.class );
                 property.setDescription( description.value() );
             }
 
-            property.setName( name );
+            if ( method.isAnnotationPresent( JsonView.class ) )
+            {
+                JsonView jsonView = method.getAnnotation( JsonView.class );
+
+                for ( Class<?> klass : jsonView.value() )
+                {
+                    if ( ExportView.class.isAssignableFrom( klass ) )
+                    {
+                        property.setOwner( true );
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                property.setOwner( true );
+            }
 
             if ( method.isAnnotationPresent( JacksonXmlProperty.class ) )
             {