dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43646
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22128: support UGA for id objects in dxf2 importer
------------------------------------------------------------
revno: 22128
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-03-03 17:04:35 +0700
message:
support UGA for id objects in dxf2 importer
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata_uga.json
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserGroupSchemaDescriptor.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.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/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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/schema/descriptors/UserGroupSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserGroupSchemaDescriptor.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/UserGroupSchemaDescriptor.java 2016-03-03 10:04:35 +0000
@@ -54,7 +54,7 @@
Schema schema = new Schema( UserGroup.class, SINGULAR, PLURAL );
schema.setRelativeApiEndpoint( API_ENDPOINT );
schema.setShareable( true );
- schema.setOrder( 1300 );
+ schema.setOrder( 102 );
schema.getAuthorities().add( new Authority( AuthorityType.CREATE_PUBLIC, Lists.newArrayList( "F_USERGROUP_PUBLIC_ADD" ) ) );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java 2016-03-01 09:01:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java 2016-03-03 10:04:35 +0000
@@ -32,6 +32,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.base.Objects;
import org.hisp.dhis.common.DxfNamespaces;
/**
@@ -117,4 +118,14 @@
{
this.userGroup = userGroup;
}
+
+
+ @Override
+ public String toString()
+ {
+ return Objects.toStringHelper( this )
+ .add( "id", id )
+ .add( "access", access )
+ .toString();
+ }
}
=== 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 06:00:45 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-03-03 10:04:35 +0000
@@ -306,7 +306,7 @@
objectBundleHooks.forEach( hook -> hook.preCreate( object, bundle ) );
preheatService.connectReferences( object, bundle.getPreheat(), bundle.getPreheatIdentifier() );
- manager.save( object, bundle.getUser() );
+ manager.save( object, bundle.getUser(), false );
bundle.getPreheat().put( bundle.getPreheatIdentifier(), object );
=== 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-03 05:13:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-03-03 10:04:35 +0000
@@ -51,6 +51,7 @@
import org.hisp.dhis.render.RenderService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserGroup;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
@@ -568,7 +569,7 @@
public void testValidateMetadataAttributeValuesUniqueAndMandatoryUID() throws IOException
{
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
- new ClassPathResource( "dxf2/metadata_av_unique_and_mandatory.json" ).getInputStream(), RenderFormat.JSON );
+ new ClassPathResource( "dxf2/simple_metadata_uga.json" ).getInputStream(), RenderFormat.JSON );
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode( ObjectBundleMode.VALIDATE );
@@ -578,6 +579,37 @@
ObjectBundleValidation validation = objectBundleService.validate( bundle );
}
+ @Test
+ public void testCreateDataSetsWithUgaUID() throws IOException
+ {
+ Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+ new ClassPathResource( "dxf2/simple_metadata_uga.json" ).getInputStream(), RenderFormat.JSON );
+
+ ObjectBundleParams params = new ObjectBundleParams();
+ params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+ params.setImportMode( ImportStrategy.CREATE );
+ params.setObjects( metadata );
+
+ ObjectBundle bundle = objectBundleService.create( params );
+ objectBundleService.validate( bundle ).getErrorReports();
+ objectBundleService.commit( bundle );
+
+ List<OrganisationUnit> organisationUnits = manager.getAll( OrganisationUnit.class );
+ List<DataElement> dataElements = manager.getAll( DataElement.class );
+ List<UserAuthorityGroup> userRoles = manager.getAll( UserAuthorityGroup.class );
+ List<User> users = manager.getAll( User.class );
+ List<UserGroup> userGroups = manager.getAll( UserGroup.class );
+
+ assertEquals( 1, organisationUnits.size() );
+ assertEquals( 2, dataElements.size() );
+ assertEquals( 1, userRoles.size() );
+ assertEquals( 1, users.size() );
+ assertEquals( 2, userGroups.size() );
+
+ assertEquals( 1, dataElements.get( 0 ).getUserGroupAccesses().size() );
+ assertEquals( 1, dataElements.get( 1 ).getUserGroupAccesses().size() );
+ }
+
private void defaultSetup()
{
DataElement de1 = createDataElement( 'A' );
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata_uga.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata_uga.json 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata_uga.json 2016-03-03 10:04:35 +0000
@@ -0,0 +1,284 @@
+{
+ "dataElements": [
+ {
+ "code": "DataElementCodeA",
+ "shortName": "DataElementShortA",
+ "categoryCombo": {
+ "id": "ygZPnD99B59"
+ },
+ "domainType": "AGGREGATE",
+ "user": {
+ "id": "jdRoHEujnZp"
+ },
+ "created": "2016-03-03T07:25:06.752+0000",
+ "id": "xCTVyx413uK",
+ "zeroIsSignificant": false,
+ "valueType": "TEXT",
+ "aggregationType": "SUM",
+ "lastUpdated": "2016-03-03T07:25:06.754+0000",
+ "name": "DataElementA",
+ "attributeValues": [],
+ "userGroupAccesses": [
+ {
+ "id": "hlXvBLHZwCt",
+ "displayName": "UGA",
+ "access": "r-------",
+ "userGroupUid": "hlXvBLHZwCt"
+ }
+ ],
+ "publicAccess": "rw------",
+ "aggregationLevels": []
+ },
+ {
+ "shortName": "DataElementShortB",
+ "code": "DataElementCodeB",
+ "domainType": "AGGREGATE",
+ "categoryCombo": {
+ "id": "ygZPnD99B59"
+ },
+ "id": "PYxjZnf8VFT",
+ "created": "2016-03-03T07:28:15.638+0000",
+ "user": {
+ "id": "jdRoHEujnZp"
+ },
+ "zeroIsSignificant": false,
+ "attributeValues": [],
+ "aggregationType": "SUM",
+ "lastUpdated": "2016-03-03T07:28:15.640+0000",
+ "name": "DataElementB",
+ "valueType": "TEXT",
+ "userGroupAccesses": [
+ {
+ "displayName": "UGB",
+ "access": "r-------",
+ "userGroupUid": "jCDKJBruqjc",
+ "id": "jCDKJBruqjc"
+ }
+ ],
+ "publicAccess": "rw------",
+ "aggregationLevels": []
+ }
+ ],
+ "organisationUnits": [
+ {
+ "path": "/DMcQns4EDCH",
+ "shortName": "Country",
+ "attributeValues": [],
+ "name": "Country",
+ "lastUpdated": "2016-03-03T07:15:22.420+0000",
+ "user": {
+ "id": "jdRoHEujnZp"
+ },
+ "id": "DMcQns4EDCH",
+ "created": "2016-03-03T07:15:22.405+0000",
+ "uuid": "86ae63ed-776c-404c-aef1-26b14ae1994e",
+ "featureType": "NONE",
+ "openingDate": "2016-03-03",
+ "description": ""
+ }
+ ],
+ "userGroups": [
+ {
+ "userGroupAccesses": [],
+ "attributeValues": [],
+ "lastUpdated": "2016-03-03T07:15:44.420+0000",
+ "name": "UGA",
+ "users": [
+ {
+ "id": "jdRoHEujnZp"
+ }
+ ],
+ "id": "hlXvBLHZwCt",
+ "created": "2016-03-03T07:15:44.419+0000",
+ "publicAccess": "rw------",
+ "user": {
+ "id": "jdRoHEujnZp"
+ },
+ "managedGroups": []
+ },
+ {
+ "userGroupAccesses": [],
+ "name": "UGB",
+ "lastUpdated": "2016-03-03T07:15:52.940+0000",
+ "attributeValues": [],
+ "users": [
+ {
+ "id": "jdRoHEujnZp"
+ }
+ ],
+ "managedGroups": [],
+ "publicAccess": "rw------",
+ "user": {
+ "id": "jdRoHEujnZp"
+ },
+ "created": "2016-03-03T07:15:52.940+0000",
+ "id": "jCDKJBruqjc"
+ }
+ ],
+ "userRoles": [
+ {
+ "publicAccess": "--------",
+ "id": "wROqj1MuHYl",
+ "created": "2016-03-03T07:15:10.078+0000",
+ "authorities": [
+ "F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS",
+ "ALL",
+ "F_USERGROUP_MANAGING_RELATIONSHIPS_ADD",
+ "F_REPORTTABLE_PUBLIC_ADD",
+ "F_TRACKED_ENTITY_INSTANCE_DELETE",
+ "F_USER_GROUPS_READ_ONLY_ADD_MEMBERS",
+ "F_MAP_PUBLIC_ADD",
+ "F_USER_ADD_WITHIN_MANAGED_GROUP",
+ "F_TRACKED_ENTITY_INSTANCE_SEARCH",
+ "F_PROGRAM_ENROLLMENT",
+ "F_REPORTTABLE_EXTERNAL",
+ "F_SQLVIEW_EXTERNAL",
+ "F_GIS_ADMIN",
+ "F_REPLICATE_USER",
+ "F_INSERT_CUSTOM_JS_CSS",
+ "F_DASHBOARD_PUBLIC_ADD",
+ "F_METADATA_IMPORT",
+ "F_CHART_PUBLIC_ADD",
+ "F_VIEW_UNAPPROVED_DATA",
+ "F_CHART_EXTERNAL",
+ "F_USERGROUP_MANAGING_RELATIONSHIPS_VIEW",
+ "F_METADATA_EXPORT",
+ "F_PROGRAM_UNENROLLMENT",
+ "F_APPROVE_DATA",
+ "F_ACCEPT_DATA_LOWER_LEVELS",
+ "F_TRACKED_ENTITY_INSTANCE_ADD",
+ "F_USERGROUP_PUBLIC_ADD",
+ "F_OAUTH2_CLIENT_MANAGE",
+ "F_TRACKED_ENTITY_DATAVALUE_ADD",
+ "F_PROGRAM_DASHBOARD_CONFIG_ADMIN",
+ "F_MAP_EXTERNAL",
+ "F_APPROVE_DATA_LOWER_LEVELS",
+ "F_TRACKED_ENTITY_DATAVALUE_DELETE"
+ ],
+ "name": "Superuser",
+ "lastUpdated": "2016-03-03T07:15:10.078+0000",
+ "userGroupAccesses": [],
+ "dataSets": [],
+ "programs": []
+ }
+ ],
+ "date": "2016-03-03T07:31:17.836+0000",
+ "categoryOptionCombos": [
+ {
+ "categoryOptions": [
+ {
+ "id": "kfZOl8heQXd"
+ }
+ ],
+ "created": "2016-03-03T07:14:00.043+0000",
+ "name": "default",
+ "lastUpdated": "2016-03-03T07:14:00.044+0000",
+ "ignoreApproval": false,
+ "id": "Kvznkmca4sQ",
+ "categoryCombo": {
+ "id": "ygZPnD99B59"
+ }
+ }
+ ],
+ "categoryOptions": [
+ {
+ "organisationUnits": [],
+ "name": "default",
+ "lastUpdated": "2016-03-03T07:14:00.063+0000",
+ "attributeValues": [],
+ "shortName": "default",
+ "userGroupAccesses": [],
+ "publicAccess": "--------",
+ "created": "2016-03-03T07:14:00.012+0000",
+ "id": "kfZOl8heQXd"
+ }
+ ],
+ "organisationUnitLevels": [
+ {
+ "level": 1,
+ "id": "lHu2WjrzT7H",
+ "name": "Level 1",
+ "created": "2016-03-03T07:15:26.669+0000",
+ "lastUpdated": "2016-03-03T07:15:26.669+0000"
+ }
+ ],
+ "trackedEntities": [
+ {
+ "attributeValues": [],
+ "id": "cvBKSpge0AD",
+ "name": "Person",
+ "description": "Person"
+ }
+ ],
+ "categories": [
+ {
+ "publicAccess": "--------",
+ "categoryOptions": [
+ {
+ "id": "kfZOl8heQXd"
+ }
+ ],
+ "created": "2016-03-03T07:14:00.038+0000",
+ "dataDimensionType": "DISAGGREGATION",
+ "id": "jOOLSNdZq8Q",
+ "dataDimension": true,
+ "lastUpdated": "2016-03-03T07:14:00.406+0000",
+ "name": "default",
+ "userGroupAccesses": []
+ }
+ ],
+ "users": [
+ {
+ "firstName": "admin",
+ "created": "2016-03-03T07:15:10.066+0000",
+ "surname": "admin",
+ "userCredentials": {
+ "created": "2016-03-03T07:15:10.199+0000",
+ "catDimensionConstraints": [],
+ "externalAuth": false,
+ "passwordLastUpdated": "2016-03-03T07:15:10.102+0000",
+ "cogsDimensionConstraints": [],
+ "selfRegistered": false,
+ "lastLogin": "2016-03-03T07:15:10.102+0000",
+ "disabled": false,
+ "username": "admin",
+ "userRoles": [
+ {
+ "id": "wROqj1MuHYl"
+ }
+ ],
+ "invitation": false,
+ "userInfo": {
+ "id": "jdRoHEujnZp"
+ }
+ },
+ "id": "jdRoHEujnZp",
+ "teiSearchOrganisationUnits": [],
+ "organisationUnits": [
+ {
+ "id": "DMcQns4EDCH"
+ }
+ ],
+ "lastUpdated": "2016-03-03T07:15:10.066+0000",
+ "attributeValues": [],
+ "dataViewOrganisationUnits": []
+ }
+ ],
+ "categoryCombos": [
+ {
+ "created": "2016-03-03T07:14:00.042+0000",
+ "id": "ygZPnD99B59",
+ "dataDimensionType": "DISAGGREGATION",
+ "publicAccess": "--------",
+ "categories": [
+ {
+ "id": "jOOLSNdZq8Q"
+ }
+ ],
+ "name": "default",
+ "skipTotal": false,
+ "lastUpdated": "2016-03-03T07:14:00.046+0000",
+ "userGroupAccesses": []
+ }
+ ]
+}