dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42713
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21802: Support scanning collection of id objects in PreheatService
------------------------------------------------------------
revno: 21802
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-01-25 11:37:41 +0700
message:
Support scanning collection of id objects in PreheatService
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.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/preheat/PreheatService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java 2016-01-25 03:56:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatService.java 2016-01-25 04:37:41 +0000
@@ -30,7 +30,6 @@
import org.hisp.dhis.common.IdentifiableObject;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -61,4 +60,13 @@
* @return Maps classes to collections of identifiers
*/
Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectForReferences( Object object, PreheatIdentifier identifier );
+
+ /**
+ * Scan objects and collect all references (both id object and collections with id objects).
+ *
+ * @param objects Objects to scan
+ * @param identifier Identifier to collect
+ * @return Maps classes to collections of identifiers
+ */
+ Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectsForReferences( Set<Object> objects, PreheatIdentifier identifier );
}
=== 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-01-25 03:56:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 04:37:41 +0000
@@ -187,4 +187,23 @@
return map;
}
+
+ @Override
+ public Map<Class<? extends IdentifiableObject>, Set<String>> scanObjectsForReferences( Set<Object> objects, PreheatIdentifier identifier )
+ {
+ Map<Class<? extends IdentifiableObject>, Set<String>> referenceMap = new HashMap<>();
+
+ for ( Object object : objects )
+ {
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = scanObjectForReferences( object, identifier );
+
+ for ( Class<? extends IdentifiableObject> klass : references.keySet() )
+ {
+ if ( !referenceMap.containsKey( klass ) ) referenceMap.put( klass, new HashSet<>() );
+ referenceMap.get( klass ).addAll( references.get( klass ) );
+ }
+ }
+
+ return referenceMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-01-25 03:56:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-01-25 04:37:41 +0000
@@ -94,9 +94,7 @@
@Test
public void testScanNoObjectsDE()
{
- DataElement dataElement = new DataElement( "DataElementA" );
- dataElement.setAutoFields();
-
+ DataElement dataElement = createDataElement( 'A' );
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectForReferences( dataElement, PreheatIdentifier.UID );
assertTrue( references.containsKey( OptionSet.class ) );
@@ -108,9 +106,7 @@
@Test
public void testScanNoObjectsDEG()
{
- DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
- dataElementGroup.setAutoFields();
-
+ DataElementGroup dataElementGroup = createDataElementGroup( 'A' );
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectForReferences( dataElementGroup, PreheatIdentifier.UID );
assertTrue( references.containsKey( DataElement.class ) );
@@ -118,29 +114,23 @@
}
@Test
- public void testScanReferenceUidDEG()
+ public void testScanObjectReferenceUidDEG()
{
- DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
- dataElementGroup.setAutoFields();
-
- DataElement de1 = new DataElement( "DataElement1" );
- DataElement de2 = new DataElement( "DataElement1" );
- DataElement de3 = new DataElement( "DataElement1" );
-
- de1.setAutoFields();
- de2.setAutoFields();
- de3.setAutoFields();
-
- User user = new User();
- user.setAutoFields();
-
- dataElementGroup.addDataElement( de1 );
- dataElementGroup.addDataElement( de2 );
- dataElementGroup.addDataElement( de3 );
-
- dataElementGroup.setUser( user );
-
- Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectForReferences( dataElementGroup, PreheatIdentifier.UID );
+ DataElementGroup deg1 = createDataElementGroup( 'A' );
+
+ DataElement de1 = createDataElement( 'A' );
+ DataElement de2 = createDataElement( 'B' );
+ DataElement de3 = createDataElement( 'C' );
+
+ User user = createUser( 'A' );
+
+ deg1.addDataElement( de1 );
+ deg1.addDataElement( de2 );
+ deg1.addDataElement( de3 );
+
+ deg1.setUser( user );
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectForReferences( deg1, PreheatIdentifier.UID );
assertTrue( references.containsKey( DataElement.class ) );
assertTrue( references.containsKey( User.class ) );
@@ -156,24 +146,40 @@
}
@Test
- public void testScanReferenceCodeDEG()
- {
- DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
- dataElementGroup.setAutoFields();
-
- DataElement de1 = new DataElement( "DataElement1" );
- DataElement de2 = new DataElement( "DataElement1" );
- DataElement de3 = new DataElement( "DataElement1" );
-
- de1.setAutoFields();
- de1.setCode( "DataElementCode1" );
- de2.setAutoFields();
- de2.setCode( "DataElementCode2" );
- de3.setAutoFields();
- de3.setCode( "DataElementCode3" );
-
- User user = new User();
- user.setAutoFields();
+ public void testScanObjectsReferenceUidDEG()
+ {
+ DataElementGroup deg1 = createDataElementGroup( 'A' );
+ DataElementGroup deg2 = createDataElementGroup( 'B' );
+
+ DataElement de1 = createDataElement( 'A' );
+ DataElement de2 = createDataElement( 'B' );
+ DataElement de3 = createDataElement( 'C' );
+
+ deg1.addDataElement( de1 );
+ deg1.addDataElement( de2 );
+ deg2.addDataElement( de3 );
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectsForReferences(
+ Sets.newHashSet( deg1, deg2 ), PreheatIdentifier.UID );
+
+ assertTrue( references.containsKey( DataElement.class ) );
+ assertEquals( 3, references.get( DataElement.class ).size() );
+
+ assertTrue( references.get( DataElement.class ).contains( de1.getUid() ) );
+ assertTrue( references.get( DataElement.class ).contains( de2.getUid() ) );
+ assertTrue( references.get( DataElement.class ).contains( de3.getUid() ) );
+ }
+
+ @Test
+ public void testScanObjectReferenceCodeDEG()
+ {
+ DataElementGroup dataElementGroup = createDataElementGroup( 'A' );
+
+ DataElement de1 = createDataElement( 'A' );
+ DataElement de2 = createDataElement( 'B' );
+ DataElement de3 = createDataElement( 'C' );
+
+ User user = createUser( 'A' );
dataElementGroup.addDataElement( de1 );
dataElementGroup.addDataElement( de2 );
@@ -187,7 +193,34 @@
assertTrue( references.containsKey( User.class ) );
assertEquals( 3, references.get( DataElement.class ).size() );
- assertTrue( references.get( User.class ).isEmpty() );
+ assertEquals( 1, references.get( User.class ).size() );
+
+ assertTrue( references.get( DataElement.class ).contains( de1.getCode() ) );
+ assertTrue( references.get( DataElement.class ).contains( de2.getCode() ) );
+ assertTrue( references.get( DataElement.class ).contains( de3.getCode() ) );
+
+ assertTrue( references.get( User.class ).contains( user.getCode() ) );
+ }
+
+ @Test
+ public void testScanObjectsReferenceCodeDEG()
+ {
+ DataElementGroup deg1 = createDataElementGroup( 'A' );
+ DataElementGroup deg2 = createDataElementGroup( 'B' );
+
+ DataElement de1 = createDataElement( 'A' );
+ DataElement de2 = createDataElement( 'B' );
+ DataElement de3 = createDataElement( 'C' );
+
+ deg1.addDataElement( de1 );
+ deg1.addDataElement( de2 );
+ deg2.addDataElement( de3 );
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.scanObjectsForReferences(
+ Sets.newHashSet( deg1, deg2 ), PreheatIdentifier.CODE );
+
+ assertTrue( references.containsKey( DataElement.class ) );
+ assertEquals( 3, references.get( DataElement.class ).size() );
assertTrue( references.get( DataElement.class ).contains( de1.getCode() ) );
assertTrue( references.get( DataElement.class ).contains( de2.getCode() ) );