=== 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-12-03 03:12:51 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-12-03 04:18:07 +0000 @@ -125,7 +125,9 @@ List getObjects( Class clazz, Collection identifiers ); - T getObject( Class clazz, IdentifiableProperty property, String id ); + T getObject( Class clazz, IdentifiableProperty property, String value ); + + T getObject( Class clazz, IdentifiableProperty property, String aid, String value ); IdentifiableObject getObject( String uid, String simpleClassName ); === 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-12-03 03:12:51 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-12-03 04:18:07 +0000 @@ -803,34 +803,51 @@ @Override @SuppressWarnings( "unchecked" ) - public T getObject( Class clazz, IdentifiableProperty property, String id ) + public T getObject( Class clazz, IdentifiableProperty property, String value ) + { + return getObject( clazz, property, null, value ); + } + + @Override + @SuppressWarnings( "unchecked" ) + public T getObject( Class clazz, IdentifiableProperty property, String aid, String value ) { GenericIdentifiableObjectStore store = (GenericIdentifiableObjectStore) getIdentifiableObjectStore( clazz ); - - if ( id != null ) - { - if ( property == null || IdentifiableProperty.ID.equals( property ) ) - { - if ( Integer.valueOf( id ) > 0 ) + Attribute attribute = null; + + if ( aid != null ) + { + attribute = get( Attribute.class, aid ); + } + + if ( value != null ) + { + if ( IdentifiableProperty.UID == property ) + { + return store.getByUid( value ); + } + else if ( IdentifiableProperty.CODE == property ) + { + return store.getByCode( value ); + } + else if ( IdentifiableProperty.NAME == property ) + { + return store.getByName( value ); + } + else if ( IdentifiableProperty.ATTRIBUTE == property ) + { + return store.getByAttributeValue( attribute, value ); + } + else if ( property == null || IdentifiableProperty.ID == property ) + { + if ( Integer.valueOf( value ) > 0 ) { - return store.get( Integer.valueOf( id ) ); + return store.get( Integer.valueOf( value ) ); } } - else if ( IdentifiableProperty.UID.equals( property ) ) - { - return store.getByUid( id ); - } else if ( IdentifiableProperty.UUID.equals( property ) && OrganisationUnit.class.isAssignableFrom( clazz ) ) { - return (T) organisationUnitService.getOrganisationUnitByUuid( id ); - } - else if ( IdentifiableProperty.CODE.equals( property ) ) - { - return store.getByCode( id ); - } - else if ( IdentifiableProperty.NAME.equals( property ) ) - { - return store.getByName( id ); + return (T) organisationUnitService.getOrganisationUnitByUuid( value ); } throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2015-12-03 03:12:51 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2015-12-03 04:18:07 +0000 @@ -43,6 +43,7 @@ import org.hisp.dhis.common.NameableObject; import org.hisp.dhis.hibernate.HibernateGenericStore; import org.hisp.dhis.hibernate.exception.ReadAccessDeniedException; +import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.Collection; @@ -176,7 +177,7 @@ @SuppressWarnings( "unchecked" ) public T getByAttributeValue( Attribute attribute, String value ) { - if ( !attribute.isUnique() ) + if ( attribute == null || StringUtils.isEmpty( value ) || !attribute.isUnique() ) { return null; }