dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43634
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22122: minor optimization, pass user object along with query in preheater
------------------------------------------------------------
revno: 22122
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-03-03 10:10:04 +0700
message:
minor optimization, pass user object along with query in preheater
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java
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-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/Preheat.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java 2016-02-24 06:10:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java 2016-03-03 03:10:04 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.dataelement.DataElementCategory;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
import java.util.ArrayList;
@@ -45,6 +46,8 @@
*/
public class Preheat
{
+ private User user;
+
private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>> map = new HashMap<>();
private Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = new HashMap<>();
@@ -55,6 +58,16 @@
{
}
+ public User getUser()
+ {
+ return user;
+ }
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
@SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> T get( PreheatIdentifier identifier, Class<? extends IdentifiableObject> klass, String key )
{
=== 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-02-01 10:27:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatParams.java 2016-03-03 03:10:04 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.user.User;
import java.util.HashMap;
import java.util.HashSet;
@@ -40,6 +41,8 @@
*/
public class PreheatParams
{
+ private User user;
+
private PreheatMode preheatMode = PreheatMode.ALL;
private PreheatIdentifier preheatIdentifier = PreheatIdentifier.UID;
@@ -52,6 +55,16 @@
{
}
+ public User getUser()
+ {
+ return user;
+ }
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
public PreheatMode getPreheatMode()
{
return preheatMode;
=== 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-02 07:56:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-03-03 03:10:04 +0000
@@ -43,6 +43,7 @@
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.system.util.ReflectionUtils;
+import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
@@ -74,14 +75,23 @@
@Autowired
private IdentifiableObjectManager manager;
+ @Autowired
+ private CurrentUserService currentUserService;
+
@Override
@SuppressWarnings( "unchecked" )
public Preheat preheat( PreheatParams params )
{
Preheat preheat = new Preheat();
+ preheat.setUser( params.getUser() );
preheat.setDefaults( manager.getDefaults() );
preheat.setUsernames( getUsernames() );
+ if ( preheat.getUser() == null )
+ {
+ preheat.setUser( currentUserService.getCurrentUser() );
+ }
+
if ( PreheatMode.ALL == params.getPreheatMode() )
{
if ( params.getClasses().isEmpty() )
@@ -93,6 +103,7 @@
for ( Class<? extends IdentifiableObject> klass : params.getClasses() )
{
Query query = Query.from( schemaService.getDynamicSchema( klass ) );
+ query.setUser( preheat.getUser() );
List<? extends IdentifiableObject> objects = queryService.query( query );
if ( PreheatIdentifier.UID == params.getPreheatIdentifier() || PreheatIdentifier.AUTO == params.getPreheatIdentifier() )
@@ -120,6 +131,7 @@
if ( !identifiers.isEmpty() )
{
Query query = Query.from( schemaService.getDynamicSchema( klass ) );
+ query.setUser( preheat.getUser() );
query.add( Restrictions.in( "id", identifiers ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
preheat.put( PreheatIdentifier.UID, objects );
@@ -136,6 +148,7 @@
if ( !identifiers.isEmpty() )
{
Query query = Query.from( schemaService.getDynamicSchema( klass ) );
+ query.setUser( preheat.getUser() );
query.add( Restrictions.in( "code", identifiers ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
preheat.put( PreheatIdentifier.CODE, objects );
=== 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 02:23:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-03 03:10:04 +0000
@@ -99,6 +99,7 @@
}
PreheatParams preheatParams = params.getPreheatParams();
+ preheatParams.setUser( params.getUser() );
if ( PreheatMode.REFERENCE == preheatParams.getPreheatMode() )
{
@@ -190,8 +191,8 @@
}
}
- List<List<PreheatErrorReport>> referenceErrors = preheatService.checkReferences( bundle.getObjects().get( klass ), bundle.getPreheat(), bundle.getPreheatIdentifier() );
- referenceErrors.forEach( objectBundleValidation::addErrorReports ); // collapsing for now, we might want to give pr object ref list
+ List<List<PreheatErrorReport>> referencesErrorReports = preheatService.checkReferences( bundle.getObjects().get( klass ), bundle.getPreheat(), bundle.getPreheatIdentifier() );
+ referencesErrorReports.forEach( objectBundleValidation::addErrorReports ); // collapsing for now, we might want to give pr object ref list
if ( !bundle.getImportMode().isDelete() )
{
@@ -200,11 +201,11 @@
while ( iterator.hasNext() )
{
IdentifiableObject object = iterator.next();
- List<ErrorReport> objectValidation = schemaValidator.validate( object );
+ List<ErrorReport> validationErrorReports = schemaValidator.validate( object );
- if ( !objectValidation.isEmpty() )
+ if ( !validationErrorReports.isEmpty() )
{
- objectBundleValidation.addErrorReports( objectValidation );
+ objectBundleValidation.addErrorReports( validationErrorReports );
iterator.remove();
}
}