=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-06-25 18:50:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2015-09-13 17:13:09 +0000 @@ -39,11 +39,13 @@ import java.util.ListIterator; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.hisp.dhis.calendar.Calendar; import org.hisp.dhis.calendar.DateTimeUnit; import org.hisp.dhis.dataelement.DataElementCategory; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOption; +import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; @@ -398,4 +400,60 @@ return map; } + + /** + * Returns a map of identifiable properties and objects. + * + * @param objects the objects. + * @param property the identifiable property. + * @return a map. + */ + @SuppressWarnings( "unchecked" ) + public static Map getMap( List objects, IdentifiableProperty property ) + { + Map map = new HashMap<>(); + + for ( T object : objects ) + { + if ( IdentifiableProperty.ID.equals( property ) ) + { + if ( object.getId() > 0 ) + { + map.put( String.valueOf( object.getId() ), object ); + } + } + else if ( IdentifiableProperty.UID.equals( property ) ) + { + if ( object.getUid() != null ) + { + map.put( object.getUid(), object ); + } + } + else if ( IdentifiableProperty.CODE.equals( property ) ) + { + if ( object.getCode() != null ) + { + map.put( object.getCode(), object ); + } + } + else if ( IdentifiableProperty.NAME.equals( property ) ) + { + if ( object.getName() != null ) + { + map.put( object.getName(), object ); + } + } + else if ( IdentifiableProperty.UUID.equals( property ) && OrganisationUnit.class.isAssignableFrom( object.getClass() ) ) + { + OrganisationUnit organisationUnit = (OrganisationUnit) object; + + if ( !StringUtils.isEmpty( organisationUnit.getUuid() ) ) + { + map.put( organisationUnit.getUuid(), (T) organisationUnit ); + } + } + } + + return map; + } } === 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-06-25 18:50:24 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-09-13 17:13:09 +0000 @@ -48,7 +48,6 @@ import org.hisp.dhis.user.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; /** * Note that it is required for nameable object stores to have concrete implementation @@ -674,40 +673,8 @@ } List objects = store.getAll(); - - for ( T object : objects ) - { - if ( IdentifiableProperty.ID.equals( property ) ) - { - if ( object.getId() > 0 ) - { - map.put( String.valueOf( object.getId() ), object ); - } - } - else if ( IdentifiableProperty.UID.equals( property ) ) - { - if ( object.getUid() != null ) - { - map.put( object.getUid(), object ); - } - } - else if ( IdentifiableProperty.CODE.equals( property ) ) - { - if ( object.getCode() != null ) - { - map.put( object.getCode(), object ); - } - } - else if ( IdentifiableProperty.NAME.equals( property ) ) - { - if ( object.getName() != null ) - { - map.put( object.getName(), object ); - } - } - } - - return map; + + return IdentifiableObjectUtils.getMap( objects, property ); } @Override @@ -725,48 +692,7 @@ List objects = store.getAllNoAcl(); - for ( T object : objects ) - { - if ( IdentifiableProperty.ID.equals( property ) ) - { - if ( object.getId() > 0 ) - { - map.put( String.valueOf( object.getId() ), object ); - } - } - else if ( IdentifiableProperty.UID.equals( property ) ) - { - if ( object.getUid() != null ) - { - map.put( object.getUid(), object ); - } - } - else if ( IdentifiableProperty.CODE.equals( property ) ) - { - if ( object.getCode() != null ) - { - map.put( object.getCode(), object ); - } - } - else if ( IdentifiableProperty.NAME.equals( property ) ) - { - if ( object.getName() != null ) - { - map.put( object.getName(), object ); - } - } - else if ( IdentifiableProperty.UUID.equals( property ) && OrganisationUnit.class.isAssignableFrom( clazz ) ) - { - OrganisationUnit organisationUnit = (OrganisationUnit) object; - - if ( !StringUtils.isEmpty( organisationUnit.getUuid() ) ) - { - map.put( organisationUnit.getUuid(), (T) organisationUnit ); - } - } - } - - return map; + return IdentifiableObjectUtils.getMap( objects, property ); } @Override