dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36480
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18659: If property.klass is enum, expose all possible constants in Property.constants, also adds Propert...
------------------------------------------------------------
revno: 18659
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-23 14:10:37 +0700
message:
If property.klass is enum, expose all possible constants in Property.constants, also adds PropertyType.CONSTANT
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/PropertyType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.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/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2015-03-06 03:20:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2015-03-23 07:10:37 +0000
@@ -29,6 +29,7 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.google.common.base.MoreObjects;
@@ -39,6 +40,7 @@
import org.springframework.core.Ordered;
import java.lang.reflect.Method;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -210,6 +212,11 @@
*/
private String inverseRole;
+ /**
+ * If property type is enum, this is the list of valid options.
+ */
+ private List<String> constants;
+
public Property()
{
}
@@ -585,6 +592,19 @@
this.inverseRole = inverseRole;
}
+ @JsonProperty
+ @JacksonXmlElementWrapper( localName = "constants", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "constant", namespace = DxfNamespaces.DXF_2_0 )
+ public List<String> getConstants()
+ {
+ return constants;
+ }
+
+ public void setConstants( List<String> constants )
+ {
+ this.constants = constants;
+ }
+
public String key()
{
return isCollection() ? collectionName : name;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java 2015-03-23 07:10:37 +0000
@@ -51,5 +51,6 @@
COLOR,
COMPLEX,
COLLECTION,
- REFERENCE
+ REFERENCE,
+ CONSTANT
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java 2015-03-23 07:10:37 +0000
@@ -105,7 +105,7 @@
}
else if ( isAssignableFrom( klass, Enum.class ) )
{
- return PropertyType.TEXT; // TODO enum payloads are text, but should we expose a different type?
+ return PropertyType.CONSTANT;
}
else if ( isAssignableFrom( klass, IdentifiableObject.class ) )
{
=== 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 2015-03-06 03:20:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2015-03-23 07:10:37 +0000
@@ -44,6 +44,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -57,7 +58,6 @@
public class Jackson2PropertyIntrospectorService
extends AbstractPropertyIntrospectorService
{
-
@Override
protected Map<String, Property> scanClass( Class<?> clazz )
{
@@ -219,6 +219,19 @@
propertyMap.put( property.getName(), property );
}
+ if ( Enum.class.isAssignableFrom( property.getKlass() ) )
+ {
+ Object[] enumConstants = property.getKlass().getEnumConstants();
+ List<String> enumValues = new ArrayList<>();
+
+ for ( Object value : enumConstants )
+ {
+ enumValues.add( value.toString() );
+ }
+
+ property.setConstants( enumValues );
+ }
+
SchemaUtils.updatePropertyTypes( property );
}