dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43281
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21975: Include current object uid/code in preheatService.collectReferences
------------------------------------------------------------
revno: 21975
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-02-16 13:00:52 +0700
message:
Include current object uid/code in preheatService.collectReferences
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate7.json
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.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-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-02-10 08:26:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-02-16 06:00:52 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.system.util.ReflectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
@@ -200,8 +201,11 @@
List<IdentifiableObject> identifiableObjects = objects.get( objectClass );
+ if ( !uidMap.containsKey( objectClass ) ) uidMap.put( objectClass, new HashSet<>() );
+ if ( !codeMap.containsKey( objectClass ) ) codeMap.put( objectClass, new HashSet<>() );
+
properties.forEach( p -> {
- for ( Object object : identifiableObjects )
+ for ( IdentifiableObject object : identifiableObjects )
{
if ( !p.isCollection() )
{
@@ -241,9 +245,11 @@
if ( code != null ) codeMap.get( klass ).add( code );
}
}
+
+ if ( !StringUtils.isEmpty( object.getUid() ) ) uidMap.get( objectClass ).add( object.getUid() );
+ if ( !StringUtils.isEmpty( object.getCode() ) ) codeMap.get( objectClass ).add( object.getCode() );
}
} );
-
}
return map;
=== 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-02-16 04:53:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-02-16 06:00:52 +0000
@@ -247,6 +247,27 @@
}
@Test
+ public void testUpdateWithPersistedObjectsRequiresValidReferencesUID() throws IOException
+ {
+ Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+ new ClassPathResource( "dxf2/de_validate7.json" ).getInputStream(), RenderFormat.JSON );
+ defaultSetup();
+
+ ObjectBundleParams params = new ObjectBundleParams();
+ params.setObjectBundleMode( ObjectBundleMode.VALIDATE );
+ params.setPreheatIdentifier( PreheatIdentifier.UID );
+ params.setImportMode( ImportStrategy.UPDATE );
+ params.setObjects( metadata );
+
+ ObjectBundle bundle = objectBundleService.create( params );
+ ObjectBundleValidation validate = objectBundleService.validate( bundle );
+
+ assertTrue( validate.getInvalidObjects().containsKey( DataElement.class ) );
+ assertEquals( 1, validate.getInvalidObjects().get( DataElement.class ).size() );
+ assertEquals( 2, bundle.getObjects().get( DataElement.class ).size() );
+ }
+
+ @Test
public void testUpdateRequiresValidReferencesCODE() throws IOException
{
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate7.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate7.json 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate7.json 2016-02-16 06:00:52 +0000
@@ -0,0 +1,13 @@
+{
+ "dataElements": [
+ {
+ "id": "deabcdefghA"
+ },
+ {
+ "id": "deabcdefghB"
+ },
+ {
+ "id": "InvalidA"
+ }
+ ]
+}