← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14282: scope validation when creating/updating TEI, no program validation for now, since program attribu...

 

------------------------------------------------------------
revno: 14282
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-03-18 16:10:26 +0100
message:
  scope validation when creating/updating TEI, no program validation for now, since program attributes should not really be part of the TEI create/update process. Will be done in enrollment.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueStore.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/TrackedEntityAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2014-03-18 13:52:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityAttribute.java	2014-03-18 15:10:26 +0000
@@ -317,7 +317,7 @@
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public Boolean isUnique()
     {
-        return unique;
+        return unique != null ? unique : false;
     }
 
     public void setUnique( Boolean unique )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueStore.java	2014-03-18 15:10:26 +0000
@@ -154,5 +154,4 @@
      * @return TrackedEntityAttributeValue list
      */
     Collection<TrackedEntityAttributeValue> get( TrackedEntityInstance instance, Program program );
-
 }

=== 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	2014-03-18 13:20:03 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-03-18 15:10:26 +0000
@@ -46,9 +46,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -73,6 +71,12 @@
     private TrackedEntityService trackedEntityService;
 
     @Autowired
+    private TrackedEntityAttributeValueService trackedEntityAttributeValueService;
+
+    @Autowired
+    private org.hisp.dhis.trackedentity.TrackedEntityInstanceService entityInstanceService;
+
+    @Autowired
     private IdentifiableObjectManager manager;
 
     // -------------------------------------------------------------------------
@@ -292,7 +296,49 @@
             {
                 importConflicts.add( new ImportConflict( "Attribute.attribute", "Invalid attribute "
                     + attribute.getAttribute() ) );
-            }
+                continue;
+            }
+
+            List<org.hisp.dhis.trackedentity.TrackedEntityInstance> instances = new ArrayList<org.hisp.dhis.trackedentity.TrackedEntityInstance>( trackedEntityAttributeValueService.getTrackedEntityInstance(
+                entityAttribute, attribute.getValue() ) );
+
+            System.err.println( "instances: " + instances );
+
+            if ( entityAttribute.isUnique() )
+            {
+                importConflicts.addAll( checkScope( trackedEntityInstance, entityAttribute, instances ) );
+            }
+        }
+
+        return importConflicts;
+    }
+
+    private List<ImportConflict> checkScope( TrackedEntityInstance trackedEntityInstance, TrackedEntityAttribute attribute, List<org.hisp.dhis.trackedentity.TrackedEntityInstance> instances )
+    {
+        List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
+        org.hisp.dhis.trackedentity.TrackedEntityInstance instance = entityInstanceService.getTrackedEntityInstance( trackedEntityInstance.getTrackedEntity() );
+
+        if ( instances.isEmpty() || (instances.size() == 1 && instances.contains( instance )) )
+        {
+            return importConflicts;
+        }
+
+        if ( attribute.getOrgunitScope() )
+        {
+            for ( org.hisp.dhis.trackedentity.TrackedEntityInstance tei : instances )
+            {
+                if ( trackedEntityInstance.getOrgUnit().equals( tei.getOrganisationUnit().getUid() ) )
+                {
+                    importConflicts.add( new ImportConflict( "Attribute.value", "Non-unique attribute value for attribute " +
+                        attribute.getUid() + ", with scope orgUnit." ) );
+                    break;
+                }
+            }
+        }
+        else
+        {
+            importConflicts.add( new ImportConflict( "Attribute.value", "Non-unique attribute value for attribute " +
+                attribute.getUid() ) );
         }
 
         return importConflicts;

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueStore.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueStore.java	2014-03-18 15:10:26 +0000
@@ -149,5 +149,4 @@
 
         return query.list();
     }
-
 }