← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17921: expose Property on Nodes

 

------------------------------------------------------------
revno: 17921
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-09 10:27:44 +0700
message:
  expose Property on Nodes
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.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/AbstractNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java	2014-12-18 17:08:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java	2015-01-09 03:27:44 +0000
@@ -28,18 +28,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  */
 
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 import org.hisp.dhis.node.exception.InvalidTypeException;
 import org.hisp.dhis.node.types.SimpleNode;
+import org.hisp.dhis.schema.Property;
 import org.springframework.core.OrderComparator;
 import org.springframework.core.Ordered;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -58,12 +58,21 @@
 
     protected List<Node> children = Lists.newArrayList();
 
+    protected Property property;
+
     protected AbstractNode( String name, NodeType nodeType )
     {
         this.name = name;
         this.nodeType = nodeType;
     }
 
+    protected AbstractNode( String name, NodeType nodeType, Property property )
+    {
+        this.name = name;
+        this.nodeType = nodeType;
+        this.property = property;
+    }
+
     @Override
     public String getName()
     {
@@ -139,6 +148,22 @@
     }
 
     @Override
+    public Property getProperty()
+    {
+        return property;
+    }
+
+    public void setProperty( Property property )
+    {
+        this.property = property;
+    }
+
+    public boolean haveProperty()
+    {
+        return property != null;
+    }
+
+    @Override
     public <T extends Node> T addChild( T child ) throws InvalidTypeException
     {
         if ( child == null || child.getName() == null )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java	2014-10-02 08:22:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java	2015-01-09 03:27:44 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  */
 
+import org.hisp.dhis.schema.Property;
 import org.springframework.core.Ordered;
 
 import java.util.List;
@@ -109,6 +110,11 @@
     String getComment();
 
     /**
+     * The associated property for this node (if any).
+     */
+    Property getProperty();
+
+    /**
      * Adds a child to this node.
      *
      * @param child Child node to add

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java	2014-10-02 08:22:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java	2015-01-09 03:27:44 +0000
@@ -32,8 +32,7 @@
 import org.hisp.dhis.node.Node;
 import org.hisp.dhis.node.NodeType;
 import org.hisp.dhis.node.exception.InvalidTypeException;
-
-import java.util.Objects;
+import org.hisp.dhis.schema.Property;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -79,7 +78,7 @@
     }
 
     @Override
-    public <T extends Node> T addChild( T child ) throws InvalidTypeException
+    public <T extends Node> T addChild( T child )
     {
         throw new InvalidTypeException();
     }
@@ -89,31 +88,4 @@
     {
         throw new InvalidTypeException();
     }
-
-    @Override
-    public int hashCode()
-    {
-        return 31 * super.hashCode() + Objects.hash( value, attribute );
-    }
-
-    @Override
-    public boolean equals( Object obj )
-    {
-        if ( this == obj )
-        {
-            return true;
-        }
-        if ( obj == null || getClass() != obj.getClass() )
-        {
-            return false;
-        }
-        if ( !super.equals( obj ) )
-        {
-            return false;
-        }
-
-        final SimpleNode other = (SimpleNode) obj;
-
-        return Objects.equals( this.value, other.value ) && Objects.equals( this.attribute, other.attribute );
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java	2014-12-01 06:33:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java	2015-01-09 03:27:44 +0000
@@ -241,7 +241,8 @@
                     {
                         for ( Object collectionObject : collection )
                         {
-                            child.addChild( new SimpleNode( property.getName(), collectionObject ) );
+                            SimpleNode simpleNode = child.addChild( new SimpleNode( property.getName(), collectionObject ) );
+                            simpleNode.setProperty( property );
                         }
                     }
                 }
@@ -291,6 +292,7 @@
             if ( child != null )
             {
                 child.setName( fieldKey );
+                child.setProperty( property );
 
                 // TODO fix ugly hack, will be replaced by custom field serializer/deserializer
                 if ( child.isSimple() && PeriodType.class.isInstance( (((SimpleNode) child).getValue()) ) )
@@ -449,6 +451,7 @@
 
         ComplexNode complexNode = new ComplexNode( currentProperty.getName() );
         complexNode.setNamespace( currentProperty.getNamespace() );
+        complexNode.setProperty( currentProperty );
 
         Schema schema;
 
@@ -476,6 +479,7 @@
             SimpleNode simpleNode = new SimpleNode( field, returnValue );
             simpleNode.setAttribute( property.isAttribute() );
             simpleNode.setNamespace( property.getNamespace() );
+            simpleNode.setProperty( property );
 
             complexNode.addChild( simpleNode );
         }