dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43923
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22284: support uniqueness check of user.userCredentials.username in dxf2 importer
------------------------------------------------------------
revno: 22284
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-03-14 13:31:31 +0700
message:
support uniqueness check of user.userCredentials.username in dxf2 importer
modified:
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
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/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/user_duplicate_username.json
--
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-03-14 01:56:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-03-14 06:31:31 +0000
@@ -103,7 +103,14 @@
{
params.getObjects().get( klass ).stream()
.filter( identifiableObject -> StringUtils.isEmpty( identifiableObject.getUid() ) )
- .forEach( identifiableObject -> ((BaseIdentifiableObject) identifiableObject).setUid( CodeGenerator.generateCode() ) );
+ .forEach( identifiableObject -> {
+ ((BaseIdentifiableObject) identifiableObject).setUid( CodeGenerator.generateCode() );
+
+ if ( User.class.isInstance( identifiableObject ) )
+ {
+ ((User) identifiableObject).getUserCredentials().setUid( identifiableObject.getUid() );
+ }
+ } );
}
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> uniqueCollectionMap = new HashMap<>();
@@ -285,6 +292,7 @@
if ( user.getUserCredentials() != null )
{
+ user.getUserCredentials().setUid( user.getUid() );
userCredentials.add( user.getUserCredentials() );
}
}
@@ -690,8 +698,19 @@
while ( iterator.hasNext() )
{
IdentifiableObject object = iterator.next();
-
- List<ErrorReport> errorReports = checkUniqueness( object, preheat, identifier );
+ List<ErrorReport> errorReports = new ArrayList<>();
+
+ if ( User.class.isInstance( object ) )
+ {
+ User user = (User) object;
+ errorReports.addAll( checkUniqueness( user, preheat, identifier ) );
+ errorReports.addAll( checkUniqueness( user.getUserCredentials(), preheat, identifier ) );
+ }
+ else
+ {
+ errorReports = checkUniqueness( object, preheat, identifier );
+ }
+
if ( !errorReports.isEmpty() )
{
=== 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-14 03:33:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-14 06:31:31 +0000
@@ -46,6 +46,7 @@
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.schema.validation.SchemaValidator;
import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.UserCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -103,6 +104,8 @@
ObjectBundle bundle = new ObjectBundle( params, preheatService.preheat( preheatParams ), params.getObjects() );
bundle.setObjectReferences( preheatService.collectObjectReferences( params.getObjects() ) );
+ System.err.println( "O: " + bundle.getObjectReferences().get( UserCredentials.class ) );
+
return bundle;
}
=== 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-03-13 04:55:03 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java 2016-03-14 06:31:31 +0000
@@ -145,8 +145,7 @@
User user = (User) identifiableObject;
UserCredentials userCredentials = user.getUserCredentials();
-
- Map<String, Object> userCredentialsReferenceMap = userCredentialsReferences.get( userCredentials.getUid() );
+ Map<String, Object> userCredentialsReferenceMap = userCredentialsReferences.get( user.getUid() );
if ( userCredentialsReferenceMap == null || userCredentialsReferenceMap.isEmpty() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-14 03:38:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-14 06:31:31 +0000
@@ -64,7 +64,6 @@
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserService;
import org.hisp.dhis.validation.ValidationRule;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
@@ -1415,7 +1414,6 @@
}
@Test
- @Ignore
public void testCreateMetadataWithDuplicateUsername() throws IOException
{
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
@@ -1429,6 +1427,8 @@
ObjectBundle bundle = objectBundleService.create( params );
objectBundleService.validate( bundle );
objectBundleService.commit( bundle );
+
+ assertEquals( 1, manager.getAll( User.class ).size() );
}
private void defaultSetup()
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/user_duplicate_username.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/user_duplicate_username.json 2016-03-14 03:38:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/user_duplicate_username.json 2016-03-14 06:31:31 +0000
@@ -1,4 +1,22 @@
{
+ "organisationUnits": [
+ {
+ "path": "/inVD5SdytkT",
+ "openingDate": "2016-03-11T17:00:00.000+0000",
+ "lastUpdated": "2016-03-12T06:19:49.665+0000",
+ "created": "2016-03-12T06:19:49.649+0000",
+ "shortName": "Country",
+ "user": {
+ "id": "enHApD3I6Ho"
+ },
+ "attributeValues": [ ],
+ "id": "inVD5SdytkT",
+ "name": "Country",
+ "description": "",
+ "featureType": "NONE",
+ "uuid": "0f2d7a85-3b6e-4cae-9d5a-e2903331629b"
+ }
+ ],
"userRoles": [
{
"dataSets": [ ],
@@ -132,48 +150,6 @@
"passwordLastUpdated": "2016-03-12T06:20:43.407+0000"
},
"teiSearchOrganisationUnits": [ ]
- },
- {
- "surname": "admin",
- "firstName": "admin",
- "organisationUnits": [
- {
- "id": "inVD5SdytkT"
- }
- ],
- "dataViewOrganisationUnits": [
- {
- "id": "inVD5SdytkT"
- }
- ],
- "userCredentials": {
- "externalAuth": false,
- "disabled": false,
- "invitation": false,
- "userRoles": [
- {
- "id": "tHEWGwIMsJk"
- }
- ],
- "username": "admin",
- "passwordLastUpdated": "2016-03-12T06:18:41.403+0000",
- "userInfo": {
- "id": "enHApD3I6Ho"
- },
- "created": "2016-03-12T06:18:41.505+0000",
- "lastLogin": "2016-03-12T06:18:41.401+0000",
- "catDimensionConstraints": [ ],
- "selfRegistered": false,
- "user": {
- "id": "enHApD3I6Ho"
- },
- "cogsDimensionConstraints": [ ]
- },
- "lastUpdated": "2016-03-12T06:20:18.336+0000",
- "created": "2016-03-12T06:18:41.374+0000",
- "teiSearchOrganisationUnits": [ ],
- "id": "enHApD3I6Ho",
- "attributeValues": [ ]
}
]
}
\ No newline at end of file