dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25077
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12360: more fixes for user import, do matching on usernames (not names\!)
------------------------------------------------------------
revno: 12360
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-10-01 13:56:18 +0200
message:
more fixes for user import, do matching on usernames (not names\!)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-10-01 09:57:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-10-01 11:56:18 +0000
@@ -96,7 +96,6 @@
private Date lastCheckedInterpretations;
- @Scanned
private UserCredentials userCredentials;
private Set<UserGroup> groups = new HashSet<UserGroup>();
@@ -215,6 +214,12 @@
// Getters and setters
// -------------------------------------------------------------------------
+ @Override
+ public boolean haveUniqueNames()
+ {
+ return false;
+ }
+
@JsonProperty
@JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-10-01 09:57:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-10-01 11:56:18 +0000
@@ -361,20 +361,16 @@
return "[" + username + "]";
}
+ @Override
+ public boolean haveUniqueNames()
+ {
+ return false;
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
- public int getId()
- {
- return id;
- }
-
- public void setId( int id )
- {
- this.id = id;
- }
-
public String getPassword()
{
return password;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java 2013-10-01 11:56:18 +0000
@@ -34,6 +34,9 @@
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.period.PeriodStore;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
@@ -63,6 +66,9 @@
@Autowired
private PeriodStore periodStore;
+ @Autowired
+ private UserService userService;
+
//-------------------------------------------------------------------------------------------------------
// Internal and Semi-Public maps
//-------------------------------------------------------------------------------------------------------
@@ -79,6 +85,8 @@
private Map<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>> nameMap;
+ private Map<String, UserCredentials> usernameMap;
+
private boolean writeEnabled = true;
//-------------------------------------------------------------------------------------------------------
@@ -88,6 +96,7 @@
static
{
registeredTypes.add( PeriodType.class );
+ registeredTypes.add( UserCredentials.class );
for ( Class<?> clazz : ExchangeClasses.getImportClasses() )
{
@@ -105,9 +114,11 @@
uidMap = new HashMap<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>();
codeMap = new HashMap<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>();
nameMap = new HashMap<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>();
+ usernameMap = new HashMap<String, UserCredentials>();
for ( Class<?> type : registeredTypes )
{
+ populateUsernameMap( type );
populatePeriodTypeMap( type );
populateIdentifiableObjectMap( type );
populateIdentifiableObjectMap( type, IdentifiableObject.IdentifiableProperty.UID );
@@ -218,6 +229,26 @@
masterMap.put( clazz, new HashSet<Object>( periodTypes ) );
}
+ private void populateUsernameMap( Class<?> clazz )
+ {
+ if ( UserCredentials.class.isAssignableFrom( clazz ) )
+ {
+ Collection<UserCredentials> allUserCredentials = userService.getAllUserCredentials();
+
+ System.err.println( "allUser: " + allUserCredentials );
+
+ for ( UserCredentials userCredentials : allUserCredentials )
+ {
+ if ( userCredentials.getUsername() != null )
+ {
+ usernameMap.put( userCredentials.getUsername(), userCredentials );
+ }
+ }
+
+ System.err.println( "usernameMap:" + usernameMap );
+ }
+ }
+
//-------------------------------------------------------------------------------------------------------
// ObjectBridge Implementation
//-------------------------------------------------------------------------------------------------------
@@ -341,6 +372,17 @@
}
}
+ if ( User.class.isInstance( object ) )
+ {
+ User user = (User) object;
+ UserCredentials userCredentials = usernameMap.get( user.getUsername() );
+
+ if ( userCredentials != null && userCredentials.getUser() != null )
+ {
+ objects.add( (T) userCredentials.getUser() );
+ }
+ }
+
if ( IdentifiableObject.class.isInstance( object ) )
{
IdentifiableObject identifiableObject = (IdentifiableObject) object;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-10-01 10:32:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-10-01 11:56:18 +0000
@@ -412,6 +412,7 @@
UserCredentials userCredentials = null;
+ /*
if ( object instanceof User )
{
userCredentials = ((User) object).getUserCredentials();
@@ -424,6 +425,7 @@
return false;
}
}
+ */
Map<Field, Object> fields = detachFields( object );
Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
@@ -438,6 +440,7 @@
objectBridge.updateObject( object );
+ /*
if ( object instanceof User )
{
userCredentials.setUser( (User) object );
@@ -455,6 +458,7 @@
objectBridge.updateObject( object );
}
+ */
if ( !options.isDryRun() )
{