dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43327
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21987: wip, create for object bundle commits
------------------------------------------------------------
revno: 21987
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-17 16:17:36 +0700
message:
wip, create for object bundle commits
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata1.json
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
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/common/DefaultIdentifiableObjectManager.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
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/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2016-01-08 16:32:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2016-02-17 09:17:36 +0000
@@ -169,6 +169,8 @@
<T extends IdentifiableObject> boolean isAttributeValueUnique( Class<? extends IdentifiableObject> klass, T object, Attribute attribute, String value );
+ Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults();
+
// -------------------------------------------------------------------------
// NO ACL
// -------------------------------------------------------------------------
=== 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-17 05:33:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java 2016-02-17 09:17:36 +0000
@@ -29,6 +29,9 @@
*/
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
import java.util.ArrayList;
import java.util.Collection;
@@ -43,6 +46,8 @@
{
private Map<PreheatIdentifier, Map<Class<? extends IdentifiableObject>, Map<String, IdentifiableObject>>> map = new HashMap<>();
+ private Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = new HashMap<>();
+
public Preheat()
{
}
@@ -160,4 +165,20 @@
return this;
}
+
+ public Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults()
+ {
+ return defaults;
+ }
+
+ public void setDefaults( Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults )
+ {
+ this.defaults = defaults;
+ }
+
+ public static boolean isDefault( IdentifiableObject object )
+ {
+ return (DataElementCategory.class.isInstance( object ) || DataElementCategoryOption.class.isInstance( object )
+ || DataElementCategoryCombo.class.isInstance( object )) && "default".equals( object.getName() );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2016-01-08 16:32:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2016-02-17 09:17:36 +0000
@@ -36,6 +36,9 @@
import org.hisp.dhis.common.NameableObject.NameableProperty;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.user.UserCredentials;
@@ -383,10 +386,10 @@
return (List<T>) store.getByUid( uids );
}
-
+
@Override
@SuppressWarnings( "unchecked" )
- public <T extends IdentifiableObject> List<T> getByCode(Class<T> clazz, Collection<String> codes)
+ public <T extends IdentifiableObject> List<T> getByCode( Class<T> clazz, Collection<String> codes )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -1071,6 +1074,17 @@
return store != null && store.isAttributeValueUnique( object, attribute, value );
}
+ @Override
+ public Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults()
+ {
+ Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = new HashMap<>();
+ defaults.put( DataElementCategory.class, getByName( DataElementCategory.class, "default" ) );
+ defaults.put( DataElementCategoryCombo.class, getByName( DataElementCategoryCombo.class, "default" ) );
+ defaults.put( DataElementCategoryOption.class, getByName( DataElementCategoryOption.class, "default" ) );
+
+ return defaults;
+ }
+
//--------------------------------------------------------------------------
// Supportive methods
//--------------------------------------------------------------------------
=== 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-16 06:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-02-17 09:17:36 +0000
@@ -30,6 +30,7 @@
import com.google.common.collect.Lists;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.query.Query;
import org.hisp.dhis.query.QueryService;
import org.hisp.dhis.query.Restrictions;
@@ -63,11 +64,15 @@
@Autowired
private QueryService queryService;
+ @Autowired
+ private IdentifiableObjectManager manager;
+
@Override
@SuppressWarnings( "unchecked" )
public Preheat preheat( PreheatParams params )
{
Preheat preheat = new Preheat();
+ preheat.setDefaults( manager.getDefaults() );
if ( PreheatMode.ALL == params.getPreheatMode() )
{
=== 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-02-17 05:33:53 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java 2016-02-17 09:17:36 +0000
@@ -34,6 +34,9 @@
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.preheat.InvalidObject;
import org.hisp.dhis.preheat.PreheatMode;
import org.hisp.dhis.preheat.PreheatParams;
@@ -196,10 +199,20 @@
private void handleCreates( Session session, List<IdentifiableObject> objects, ObjectBundle bundle )
{
+ for ( IdentifiableObject object : objects )
+ {
+ preheatService.connectReferences( object, bundle.getPreheat(), bundle.getPreheatIdentifier() );
+ session.save( object );
+ if ( log.isDebugEnabled() )
+ {
+ String msg = "Created object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";
+ log.debug( msg );
+ }
+ }
}
- private void handleUpdates( Session klass, List<IdentifiableObject> objects, ObjectBundle bundle )
+ private void handleUpdates( Session session, List<IdentifiableObject> objects, ObjectBundle bundle )
{
}
=== 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-02-17 05:45:31 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java 2016-02-17 09:17:36 +0000
@@ -35,8 +35,10 @@
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.importexport.ImportStrategy;
import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.preheat.InvalidReference;
import org.hisp.dhis.preheat.PreheatIdentifier;
import org.hisp.dhis.preheat.PreheatMode;
@@ -44,6 +46,7 @@
import org.hisp.dhis.render.RenderFormat;
import org.hisp.dhis.render.RenderService;
import org.hisp.dhis.user.User;
+import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
@@ -421,6 +424,31 @@
assertEquals( "DataElementCodeD", dataElements.get( 0 ).getCode() );
}
+ @Test
+ @Ignore
+ public void testCreateSimpleMetadataUID() throws IOException
+ {
+ Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+ new ClassPathResource( "dxf2/simple_metadata1.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 );
+ objectBundleService.commit( bundle );
+
+ List<OrganisationUnit> organisationUnits = manager.getAll( OrganisationUnit.class );
+ List<DataElement> dataElements = manager.getAll( DataElement.class );
+ List<DataSet> dataSets = manager.getAll( DataSet.class );
+
+ assertFalse( organisationUnits.isEmpty() );
+ assertFalse( dataElements.isEmpty() );
+ assertFalse( dataSets.isEmpty() );
+ }
+
private void defaultSetup()
{
DataElement de1 = createDataElement( 'A' );
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata1.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata1.json 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/simple_metadata1.json 2016-02-17 09:17:36 +0000
@@ -0,0 +1,186 @@
+{
+ "organisationUnitLevels": [
+ {
+ "id": "e1DcQuAONBm",
+ "level": 1,
+ "lastUpdated": "2016-02-17T06:19:09.255+0000",
+ "created": "2016-02-17T06:17:12.379+0000",
+ "name": "Country"
+ }
+ ],
+ "categoryOptions": [
+ {
+ "created": "2016-02-17T06:13:29.120+0000",
+ "name": "default",
+ "attributeValues": [],
+ "publicAccess": "--------",
+ "shortName": "default",
+ "lastUpdated": "2016-02-17T06:13:29.137+0000",
+ "userGroupAccesses": [],
+ "organisationUnits": [],
+ "id": "SMHi6P8WZ1H"
+ }
+ ],
+ "categories": [
+ {
+ "name": "default",
+ "created": "2016-02-17T06:13:29.131+0000",
+ "categoryOptions": [
+ {
+ "id": "SMHi6P8WZ1H"
+ }
+ ],
+ "dataDimension": true,
+ "publicAccess": "--------",
+ "userGroupAccesses": [],
+ "lastUpdated": "2016-02-17T06:25:08.743+0000",
+ "dataDimensionType": "DISAGGREGATION",
+ "id": "XSypGD15atv"
+ }
+ ],
+ "categoryOptionCombos": [
+ {
+ "categoryCombo": {
+ "id": "zU1OZFVxnw7"
+ },
+ "id": "gOeVvNgprQ8",
+ "name": "default",
+ "ignoreApproval": false,
+ "lastUpdated": "2016-02-17T06:13:29.134+0000",
+ "created": "2016-02-17T06:13:29.133+0000",
+ "categoryOptions": [
+ {
+ "id": "SMHi6P8WZ1H"
+ }
+ ]
+ }
+ ],
+ "dataSets": [
+ {
+ "indicators": [],
+ "dataElementDecoration": false,
+ "renderHorizontally": false,
+ "code": "DataSetCodeA",
+ "fieldCombinationRequired": false,
+ "notifyCompletingUser": false,
+ "created": "2016-02-17T06:16:40.204+0000",
+ "renderAsTabs": false,
+ "id": "DSaKQTwN4qg",
+ "lastUpdated": "2016-02-17T06:19:18.986+0000",
+ "expiryDays": 0,
+ "validCompleteOnly": false,
+ "userGroupAccesses": [],
+ "attributeValues": [],
+ "skipOffline": false,
+ "publicAccess": "rw------",
+ "noValueRequiresComment": false,
+ "shortName": "DataSetShortA",
+ "compulsoryDataElementOperands": [],
+ "timelyDays": 15,
+ "name": "DataSetA",
+ "openFuturePeriods": 0,
+ "categoryCombo": {
+ "id": "zU1OZFVxnw7"
+ },
+ "dataElements": [
+ {
+ "id": "CCwk5Yx440o"
+ },
+ {
+ "id": "SG4HuKlNEFH"
+ }
+ ],
+ "mobile": false,
+ "organisationUnits": [
+ {
+ "id": "PdWlltZnVZe"
+ }
+ ],
+ "version": 1,
+ "periodType": "Monthly"
+ }
+ ],
+ "categoryCombos": [
+ {
+ "lastUpdated": "2016-02-17T06:13:29.135+0000",
+ "userGroupAccesses": [],
+ "dataDimensionType": "DISAGGREGATION",
+ "id": "zU1OZFVxnw7",
+ "created": "2016-02-17T06:13:29.133+0000",
+ "categories": [
+ {
+ "id": "XSypGD15atv"
+ }
+ ],
+ "name": "default",
+ "skipTotal": false,
+ "publicAccess": "--------"
+ }
+ ],
+ "dataElements": [
+ {
+ "zeroIsSignificant": false,
+ "aggregationType": "SUM",
+ "domainType": "AGGREGATE",
+ "created": "2016-02-17T06:15:06.079+0000",
+ "code": "DataElementCodeA",
+ "id": "SG4HuKlNEFH",
+ "userGroupAccesses": [],
+ "lastUpdated": "2016-02-17T06:15:59.378+0000",
+ "shortName": "DataElementShortA",
+ "publicAccess": "rw------",
+ "attributeValues": [],
+ "name": "DataElementA",
+ "categoryCombo": {
+ "id": "zU1OZFVxnw7"
+ },
+ "aggregationLevels": [],
+ "valueType": "TEXT"
+ },
+ {
+ "publicAccess": "rw------",
+ "attributeValues": [],
+ "shortName": "DataElementShortB",
+ "name": "DataElementB",
+ "categoryCombo": {
+ "id": "zU1OZFVxnw7"
+ },
+ "aggregationLevels": [],
+ "valueType": "TEXT",
+ "zeroIsSignificant": false,
+ "aggregationType": "SUM",
+ "created": "2016-02-17T06:15:49.487+0000",
+ "code": "DataElementCodeB",
+ "domainType": "AGGREGATE",
+ "id": "CCwk5Yx440o",
+ "lastUpdated": "2016-02-17T06:16:08.180+0000",
+ "userGroupAccesses": []
+ }
+ ],
+ "organisationUnits": [
+ {
+ "id": "PdWlltZnVZe",
+ "path": "/PdWlltZnVZe",
+ "lastUpdated": "2016-02-17T06:17:01.228+0000",
+ "description": "",
+ "uuid": "6ea86a20-1eb1-4bbd-87ea-948ee1e01f20",
+ "shortName": "OrgUnitShortA",
+ "attributeValues": [],
+ "name": "OrgUnitA",
+ "featureType": "NONE",
+ "created": "2016-02-17T06:17:01.218+0000",
+ "openingDate": "2016-02-17",
+ "code": "OrgUnitCodeA"
+ }
+ ],
+ "trackedEntities": [
+ {
+ "id": "NdUUIOhQPcu",
+ "attributeValues": [],
+ "name": "Person",
+ "created": "2016-02-17T06:25:08.000+0000",
+ "lastUpdated": "2016-02-17T06:25:08.000+0000",
+ "description": "Person"
+ }
+ ]
+}