dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32138
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16422: minor additions to node annotations, also adds simple tests for NodePropertyIntrospectorService
------------------------------------------------------------
revno: 16422
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-08-16 21:30:22 +0700
message:
minor additions to node annotations, also adds simple tests for NodePropertyIntrospectorService
added:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/NodePropertyIntrospectorServiceTest.java
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/node/annotation/NodeSimple.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/NodePropertyIntrospectorService.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-17 09:21:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeCollection.java 2014-08-16 14:30:22 +0000
@@ -36,7 +36,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Target( { ElementType.FIELD } )
+@Target( { ElementType.FIELD, ElementType.METHOD } )
@Retention( RetentionPolicy.RUNTIME )
@NodeAnnotation
public @interface NodeCollection
=== 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-17 09:21:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeComplex.java 2014-08-16 14:30:22 +0000
@@ -36,7 +36,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Target( { ElementType.FIELD } )
+@Target( { ElementType.FIELD, ElementType.METHOD } )
@Retention( RetentionPolicy.RUNTIME )
@NodeAnnotation
public @interface NodeComplex
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeSimple.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeSimple.java 2014-06-17 09:21:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/NodeSimple.java 2014-08-16 14:30:22 +0000
@@ -36,7 +36,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Target( { ElementType.FIELD } )
+@Target( { ElementType.FIELD, ElementType.METHOD } )
@Retention( RetentionPolicy.RUNTIME )
@NodeAnnotation
public @interface NodeSimple
=== 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-17 09:21:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-08-16 14:30:22 +0000
@@ -162,6 +162,12 @@
@NodeSimple
private boolean nameableObject;
+ @NodeSimple
+ private boolean readable;
+
+ @NodeSimple
+ private boolean writable;
+
public Property()
{
}
@@ -375,6 +381,30 @@
this.nameableObject = nameableObject;
}
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isReadable()
+ {
+ return readable;
+ }
+
+ public void setReadable( boolean readable )
+ {
+ this.readable = readable;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isWritable()
+ {
+ return writable;
+ }
+
+ public void setWritable( boolean writable )
+ {
+ this.writable = writable;
+ }
+
@Override
public int getOrder()
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-06-09 14:26:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-08-16 14:30:22 +0000
@@ -116,6 +116,8 @@
property.setAttribute( nodeSimple.isAttribute() );
property.setPersisted( nodeSimple.isPersisted() );
property.setNamespace( nodeSimple.namespace() );
+ property.setWritable( nodeSimple.isWritable() );
+ property.setReadable( nodeSimple.isReadable() );
if ( !StringUtils.isEmpty( nodeSimple.value() ) )
{
@@ -127,6 +129,8 @@
NodeComplex nodeComplex = field.getAnnotation( NodeComplex.class );
property.setSimple( false );
property.setNamespace( nodeComplex.namespace() );
+ property.setWritable( nodeComplex.isWritable() );
+ property.setReadable( nodeComplex.isReadable() );
if ( !StringUtils.isEmpty( nodeComplex.value() ) )
{
@@ -137,6 +141,8 @@
{
NodeCollection nodeCollection = field.getAnnotation( NodeCollection.class );
property.setCollectionWrapping( nodeCollection.useWrapping() );
+ property.setWritable( nodeCollection.isWritable() );
+ property.setReadable( nodeCollection.isReadable() );
if ( !StringUtils.isEmpty( nodeCollection.value() ) )
{
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/NodePropertyIntrospectorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/NodePropertyIntrospectorServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/NodePropertyIntrospectorServiceTest.java 2014-08-16 14:30:22 +0000
@@ -0,0 +1,93 @@
+package org.hisp.dhis.schema;
+
+/*
+ * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.annotation.NodeSimple;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+class SimpleFieldsOnly
+{
+ @NodeSimple( isAttribute = false )
+ private String simpleProperty;
+
+ @NodeSimple( value = "renamedProperty", isAttribute = true )
+ private String simplePropertyRenamed;
+
+ @NodeSimple( isPersisted = false )
+ private String notPersistedProperty;
+
+ @NodeSimple( isReadable = true, isWritable = false )
+ private String readOnly;
+
+ @NodeSimple( isReadable = false, isWritable = true )
+ private String writeOnly;
+}
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class NodePropertyIntrospectorServiceTest
+{
+ private NodePropertyIntrospectorService introspectorService;
+
+ @Before
+ public void setup()
+ {
+ introspectorService = new NodePropertyIntrospectorService();
+ }
+
+ @Test
+ public void simpleProperties() throws NoSuchFieldException
+ {
+ Map<String, Property> propertyMap = introspectorService.scanClass( SimpleFieldsOnly.class );
+
+ assertTrue( propertyMap.containsKey( "simpleProperty" ) );
+ assertFalse( propertyMap.containsKey( "simplePropertyRenamed" ) );
+ assertTrue( propertyMap.containsKey( "renamedProperty" ) );
+ assertTrue( propertyMap.containsKey( "readOnly" ) );
+ assertTrue( propertyMap.containsKey( "writeOnly" ) );
+
+ assertFalse( propertyMap.get( "simpleProperty" ).isAttribute() );
+ assertTrue( propertyMap.get( "renamedProperty" ).isAttribute() );
+ assertFalse( propertyMap.get( "notPersistedProperty" ).isPersisted() );
+
+ assertTrue( propertyMap.get( "readOnly" ).isReadable() );
+ assertFalse( propertyMap.get( "readOnly" ).isWritable() );
+
+ assertFalse( propertyMap.get( "writeOnly" ).isReadable() );
+ assertTrue( propertyMap.get( "writeOnly" ).isWritable() );
+
+ assertEquals( "simplePropertyRenamed", propertyMap.get( "renamedProperty" ).getFieldName() );
+ }
+}