dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40293
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20409: Minor updates, move scope validation message to TEA service
------------------------------------------------------------
revno: 20409
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-30 13:22:47 +0700
message:
Minor updates, move scope validation message to TEA service
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/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:14:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttributeService.java 2015-09-30 06:22:47 +0000
@@ -195,9 +195,9 @@
* @param trackedEntityAttribute TrackedEntityAttribute
* @param organisationUnit OrganisationUnit - only required if org unit scoped
* @param value Value
- * @return true is unique, false otherwise
+ * @return null if valid, a message if not
*/
- boolean validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
+ String validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
OrganisationUnit organisationUnit, String value );
/**
=== 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:14:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java 2015-09-30 06:22:47 +0000
@@ -200,7 +200,7 @@
}
@Override
- public boolean validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
+ public String validateScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute trackedEntityAttribute,
OrganisationUnit organisationUnit, String value )
{
Assert.notNull( trackedEntityInstance, "trackedEntityInstance is required." );
@@ -208,7 +208,7 @@
if ( !trackedEntityAttribute.isUnique() )
{
- return true;
+ return null;
}
TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
@@ -227,7 +227,12 @@
Grid instances = trackedEntityInstanceService.getTrackedEntityInstancesGrid( params );
- return instances.getHeight() == 0 || instances.getHeight() == 1 && instances.getRow( 0 ).contains( trackedEntityInstance.getUid() );
+ if ( !(instances.getHeight() == 0 || instances.getHeight() == 1 && instances.getRow( 0 ).contains( trackedEntityInstance.getUid() )) )
+ {
+ return "Non-unique attribute value '" + value + "' for attribute " + trackedEntityAttribute.getUid();
+ }
+
+ return null;
}
@Override
=== 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:14:51 +0000
+++ 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
@@ -431,19 +431,19 @@
return importConflicts;
}
- TrackedEntityAttribute teAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
+ TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttribute( attribute.getAttribute() );
- if ( teAttribute == null )
+ if ( trackedEntityAttribute == null )
{
importConflicts.add( new ImportConflict( "Attribute.attribute", "Does not point to a valid attribute." ) );
return importConflicts;
}
- String message = trackedEntityAttributeService.validateValueType( teAttribute, attribute.getValue() );
+ String errorMessage = trackedEntityAttributeService.validateValueType( trackedEntityAttribute, attribute.getValue() );
- if ( message != null )
+ if ( errorMessage != null )
{
- importConflicts.add( new ImportConflict( "Attribute.value", message ) );
+ importConflicts.add( new ImportConflict( "Attribute.value", errorMessage ) );
}
return importConflicts;
@@ -482,21 +482,23 @@
return importConflicts;
}
- private List<ImportConflict> checkScope( org.hisp.dhis.trackedentity.TrackedEntityInstance tei, TrackedEntityAttribute attribute, String value, OrganisationUnit organisationUnit )
+ private List<ImportConflict> checkScope( org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance,
+ TrackedEntityAttribute trackedEntityAttribute, String value, OrganisationUnit organisationUnit )
{
List<ImportConflict> importConflicts = new ArrayList<>();
- if ( attribute == null || value == null )
- {
- return importConflicts;
- }
-
- if ( trackedEntityAttributeService.validateScope( tei, attribute, organisationUnit, value ) )
- {
- return importConflicts;
- }
-
- importConflicts.add( new ImportConflict( "Attribute.value", "Non-unique attribute value '" + value + "' for attribute " + attribute.getUid() ) );
+ if ( trackedEntityAttribute == null || value == null )
+ {
+ return importConflicts;
+ }
+
+ String errorMessage = trackedEntityAttributeService.validateScope( trackedEntityInstance, trackedEntityAttribute, organisationUnit, value );
+
+ if ( errorMessage != null )
+ {
+ importConflicts.add( new ImportConflict( "Attribute.value", errorMessage ) );
+ }
+
return importConflicts;
}