dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43638
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22125: If mode is CREATE and object exists, report back and remove from object bundle
------------------------------------------------------------
revno: 22125
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-03-03 12:13:32 +0700
message:
If mode is CREATE and object exists, report back and remove from object bundle
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorCode.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java
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/metadata2/objectbundle/DefaultObjectBundleService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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/feedback/ErrorCode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorCode.java 2016-03-03 01:20:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorCode.java 2016-03-03 05:13:32 +0000
@@ -52,8 +52,9 @@
E4011( "Attribute \"{0}\" is required, but not value was found." ),
/* Preheat Errors */
- E5000( "No matching object for given reference. Identifier was {0}, and object was {1}." ),
- E5001( "Invalid reference {0} on object {1} for association \"{2}\"." );
+ E5000( "Found matching object for given reference, but import mode is CREATE. Identifier was {0}, and object was {1}." ),
+ E5001( "No matching object for given reference. Identifier was {0}, and object was {1}." ),
+ E5002( "Invalid reference {0} on object {1} for association \"{2}\"." );
private String message;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-03-03 05:02:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-03-03 05:13:32 +0000
@@ -471,7 +471,7 @@
if ( ref == null && refObject != null && !Preheat.isDefault( refObject ) )
{
- preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5001,
+ preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
identifier.getIdentifiersWithName( refObject ), identifier.getIdentifiersWithName( object ), p.getName() ) );
}
}
@@ -488,7 +488,7 @@
if ( ref == null && refObject != null )
{
- preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5001,
+ preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
identifier.getIdentifiersWithName( refObject ), identifier.getIdentifiersWithName( object ), p.getCollectionName() ) );
}
else
=== 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 2016-03-03 01:20:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2016-03-03 05:13:32 +0000
@@ -980,7 +980,7 @@
if ( attribute == null )
{
- errorReports.add( new ErrorReport( Attribute.class, ErrorCode.E5001, attributeValue.getAttribute().getUid(),
+ errorReports.add( new ErrorReport( Attribute.class, ErrorCode.E5002, attributeValue.getAttribute().getUid(),
object.getUid(), "attributeValues" ) );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-03 05:02:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-03 05:13:32 +0000
@@ -173,7 +173,24 @@
for ( Class<? extends IdentifiableObject> klass : klasses )
{
- if ( bundle.getImportMode().isUpdate() || bundle.getImportMode().isDelete() )
+ if ( bundle.getImportMode().isCreate() )
+ {
+ Iterator<IdentifiableObject> iterator = bundle.getObjects().get( klass ).iterator();
+
+ while ( iterator.hasNext() )
+ {
+ IdentifiableObject identifiableObject = iterator.next();
+ IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject );
+
+ if ( object != null )
+ {
+ objectBundleValidation.addErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(),
+ bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) );
+ iterator.remove();
+ }
+ }
+ }
+ else if ( bundle.getImportMode().isUpdate() || bundle.getImportMode().isDelete() )
{
Iterator<IdentifiableObject> iterator = bundle.getObjects().get( klass ).iterator();
@@ -184,7 +201,7 @@
if ( object == null )
{
- objectBundleValidation.addErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(),
+ objectBundleValidation.addErrorReport( klass, ErrorCode.E5001, bundle.getPreheatIdentifier(),
bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) );
iterator.remove();
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-03 02:03:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-03 05:13:32 +0000
@@ -257,7 +257,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test
@@ -276,7 +276,7 @@
ObjectBundle bundle = objectBundleService.create( params );
ObjectBundleValidation validate = objectBundleService.validate( bundle );
- assertEquals( 1, validate.getErrorReports( DataElement.class ).get( ErrorCode.E5000 ).size() );
+ assertEquals( 1, validate.getErrorReports( DataElement.class ).get( ErrorCode.E5001 ).size() );
assertFalse( validate.getErrorReports( DataElement.class ).get( ErrorCode.E4000 ).isEmpty() );
assertEquals( 0, bundle.getObjects().get( DataElement.class ).size() );
}
@@ -297,7 +297,7 @@
ObjectBundleValidation validate = objectBundleService.validate( bundle );
assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test
@@ -316,7 +316,7 @@
ObjectBundleValidation validate = objectBundleService.validate( bundle );
assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test
@@ -335,7 +335,7 @@
ObjectBundleValidation validate = objectBundleService.validate( bundle );
assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test
@@ -354,7 +354,7 @@
ObjectBundleValidation validate = objectBundleService.validate( bundle );
assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test
@@ -373,7 +373,7 @@
ObjectBundleValidation validate = objectBundleService.validate( bundle );
assertFalse( validate.getErrorReports( DataElement.class ).isEmpty() );
- assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5000 ).size() );
+ assertEquals( 3, validate.getErrorReports( DataElement.class, ErrorCode.E5001 ).size() );
}
@Test