dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33214
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16948: Data value set import. Added support for a general identifier scheme (idScheme=UID|CODE). This wi...
------------------------------------------------------------
revno: 16948
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-03 13:44:35 +0200
message:
Data value set import. Added support for a general identifier scheme (idScheme=UID|CODE). This will override the specific object identifier schemes, and apply for data sets and category option combos as well.
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2014-10-03 11:44:35 +0000
@@ -28,21 +28,27 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.dxf2.datavalue.DataValue;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.view.DetailedView;
-import org.hisp.dhis.common.view.ExportView;
-import org.hisp.dhis.dxf2.datavalue.DataValue;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
+/**
+ * @author Lars Helge Overland
+ */
@JacksonXmlRootElement(localName = "dataValueSet", namespace = DxfNamespaces.DXF_2_0)
public class DataValueSet
{
@@ -50,6 +56,8 @@
// Options
//--------------------------------------------------------------------------
+ protected String idScheme;
+
protected String dataElementIdScheme;
protected String orgUnitIdScheme;
@@ -89,6 +97,19 @@
@JsonProperty
@JsonView({ DetailedView.class, ExportView.class })
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
+ public String getIdScheme()
+ {
+ return idScheme;
+ }
+
+ public void setIdScheme( String idScheme )
+ {
+ this.idScheme = idScheme;
+ }
+
+ @JsonProperty
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getDataElementIdScheme()
{
return dataElementIdScheme;
@@ -257,6 +278,29 @@
{
}
+ public IdentifiableProperty getIdSchemeProperty()
+ {
+ return idScheme != null ? IdentifiableProperty.valueOf( idScheme.toUpperCase() ) : null;
+ }
+
+ public IdentifiableProperty getDataElementIdSchemeProperty()
+ {
+ String scheme = defaultIfEmpty( idScheme, dataElementIdScheme );
+
+ return scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
+ }
+
+ public IdentifiableProperty getOrgUnitIdSchemeProperty()
+ {
+ String scheme = defaultIfEmpty( idScheme, orgUnitIdScheme );
+
+ return scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
+ }
+
+ //--------------------------------------------------------------------------
+ // toString
+ //--------------------------------------------------------------------------
+
@Override
public String toString()
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-09-24 17:24:34 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-10-03 11:44:35 +0000
@@ -508,13 +508,16 @@
importOptions = importOptions != null ? importOptions : ImportOptions.getDefaultImportOptions();
- IdentifiableProperty dataElementIdScheme = dataValueSet.getDataElementIdScheme() != null ?
- IdentifiableProperty.valueOf( dataValueSet.getDataElementIdScheme().toUpperCase() ) :
- importOptions.getDataElementIdScheme();
-
- IdentifiableProperty orgUnitIdScheme = dataValueSet.getOrgUnitIdScheme() != null ?
- IdentifiableProperty.valueOf( dataValueSet.getOrgUnitIdScheme().toUpperCase() ) :
- importOptions.getOrgUnitIdScheme();
+ IdentifiableProperty dataElementIdScheme = dataValueSet.getDataElementIdSchemeProperty() != null ?
+ dataValueSet.getDataElementIdSchemeProperty() : importOptions.getDataElementIdScheme();
+
+ IdentifiableProperty orgUnitIdScheme = dataValueSet.getOrgUnitIdSchemeProperty() != null ?
+ dataValueSet.getOrgUnitIdSchemeProperty() : importOptions.getOrgUnitIdScheme();
+
+ IdentifiableProperty idScheme = dataValueSet.getIdSchemeProperty() != null ?
+ dataValueSet.getIdSchemeProperty() : importOptions.getIdScheme();
+
+ log.info( "Data element scheme: " + dataElementIdScheme + ", org unit scheme: " + orgUnitIdScheme + ", scheme: " + idScheme );
boolean dryRun = dataValueSet.getDryRun() != null ? dataValueSet.getDryRun() : importOptions.isDryRun();
@@ -526,10 +529,10 @@
Map<String, DataElement> dataElementMap = identifiableObjectManager.getIdMap( DataElement.class, dataElementIdScheme );
Map<String, OrganisationUnit> orgUnitMap = orgUnitIdScheme == UUID ? getUuidOrgUnitMap() : identifiableObjectManager.getIdMap( OrganisationUnit.class, orgUnitIdScheme );
- Map<String, DataElementCategoryOptionCombo> categoryOptionComboMap = identifiableObjectManager.getIdMap( DataElementCategoryOptionCombo.class, IdentifiableProperty.UID );
+ Map<String, DataElementCategoryOptionCombo> categoryOptionComboMap = identifiableObjectManager.getIdMap( DataElementCategoryOptionCombo.class, idScheme );
Map<String, Period> periodMap = new HashMap<>();
- DataSet dataSet = dataValueSet.getDataSet() != null ? identifiableObjectManager.getObject( DataSet.class, IdentifiableProperty.UID, dataValueSet.getDataSet() ) : null;
+ DataSet dataSet = dataValueSet.getDataSet() != null ? identifiableObjectManager.getObject( DataSet.class, idScheme, dataValueSet.getDataSet() ) : null;
Date completeDate = getDefaultDate( dataValueSet.getCompleteDate() );
Period outerPeriod = PeriodType.getPeriodFromIsoString( trimToNull( dataValueSet.getPeriod() ) );
@@ -548,7 +551,7 @@
}
DataElementCategoryOptionCombo outerAttrOptionCombo = dataValueSet.getAttributeOptionCombo() != null ?
- identifiableObjectManager.getObject( DataElementCategoryOptionCombo.class, IdentifiableProperty.UID, trimToNull( dataValueSet.getAttributeOptionCombo() ) ) : null;
+ identifiableObjectManager.getObject( DataElementCategoryOptionCombo.class, idScheme, trimToNull( dataValueSet.getAttributeOptionCombo() ) ) : null;
if ( dataSet != null && completeDate != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultExportService.java 2014-10-03 11:44:35 +0000
@@ -64,6 +64,7 @@
implements ExportService
{
private static final Log log = LogFactory.getLog( DefaultExportService.class );
+
//-------------------------------------------------------------------------------------------------------
// Dependencies
//-------------------------------------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java 2014-09-12 15:26:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java 2014-10-03 11:44:35 +0000
@@ -32,10 +32,16 @@
import org.hisp.dhis.importexport.ImportStrategy;
/**
+ * The idScheme is a general setting which will apply to all objects. The idSchemes
+ * can also be defined for specific objects such as dataElementIdScheme. The
+ * general setting will override specific settings.
+ *
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public class ImportOptions
{
+ private IdentifiableProperty idScheme;
+
private IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
private IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
@@ -80,16 +86,21 @@
// Get methods
//--------------------------------------------------------------------------
+ public IdentifiableProperty getIdScheme()
+ {
+ return idScheme != null ? idScheme : IdentifiableProperty.UID;
+ }
+
public IdentifiableProperty getDataElementIdScheme()
{
- return dataElementIdScheme != null ? dataElementIdScheme : IdentifiableProperty.UID;
+ return idScheme != null ? idScheme : ( dataElementIdScheme != null ? dataElementIdScheme : IdentifiableProperty.UID );
}
public IdentifiableProperty getOrgUnitIdScheme()
{
- return orgUnitIdScheme != null ? orgUnitIdScheme : IdentifiableProperty.UID;
+ return idScheme != null ? idScheme : ( orgUnitIdScheme != null ? orgUnitIdScheme : IdentifiableProperty.UID );
}
-
+
public boolean isDryRun()
{
return dryRun;
@@ -114,6 +125,11 @@
// Set methods
//--------------------------------------------------------------------------
+ public void setIdScheme( String scheme )
+ {
+ this.idScheme = scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
+ }
+
public void setDataElementIdScheme( String scheme )
{
this.dataElementIdScheme = scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
@@ -162,7 +178,7 @@
@Override
public String toString()
{
- return "[data element id scheme: " + dataElementIdScheme + ", org unit id scheme: " +
+ return "[General id scheme: " + idScheme + ", data element id scheme: " + dataElementIdScheme + ", org unit id scheme: " +
orgUnitIdScheme + ", dry run: " + dryRun + ", async: " + async + ", strategy: " + importStrategy + ", skip check: " + skipExistingCheck + "]";
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2014-07-22 16:44:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2014-10-03 11:44:35 +0000
@@ -64,6 +64,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
+/**
+ * @author Lars Helge Overland
+ */
public class DataValueSetServiceTest
extends DhisTest
{