=== 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-04 05:41:43 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdSchemes.java 2015-12-16 07:53:48 +0000 @@ -47,6 +47,10 @@ private IdScheme programStageIdScheme = IdScheme.UID; + private IdScheme trackedEntity = IdScheme.UID; + + private IdScheme trackedEntityAttribute = IdScheme.UID; + public IdSchemes() { } @@ -122,6 +126,28 @@ 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 static String getValue( String uid, String code, IdentifiableProperty identifiableProperty ) { return getValue( uid, code, IdScheme.from( 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-04 05:41:43 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java 2015-12-16 07:53:48 +0000 @@ -172,45 +172,52 @@ // Set methods //-------------------------------------------------------------------------- + public ImportOptions setIdSchemes( IdSchemes idSchemes ) + { + this.idSchemes = idSchemes; + return this; + } + + public ImportOptions setIdScheme( String idScheme ) + { + idSchemes.setIdScheme( idScheme ); + return this; + } + + public ImportOptions setDataElementIdScheme( String idScheme ) + { + idSchemes.setDataElementIdScheme( idScheme ); + return this; + } + + public ImportOptions setCategoryOptionComboIdScheme( String idScheme ) + { + idSchemes.setCategoryOptionComboIdScheme( idScheme ); + return this; + } + + public ImportOptions setOrgUnitIdScheme( String idScheme ) + { + idSchemes.setOrgUnitIdScheme( idScheme ); + return this; + } + + public ImportOptions setProgramIdScheme( String idScheme ) + { + idSchemes.setProgramIdScheme( idScheme ); + return this; + } + public ImportOptions setProgramStageIdScheme( String idScheme ) { idSchemes.setProgramStageIdScheme( idScheme ); return this; } - public ImportOptions setProgramIdScheme( String idScheme ) - { - idSchemes.setProgramIdScheme( idScheme ); - return this; - } - - public ImportOptions setOrgUnitIdScheme( String idScheme ) - { - idSchemes.setOrgUnitIdScheme( idScheme ); - return this; - } - - public ImportOptions setCategoryOptionComboIdScheme( String idScheme ) - { - idSchemes.setCategoryOptionComboIdScheme( idScheme ); - return this; - } - - public ImportOptions setDataElementIdScheme( String idScheme ) - { - idSchemes.setDataElementIdScheme( idScheme ); - return this; - } - - public ImportOptions setIdScheme( String idScheme ) - { - idSchemes.setIdScheme( idScheme ); - return this; - } - - public void setIdSchemes( IdSchemes idSchemes ) - { - this.idSchemes = idSchemes == null ? new IdSchemes() : idSchemes; + public ImportOptions setTrackedEntityAttribute( String idScheme ) + { + idSchemes.setTrackedEntityAttribute( idScheme ); + return this; } public ImportOptions setDryRun( boolean dryRun ) === 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-15 14:46:39 +0000 +++ 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 @@ -30,6 +30,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.hisp.dhis.common.IdSchemes; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.common.OrganisationUnitSelectionMode; import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException; @@ -53,7 +54,7 @@ import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.program.ProgramStatus; import org.hisp.dhis.program.ProgramTrackedEntityAttribute; -import org.hisp.dhis.system.callable.IdentifiableObjectSearchCallable; +import org.hisp.dhis.system.callable.IdentifiableObjectCallable; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; @@ -238,7 +239,7 @@ org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() ); TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance( entityInstance ); - Program program = getProgram( enrollment.getProgram() ); + Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() ); ProgramInstanceQueryParams params = new ProgramInstanceQueryParams(); params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL ); @@ -278,7 +279,7 @@ } Set importConflicts = new HashSet<>(); - importConflicts.addAll( checkAttributes( enrollment ) ); + importConflicts.addAll( checkAttributes( enrollment, importOptions ) ); importSummary.setConflicts( importConflicts ); @@ -290,7 +291,7 @@ return importSummary; } - OrganisationUnit organisationUnit = getOrganisationUnit( enrollment.getOrgUnit() ); + OrganisationUnit organisationUnit = getOrganisationUnit( enrollment.getOrgUnit(), importOptions.getIdSchemes() ); ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program, enrollment.getEnrollmentDate(), enrollment.getIncidentDate(), organisationUnit, enrollment.getEnrollment() ); @@ -305,7 +306,7 @@ return importSummary; } - updateAttributeValues( enrollment ); + updateAttributeValues( enrollment, importOptions ); programInstance.setFollowup( enrollment.getFollowup() ); programInstanceService.updateProgramInstance( programInstance ); @@ -370,7 +371,7 @@ } Set importConflicts = new HashSet<>(); - importConflicts.addAll( checkAttributes( enrollment ) ); + importConflicts.addAll( checkAttributes( enrollment, importOptions ) ); importSummary.setConflicts( importConflicts ); @@ -383,7 +384,7 @@ } org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() ); - Program program = getProgram( enrollment.getProgram() ); + Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() ); programInstance.setProgram( program ); programInstance.setEntityInstance( entityInstance ); @@ -407,7 +408,7 @@ } } - updateAttributeValues( enrollment ); + updateAttributeValues( enrollment, importOptions ); programInstanceService.updateProgramInstance( programInstance ); saveTrackedEntityComment( programInstance, enrollment ); @@ -507,11 +508,11 @@ // HELPERS // ------------------------------------------------------------------------- - private List checkAttributes( Enrollment enrollment ) + private List checkAttributes( Enrollment enrollment, ImportOptions importOptions ) { List importConflicts = new ArrayList<>(); - Program program = getProgram( enrollment.getProgram() ); + Program program = getProgram( enrollment.getProgram(), importOptions.getIdSchemes() ); org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = teiService.getTrackedEntityInstance( enrollment.getTrackedEntityInstance() ); @@ -531,7 +532,7 @@ for ( Attribute attribute : enrollment.getAttributes() ) { attributeValueMap.put( attribute.getAttribute(), attribute.getValue() ); - importConflicts.addAll( validateAttributeType( attribute ) ); + importConflicts.addAll( validateAttributeType( attribute, importOptions ) ); } TrackedEntityInstance instance = trackedEntityInstanceService.getTrackedEntityInstance( enrollment.getTrackedEntityInstance() ); @@ -588,7 +589,7 @@ return importConflicts; } - private void updateAttributeValues( Enrollment enrollment ) + private void updateAttributeValues( Enrollment enrollment, ImportOptions importOptions ) { org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance = teiService.getTrackedEntityInstance( enrollment.getTrackedEntityInstance() ); @@ -612,7 +613,7 @@ for ( String key : attributeValueMap.keySet() ) { - TrackedEntityAttribute attribute = getTrackedEntityAttribute( key ); + TrackedEntityAttribute attribute = getTrackedEntityAttribute( key, importOptions.getIdSchemes() ); if ( attribute != null ) { @@ -639,10 +640,10 @@ return entityInstance; } - private List validateAttributeType( Attribute attribute ) + private List validateAttributeType( Attribute attribute, ImportOptions importOptions ) { List importConflicts = Lists.newArrayList(); - TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( attribute.getAttribute() ); + TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( attribute.getAttribute(), importOptions.getIdSchemes() ); if ( teAttribute == null ) { @@ -679,18 +680,18 @@ } } - private OrganisationUnit getOrganisationUnit( String id ) - { - return organisationUnitCache.get( id, new IdentifiableObjectSearchCallable<>( manager, OrganisationUnit.class, id ) ); - } - - private Program getProgram( String id ) - { - return programCache.get( id, new IdentifiableObjectSearchCallable<>( manager, Program.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 Program getProgram( String id, IdSchemes idSchemes ) + { + return programCache.get( id, new IdentifiableObjectCallable<>( manager, Program.class, idSchemes.getProgramIdScheme(), id ) ); + } + + private TrackedEntityAttribute getTrackedEntityAttribute( String id, IdSchemes idSchemes ) + { + return trackedEntityAttributeCache.get( id, new IdentifiableObjectCallable<>( manager, TrackedEntityAttribute.class, idSchemes.getTrackedEntityAttribute(), id ) ); } }