dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43453
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22034: include usernames=>uc map in preheater
------------------------------------------------------------
revno: 22034
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-24 13:10:49 +0700
message:
include usernames=>uc map in preheater
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.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/hooks/AbstractObjectBundleHook.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.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-19 02:27:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java 2016-02-24 06:10:49 +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.UserCredentials;
import java.util.ArrayList;
import java.util.Collection;
@@ -48,6 +49,8 @@
private Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = new HashMap<>();
+ private Map<String, UserCredentials> usernames = new HashMap<>();
+
public Preheat()
{
}
@@ -222,6 +225,16 @@
this.defaults = defaults;
}
+ public Map<String, UserCredentials> getUsernames()
+ {
+ return usernames;
+ }
+
+ public void setUsernames( Map<String, UserCredentials> usernames )
+ {
+ this.usernames = usernames;
+ }
+
public static boolean isDefaultClass( IdentifiableObject object )
{
return (DataElementCategory.class.isInstance( object ) || DataElementCategoryOption.class.isInstance( object )
=== 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-23 10:58:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-02-24 06:10:49 +0000
@@ -75,6 +75,7 @@
{
Preheat preheat = new Preheat();
preheat.setDefaults( manager.getDefaults() );
+ preheat.setUsernames( getUsernames() );
if ( PreheatMode.ALL == params.getPreheatMode() )
{
@@ -392,4 +393,19 @@
}
} );
}
+
+ @SuppressWarnings( "unchecked" )
+ private Map<String, UserCredentials> getUsernames()
+ {
+ Map<String, UserCredentials> userCredentialsMap = new HashMap<>();
+ Query query = Query.from( schemaService.getDynamicSchema( UserCredentials.class ) );
+ List<UserCredentials> userCredentials = (List<UserCredentials>) queryService.query( query );
+
+ for ( UserCredentials uc : userCredentials )
+ {
+ userCredentialsMap.put( uc.getUsername(), uc );
+ }
+
+ return userCredentialsMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/AbstractObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/AbstractObjectBundleHook.java 2016-02-23 10:32:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/AbstractObjectBundleHook.java 2016-02-24 06:10:49 +0000
@@ -29,13 +29,26 @@
*/
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dxf2.metadata2.objectbundle.ObjectBundle;
+import org.hisp.dhis.preheat.PreheatService;
+import org.hisp.dhis.schema.validation.SchemaValidator;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public class AbstractObjectBundleHook implements ObjectBundleHook
{
+ @Autowired
+ protected IdentifiableObjectManager manager;
+
+ @Autowired
+ protected PreheatService preheatService;
+
+ @Autowired
+ protected SchemaValidator validator;
+
@Override
public void preCreate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java 2016-02-23 10:32:50 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java 2016-02-24 06:10:49 +0000
@@ -29,10 +29,9 @@
*/
import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dxf2.metadata2.objectbundle.ObjectBundle;
import org.hisp.dhis.user.User;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.hisp.dhis.user.UserCredentials;
import org.springframework.stereotype.Component;
/**
@@ -41,9 +40,6 @@
@Component
public class UserObjectBundleHook extends AbstractObjectBundleHook
{
- @Autowired
- private IdentifiableObjectManager manager;
-
@Override
public void preCreate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
{
@@ -51,5 +47,13 @@
{
return;
}
+
+ User user = (User) identifiableObject;
+ UserCredentials userCredentials = user.getUserCredentials();
+
+ preheatService.connectReferences( userCredentials, objectBundle.getPreheat(), objectBundle.getPreheatIdentifier() );
+ manager.save( userCredentials );
+
+ user.setUserCredentials( userCredentials );
}
}