dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43909
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22275: Minor cleanup, removes references from preheat params, now uses objects (and collect references i...
------------------------------------------------------------
revno: 22275
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2016-03-13 17:42:16 +0700
message:
Minor cleanup, removes references from preheat params, now uses objects (and collect references itself), switches uniqueness klasses to use klassses from this object list only
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatParams.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
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.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/PreheatParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatParams.java 2016-03-13 10:19:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatParams.java 2016-03-13 10:42:16 +0000
@@ -51,8 +51,6 @@
private Set<Class<? extends IdentifiableObject>> classes = new HashSet<>();
- private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> references = new HashMap<>();
-
private Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objects = new HashMap<>();
public PreheatParams()
@@ -112,17 +110,6 @@
this.objects = objects;
}
- public Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> getReferences()
- {
- return references;
- }
-
- public PreheatParams setReferences( Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> references )
- {
- this.references = references;
- return this;
- }
-
@Override
public String toString()
{
@@ -131,7 +118,7 @@
.add( "preheatMode", preheatMode )
.add( "preheatIdentifier", preheatIdentifier )
.add( "classes", classes )
- .add( "references", references )
+ .add( "objects", objects )
.toString();
}
}
=== 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-13 10:19:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-03-13 10:42:16 +0000
@@ -30,6 +30,8 @@
import com.google.common.collect.Lists;
import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.MergeMode;
@@ -96,6 +98,16 @@
preheat.setUser( currentUserService.getCurrentUser() );
}
+ for ( Class<? extends IdentifiableObject> klass : params.getObjects().keySet() )
+ {
+ params.getObjects().get( klass ).stream()
+ .filter( identifiableObject -> StringUtils.isEmpty( identifiableObject.getUid() ) )
+ .forEach( identifiableObject -> ((BaseIdentifiableObject) identifiableObject).setUid( CodeGenerator.generateCode() ) );
+ }
+
+ Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> uniqueCollectionMap = new HashMap<>();
+ Set<Class<? extends IdentifiableObject>> klasses = new HashSet<>( params.getObjects().keySet() );
+
if ( PreheatMode.ALL == params.getPreheatMode() )
{
if ( params.getClasses().isEmpty() )
@@ -119,12 +131,19 @@
{
preheat.put( PreheatIdentifier.CODE, objects );
}
+
+ if ( klasses.contains( klass ) && !objects.isEmpty() )
+ {
+ uniqueCollectionMap.put( klass, new ArrayList<>( objects ) );
+ }
}
}
else if ( PreheatMode.REFERENCE == params.getPreheatMode() )
{
- Map<Class<? extends IdentifiableObject>, Set<String>> uidMap = params.getReferences().get( PreheatIdentifier.UID );
- Map<Class<? extends IdentifiableObject>, Set<String>> codeMap = params.getReferences().get( PreheatIdentifier.CODE );
+ Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> references = collectReferences( params.getObjects() );
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> uidMap = references.get( PreheatIdentifier.UID );
+ Map<Class<? extends IdentifiableObject>, Set<String>> codeMap = references.get( PreheatIdentifier.CODE );
if ( uidMap != null && (PreheatIdentifier.UID == params.getPreheatIdentifier() || PreheatIdentifier.AUTO == params.getPreheatIdentifier()) )
{
@@ -159,32 +178,17 @@
}
}
}
- }
-
- Set<Class<? extends IdentifiableObject>> klasses = new HashSet<>();
-
- if ( params.getReferences().containsKey( PreheatIdentifier.UID ) )
- {
- klasses.addAll( params.getReferences().get( PreheatIdentifier.UID ).keySet() );
- }
-
- if ( params.getReferences().containsKey( PreheatIdentifier.CODE ) )
- {
- klasses.addAll( params.getReferences().get( PreheatIdentifier.CODE ).keySet() );
- }
-
- Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> uniqueCollectionMap = new HashMap<>();
-
- // TODO fix this, should be part of main preheat process, this will slow things down.. but we need all objects to check for uniqueness
- for ( Class<? extends IdentifiableObject> klass : klasses )
- {
- Query query = Query.from( schemaService.getDynamicSchema( klass ) );
- query.setUser( preheat.getUser() );
- List<? extends IdentifiableObject> objects = queryService.query( query );
-
- if ( !objects.isEmpty() )
+
+ for ( Class<? extends IdentifiableObject> klass : klasses )
{
- uniqueCollectionMap.put( klass, new ArrayList<>( objects ) );
+ Query query = Query.from( schemaService.getDynamicSchema( klass ) );
+ query.setUser( preheat.getUser() );
+ List<? extends IdentifiableObject> objects = queryService.query( query );
+
+ if ( !objects.isEmpty() )
+ {
+ uniqueCollectionMap.put( klass, new ArrayList<>( objects ) );
+ }
}
}
@@ -202,9 +206,9 @@
}
else if ( PreheatMode.REFERENCE == params.getPreheatMode() )
{
- if ( params.getReferences().isEmpty() )
+ if ( params.getObjects().isEmpty() )
{
- throw new PreheatException( "PreheatMode.REFERENCE, but no references was provided." );
+ throw new PreheatException( "PreheatMode.REFERENCE, but no objects were provided." );
}
}
else
=== 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-03-01 07:51:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-03-13 10:42:16 +0000
@@ -45,7 +45,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -90,23 +89,6 @@
preheatService.validate( params );
}
- @Test( expected = PreheatException.class )
- public void testValidateRefFail()
- {
- PreheatParams params = new PreheatParams().setPreheatMode( PreheatMode.REFERENCE );
- preheatService.validate( params );
- }
-
- @Test
- public void testValidateRef()
- {
- PreheatParams params = new PreheatParams().setPreheatMode( PreheatMode.REFERENCE );
- params.getReferences().put( PreheatIdentifier.UID, new HashMap<>() );
- params.getReferences().get( PreheatIdentifier.UID ).put( DataElement.class, Sets.newHashSet( "ID1", "ID2" ) );
-
- preheatService.validate( params );
- }
-
@Test
public void testCollectNoObjectsDE()
{
@@ -362,13 +344,8 @@
PreheatParams params = new PreheatParams();
params.setPreheatMode( PreheatMode.REFERENCE );
- Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> references = new HashMap<>();
- references.put( PreheatIdentifier.UID, new HashMap<>() );
-
- references.get( PreheatIdentifier.UID ).put( DataElement.class, Sets.newHashSet( de1.getUid(), de2.getUid() ) );
- references.get( PreheatIdentifier.UID ).put( User.class, Sets.newHashSet( user.getUid() ) );
-
- params.setReferences( references );
+ params.getObjects().put( DataElement.class, Lists.newArrayList( de1, de2 ) );
+ params.getObjects().put( User.class, Lists.newArrayList( user ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -414,13 +391,8 @@
params.setPreheatIdentifier( PreheatIdentifier.CODE );
params.setPreheatMode( PreheatMode.REFERENCE );
- Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Set<String>>> references = new HashMap<>();
- references.put( PreheatIdentifier.CODE, new HashMap<>() );
-
- references.get( PreheatIdentifier.CODE ).put( DataElement.class, Sets.newHashSet( de1.getCode(), de2.getCode() ) );
- references.get( PreheatIdentifier.CODE ).put( User.class, Sets.newHashSet( user.getCode() ) );
-
- params.setReferences( references );
+ params.getObjects().put( DataElement.class, Lists.newArrayList( de1, de2 ) );
+ params.getObjects().put( User.class, Lists.newArrayList( user ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -446,7 +418,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -472,7 +444,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier( PreheatIdentifier.CODE );
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -497,7 +469,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -516,7 +488,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -545,7 +517,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier( PreheatIdentifier.CODE );
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
@@ -574,7 +546,7 @@
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier( PreheatIdentifier.AUTO );
params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( preheatService.collectReferences( dataElementGroup ) );
+ params.getObjects().put( DataElementGroup.class, Lists.newArrayList( dataElementGroup ) );
preheatService.validate( params );
Preheat preheat = preheatService.preheat( params );
=== 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-13 10:19:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-13 10:42:16 +0000
@@ -107,18 +107,6 @@
preheatParams.setUser( params.getUser() );
preheatParams.setObjects( params.getObjects() );
- if ( PreheatMode.REFERENCE == preheatParams.getPreheatMode() )
- {
- preheatParams.setReferences( preheatService.collectReferences( params.getObjects() ) );
- }
-
- for ( Class<? extends IdentifiableObject> klass : params.getObjects().keySet() )
- {
- params.getObjects().get( klass ).stream()
- .filter( identifiableObject -> StringUtils.isEmpty( identifiableObject.getUid() ) )
- .forEach( identifiableObject -> ((BaseIdentifiableObject) identifiableObject).setUid( CodeGenerator.generateCode() ) );
- }
-
ObjectBundle bundle = new ObjectBundle( params, preheatService.preheat( preheatParams ), params.getObjects() );
bundle.setObjectReferences( preheatService.collectObjectReferences( params.getObjects() ) );