← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21462: Update TEIService to support IdScheme for matching, means that 'search mode' does not work anymor...

 

------------------------------------------------------------
revno: 21462
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-16 09:36:30 +0100
message:
  Update TEIService to support IdScheme for matching, means that 'search mode' does not work anymore, now supports explicit matching with uid, code, attribute: etc.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.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/IdSchemes.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java	2015-12-16 07:53:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java	2015-12-16 08:36:30 +0000
@@ -47,9 +47,9 @@
 
     private IdScheme programStageIdScheme = IdScheme.UID;
 
-    private IdScheme trackedEntity = IdScheme.UID;
+    private IdScheme trackedEntityIdScheme = IdScheme.UID;
 
-    private IdScheme trackedEntityAttribute = IdScheme.UID;
+    private IdScheme trackedEntityAttributeIdScheme = IdScheme.UID;
 
     public IdSchemes()
     {
@@ -126,26 +126,26 @@
         return this;
     }
 
-    public IdSchemes setTrackedEntity( String idScheme )
-    {
-        this.trackedEntity = IdScheme.from( idScheme );
-        return this;
-    }
-
-    public IdScheme getTrackedEntity()
-    {
-        return trackedEntity;
-    }
-
-    public IdSchemes setTrackedEntityAttribute( String idScheme )
-    {
-        this.trackedEntityAttribute = IdScheme.from( idScheme );
-        return this;
-    }
-
-    public IdScheme getTrackedEntityAttribute()
-    {
-        return trackedEntityAttribute;
+    public IdSchemes setTrackedEntityIdScheme( String idScheme )
+    {
+        this.trackedEntityIdScheme = IdScheme.from( idScheme );
+        return this;
+    }
+
+    public IdScheme getTrackedEntityIdScheme()
+    {
+        return trackedEntityIdScheme;
+    }
+
+    public IdSchemes setTrackedEntityAttributeIdScheme( String idScheme )
+    {
+        this.trackedEntityAttributeIdScheme = IdScheme.from( idScheme );
+        return this;
+    }
+
+    public IdScheme getTrackedEntityAttributeIdScheme()
+    {
+        return trackedEntityAttributeIdScheme;
     }
 
     public static String getValue( String uid, String code, IdentifiableProperty identifiableProperty )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java	2015-12-16 07:53:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java	2015-12-16 08:36:30 +0000
@@ -214,9 +214,15 @@
         return this;
     }
 
-    public ImportOptions setTrackedEntityAttribute( String idScheme )
-    {
-        idSchemes.setTrackedEntityAttribute( idScheme );
+    public ImportOptions setTrackedEntityIdScheme( String idScheme )
+    {
+        idSchemes.setTrackedEntityIdScheme( idScheme );
+        return this;
+    }
+
+    public ImportOptions setTrackedEntityAttributeIdScheme( String idScheme )
+    {
+        idSchemes.setTrackedEntityAttributeIdScheme( idScheme );
         return this;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-12-16 07:53:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-12-16 08:36:30 +0000
@@ -692,6 +692,6 @@
 
     private TrackedEntityAttribute getTrackedEntityAttribute( String id, IdSchemes idSchemes )
     {
-        return trackedEntityAttributeCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntityAttribute.class, idSchemes.getTrackedEntityAttribute(), id ) );
+        return trackedEntityAttributeCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntityAttribute.class, idSchemes.getTrackedEntityAttributeIdScheme(), id ) );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-12-15 14:46:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-12-16 08:36:30 +0000
@@ -30,6 +30,7 @@
 
 import com.google.common.collect.Lists;
 import org.hisp.dhis.common.CodeGenerator;
+import org.hisp.dhis.common.IdSchemes;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.commons.collection.CachingMap;
 import org.hisp.dhis.dbms.DbmsManager;
@@ -42,7 +43,7 @@
 import org.hisp.dhis.relationship.Relationship;
 import org.hisp.dhis.relationship.RelationshipService;
 import org.hisp.dhis.relationship.RelationshipType;
-import org.hisp.dhis.system.callable.IdentifiableObjectSearchCallable;
+import org.hisp.dhis.system.callable.IdentifiableObjectCallable;
 import org.hisp.dhis.trackedentity.TrackedEntity;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
@@ -191,17 +192,17 @@
         return trackedEntityInstance;
     }
 
-    public org.hisp.dhis.trackedentity.TrackedEntityInstance getTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance )
+    public org.hisp.dhis.trackedentity.TrackedEntityInstance getTrackedEntityInstance( TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions )
     {
         Assert.hasText( trackedEntityInstance.getOrgUnit() );
 
         org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
 
-        OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit() );
+        OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit(), importOptions.getIdSchemes() );
         Assert.notNull( organisationUnit );
         entityInstance.setOrganisationUnit( organisationUnit );
 
-        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity() );
+        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity(), importOptions.getIdSchemes() );
         entityInstance.setTrackedEntity( trackedEntity );
         entityInstance.setUid( CodeGenerator.isValidCode( trackedEntityInstance.getTrackedEntityInstance() ) ?
             trackedEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateCode() );
@@ -252,8 +253,8 @@
         trackedEntityInstance.trimValuesToNull();
 
         Set<ImportConflict> importConflicts = new HashSet<>();
-        importConflicts.addAll( checkTrackedEntity( trackedEntityInstance ) );
-        importConflicts.addAll( checkAttributes( trackedEntityInstance ) );
+        importConflicts.addAll( checkTrackedEntity( trackedEntityInstance, importOptions ) );
+        importConflicts.addAll( checkAttributes( trackedEntityInstance, importOptions ) );
 
         importSummary.setConflicts( importConflicts );
 
@@ -264,7 +265,7 @@
             return importSummary;
         }
 
-        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( trackedEntityInstance );
+        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( trackedEntityInstance, importOptions );
 
         teiService.addTrackedEntityInstance( entityInstance );
 
@@ -322,7 +323,7 @@
 
         Set<ImportConflict> importConflicts = new HashSet<>();
         importConflicts.addAll( checkRelationships( trackedEntityInstance ) );
-        importConflicts.addAll( checkAttributes( trackedEntityInstance ) );
+        importConflicts.addAll( checkAttributes( trackedEntityInstance, importOptions ) );
 
         org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = manager.get( org.hisp.dhis.trackedentity.TrackedEntityInstance.class,
             trackedEntityInstance.getTrackedEntityInstance() );
@@ -460,26 +461,26 @@
         teiService.updateTrackedEntityInstance( entityInstance );
     }
 
-    private OrganisationUnit getOrganisationUnit( String id )
-    {
-        return organisationUnitCache.get( id, new IdentifiableObjectSearchCallable<>( manager, OrganisationUnit.class, id ) );
-    }
-
-    private TrackedEntity getTrackedEntity( String id )
-    {
-        return trackedEntityCache.get( id, new IdentifiableObjectSearchCallable<>( manager, TrackedEntity.class, id ) );
-    }
-
-    private TrackedEntityAttribute getTrackedEntityAttribute( String id )
-    {
-        return trackedEntityAttributeCache.get( id, new IdentifiableObjectSearchCallable<>( manager, TrackedEntityAttribute.class, id ) );
+    private OrganisationUnit getOrganisationUnit( String id, IdSchemes idSchemes )
+    {
+        return organisationUnitCache.get( id, new IdentifiableObjectCallable<>( manager, OrganisationUnit.class, idSchemes.getOrgUnitIdScheme(), id ) );
+    }
+
+    private TrackedEntity getTrackedEntity( String id, IdSchemes idSchemes )
+    {
+        return trackedEntityCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntity.class, idSchemes.getTrackedEntityIdScheme(), id ) );
+    }
+
+    private TrackedEntityAttribute getTrackedEntityAttribute( String id, IdSchemes idSchemes )
+    {
+        return trackedEntityAttributeCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntityAttribute.class, idSchemes.getTrackedEntityAttributeIdScheme(), id ) );
     }
 
     //--------------------------------------------------------------------------
     // VALIDATION
     //--------------------------------------------------------------------------
 
-    private List<ImportConflict> validateAttributeType( Attribute attribute )
+    private List<ImportConflict> validateAttributeType( Attribute attribute, ImportOptions importOptions )
     {
         List<ImportConflict> importConflicts = Lists.newArrayList();
 
@@ -488,7 +489,7 @@
             return importConflicts;
         }
 
-        TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
+        TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() );
 
         if ( trackedEntityAttribute == null )
         {
@@ -560,13 +561,13 @@
         return importConflicts;
     }
 
-    private List<ImportConflict> checkAttributes( TrackedEntityInstance trackedEntityInstance )
+    private List<ImportConflict> checkAttributes( TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions )
     {
         List<ImportConflict> importConflicts = new ArrayList<>();
 
         for ( Attribute attribute : trackedEntityInstance.getAttributes() )
         {
-            TrackedEntityAttribute entityAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
+            TrackedEntityAttribute entityAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() );
 
             if ( entityAttribute == null )
             {
@@ -576,18 +577,18 @@
 
             if ( entityAttribute.isUnique() )
             {
-                OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit() );
+                OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit(), importOptions.getIdSchemes() );
                 org.hisp.dhis.trackedentity.TrackedEntityInstance tei = teiService.getTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance() );
                 importConflicts.addAll( checkScope( tei, entityAttribute, attribute.getValue(), organisationUnit ) );
             }
 
-            importConflicts.addAll( validateAttributeType( attribute ) );
+            importConflicts.addAll( validateAttributeType( attribute, importOptions ) );
         }
 
         return importConflicts;
     }
 
-    private List<ImportConflict> checkTrackedEntity( TrackedEntityInstance trackedEntityInstance )
+    private List<ImportConflict> checkTrackedEntity( TrackedEntityInstance trackedEntityInstance, ImportOptions importOptions )
     {
         List<ImportConflict> importConflicts = new ArrayList<>();
 
@@ -597,7 +598,7 @@
             return importConflicts;
         }
 
-        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity() );
+        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity(), importOptions.getIdSchemes() );
 
         if ( trackedEntity == null )
         {