dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40300
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20415: updated TEASerivce validate scope to support program scope, move EnrollmentService to validate sc...
------------------------------------------------------------
revno: 20415
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 15:57:38 +0700
message:
updated TEASerivce validate scope to support program scope, move EnrollmentService to validate scope using TEAService
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.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/trackedentity/TrackedEntityAttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java 2015-09-30 06:53:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java 2015-09-30 08:57:38 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.Program;
import java.util.List;
@@ -190,12 +191,13 @@
*
* @param trackedEntityInstance TrackedEntityInstance
* @param trackedEntityAttribute TrackedEntityAttribute
+ * @param value Value
* @param organisationUnit OrganisationUnit - only required if org unit scoped
- * @param value Value
+ * @param program Program - only required if program scoped
* @return null if valid, a message if not
*/
String validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
- OrganisationUnit organisationUnit, String value );
+ String value, OrganisationUnit organisationUnit, Program program );
/**
* Validate value against tracked entity attribute value type.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java 2015-09-30 06:53:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java 2015-09-30 08:57:38 +0000
@@ -201,7 +201,7 @@
@Override
public String validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
- OrganisationUnit organisationUnit, String value )
+ String value, OrganisationUnit organisationUnit, Program program )
{
Assert.notNull( trackedEntityInstance, "trackedEntityInstance is required." );
Assert.notNull( trackedEntityAttribute, "trackedEntityAttribute is required." );
@@ -215,10 +215,25 @@
params.addAttribute( new QueryItem( trackedEntityAttribute, QueryOperator.EQ, value, trackedEntityAttribute.getValueType(),
trackedEntityAttribute.getAggregationType(), trackedEntityAttribute.getOptionSet() ) );
- if ( trackedEntityAttribute.getOrgunitScope() )
- {
- params.getOrganisationUnits().add( organisationUnit );
- params.setOrganisationUnitMode( OrganisationUnitSelectionMode.SELECTED );
+ if ( trackedEntityAttribute.getOrgunitScope() && trackedEntityAttribute.getProgramScope() )
+ {
+ Assert.notNull( program, "program is required for program scope" );
+ Assert.notNull( organisationUnit, "organisationUnit is required for org unit scope" );
+ params.setProgram( program );
+ params.addOrganisationUnit( organisationUnit );
+ params.setOrganisationUnitMode( OrganisationUnitSelectionMode.SELECTED );
+ }
+ else if ( trackedEntityAttribute.getOrgunitScope() )
+ {
+ Assert.notNull( organisationUnit, "organisationUnit is required for org unit scope" );
+ params.setOrganisationUnitMode( OrganisationUnitSelectionMode.SELECTED );
+ params.addOrganisationUnit( organisationUnit );
+ }
+ else if ( trackedEntityAttribute.getProgramScope() )
+ {
+ Assert.notNull( program, "program is required for program scope" );
+ params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL );
+ params.setProgram( program );
}
else
{
=== 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-09-30 08:37:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2015-09-30 08:57:38 +0000
@@ -30,11 +30,8 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.OrganisationUnitSelectionMode;
-import org.hisp.dhis.common.QueryItem;
-import org.hisp.dhis.common.QueryOperator;
import org.hisp.dhis.commons.collection.CachingMap;
import org.hisp.dhis.dbms.DbmsManager;
import org.hisp.dhis.dxf2.events.event.Note;
@@ -57,7 +54,6 @@
import org.hisp.dhis.system.callable.IdentifiableObjectSearchCallable;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.trackedentitycomment.TrackedEntityComment;
@@ -508,45 +504,23 @@
return importConflicts;
}
- private List<ImportConflict> checkScope( org.hisp.dhis.trackedentity.TrackedEntityInstance tei,
- TrackedEntityAttribute attribute, String value, OrganisationUnit organisationUnit, Program program )
+ private List<ImportConflict> checkScope( org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance,
+ TrackedEntityAttribute trackedEntityAttribute, String value, OrganisationUnit organisationUnit, Program program )
{
List<ImportConflict> importConflicts = new ArrayList<>();
- TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
-
- QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, attribute.getValueType(), attribute.getAggregationType(), null );
- params.addAttribute( queryItem );
-
- if ( attribute.getOrgunitScope() && attribute.getProgramScope() )
- {
- params.setProgram( program );
- params.addOrganisationUnit( organisationUnit );
- }
- else if ( attribute.getOrgunitScope() )
- {
- params.addOrganisationUnit( organisationUnit );
- }
- else if ( attribute.getProgramScope() )
- {
- params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL );
- params.setProgram( program );
- }
- else
- {
- params.setOrganisationUnitMode( OrganisationUnitSelectionMode.ALL );
- }
-
- Grid instances = teiService.getTrackedEntityInstancesGrid( params );
-
- if ( instances.getHeight() == 0
- || (instances.getHeight() == 1 && instances.getRow( 0 ).contains( tei.getUid() )) )
+ if ( trackedEntityAttribute == null || value == null )
{
return importConflicts;
}
- importConflicts.add( new ImportConflict( "Attribute.value", "Non-unique attribute value '" + value
- + "' for attribute " + attribute.getUid() ) );
+ String errorMessage = trackedEntityAttributeService.validateScope( trackedEntityInstance, trackedEntityAttribute,
+ value, organisationUnit, program );
+
+ if ( errorMessage != null )
+ {
+ importConflicts.add( new ImportConflict( "Attribute.value", errorMessage ) );
+ }
return importConflicts;
}
@@ -607,15 +581,15 @@
private List<ImportConflict> validateAttributeType( Attribute attribute )
{
List<ImportConflict> importConflicts = Lists.newArrayList();
- TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
+ TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
- if ( trackedEntityAttribute == null )
+ if ( teAttribute == null )
{
importConflicts.add( new ImportConflict( "Attribute.attribute", "Does not point to a valid attribute." ) );
return importConflicts;
}
- String errorMessage = trackedEntityAttributeService.validateValueType( trackedEntityAttribute, attribute.getValue() );
+ String errorMessage = trackedEntityAttributeService.validateValueType( teAttribute, attribute.getValue() );
if ( errorMessage != null )
{
=== 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-09-30 06:22:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java 2015-09-30 08:57:38 +0000
@@ -492,7 +492,8 @@
return importConflicts;
}
- String errorMessage = trackedEntityAttributeService.validateScope( trackedEntityInstance, trackedEntityAttribute, organisationUnit, value );
+ String errorMessage = trackedEntityAttributeService.validateScope( trackedEntityInstance, trackedEntityAttribute,
+ value, organisationUnit, null );
if ( errorMessage != null )
{