dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42718
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21807: Minor fix, supply all metadata classes as preheat classes if params.classes is empty
------------------------------------------------------------
revno: 21807
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-01-25 13:22:42 +0700
message:
Minor fix, supply all metadata classes as preheat classes if params.classes is empty
modified:
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-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 04:56:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 06:22:42 +0000
@@ -60,12 +60,19 @@
private IdentifiableObjectManager manager;
@Override
+ @SuppressWarnings( "unchecked" )
public Preheat preheat( PreheatParams params )
{
Preheat preheat = new Preheat();
if ( PreheatMode.ALL == params.getPreheatMode() )
{
+ if ( params.getClasses().isEmpty() )
+ {
+ schemaService.getMetadataSchemas().stream().filter( Schema::isIdentifiableObject )
+ .forEach( schema -> params.getClasses().add( (Class<? extends IdentifiableObject>) schema.getKlass() ) );
+ }
+
for ( Class<? extends IdentifiableObject> klass : params.getClasses() )
{
List<? extends IdentifiableObject> objects = manager.getAllNoAcl( klass ); // should we use getAll here? are we allowed to reference unshared objects?
@@ -99,10 +106,7 @@
{
if ( PreheatMode.ALL == params.getPreheatMode() )
{
- if ( params.getClasses().isEmpty() )
- {
- throw new PreheatException( "PreheatMode.ALL, but no classes was provided." );
- }
+ // nothing to validate for now, if classes is empty it will get all metadata classes
}
else if ( PreheatMode.REFERENCE == params.getPreheatMode() )
{
=== 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 04:37:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-01-25 06:22:42 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.legend.LegendSet;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.user.User;
+import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,6 +60,7 @@
@Autowired
private IdentifiableObjectManager manager;
+ @Ignore
@Test( expected = PreheatException.class )
public void testValidateAllFail()
{
@@ -274,6 +276,50 @@
@Test
@SuppressWarnings( "unchecked" )
+ public void testPreheatAllMetadataUID()
+ {
+ DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
+ dataElementGroup.setAutoFields();
+
+ DataElement de1 = createDataElement( 'A' );
+ DataElement de2 = createDataElement( 'B' );
+ DataElement de3 = createDataElement( 'C' );
+
+ manager.save( de1 );
+ manager.save( de2 );
+ manager.save( de3 );
+
+ User user = createUser( 'A' );
+ manager.save( user );
+
+ dataElementGroup.addDataElement( de1 );
+ dataElementGroup.addDataElement( de2 );
+ dataElementGroup.addDataElement( de3 );
+
+ dataElementGroup.setUser( user );
+ manager.save( dataElementGroup );
+
+ PreheatParams params = new PreheatParams();
+ params.setPreheatMode( PreheatMode.ALL );
+
+ preheatService.validate( params );
+ Preheat preheat = preheatService.preheat( params );
+
+ assertFalse( preheat.isEmpty() );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.UID ) );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.UID, DataElement.class ) );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.UID, DataElementGroup.class ) );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.UID, User.class ) );
+
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de1.getUid() ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de2.getUid() ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de3.getUid() ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid() ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, User.class, user.getUid() ) );
+ }
+
+ @Test
+ @SuppressWarnings( "unchecked" )
public void testPreheatReferenceUID()
{
DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );