← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21103: unique metadata attributes, wip

 

------------------------------------------------------------
revno: 21103
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-11-18 11:39:26 +0700
message:
  unique metadata attributes, wip
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm


--
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/attribute/Attribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java	2015-11-18 04:39:26 +0000
@@ -88,6 +88,8 @@
 
     private boolean mandatory;
 
+    private boolean unique;
+
     private Integer sortOrder;
 
     private OptionSet optionSet;
@@ -134,6 +136,19 @@
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public boolean isUnique()
+    {
+        return unique;
+    }
+
+    public void setUnique( boolean unique )
+    {
+        this.unique = unique;
+    }
+
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isDataElementAttribute()
     {
         return dataElementAttribute;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java	2015-10-15 07:36:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java	2015-11-18 04:39:26 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.common.NameableObject.NameableProperty;
 
 import java.util.Collection;
@@ -58,7 +60,7 @@
     <T extends IdentifiableObject> T get( Class<T> clazz, String uid );
 
     <T extends IdentifiableObject> boolean exists( Class<T> clazz, String uid );
-    
+
     <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes, String uid );
 
     <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code );
@@ -82,7 +84,7 @@
     <T extends IdentifiableObject> List<T> getByUid( Class<T> clazz, Collection<String> uids );
 
     <T extends IdentifiableObject> List<T> getByUidOrdered( Class<T> clazz, List<String> uids );
-    
+
     <T extends IdentifiableObject> List<T> getLikeName( Class<T> clazz, String name );
 
     <T extends NameableObject> List<T> getLikeShortName( Class<T> clazz, String shortName );
@@ -120,7 +122,7 @@
     <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, IdentifiableProperty property, Collection<String> identifiers );
 
     <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, Collection<Integer> identifiers );
-    
+
     <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String id );
 
     IdentifiableObject getObject( String uid, String simpleClassName );
@@ -140,7 +142,7 @@
     <T extends IdentifiableObject> int getCountLikeName( Class<T> clazz, String name );
 
     <T extends NameableObject> int getCountLikeShortName( Class<T> clazz, String shortName );
-    
+
     <T extends DimensionalObject> List<T> getDataDimensions( Class<T> clazz );
 
     <T extends DimensionalObject> List<T> getDataDimensionsNoAcl( Class<T> clazz );
@@ -149,12 +151,14 @@
 
     void evict( Object object );
 
+    <T extends IdentifiableObject> AttributeValue getAttributeValueByAttribute( Class<T> klass, Attribute attribute );
+
     // -------------------------------------------------------------------------
     // NO ACL
     // -------------------------------------------------------------------------
 
     <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, String uid );
-    
+
     <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, int id );
 
     <T extends IdentifiableObject> void updateNoAcl( T object );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2015-11-15 20:02:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2015-11-18 04:39:26 +0000
@@ -28,19 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.SessionFactory;
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeValue;
 import org.hisp.dhis.common.NameableObject.NameableProperty;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
@@ -50,11 +42,21 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Note that it is required for nameable object stores to have concrete implementation
- * classes, not rely on the HibernateIdentifiableObjectStore class, in order to 
+ * classes, not rely on the HibernateIdentifiableObjectStore class, in order to
  * be injected as nameable object stores.
- * 
+ *
  * @author Lars Helge Overland
  */
 @Transactional
@@ -195,20 +197,20 @@
     @Override
     @SuppressWarnings( "unchecked" )
     public <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes, String uid )
-    {        
+    {
         for ( Class<? extends IdentifiableObject> clazz : classes )
         {
             T object = (T) get( clazz, uid );
-            
+
             if ( object != null )
             {
                 return object;
             }
         }
-        
+
         return null;
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code )
@@ -674,7 +676,7 @@
         }
 
         List<T> objects = store.getAll();
-        
+
         return IdentifiableObjectUtils.getMap( objects, property );
     }
 
@@ -764,7 +766,7 @@
             {
                 return store.getByName( identifiers );
             }
-            
+
             throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property );
         }
 
@@ -784,7 +786,7 @@
 
         return store.getById( identifiers );
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String id )
@@ -816,7 +818,7 @@
             {
                 return store.getByName( id );
             }
-            
+
             throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property );
         }
 
@@ -876,7 +878,7 @@
 
         return (T) store.getByUidNoAcl( uid );
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, int id )
@@ -956,7 +958,7 @@
 
         return (List<T>) store.getByDataDimension( true );
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public <T extends DimensionalObject> List<T> getDataDimensionsNoAcl( Class<T> clazz )
@@ -970,7 +972,21 @@
 
         return (List<T>) store.getByDataDimensionNoAcl( true );
     }
-    
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public <T extends IdentifiableObject> AttributeValue getAttributeValueByAttribute( Class<T> klass, Attribute attribute )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );
+
+        if ( store == null )
+        {
+            return null;
+        }
+
+        return store.getAttributeValueByAttribute( attribute );
+    }
+
     //--------------------------------------------------------------------------
     // Supportive methods
     //--------------------------------------------------------------------------
@@ -1055,9 +1071,9 @@
         {
             nameableObjectStoreMap.put( store.getClazz(), store );
         }
-        
+
         dimensionalObjectStoreMap = new HashMap<>();
-        
+
         for ( GenericDimensionalObjectStore<? extends DimensionalObject> store : dimensionalObjectStores )
         {
             dimensionalObjectStoreMap.put( store.getClazz(), store );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/InitTableAlteror.java	2015-11-18 04:39:26 +0000
@@ -82,6 +82,7 @@
 
         executeSql( "alter table programstage rename column irregular to repeatable" );
         executeSql( "update programstage set repeatable=false where repeatable is null" );
+        executeSql( "update attribute set isunique=false where isunique is null" );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml	2015-11-18 04:39:26 +0000
@@ -27,6 +27,8 @@
 
     <property name="mandatory" not-null="true" />
 
+    <property name="unique" column="isunique" not-null="true" />
+
     <property name="dataElementAttribute" not-null="true" />
 
     <property name="dataElementGroupAttribute" not-null="false" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java	2015-11-18 04:39:26 +0000
@@ -85,6 +85,13 @@
         this.mandatory = mandatory;
     }
 
+    private Boolean unique = false;
+
+    public void setUnique( Boolean unique )
+    {
+        this.unique = unique;
+    }
+
     private Boolean dataElementAttribute = false;
 
     public void setDataElementAttribute( Boolean dataElementAttribute )
@@ -217,6 +224,7 @@
         Attribute attribute = new Attribute( StringUtils.trimToNull( name ), valueType );
         attribute.setCode( StringUtils.trimToNull( code ) );
         attribute.setMandatory( mandatory );
+        attribute.setUnique( unique );
         attribute.setDataElementAttribute( dataElementAttribute );
         attribute.setDataElementGroupAttribute( dataElementGroupAttribute );
         attribute.setIndicatorAttribute( indicatorAttribute );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java	2015-11-18 04:39:26 +0000
@@ -92,6 +92,13 @@
         this.mandatory = mandatory;
     }
 
+    private Boolean unique = false;
+
+    public void setUnique( Boolean unique )
+    {
+        this.unique = unique;
+    }
+
     private Boolean dataElementAttribute = false;
 
     public void setDataElementAttribute( Boolean dataElementAttribute )
@@ -230,6 +237,7 @@
             attribute.setValueType( valueType );
             attribute.setOptionSet( optionSet );
             attribute.setMandatory( mandatory );
+            attribute.setUnique( unique );
             attribute.setDataElementAttribute( dataElementAttribute );
             attribute.setDataElementGroupAttribute( dataElementGroupAttribute );
             attribute.setIndicatorAttribute( indicatorAttribute );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2015-09-26 16:08:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2015-11-18 04:39:26 +0000
@@ -258,6 +258,7 @@
 attribute_management=Attribute Management
 value_type=Value Type
 mandatory=Mandatory
+unique=Unique
 indicator=Indicator
 indicator_group=Indicator Group
 organisation_unit=Organisation Unit

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm	2015-11-18 04:39:26 +0000
@@ -47,6 +47,11 @@
 	</tr>
 
 	<tr>
+		<td><label for="mandatory">$i18n.getString( "unique" )</td>
+		<td><input type="checkbox" id="unique" name="unique" value="true" /></td>
+	</tr>
+
+	<tr>
 		<td style="vertical-align: text-top;">$i18n.getString( "assigned_to" )</td>
 		<td>
       <input type="checkbox" id="dataElementAttribute" name="dataElementAttribute" value="true" /><label for="dataElementAttribute">$i18n.getString( 'data_element' )</label> <br />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm	2015-11-16 05:51:35 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm	2015-11-18 04:39:26 +0000
@@ -48,6 +48,11 @@
 	</tr>
 
 	<tr>
+		<td><label for="unique">$i18n.getString( "unique" )</td>
+		<td><input type="checkbox" id="unique" name="unique" value="true" #if( $attribute.unique ) checked="checked" #end /></td>
+	</tr>
+
+	<tr>
 		<td style="vertical-align: text-top;">$i18n.getString( "assigned_to" )</td>
 		<td>
       <input type="checkbox" id="dataElementAttribute" name="dataElementAttribute" value="true" #if( $attribute.dataElementAttribute ) checked="checked" #end /><label for="dataElementAttribute">$i18n.getString( 'data_element' )</label> <br />