← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21463: minor fixes

 

------------------------------------------------------------
revno: 21463
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-16 09:59:10 +0100
message:
  minor fixes
modified:
  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/event/AbstractEventService.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-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 08:36:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-12-16 08:59:10 +0000
@@ -239,7 +239,7 @@
         org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
         TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance( entityInstance );
 
-        Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() );
+        Program program = getProgram( importOptions.getIdSchemes(), enrollment.getProgram() );
 
         ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
         params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL );
@@ -291,7 +291,7 @@
             return importSummary;
         }
 
-        OrganisationUnit organisationUnit = getOrganisationUnit( enrollment.getOrgUnit(), importOptions.getIdSchemes() );
+        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), enrollment.getOrgUnit() );
 
         ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program,
             enrollment.getEnrollmentDate(), enrollment.getIncidentDate(), organisationUnit, enrollment.getEnrollment() );
@@ -384,7 +384,7 @@
         }
 
         org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
-        Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() );
+        Program program = getProgram( importOptions.getIdSchemes(), enrollment.getProgram() );
 
         programInstance.setProgram( program );
         programInstance.setEntityInstance( entityInstance );
@@ -512,7 +512,7 @@
     {
         List<ImportConflict> importConflicts = new ArrayList<>();
 
-        Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() );
+        Program program = getProgram( importOptions.getIdSchemes(), enrollment.getProgram() );
         org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = teiService.getTrackedEntityInstance(
             enrollment.getTrackedEntityInstance() );
 
@@ -613,7 +613,7 @@
 
         for ( String key : attributeValueMap.keySet() )
         {
-            TrackedEntityAttribute attribute = getTrackedEntityAttribute( key, importOptions.getIdSchemes() );
+            TrackedEntityAttribute attribute = getTrackedEntityAttribute( importOptions.getIdSchemes(), key );
 
             if ( attribute != null )
             {
@@ -643,7 +643,7 @@
     private List<ImportConflict> validateAttributeType( Attribute attribute, ImportOptions importOptions )
     {
         List<ImportConflict> importConflicts = Lists.newArrayList();
-        TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() );
+        TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( importOptions.getIdSchemes(), attribute.getAttribute() );
 
         if ( teAttribute == null )
         {
@@ -680,17 +680,17 @@
         }
     }
 
-    private OrganisationUnit getOrganisationUnit( String id, IdSchemes idSchemes )
+    private OrganisationUnit getOrganisationUnit( IdSchemes idSchemes, String id )
     {
         return organisationUnitCache.get( id, new IdentifiableObjectCallable<>( manager, OrganisationUnit.class, idSchemes.getOrgUnitIdScheme(), id ) );
     }
 
-    private Program getProgram( String id, IdSchemes idSchemes )
+    private Program getProgram( IdSchemes idSchemes, String id )
     {
         return programCache.get( id, new IdentifiableObjectCallable<>( manager, Program.class, idSchemes.getProgramIdScheme(), id ) );
     }
 
-    private TrackedEntityAttribute getTrackedEntityAttribute( String id, IdSchemes idSchemes )
+    private TrackedEntityAttribute getTrackedEntityAttribute( IdSchemes idSchemes, String 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/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-12-15 14:46:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-12-16 08:59:10 +0000
@@ -34,12 +34,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.SessionFactory;
-import org.hisp.dhis.attribute.Attribute;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdScheme;
 import org.hisp.dhis.common.IdSchemes;
 import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.IdentifiableProperty;
 import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.common.Pager;
@@ -399,7 +397,7 @@
             }
         }
 
-        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes().getOrgUnitIdScheme(), event.getOrgUnit() );
+        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), event.getOrgUnit() );
 
         if ( organisationUnit == null )
         {
@@ -662,7 +660,7 @@
             return importSummary.incrementIgnored();
         }
 
-        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes().getOrgUnitIdScheme(), event.getOrgUnit() );
+        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), event.getOrgUnit() );
 
         if ( organisationUnit == null )
         {
@@ -818,8 +816,8 @@
         }
 
         ImportOptions importOptions = new ImportOptions();
-        
-        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes().getOrgUnitIdScheme(), event.getOrgUnit() );
+
+        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), event.getOrgUnit() );
 
         if ( organisationUnit == null )
         {
@@ -1280,53 +1278,9 @@
         }
     }
 
-    private OrganisationUnit getOrganisationUnit( IdScheme idScheme, String value )
+    private OrganisationUnit getOrganisationUnit( IdSchemes idSchemes, String id )
     {
-        OrganisationUnit organisationUnit = null;
-
-        if ( StringUtils.isEmpty( value ) )
-        {
-            return null;
-        }
-
-        if ( organisationUnitCache.containsKey( value ) )
-        {
-            return organisationUnitCache.get( value );
-        }
-
-        if ( idScheme.is( IdentifiableProperty.UUID ) )
-        {
-            organisationUnit = organisationUnitService.getOrganisationUnitByUuid( value );
-        }
-        else if ( idScheme.is( IdentifiableProperty.CODE ) )
-        {
-            organisationUnit = organisationUnitService.getOrganisationUnitByCode( value );
-        }
-        else if ( idScheme.is( IdentifiableProperty.NAME ) )
-        {
-            List<OrganisationUnit> organisationUnitByName = organisationUnitService.getOrganisationUnitByName( value );
-
-            if ( organisationUnitByName.size() == 1 )
-            {
-                organisationUnit = organisationUnitByName.get( 0 );
-            }
-        }
-        else if ( idScheme.is( IdentifiableProperty.ATTRIBUTE ) )
-        {
-            Attribute attribute = manager.get( Attribute.class, idScheme.getAttribute() );
-            organisationUnit = manager.getByUniqueAttributeValue( OrganisationUnit.class, attribute, value );
-        }
-        else
-        {
-            organisationUnit = organisationUnitService.getOrganisationUnit( value );
-        }
-
-        if ( organisationUnit != null )
-        {
-            organisationUnitCache.put( value, organisationUnit );
-        }
-
-        return organisationUnit;
+        return organisationUnitCache.get( id, new IdentifiableObjectCallable<>( manager, OrganisationUnit.class, idSchemes.getOrgUnitIdScheme(), id ) );
     }
 
     private Program getProgram( IdScheme idScheme, String 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-16 08:36:30 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2015-12-16 08:59:10 +0000
@@ -198,11 +198,11 @@
 
         org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = new org.hisp.dhis.trackedentity.TrackedEntityInstance();
 
-        OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit(), importOptions.getIdSchemes() );
+        OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit() );
         Assert.notNull( organisationUnit );
         entityInstance.setOrganisationUnit( organisationUnit );
 
-        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity(), importOptions.getIdSchemes() );
+        TrackedEntity trackedEntity = getTrackedEntity( importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity() );
         entityInstance.setTrackedEntity( trackedEntity );
         entityInstance.setUid( CodeGenerator.isValidCode( trackedEntityInstance.getTrackedEntityInstance() ) ?
             trackedEntityInstance.getTrackedEntityInstance() : CodeGenerator.generateCode() );
@@ -461,17 +461,17 @@
         teiService.updateTrackedEntityInstance( entityInstance );
     }
 
-    private OrganisationUnit getOrganisationUnit( String id, IdSchemes idSchemes )
+    private OrganisationUnit getOrganisationUnit( IdSchemes idSchemes, String id )
     {
         return organisationUnitCache.get( id, new IdentifiableObjectCallable<>( manager, OrganisationUnit.class, idSchemes.getOrgUnitIdScheme(), id ) );
     }
 
-    private TrackedEntity getTrackedEntity( String id, IdSchemes idSchemes )
+    private TrackedEntity getTrackedEntity( IdSchemes idSchemes, String id )
     {
         return trackedEntityCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntity.class, idSchemes.getTrackedEntityIdScheme(), id ) );
     }
 
-    private TrackedEntityAttribute getTrackedEntityAttribute( String id, IdSchemes idSchemes )
+    private TrackedEntityAttribute getTrackedEntityAttribute( IdSchemes idSchemes, String id )
     {
         return trackedEntityAttributeCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntityAttribute.class, idSchemes.getTrackedEntityAttributeIdScheme(), id ) );
     }
@@ -489,7 +489,7 @@
             return importConflicts;
         }
 
-        TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() );
+        TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( importOptions.getIdSchemes(), attribute.getAttribute() );
 
         if ( trackedEntityAttribute == null )
         {
@@ -567,7 +567,7 @@
 
         for ( Attribute attribute : trackedEntityInstance.getAttributes() )
         {
-            TrackedEntityAttribute entityAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() );
+            TrackedEntityAttribute entityAttribute = getTrackedEntityAttribute( importOptions.getIdSchemes(), attribute.getAttribute() );
 
             if ( entityAttribute == null )
             {
@@ -577,7 +577,7 @@
 
             if ( entityAttribute.isUnique() )
             {
-                OrganisationUnit organisationUnit = getOrganisationUnit( trackedEntityInstance.getOrgUnit(), importOptions.getIdSchemes() );
+                OrganisationUnit organisationUnit = getOrganisationUnit( importOptions.getIdSchemes(), trackedEntityInstance.getOrgUnit() );
                 org.hisp.dhis.trackedentity.TrackedEntityInstance tei = teiService.getTrackedEntityInstance( trackedEntityInstance.getTrackedEntityInstance() );
                 importConflicts.addAll( checkScope( tei, entityAttribute, attribute.getValue(), organisationUnit ) );
             }
@@ -598,7 +598,7 @@
             return importConflicts;
         }
 
-        TrackedEntity trackedEntity = getTrackedEntity( trackedEntityInstance.getTrackedEntity(), importOptions.getIdSchemes() );
+        TrackedEntity trackedEntity = getTrackedEntity( importOptions.getIdSchemes(), trackedEntityInstance.getTrackedEntity() );
 
         if ( trackedEntity == null )
         {