← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19906: Data import, code re-org

 

------------------------------------------------------------
revno: 19906
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-08-31 10:42:14 +0200
message:
  Data import, code re-org
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.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/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2015-08-31 08:31:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2015-08-31 08:42:14 +0000
@@ -696,8 +696,6 @@
         {
             org.hisp.dhis.dxf2.datavalue.DataValue dataValue = dataValueSet.getNextDataValue();
 
-            DataValue internalValue = new DataValue();
-
             totalCount++;
 
             final DataElement dataElement = dataElementMap.get( trimToNull( dataValue.getDataElement() ), dataElementCallable.setId( trimToNull( dataValue.getDataElement() ) ) );
@@ -714,8 +712,6 @@
             // Validation
             // -----------------------------------------------------------------
 
-            // TODO Use objects instead of data value references to handle outer objects
-            
             if ( dataElement == null )
             {
                 summary.getConflicts().add( new ImportConflict( dataValue.getDataElement(), "Data element not found or not acccessible" ) );
@@ -837,43 +833,43 @@
                     "Data element: " + dataElement.getUid() + " must be assigned through data sets to organisation unit: " + orgUnit.getUid() ) );
                 continue;
             }
+
+            boolean zeroInsignificant = ValidationUtils.dataValueIsZeroAndInsignificant( dataValue.getValue(), dataElement );
+
+            if ( zeroInsignificant )
+            {
+                summary.getConflicts().add( new ImportConflict( dataValue.getValue(), "Value is zero and not significant, must match data element: " + dataElement.getUid() ) );
+                continue;
+            }
+
+            String storedByValid = ValidationUtils.storedByIsValid( dataValue.getStoredBy() );
+
+            if ( storedByValid != null )
+            {
+                summary.getConflicts().add( new ImportConflict( dataValue.getStoredBy(), i18n.getString( storedByValid ) ) );
+                continue;
+            }
             
+            String storedBy = dataValue.getStoredBy() == null || dataValue.getStoredBy().trim().isEmpty() ? currentUser : dataValue.getStoredBy();
+
+            // -----------------------------------------------------------------
+            // Create data value
+            // -----------------------------------------------------------------
+
+            DataValue internalValue = new DataValue();
+
             internalValue.setDataElement( dataElement );
             internalValue.setPeriod( period );
             internalValue.setSource( orgUnit );
             internalValue.setCategoryOptionCombo( categoryOptionCombo );
             internalValue.setAttributeOptionCombo( attrOptionCombo );
             internalValue.setValue( trimToNull( dataValue.getValue() ) );
-
-            String storedByValid = ValidationUtils.storedByIsValid( dataValue.getStoredBy() );
-
-            if ( dataValue.getStoredBy() == null || dataValue.getStoredBy().trim().isEmpty() )
-            {
-                internalValue.setStoredBy( currentUser );
-            }
-            else if ( storedByValid == null )
-            {
-                internalValue.setStoredBy( dataValue.getStoredBy() );
-            }
-            else
-            {
-                summary.getConflicts().add( new ImportConflict( dataValue.getStoredBy(), i18n.getString( storedByValid ) ) );
-                continue;
-            }
-
+            internalValue.setStoredBy( storedBy );
             internalValue.setCreated( dataValue.hasCreated() ? parseDate( dataValue.getCreated() ) : now );
             internalValue.setLastUpdated( dataValue.hasLastUpdated() ? parseDate( dataValue.getLastUpdated() ) : now );
             internalValue.setComment( trimToNull( dataValue.getComment() ) );
             internalValue.setFollowup( dataValue.getFollowup() );
 
-            boolean zeroInsignificant = ValidationUtils.dataValueIsZeroAndInsignificant( internalValue.getValue(), dataElement );
-
-            if ( zeroInsignificant )
-            {
-                summary.getConflicts().add( new ImportConflict( internalValue.getValue(), "Value is zero and not significant, must match data element: " + dataElement.getUid() ) );
-                continue;
-            }
-
             // -----------------------------------------------------------------
             // Save, update or delete data value
             // -----------------------------------------------------------------