dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26676
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13195: support importing DataSet.compulsoryDataElements
------------------------------------------------------------
revno: 13195
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-10 17:38:55 +0100
message:
support importing DataSet.compulsoryDataElements
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-10-14 14:38:11 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-12-10 16:38:55 +0000
@@ -163,7 +163,7 @@
deleteExpression( object, "leftSide" );
deleteExpression( object, "rightSide" );
deleteDataEntryForm( object, "dataEntryForm" );
- // deleteDataElementOperands( idObject, "compulsoryDataElementOperands" );
+ // deleteDataElementOperands( object, "compulsoryDataElementOperands" );
deleteDataElementOperands( object, "greyedFields" );
}
}
@@ -174,7 +174,7 @@
saveExpression( object, "leftSide", leftSide );
saveExpression( object, "rightSide", rightSide );
saveDataEntryForm( object, "dataEntryForm", dataEntryForm );
- // saveDataElementOperands( idObject, "compulsoryDataElementOperands", compulsoryDataElementOperands );
+ saveDataElementOperands( object, "compulsoryDataElementOperands", compulsoryDataElementOperands );
saveDataElementOperands( object, "greyedFields", greyedFields );
}
@@ -291,16 +291,33 @@
{
if ( dataElementOperands.size() > 0 )
{
- for ( DataElementOperand dataElementOperand : dataElementOperands )
- {
- Map<Field, Object> identifiableObjects = detachFields( dataElementOperand );
- reattachFields( dataElementOperand, identifiableObjects );
-
- dataElementOperand.setId( 0 );
- dataElementOperandService.addDataElementOperand( dataElementOperand );
- }
-
- ReflectionUtils.invokeSetterMethod( fieldName, object, dataElementOperands );
+ // need special handling for compulsoryDataElementOperands since they cascade with all-delete-orphan
+ if ( "compulsoryDataElementOperands".equals( fieldName ) )
+ {
+ for ( DataElementOperand dataElementOperand : dataElementOperands )
+ {
+ Map<Field, Object> identifiableObjects = detachFields( dataElementOperand );
+ reattachFields( dataElementOperand, identifiableObjects );
+ }
+
+ Set<DataElementOperand> detachedDataElementOperands = ReflectionUtils.invokeGetterMethod( fieldName, object );
+ detachedDataElementOperands.clear();
+ detachedDataElementOperands.addAll( dataElementOperands );
+ sessionFactory.getCurrentSession().flush();
+ }
+ else
+ {
+ for ( DataElementOperand dataElementOperand : dataElementOperands )
+ {
+ Map<Field, Object> identifiableObjects = detachFields( dataElementOperand );
+ reattachFields( dataElementOperand, identifiableObjects );
+
+ dataElementOperand.setId( 0 );
+ dataElementOperandService.addDataElementOperand( dataElementOperand );
+ }
+
+ ReflectionUtils.invokeSetterMethod( fieldName, object, dataElementOperands );
+ }
}
}