=== 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 2012-03-26 18:11:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2012-04-22 18:21:40 +0000 @@ -28,12 +28,7 @@ */ import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; +import java.util.*; /** * @author Lars Helge Overland @@ -43,12 +38,12 @@ private static final String SEPARATOR_JOIN = ", "; private static final String SEPARATOR = "-"; private static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ); - + /** - * Joins the names of the IdentifiableObjects in the given list and separates - * them with a comma and space. Returns null if the given list is null or has + * Joins the names of the IdentifiableObjects in the given list and separates + * them with a comma and space. Returns null if the given list is null or has * no elements. - * + * * @param objects the list of IdentifiableObjects. * @return the joined string. */ @@ -57,30 +52,30 @@ if ( objects != null && objects.size() > 0 ) { Iterator iterator = objects.iterator(); - + StringBuilder builder = new StringBuilder( iterator.next().getDisplayName() ); - + while ( iterator.hasNext() ) { builder.append( SEPARATOR_JOIN ).append( iterator.next().getDisplayName() ); } - + return builder.toString(); } - + return null; } - + /** * Filters the given list of IdentifiableObjects based on the given key. - * + * * @param identifiableObjects the list of IdentifiableObjects. - * @param key the key. - * @param ignoreCase indicates whether to ignore case when filtering. + * @param key the key. + * @param ignoreCase indicates whether to ignore case when filtering. * @return a filtered list of IdentifiableObjects. */ public static List filterNameByKey( List identifiableObjects, String key, - boolean ignoreCase ) + boolean ignoreCase ) { List objects = new ArrayList(); ListIterator iterator = identifiableObjects.listIterator(); @@ -103,29 +98,29 @@ return objects; } - + /** * Generates a tag reflecting when the date of when the most recently updated * IdentifiableObject in the given collection was modified. - * + * * @param objects the collection of IdentifiableObjects. * @return a string tag. */ public static String getLastUpdatedTag( Collection objects ) { Date latest = null; - + if ( objects != null ) { for ( IdentifiableObject object : objects ) { - if ( object != null && object.getLastUpdated() != null && ( latest == null || object.getLastUpdated().after( latest ) ) ) + if ( object != null && object.getLastUpdated() != null && (latest == null || object.getLastUpdated().after( latest )) ) { latest = object.getLastUpdated(); } } } - + return latest != null && objects != null ? objects.size() + SEPARATOR + LONG_DATE_FORMAT.format( latest ) : null; } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2012-04-20 18:31:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2012-04-22 18:21:40 +0000 @@ -87,7 +87,6 @@ /** * Set of the dynamic attributes values that belong to this User. */ - @Scanned private Set attributeValues = new HashSet(); // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-22 16:16:24 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2012-04-22 18:21:40 +0000 @@ -35,6 +35,7 @@ import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.Date; @@ -92,17 +93,13 @@ doImport( metaData.getUsers(), importOptions, importSummary ); doImport( metaData.getUserGroups(), importOptions, importSummary ); doImport( metaData.getUserAuthorityGroups(), importOptions, importSummary ); -*/ -/* doImport( metaData.getConcepts(), importOptions, importSummary ); doImport( metaData.getConstants(), importOptions, importSummary ); doImport( metaData.getDocuments(), importOptions, importSummary ); doImport( metaData.getAttributeTypes(), importOptions, importSummary ); doImport( metaData.getOptionSets(), importOptions, importSummary ); -*/ -/* doImport( metaData.getCategoryOptions(), importOptions, importSummary ); doImport( metaData.getCategories(), importOptions, importSummary ); doImport( metaData.getCategoryCombos(), importOptions, importSummary ); @@ -111,9 +108,7 @@ doImport( metaData.getDataElements(), importOptions, importSummary ); doImport( metaData.getDataElementGroups(), importOptions, importSummary ); doImport( metaData.getDataElementGroupSets(), importOptions, importSummary ); -*/ -/* doImport( metaData.getIndicatorTypes(), importOptions, importSummary ); doImport( metaData.getIndicators(), importOptions, importSummary ); doImport( metaData.getIndicatorGroups(), importOptions, importSummary ); === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2012-04-22 16:42:06 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2012-04-22 18:21:40 +0000 @@ -267,11 +267,11 @@ } else if ( objects.size() > 1 ) { - log.warn( "Multiple objects found.. object discarded, returning null." ); + log.debug( "Multiple objects found.. object discarded, returning null." ); } else { - log.warn( "No object found, returning null." ); + log.debug( "No object found, returning null." ); } return null; === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-04-22 16:42:06 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-04-22 18:21:40 +0000 @@ -32,6 +32,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.common.NameableObject; import org.hisp.dhis.common.annotation.Scanned; import org.hisp.dhis.dxf2.importsummary.ImportConflict; import org.hisp.dhis.dxf2.importsummary.ImportCount; @@ -99,19 +100,29 @@ /** * Called every time a new object is to be imported. * - * @param object Object to import - * @param options Current import options + * @param object Object to import * @return An ImportConflict instance if there was a conflict, otherwise null */ - protected ImportConflict newObject( T object, ImportOptions options ) + protected ImportConflict newObject( T object ) { // make sure that the internalId is 0, so that the system will generate a ID object.setId( 0 ); object.setUid( CodeGenerator.generateCode() ); - log.info( "Trying to save new object => " + getDisplayName( object ) ); - - Map> identifiableObjectCollections = scanIdentifiableObjectCollections( object ); + log.debug( "Trying to save new object => " + getDisplayName( object ) ); + + if ( NameableObject.class.isInstance( object ) ) + { + NameableObject nameableObject = (NameableObject) object; + + if ( nameableObject.getShortName() == null ) + { + log.info( "shortName is null on " + object ); + } + } + + Map> identifiableObjectCollections = + scanIdentifiableObjectCollections( object ); updateIdentifiableObjects( object, scanIdentifiableObjects( object ) ); @@ -122,8 +133,7 @@ updatePeriodTypes( object ); objectBridge.updateObject( object ); - log.info( "Save successful." ); - log.info( object ); + log.debug( "Save successful." ); return null; } @@ -133,12 +143,12 @@ * * @param object Object to import * @param oldObject The current version of the object - * @param options Current import options * @return An ImportConflict instance if there was a conflict, otherwise null */ - protected ImportConflict updatedObject( T object, T oldObject, ImportOptions options ) + protected ImportConflict updatedObject( T object, T oldObject ) { - log.info( "Starting update of object " + getDisplayName( oldObject ) + " (" + oldObject.getClass().getSimpleName() + ")" ); + log.debug( "Starting update of object " + getDisplayName( oldObject ) + " (" + oldObject.getClass() + .getSimpleName() + ")" ); updateIdentifiableObjects( object, scanIdentifiableObjects( object ) ); updateIdentifiableObjectCollections( object, scanIdentifiableObjectCollections( object ) ); @@ -148,7 +158,7 @@ objectBridge.updateObject( oldObject ); - log.info( "Update successful." ); + log.debug( "Update successful." ); return null; } @@ -234,7 +244,11 @@ */ protected String getDisplayName( IdentifiableObject object ) { - if ( object.getName() != null ) + if ( object == null ) + { + return "[ object is null ]"; + } + else if ( object.getName() != null ) { return object.getName(); } @@ -291,7 +305,7 @@ if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) ) { - conflict = newObject( object, options ); + conflict = newObject( object ); if ( conflict != null ) { @@ -302,7 +316,7 @@ } else if ( ImportStrategy.UPDATES.equals( options.getImportStrategy() ) ) { - conflict = updatedObject( object, oldObject, options ); + conflict = updatedObject( object, oldObject ); if ( conflict != null ) { @@ -315,7 +329,7 @@ { if ( oldObject != null ) { - conflict = updatedObject( object, oldObject, options ); + conflict = updatedObject( object, oldObject ); if ( conflict != null ) { @@ -326,7 +340,7 @@ } else { - conflict = newObject( object, options ); + conflict = newObject( object ); if ( conflict != null ) { @@ -448,7 +462,8 @@ return identifiableObjects; } - private void updateIdentifiableObjects( IdentifiableObject identifiableObject, Map identifiableObjects ) + private void updateIdentifiableObjects( IdentifiableObject identifiableObject, Map identifiableObjects ) { for ( Field field : identifiableObjects.keySet() ) { @@ -460,23 +475,28 @@ } else { - log.info( "--> Ignored reference " + getDisplayName( identifiableObject ) + "." ); + log.warn( "Ignored reference " + getDisplayName( ref ) + " on object " + getDisplayName( + identifiableObject ) + "." ); } } } - private Map> scanIdentifiableObjectCollections( IdentifiableObject identifiableObject ) + private Map> scanIdentifiableObjectCollections( IdentifiableObject + identifiableObject ) { - Map> collected = new HashMap>(); + Map> collected = new HashMap>(); Field[] fields = identifiableObject.getClass().getDeclaredFields(); for ( Field field : fields ) { - boolean b = ReflectionUtils.isCollection( field.getName(), identifiableObject, IdentifiableObject.class, Scanned.class ); + boolean b = ReflectionUtils.isCollection( field.getName(), identifiableObject, IdentifiableObject.class, + Scanned.class ); if ( b ) { - Collection objects = ReflectionUtils.invokeGetterMethod( field.getName(), identifiableObject ); + Collection objects = ReflectionUtils.invokeGetterMethod( field.getName(), + identifiableObject ); if ( objects != null && !objects.isEmpty() ) { @@ -491,7 +511,7 @@ } private void updateIdentifiableObjectCollections( IdentifiableObject identifiableObject, - Map> identifiableObjectCollections ) + Map> identifiableObjectCollections ) { for ( Field field : identifiableObjectCollections.keySet() ) { @@ -508,7 +528,7 @@ } else { - log.warn( "Unknown Collection type!" ); + log.warn( "Unknown Collection type." ); continue; } @@ -522,7 +542,8 @@ } else { - log.info( "--> Ignored reference " + getDisplayName( identifiableObject ) + "." ); + log.warn( "Ignored reference " + getDisplayName( identifiableObject ) + " on object " + + getDisplayName( identifiableObject ) + "." ); } } === 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 2012-04-13 14:11:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-04-22 18:21:40 +0000 @@ -27,16 +27,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; import org.hisp.dhis.common.NameableObject.NameableProperty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author Lars Helge Overland @@ -45,6 +44,8 @@ public class DefaultIdentifiableObjectManager implements IdentifiableObjectManager { + private static final Log log = LogFactory.getLog( DefaultIdentifiableObjectManager.class ); + @Autowired private Set> objectStores; @@ -73,6 +74,7 @@ } } + @Override public void save( IdentifiableObject object ) { if ( objectStoreMap.get( object.getClass() ) != null ) @@ -81,6 +83,7 @@ } } + @Override public void update( IdentifiableObject object ) { if ( objectStoreMap.get( object.getClass() ) != null ) @@ -89,42 +92,68 @@ } } + @Override + @SuppressWarnings( "unchecked" ) public T get( Class clazz, String uid ) { - if ( objectStoreMap.get( clazz ) != null ) + GenericIdentifiableObjectStore store = objectStoreMap.get( clazz ); + + if ( store == null ) { - return (T) objectStoreMap.get( clazz ).getByUid( uid ); + log.warn( "No IdentifiableObject store found for " + clazz + ", returning null." ); + + return null; } - return null; + return (T) store.getByUid( uid ); } @Override + @SuppressWarnings( "unchecked" ) public T getByCode( Class clazz, String code ) { - if ( objectStoreMap.get( clazz ) != null ) + GenericIdentifiableObjectStore store = objectStoreMap.get( clazz ); + + if ( store == null ) { - return (T) objectStoreMap.get( clazz ).getByCode( code ); + log.warn( "No IdentifiableObject store found for " + clazz + ", returning null." ); + + return null; } - return null; + return (T) store.getByCode( code ); } @Override + @SuppressWarnings( "unchecked" ) public T getByName( Class clazz, String name ) { - if ( objectStoreMap.get( clazz ) != null ) + GenericIdentifiableObjectStore store = objectStoreMap.get( clazz ); + + if ( store == null ) { - return (T) objectStoreMap.get( clazz ).getByName( name ); + log.warn( "No IdentifiableObject store found for " + clazz + ", returning null." ); + + return null; } - return null; + return (T) store.getByName( name ); } + @Override @SuppressWarnings( "unchecked" ) public Collection getAll( Class clazz ) { - return (Collection) objectStoreMap.get( clazz ).getAll(); + GenericIdentifiableObjectStore store = objectStoreMap.get( clazz ); + + if ( store == null ) + { + log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection." ); + + return new ArrayList(); + } + + return (Collection) store.getAll(); } public void delete( IdentifiableObject object ) @@ -132,6 +161,7 @@ objectStoreMap.get( object.getClass() ).delete( object ); } + @Override @SuppressWarnings( "unchecked" ) public Map getIdMap( Class clazz, IdentifiableProperty property ) { @@ -206,6 +236,7 @@ return map; } + @Override @SuppressWarnings( "unchecked" ) public T getObject( Class clazz, IdentifiableProperty property, String id ) { @@ -237,6 +268,7 @@ throw new IllegalArgumentException( String.valueOf( property ) ); } + @Override public IdentifiableObject getObject( String uid, String simpleClassName ) { for ( GenericIdentifiableObjectStore objectStore : objectStores ) @@ -250,6 +282,7 @@ return null; } + @Override public IdentifiableObject getObject( int id, String simpleClassName ) { for ( GenericIdentifiableObjectStore objectStore : objectStores )