=== 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 get( Class clazz, String uid ); boolean exists( Class clazz, String uid ); - + T get( Collection> classes, String uid ); T getByCode( Class clazz, String code ); @@ -82,7 +84,7 @@ List getByUid( Class clazz, Collection uids ); List getByUidOrdered( Class clazz, List uids ); - + List getLikeName( Class clazz, String name ); List getLikeShortName( Class clazz, String shortName ); @@ -120,7 +122,7 @@ List getObjects( Class clazz, IdentifiableProperty property, Collection identifiers ); List getObjects( Class clazz, Collection identifiers ); - + T getObject( Class clazz, IdentifiableProperty property, String id ); IdentifiableObject getObject( String uid, String simpleClassName ); @@ -140,7 +142,7 @@ int getCountLikeName( Class clazz, String name ); int getCountLikeShortName( Class clazz, String shortName ); - + List getDataDimensions( Class clazz ); List getDataDimensionsNoAcl( Class clazz ); @@ -149,12 +151,14 @@ void evict( Object object ); + AttributeValue getAttributeValueByAttribute( Class klass, Attribute attribute ); + // ------------------------------------------------------------------------- // NO ACL // ------------------------------------------------------------------------- T getNoAcl( Class clazz, String uid ); - + T getNoAcl( Class clazz, int id ); 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 get( Collection> classes, String uid ) - { + { for ( Class clazz : classes ) { T object = (T) get( clazz, uid ); - + if ( object != null ) { return object; } } - + return null; } - + @Override @SuppressWarnings( "unchecked" ) public T getByCode( Class clazz, String code ) @@ -674,7 +676,7 @@ } List 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 getObject( Class 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 getNoAcl( Class clazz, int id ) @@ -956,7 +958,7 @@ return (List) store.getByDataDimension( true ); } - + @Override @SuppressWarnings( "unchecked" ) public List getDataDimensionsNoAcl( Class clazz ) @@ -970,7 +972,21 @@ return (List) store.getByDataDimensionNoAcl( true ); } - + + @Override + @SuppressWarnings( "unchecked" ) + public AttributeValue getAttributeValueByAttribute( Class klass, Attribute attribute ) + { + GenericIdentifiableObjectStore 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 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 @@ + + === 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 @@ +