← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14961: Fixed bug - Cannot delete attributes

 

------------------------------------------------------------
revno: 14961
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-24 20:27:51 +0800
message:
  Fixed bug - Cannot delete attributes
modified:
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.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-tracker/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramDeletionHandler.java	2014-04-24 12:27:51 +0000
@@ -33,6 +33,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.hisp.dhis.trackedentity.TrackedEntity;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.validation.ValidationCriteria;
 
@@ -109,6 +110,25 @@
     {
         Collection<Program> programs = programService.getProgramsByTrackedEntity( trackedEntity );
 
-        return (programs!=null && programs.size() > 0) ? ERROR : null;
+        return (programs != null && programs.size() > 0) ? ERROR : null;
+    }
+
+    @Override
+    public void deleteTrackedEntityAttribute( TrackedEntityAttribute trackedEntityAttribute )
+    {
+        Collection<Program> programs = programService.getAllPrograms();
+
+        for ( Program program : programs )
+        {
+            for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
+            {
+                if ( programAttribute.getAttribute().equals( trackedEntityAttribute ) )
+                {
+                    program.getAttributes().remove( programAttribute );
+                    programService.updateProgram( program );
+                    break;
+                }
+            }
+        }
     }
 }