------------------------------------------------------------
revno: 17522
committer: Morten Olav Hansen <morte...@gmail.com>
branch nick: dhis2
timestamp: Tue 2014-11-18 20:45:13 +0700
message:
  add unique/notNull to Property class, set on name/code properties according 
to haveUniqueNames / haveUniqueCode
modified:
  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/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-10-23 09:02:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-11-18 13:45:13 +0000
@@ -154,6 +154,16 @@
      */
     private boolean writable;
 
+    /**
+     * Are the values for this property required to be unique?
+     */
+    private boolean unique;
+
+    /**
+     * Are the values for this property required to be not-null?
+     */
+    private boolean notNull;
+
     public Property()
     {
     }
@@ -396,6 +406,30 @@
         this.writable = writable;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isUnique()
+    {
+        return unique;
+    }
+
+    public void setUnique( boolean unique )
+    {
+        this.unique = unique;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isNotNull()
+    {
+        return notNull;
+    }
+
+    public void setNotNull( boolean notNull )
+    {
+        this.notNull = notNull;
+    }
+
     public String key()
     {
         return isCollection() ? collectionName : name;

=== 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-10-21 17:05:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java	2014-11-18 13:45:13 +0000
@@ -59,7 +59,7 @@
  *
  * @author Morten Olav Hansen <morte...@gmail.com>
  */
-public class Jackson2PropertyIntrospectorService 
+public class Jackson2PropertyIntrospectorService
     extends AbstractPropertyIntrospectorService
 {
     @Autowired
@@ -117,6 +117,31 @@
                 property.setWritable( property.isPersisted() );
             }
 
+            // This will be replaced later and fetched from hibernate mapping files instead
+            if ( property.isPersisted() && ("name".equals( fieldName ) || "code".equals( fieldName )) )
+            {
+                IdentifiableObject identifiableObject;
+
+                try
+                {
+                    identifiableObject = (IdentifiableObject) clazz.newInstance();
+
+                    if ( "name".equals( fieldName ) )
+                    {
+                        property.setUnique( identifiableObject.haveUniqueNames() );
+                        property.setNotNull( true );
+                    }
+                    else if ( "code".equals( fieldName ) )
+                    {
+                        property.setUnique( identifiableObject.haveUniqueCode() );
+                        property.setNotNull( true );
+                    }
+                }
+                catch ( InstantiationException | IllegalAccessException ignored )
+                {
+                }
+            }
+
             if ( method.isAnnotationPresent( Description.class ) )
             {
                 Description description = method.getAnnotation( Description.class );

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to