← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14549: support orgUnitIdScheme in event import web-api

 

------------------------------------------------------------
revno: 14549
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-31 13:42:29 +0700
message:
  support orgUnitIdScheme in event import web-api
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.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/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2014-03-31 06:42:29 +0000
@@ -28,14 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
@@ -67,8 +62,13 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -244,13 +244,15 @@
             {
                 return new ImportSummary( ImportStatus.ERROR,
                     "No active event exists for single event no registration program " + program.getUid()
-                        + ", please check and correct your database." );
+                        + ", please check and correct your database."
+                );
             }
             else if ( programInstances.size() > 1 )
             {
                 return new ImportSummary( ImportStatus.ERROR,
                     "Multiple active events exists for single event no registration program " + program.getUid()
-                        + ", please check and correct your database." );
+                        + ", please check and correct your database."
+                );
             }
 
             programInstance = programInstances.get( 0 );
@@ -266,7 +268,30 @@
             }
         }
 
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( event.getOrgUnit() );
+        OrganisationUnit organisationUnit = null;
+
+        if ( IdentifiableObject.IdentifiableProperty.ID.equals( importOptions.getOrgUnitIdScheme() ) ||
+            IdentifiableObject.IdentifiableProperty.UID.equals( importOptions.getOrgUnitIdScheme() ) )
+        {
+            organisationUnit = organisationUnitService.getOrganisationUnit( event.getOrgUnit() );
+        }
+        else if ( IdentifiableObject.IdentifiableProperty.UUID.equals( importOptions.getOrgUnitIdScheme() ) )
+        {
+            organisationUnit = organisationUnitService.getOrganisationUnitByUuid( event.getOrgUnit() );
+        }
+        else if ( IdentifiableObject.IdentifiableProperty.CODE.equals( importOptions.getOrgUnitIdScheme() ) )
+        {
+            organisationUnit = organisationUnitService.getOrganisationUnitByCode( event.getOrgUnit() );
+        }
+        else if ( IdentifiableObject.IdentifiableProperty.NAME.equals( importOptions.getOrgUnitIdScheme() ) )
+        {
+            List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName( event.getOrgUnit() );
+
+            if ( organisationUnitByName.size() == 1 )
+            {
+                organisationUnit = organisationUnitByName.get( 0 );
+            }
+        }
 
         if ( organisationUnit == null )
         {
@@ -517,17 +542,17 @@
                     value.getProvidedElsewhere() );
             }
         }
-        
-        if( !singleValue )
+
+        if ( !singleValue )
         {
             for ( TrackedEntityDataValue value : dataValues )
             {
                 dataValueService.deleteTrackedEntityDataValue( value );
-            }   
+            }
         }
-        
+
     }
-    
+
     // -------------------------------------------------------------------------
     // DELETE
     // -------------------------------------------------------------------------
@@ -589,7 +614,8 @@
                     List<Double> list = objectMapper.readValue( coordinate.getCoordinateString(),
                         new TypeReference<List<Double>>()
                         {
-                        } );
+                        }
+                    );
 
                     coordinate.setLongitude( list.get( 0 ) );
                     coordinate.setLatitude( list.get( 1 ) );
@@ -695,7 +721,8 @@
             {
                 importSummary.getConflicts().add(
                     new ImportConflict( "storedBy", storedBy
-                        + " is more than 31 characters, using current username instead." ) );
+                        + " is more than 31 characters, using current username instead." )
+                );
             }
             storedBy = currentUserService.getCurrentUsername();
         }

=== 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-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2014-03-31 06:42:29 +0000
@@ -38,7 +38,7 @@
 {
     private IdentifiableProperty dataElementIdScheme;
 
-    private IdentifiableProperty orgUnitIdScheme;
+    private IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
 
     private boolean dryRun;