dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21126
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9918: more fixes to dxf2 importer
------------------------------------------------------------
revno: 9918
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-28 12:17:00 +0700
message:
more fixes to dxf2 importer
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java
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/importers/DefaultIdentifiableObjectImporter.java
dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
--
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/SharingUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-02-20 08:38:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-02-28 05:17:00 +0000
@@ -51,7 +51,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-public class SharingUtils
+public final class SharingUtils
{
public static Map<Class<? extends IdentifiableObject>, String> PUBLIC_AUTHORITIES = new HashMap<Class<? extends IdentifiableObject>, String>();
@@ -283,4 +283,8 @@
{
return user != null && user.getUserCredentials().getAllAuthorities().contains( SHARING_OVERRIDE_AUTHORITY );
}
+
+ private SharingUtils()
+ {
+ }
}
=== 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 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2013-02-28 05:17:00 +0000
@@ -132,7 +132,7 @@
// Populate Helpers
//-------------------------------------------------------------------------------------------------------
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void populateIdentifiableObjectMap( Class<?> clazz )
{
Collection<IdentifiableObject> map = new ArrayList<IdentifiableObject>();
@@ -148,7 +148,7 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void populateIdentifiableObjectMap( Class<?> clazz, IdentifiableObject.IdentifiableProperty property )
{
Map<String, IdentifiableObject> map = new HashMap<String, IdentifiableObject>();
@@ -218,6 +218,8 @@
{
manager.save( (IdentifiableObject) object );
}
+
+ _updateInternalMaps( object );
}
else
{
@@ -288,7 +290,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public <T> Collection<T> getAllObjects( Class<T> clazz )
{
return (Collection<T>) masterMap.get( clazz );
@@ -320,7 +322,7 @@
// Internal Methods
//-------------------------------------------------------------------------------------------------------
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private <T> Collection<T> _findMatches( T object )
{
Collection<T> objects = new HashSet<T>();
@@ -405,6 +407,19 @@
map.put( identifiableObject.getCode(), identifiableObject );
}
+
+ if ( identifiableObject.haveUniqueNames() && identifiableObject.getName() != null )
+ {
+ Map<String, IdentifiableObject> map = nameMap.get( identifiableObject.getClass() );
+
+ if ( map == null )
+ {
+ // might be dynamically sub-classed by javassist or cglib, fetch superclass and try again
+ map = nameMap.get( identifiableObject.getClass().getSuperclass() );
+ }
+
+ map.put( identifiableObject.getCode(), identifiableObject );
+ }
}
}
=== 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 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-02-28 05:17:00 +0000
@@ -150,7 +150,7 @@
deleteAttributeValues( object );
deleteExpression( object, "leftSide" );
deleteExpression( object, "rightSide" );
- // deleteDataElementOperands( object, "compulsoryDataElementOperands" );
+ // deleteDataElementOperands( idObject, "compulsoryDataElementOperands" );
deleteDataElementOperands( object, "greyedFields" );
}
}
@@ -160,7 +160,7 @@
saveAttributeValues( object, attributeValues );
saveExpression( object, "leftSide", leftSide );
saveExpression( object, "rightSide", rightSide );
- // saveDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
+ // saveDataElementOperands( idObject, "compulsoryDataElementOperands", compulsoryDataElementOperands );
saveDataElementOperands( object, "greyedFields", greyedFields );
}
@@ -326,7 +326,7 @@
//-------------------------------------------------------------------------------------------------------
/**
- * Called every time a new object is to be imported.
+ * Called every time a new idObject is to be imported.
*
* @param object Object to import
* @return An ImportConflict instance if there was a conflict, otherwise null
@@ -365,10 +365,10 @@
}
/**
- * Update object from old => new.
+ * Update idObject from old => new.
*
* @param object Object to import
- * @param persistedObject The current version of the object
+ * @param persistedObject The current version of the idObject
* @return An ImportConflict instance if there was a conflict, otherwise null
*/
protected boolean updateObject( T object, T persistedObject )
@@ -457,7 +457,9 @@
this.options = options;
this.summaryType = new ImportTypeSummary( importerClass.getSimpleName() );
+ ObjectHandlerUtils.preObjectHandlers( object, objectHandlers );
importObjectLocal( object );
+ ObjectHandlerUtils.postObjectHandlers( object, objectHandlers );
return summaryType;
}
@@ -701,7 +703,7 @@
return collectionFields;
}
- private void reattachCollectionFields( final Object object, Map<Field, Collection<Object>> collectionFields )
+ private void reattachCollectionFields( final Object idObject, Map<Field, Collection<Object>> collectionFields )
{
for ( Field field : collectionFields.keySet() )
{
@@ -721,9 +723,9 @@
}
else
{
- if ( ExchangeClasses.getImportMap().get( object.getClass() ) != null )
+ if ( ExchangeClasses.getImportMap().get( idObject.getClass() ) != null )
{
- reportReferenceError( object, object );
+ reportReferenceError( idObject, object );
}
}
}
@@ -731,7 +733,7 @@
if ( !options.isDryRun() )
{
- ReflectionUtils.invokeSetterMethod( field.getName(), object, objects );
+ ReflectionUtils.invokeSetterMethod( field.getName(), idObject, objects );
}
}
}
@@ -751,13 +753,32 @@
return new ImportConflict( ImportUtils.getDisplayName( object ), "Object already exists." );
}
- private void reportReferenceError( Object object, Object idObject )
- {
- String referenceName = idObject != null ? idObject.getClass().getSimpleName() : "null";
+ public String identifiableObjectToString( Object object )
+ {
+ if ( IdentifiableObject.class.isInstance( object ) )
+ {
+ IdentifiableObject identifiableObject = (IdentifiableObject) object;
+
+ return "IdentifiableObject{" +
+ "id=" + identifiableObject.getId() +
+ ", uid='" + identifiableObject.getUid() + '\'' +
+ ", code='" + identifiableObject.getCode() + '\'' +
+ ", name='" + identifiableObject.getName() + '\'' +
+ ", created=" + identifiableObject.getCreated() +
+ ", lastUpdated=" + identifiableObject.getLastUpdated() +
+ '}';
+ }
+
+ return object.toString();
+ }
+
+ private void reportReferenceError( Object object, Object reference )
+ {
String objectName = object != null ? object.getClass().getSimpleName() : "null";
+ String referenceName = reference != null ? reference.getClass().getSimpleName() : "null";
- String logMsg = "Unknown reference to " + idObject + " (" + referenceName + ")" +
- " on object " + object + " (" + objectName + ").";
+ String logMsg = "Unknown reference to " + identifiableObjectToString( reference ) + " (" + referenceName + ")" +
+ " on object " + identifiableObjectToString( object ) + " (" + objectName + ").";
log.warn( logMsg );
=== modified file 'dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-02-27 10:24:44 +0000
+++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2013-02-28 05:17:00 +0000
@@ -14,7 +14,7 @@
<bean id="org.hisp.dhis.dxf2.datavalueset.DataValueSetStore"
class="org.hisp.dhis.dxf2.datavalueset.SpringDataValueSetStore" />
- <!-- register object handlers -->
+ <!-- register idObject handlers -->
<bean id="organisationUnitObjectHandler"
class="org.hisp.dhis.dxf2.metadata.handlers.OrganisationUnitObjectHandler" scope="prototype"/>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-02-18 03:55:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-02-28 05:17:00 +0000
@@ -1030,13 +1030,13 @@
</aop:aspect>
<!-- <aop:aspect ref="i18nTranslationInterceptor"> <aop:after-returning pointcut="execution( * org.hisp.dhis.dataelement.DataElementService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.dataelement.DataElementCategoryService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.indicator.IndicatorService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.datadictionary.DataDictionaryService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.dataset.DataSetService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.organisationunit.OrganisationUnitService.get*(..)
- )" method="intercept" returning="object"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.organisationunit.OrganisationUnitGroupService.get*(..)
- )" method="intercept" returning="object"/> </aop:aspect> -->
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.dataelement.DataElementCategoryService.get*(..)
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.indicator.IndicatorService.get*(..)
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.datadictionary.DataDictionaryService.get*(..)
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.dataset.DataSetService.get*(..)
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.organisationunit.OrganisationUnitService.get*(..)
+ )" method="intercept" returning="idObject"/> <aop:after-returning pointcut="execution( * org.hisp.dhis.organisationunit.OrganisationUnitGroupService.get*(..)
+ )" method="intercept" returning="idObject"/> </aop:aspect> -->
</aop:config>
<!-- Security import -->