dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34439
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17683: Data import. Improved validation for invalid identifiers.
------------------------------------------------------------
revno: 17683
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-09 09:25:53 +0200
message:
Data import. Improved validation for invalid identifiers.
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetF.xml
modified:
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/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
--
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/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-12-08 21:01:08 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-12-09 07:25:53 +0000
@@ -635,7 +635,7 @@
Period outerPeriod = PeriodType.getPeriodFromIsoString( trimToNull( dataValueSet.getPeriod() ) );
- OrganisationUnit outerOrgUnit;
+ OrganisationUnit outerOrgUnit = null;
DataElementCategoryOptionCombo fallbackCategoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
@@ -651,6 +651,36 @@
DataElementCategoryOptionCombo outerAttrOptionCombo = dataValueSet.getAttributeOptionCombo() != null ?
identifiableObjectManager.getObject( DataElementCategoryOptionCombo.class, idScheme, trimToNull( dataValueSet.getAttributeOptionCombo() ) ) : null;
+ // ---------------------------------------------------------------------
+ // Validation
+ // ---------------------------------------------------------------------
+
+ if ( dataSet == null && trimToNull( dataValueSet.getDataSet() ) != null )
+ {
+ summary.getConflicts().add( new ImportConflict( dataValueSet.getDataSet(), "Data set not found or not accessible" ) );
+ summary.setStatus( ImportStatus.ERROR );
+ }
+
+ if ( outerOrgUnit == null && trimToNull( dataValueSet.getOrgUnit() ) != null )
+ {
+ summary.getConflicts().add( new ImportConflict( dataValueSet.getDataSet(), "Org unit not found or not accessible" ) );
+ summary.setStatus( ImportStatus.ERROR );
+ }
+
+ if ( outerAttrOptionCombo == null && trimToNull( dataValueSet.getAttributeOptionCombo() ) != null )
+ {
+ summary.getConflicts().add( new ImportConflict( dataValueSet.getDataSet(), "Attribute option combo not found or not accessible" ) );
+ summary.setStatus( ImportStatus.ERROR );
+ }
+
+ if ( ImportStatus.ERROR.equals( summary.getStatus() ) )
+ {
+ summary.setDescription( "Import process was aborted" );
+ notifier.notify( id, INFO, "Import process aborted", true ).addTaskSummary( id, summary );
+ dataValueSet.close();
+ return summary;
+ }
+
if ( dataSet != null && completeDate != null )
{
notifier.notify( id, "Completing data set" );
@@ -693,6 +723,10 @@
DataElementCategoryOptionCombo attrOptionCombo = outerAttrOptionCombo != null ? outerAttrOptionCombo :
categoryOptionComboMap.get( trimToNull( dataValue.getAttributeOptionCombo() ) );
+ // -----------------------------------------------------------------
+ // Validation
+ // -----------------------------------------------------------------
+
if ( dataElement == null )
{
summary.getConflicts().add( new ImportConflict( dataValue.getDataElement(), "Data element not found or not acccessible" ) );
@@ -792,7 +826,11 @@
summary.getConflicts().add( new ImportConflict( internalValue.getValue(), "Value is zero and not significant" ) );
continue;
}
-
+
+ // -----------------------------------------------------------------
+ // Save, update or delete data value
+ // -----------------------------------------------------------------
+
if ( !skipExistingCheck && batchHandler.objectExists( internalValue ) )
{
if ( strategy.isCreateAndUpdate() || strategy.isUpdate() )
=== 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-10-15 18:59:11 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2014-12-09 07:25:53 +0000
@@ -52,6 +52,7 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler;
@@ -194,6 +195,7 @@
assertNotNull( summary );
assertNotNull( summary.getDataValueCount() );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
@@ -222,6 +224,7 @@
assertNotNull( summary );
assertNotNull( summary.getDataValueCount() );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
@@ -247,6 +250,8 @@
in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSet( in );
+
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
assertImportDataValues( summary );
}
@@ -259,6 +264,8 @@
ImportOptions options = new ImportOptions( CODE, CODE, false, true, NEW_AND_UPDATES, false );
ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
+
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
assertImportDataValues( summary );
}
@@ -270,6 +277,8 @@
in = new ClassPathResource( "datavalueset/dataValueSetB.csv" ).getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSetCsv( in, null, null );
+
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
assertImportDataValues( summary );
}
@@ -282,8 +291,10 @@
ImportOptions options = new ImportOptions( UID, UID, true, true, NEW_AND_UPDATES, false );
- dataValueSetService.saveDataValueSet( in, options );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull( dataValues );
@@ -298,8 +309,10 @@
ImportOptions options = new ImportOptions( UID, UID, false, true, UPDATES, false );
- dataValueSetService.saveDataValueSet( in, options );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull( dataValues );
@@ -310,8 +323,10 @@
public void testImportDataValuesWithNewPeriod()
throws Exception
{
- dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetC.xml" ).getInputStream() );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetC.xml" ).getInputStream() );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull( dataValues );
@@ -324,8 +339,10 @@
{
in = new ClassPathResource( "datavalueset/dataValueSetD.xml" ).getInputStream();
- dataValueSetService.saveDataValueSet( in );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( in );
+ assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull( dataValues );
@@ -335,6 +352,21 @@
assertTrue( dataValues.contains( new DataValue( deC, peA, ouA, ocDef, ocA ) ) );
}
+ @Test
+ public void testImportDataValuesWithInvalidAttributeOptionCombo()
+ throws Exception
+ {
+ in = new ClassPathResource( "datavalueset/dataValueSetF.xml" ).getInputStream();
+
+ ImportSummary summary = dataValueSetService.saveDataValueSet( in );
+
+ Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
+
+ assertNotNull( dataValues );
+ assertEquals( 0, dataValues.size() );
+ assertEquals( ImportStatus.ERROR, summary.getStatus() );
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetF.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetF.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetF.xml 2014-12-09 07:25:53 +0000
@@ -0,0 +1,6 @@
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" completeDate="2012-01-09" attributeOptionCombo="inValidUid1">
+ <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" period="201201" orgUnit="DiszpKrYNg8" value="10002" storedBy="john" timestamp="2012-01-02" comment="comment" followup="false"/>
+ <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" value="10004" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" period="201201" orgUnit="DiszpKrYNg8" value="10003" storedBy="john" timestamp="2012-01-03" comment="comment" followup="false"/>
+</dataValueSet>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2014-12-04 15:32:30 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/security.xml 2014-12-09 07:25:53 +0000
@@ -308,8 +308,6 @@
<value>F_REPORTTABLE_EXTERNAL</value>
<value>F_METADATA_EXPORT</value>
<value>F_METADATA_IMPORT</value>
- <value>F_METADATA_SUBSET_IMPORT</value>
- <value>F_METADATA_SUBSET_EXPORT</value>
<value>F_APPROVE_DATA</value>
<value>F_APPROVE_DATA_LOWER_LEVELS</value>
<value>F_ACCEPT_DATA_LOWER_LEVELS</value>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-12-08 19:51:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-12-09 07:25:53 +0000
@@ -259,8 +259,6 @@
F_IMPORT_GML=Import GML
F_EXPORT_DATA=Export data
F_EXPORT_EVENTS=Export events
-F_METADATA_SUBSET_IMPORT=Import sub-set of meta-data
-F_METADATA_SUBSET_EXPORT=Export sub-set of meta-data
F_METADATA_IMPORT=Import meta-Data
F_METADATA_EXPORT=Export meta-Data
F_APPROVE_DATA=Approve data