dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30571
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15531: minor changes to schema/property classes
------------------------------------------------------------
revno: 15531
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-03 09:51:25 +0200
message:
minor changes to schema/property classes
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.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 2014-05-28 09:57:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-06-03 07:51:25 +0000
@@ -32,6 +32,8 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.NameableObject;
import java.lang.reflect.Method;
@@ -42,11 +44,27 @@
public class Property
{
/**
- * Name of property.
+ * Class for property.
+ */
+ private Class<?> klass;
+
+ /**
+ * Direct link to getter for this property.
+ */
+ private final Method getterMethod;
+
+ /**
+ * Name for this property, if this class is a collection, it is the name of the items -inside- the collection
+ * and not the collection wrapper itself.
*/
private String name;
/**
+ * Name of collection wrapper.
+ */
+ private String collectionName;
+
+ /**
* Description if provided, will be fetched from @Description annotation.
*
* @see org.hisp.dhis.common.annotation.Description
@@ -54,34 +72,14 @@
private String description;
/**
- * Usually equals to name, but for lists the name and xmlName might differ.
- */
- private String xmlName;
-
- /**
* XML-Namespace used for this property.
*/
- private String xmlNamespace;
-
- /**
- * Is this property exposed as a attribute in XML.
- */
- private boolean xmlAttribute;
-
- /**
- * Name of collection wrapper.
- */
- private String xmlCollectionName;
-
- /**
- * Class for property.
- */
- private Class<?> klass;
-
- /**
- * Direct link to getter for this property.
- */
- private Method getterMethod;
+ private String namespaceURI;
+
+ /**
+ * Usually only used for XML. Is this property considered an attribute.
+ */
+ private boolean attribute;
/**
* Is this a Collection sub-class.
@@ -109,6 +107,31 @@
this.getterMethod = getterMethod;
}
+ public Property( Method getterMethod, Class<?> klass )
+ {
+ this.getterMethod = getterMethod;
+ setKlass( klass );
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Class<?> getKlass()
+ {
+ return klass;
+ }
+
+ public void setKlass( Class<?> klass )
+ {
+ this.identifiableObject = IdentifiableObject.class.isAssignableFrom( klass );
+ this.nameableObject = NameableObject.class.isAssignableFrom( klass );
+ this.klass = klass;
+ }
+
+ public Method getGetterMethod()
+ {
+ return getterMethod;
+ }
+
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getName()
@@ -123,6 +146,18 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getCollectionName()
+ {
+ return collectionName == null ? name : collectionName;
+ }
+
+ public void setCollectionName( String collectionName )
+ {
+ this.collectionName = collectionName;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getDescription()
{
return description;
@@ -135,72 +170,26 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public String getXmlName()
- {
- return xmlName;
- }
-
- public void setXmlName( String xmlName )
- {
- this.xmlName = xmlName;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public String getXmlNamespace()
- {
- return xmlNamespace;
- }
-
- public void setXmlNamespace( String xmlNamespace )
- {
- this.xmlNamespace = xmlNamespace;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public boolean isXmlAttribute()
- {
- return xmlAttribute;
- }
-
- public void setXmlAttribute( boolean xmlAttribute )
- {
- this.xmlAttribute = xmlAttribute;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public String getXmlCollectionName()
- {
- return xmlCollectionName;
- }
-
- public void setXmlCollectionName( String xmlCollectionName )
- {
- this.xmlCollectionName = xmlCollectionName;
- }
-
- @JsonProperty
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
- public Class<?> getKlass()
- {
- return klass;
- }
-
- public void setKlass( Class<?> klass )
- {
- this.klass = klass;
- }
-
- public Method getGetterMethod()
- {
- return getterMethod;
- }
-
- public void setGetterMethod( Method getterMethod )
- {
- this.getterMethod = getterMethod;
+ public String getNamespaceURI()
+ {
+ return namespaceURI;
+ }
+
+ public void setNamespaceURI( String namespaceURI )
+ {
+ this.namespaceURI = namespaceURI;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public boolean isAttribute()
+ {
+ return attribute;
+ }
+
+ public void setAttribute( boolean attribute )
+ {
+ this.attribute = attribute;
}
@JsonProperty
@@ -240,18 +229,57 @@
}
@Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Property property = (Property) o;
+
+ if ( attribute != property.attribute ) return false;
+ if ( collection != property.collection ) return false;
+ if ( identifiableObject != property.identifiableObject ) return false;
+ if ( nameableObject != property.nameableObject ) return false;
+ if ( collectionName != null ? !collectionName.equals( property.collectionName ) : property.collectionName != null ) return false;
+ if ( description != null ? !description.equals( property.description ) : property.description != null ) return false;
+ if ( getterMethod != null ? !getterMethod.equals( property.getterMethod ) : property.getterMethod != null ) return false;
+ if ( klass != null ? !klass.equals( property.klass ) : property.klass != null ) return false;
+ if ( name != null ? !name.equals( property.name ) : property.name != null ) return false;
+ if ( namespaceURI != null ? !namespaceURI.equals( property.namespaceURI ) : property.namespaceURI != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = klass != null ? klass.hashCode() : 0;
+ result = 31 * result + (getterMethod != null ? getterMethod.hashCode() : 0);
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (collectionName != null ? collectionName.hashCode() : 0);
+ result = 31 * result + (description != null ? description.hashCode() : 0);
+ result = 31 * result + (namespaceURI != null ? namespaceURI.hashCode() : 0);
+ result = 31 * result + (attribute ? 1 : 0);
+ result = 31 * result + (collection ? 1 : 0);
+ result = 31 * result + (identifiableObject ? 1 : 0);
+ result = 31 * result + (nameableObject ? 1 : 0);
+ return result;
+ }
+
+ @Override
public String toString()
{
return "Property{" +
- "name='" + name + '\'' +
+ "klass=" + klass +
+ ", getterMethod=" + getterMethod +
+ ", name='" + name + '\'' +
+ ", collectionName='" + collectionName + '\'' +
", description='" + description + '\'' +
- ", xmlName='" + xmlName + '\'' +
- ", xmlAttribute=" + xmlAttribute +
- ", xmlCollectionName='" + xmlCollectionName + '\'' +
- ", klass=" + klass +
- ", getter=" + getterMethod +
+ ", namespaceURI='" + namespaceURI + '\'' +
+ ", attribute=" + attribute +
", collection=" + collection +
", identifiableObject=" + identifiableObject +
+ ", nameableObject=" + nameableObject +
'}';
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java 2014-06-02 21:00:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java 2014-06-03 07:51:25 +0000
@@ -78,6 +78,23 @@
private String plural;
/**
+ * Namespace URI to be used for this class.
+ */
+ private String namespaceURI;
+
+ /**
+ * This will normally be set to equal plural, and is normally used as a wrapper for a collection of
+ * instances of this klass type.
+ */
+ private String collectionName;
+
+ /**
+ * This will normally be set to equal singular, but in certain cases it might be useful to have another name
+ * for when this class is used as an item inside a collection.
+ */
+ private String collectionItemName;
+
+ /**
* Is sharing supported for instances of this class.
*/
private boolean shareable;
@@ -98,11 +115,6 @@
private List<Authority> authorities = Lists.newArrayList();
/**
- * List of all exposed properties on this class.
- */
- private List<Property> properties = Lists.newArrayList();
-
- /**
* Map of all exposed properties on this class, where key is property
* name, and value is instance of Property class.
*
@@ -177,6 +189,42 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getNamespaceURI()
+ {
+ return namespaceURI;
+ }
+
+ public void setNamespaceURI( String namespaceURI )
+ {
+ this.namespaceURI = namespaceURI;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getCollectionName()
+ {
+ return collectionName == null ? plural : collectionName;
+ }
+
+ public void setCollectionName( String collectionName )
+ {
+ this.collectionName = collectionName;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public String getCollectionItemName()
+ {
+ return collectionItemName == null ? singular : collectionItemName;
+ }
+
+ public void setCollectionItemName( String collectionItemName )
+ {
+ this.collectionItemName = collectionItemName;
+ }
+
+ @JsonProperty
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public boolean isShareable()
{
return shareable;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-03-26 16:25:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-06-03 07:51:25 +0000
@@ -122,21 +122,25 @@
if ( jacksonXmlProperty.localName().isEmpty() )
{
- property.setXmlName( name );
+ property.setName( name );
}
else
{
- property.setXmlName( jacksonXmlProperty.localName() );
- }
-
- property.setXmlNamespace( jacksonXmlProperty.namespace() );
- property.setXmlAttribute( jacksonXmlProperty.isAttribute() );
+ property.setName( jacksonXmlProperty.localName() );
+ }
+
+ if ( !StringUtils.isEmpty( jacksonXmlProperty.namespace() ) )
+ {
+ property.setNamespaceURI( jacksonXmlProperty.namespace() );
+ }
+
+ property.setAttribute( jacksonXmlProperty.isAttribute() );
}
if ( method.isAnnotationPresent( JacksonXmlElementWrapper.class ) )
{
JacksonXmlElementWrapper jacksonXmlElementWrapper = method.getAnnotation( JacksonXmlElementWrapper.class );
- property.setXmlCollectionName( jacksonXmlElementWrapper.localName() );
+ property.setCollectionName( jacksonXmlElementWrapper.localName() );
}
property.setName( name );
@@ -145,16 +149,7 @@
Class<?> returnType = method.getReturnType();
property.setKlass( returnType );
- if ( IdentifiableObject.class.isAssignableFrom( returnType ) )
- {
- property.setIdentifiableObject( true );
-
- if ( NameableObject.class.isAssignableFrom( returnType ) )
- {
- property.setNameableObject( true );
- }
- }
- else if ( Collection.class.isAssignableFrom( returnType ) )
+ if ( Collection.class.isAssignableFrom( returnType ) )
{
property.setCollection( true );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-02 22:47:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-03 07:51:25 +0000
@@ -176,7 +176,7 @@
{
if ( property.isCollection() )
{
- CollectionNode collectionNode = complexNode.addNode( new CollectionNode( property.getXmlCollectionName() ) );
+ CollectionNode collectionNode = complexNode.addNode( new CollectionNode( property.getCollectionName() ) );
for ( Object collectionObject : (Collection<?>) returnValue )
{