dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17091
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6700: Added empty string check in setAutoFields. Made IdentifiableObjectManager work correctly with dyn...
------------------------------------------------------------
revno: 6700
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-04-23 14:13:41 +0300
message:
Added empty string check in setAutoFields. Made IdentifiableObjectManager work correctly with dynamically subclassed classes. Added simple validation of name/shortname for importer.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java
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/utils/JacksonUtils.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
--
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/common/BaseIdentifiableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2012-04-17 08:04:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2012-04-23 11:13:41 +0000
@@ -122,7 +122,7 @@
// -------------------------------------------------------------------------
@JsonProperty( value = "internalId" )
- @JsonView( {DetailedView.class, IdentifiableObjectView.class, ExportView.class } )
+ @JsonView( {DetailedView.class, IdentifiableObjectView.class, ExportView.class} )
@JacksonXmlProperty( isAttribute = true )
public int getId()
{
@@ -230,7 +230,7 @@
*/
public void setAutoFields()
{
- if ( uid == null )
+ if ( uid == null || uid.length() == 0 )
{
setUid( CodeGenerator.generateCode() );
}
=== 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 21:29:34 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-04-23 11:13:41 +0000
@@ -113,16 +113,6 @@
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<Field, Set<? extends IdentifiableObject>> identifiableObjectCollections =
scanIdentifiableObjectCollections( object );
@@ -250,15 +240,15 @@
{
return "[ object is null ]";
}
- else if ( object.getName() != null )
+ else if ( object.getName() != null && object.getName().length() > 0 )
{
return object.getName();
}
- else if ( object.getUid() != null )
+ else if ( object.getUid() != null && object.getName().length() > 0 )
{
return object.getUid();
}
- else if ( object.getCode() != null )
+ else if ( object.getCode() != null && object.getName().length() > 0 )
{
return object.getCode();
}
@@ -360,6 +350,23 @@
{
ImportConflict conflict = null;
+ // FIXME add bean validation for this
+ if ( object.getName() == null || object.getName().length() == 0 )
+ {
+ return new ImportConflict( getDisplayName( object ), "Empty name." );
+ }
+
+ if ( NameableObject.class.isInstance( object ) )
+ {
+ NameableObject nameableObject = (NameableObject) object;
+
+ if ( nameableObject.getShortName() == null || nameableObject.getShortName().length() == 0 )
+ {
+ return new ImportConflict( getDisplayName( object ), "Empty shortName." );
+ }
+ }
+ // end
+
if ( ImportStrategy.NEW.equals( options.getImportStrategy() ) )
{
conflict = validateForNewStrategy( object );
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java 2012-04-14 16:20:11 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java 2012-04-23 11:13:41 +0000
@@ -29,6 +29,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
=== 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-23 08:38:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-04-23 11:13:41 +0000
@@ -47,23 +47,23 @@
private static final Log log = LogFactory.getLog( DefaultIdentifiableObjectManager.class );
@Autowired
- private Set<GenericIdentifiableObjectStore<IdentifiableObject>> objectStores;
+ private Set<GenericIdentifiableObjectStore<IdentifiableObject>> identifiableObjectStores;
@Autowired
private Set<GenericNameableObjectStore<NameableObject>> nameableObjectStores;
- private Map<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>> objectStoreMap;
+ private Map<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>> identifiableObjectStoreMap;
private Map<Class<NameableObject>, GenericNameableObjectStore<NameableObject>> nameableObjectStoreMap;
@PostConstruct
public void init()
{
- objectStoreMap = new HashMap<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>>();
+ identifiableObjectStoreMap = new HashMap<Class<IdentifiableObject>, GenericIdentifiableObjectStore<IdentifiableObject>>();
- for ( GenericIdentifiableObjectStore<IdentifiableObject> store : objectStores )
+ for ( GenericIdentifiableObjectStore<IdentifiableObject> store : identifiableObjectStores )
{
- objectStoreMap.put( store.getClazz(), store );
+ identifiableObjectStoreMap.put( store.getClazz(), store );
}
nameableObjectStoreMap = new HashMap<Class<NameableObject>, GenericNameableObjectStore<NameableObject>>();
@@ -77,7 +77,7 @@
@Override
public void save( IdentifiableObject object )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( object.getClass() );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( object.getClass() );
if ( store != null )
{
@@ -92,7 +92,7 @@
@Override
public void update( IdentifiableObject object )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( object.getClass() );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( object.getClass() );
if ( store != null )
{
@@ -107,7 +107,7 @@
@Override
public void delete( IdentifiableObject object )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( object.getClass() );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( object.getClass() );
if ( store != null )
{
@@ -123,7 +123,7 @@
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T get( Class<T> clazz, String uid )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
if ( store == null )
{
@@ -139,7 +139,7 @@
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
if ( store == null )
{
@@ -155,7 +155,7 @@
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T getByName( Class<T> clazz, String name )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
if ( store == null )
{
@@ -171,7 +171,7 @@
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Collection<T> getAll( Class<T> clazz )
{
- GenericIdentifiableObjectStore<IdentifiableObject> store = objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
if ( store == null )
{
@@ -189,7 +189,7 @@
{
Map<String, T> map = new HashMap<String, T>();
- GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
Collection<T> objects = store.getAll();
@@ -229,11 +229,12 @@
}
@Override
+ @SuppressWarnings( "unchecked" )
public <T extends NameableObject> Map<String, T> getIdMap( Class<T> clazz, NameableProperty property )
{
Map<String, T> map = new HashMap<String, T>();
- GenericNameableObjectStore<T> store = (GenericNameableObjectStore<T>) nameableObjectStoreMap.get( clazz );
+ GenericNameableObjectStore<T> store = (GenericNameableObjectStore<T>) getNameableObjectStore( clazz );
Collection<T> objects = store.getAll();
@@ -262,7 +263,7 @@
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String id )
{
- GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) objectStoreMap.get( clazz );
+ GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
if ( id != null )
{
@@ -293,7 +294,7 @@
@Override
public IdentifiableObject getObject( String uid, String simpleClassName )
{
- for ( GenericIdentifiableObjectStore<IdentifiableObject> objectStore : objectStores )
+ for ( GenericIdentifiableObjectStore<IdentifiableObject> objectStore : identifiableObjectStores )
{
if ( simpleClassName.equals( objectStore.getClass().getSimpleName() ) )
{
@@ -307,7 +308,7 @@
@Override
public IdentifiableObject getObject( int id, String simpleClassName )
{
- for ( GenericIdentifiableObjectStore<IdentifiableObject> objectStore : objectStores )
+ for ( GenericIdentifiableObjectStore<IdentifiableObject> objectStore : identifiableObjectStores )
{
if ( simpleClassName.equals( objectStore.getClazz().getSimpleName() ) )
{
@@ -317,4 +318,28 @@
return null;
}
+
+ private <T extends IdentifiableObject> GenericIdentifiableObjectStore<IdentifiableObject> getIdentifiableObjectStore( Class<T> clazz )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = identifiableObjectStoreMap.get( clazz );
+
+ if ( store == null )
+ {
+ store = identifiableObjectStoreMap.get( clazz.getSuperclass() );
+ }
+
+ return store;
+ }
+
+ private <T extends NameableObject> GenericNameableObjectStore<NameableObject> getNameableObjectStore( Class<T> clazz )
+ {
+ GenericNameableObjectStore<NameableObject> store = nameableObjectStoreMap.get( clazz );
+
+ if ( store == null )
+ {
+ store = nameableObjectStoreMap.get( clazz.getSuperclass() );
+ }
+
+ return store;
+ }
}