← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7165: updated deletionhandler for attributevalue to support userGroup, orgUnitGroup, dataElementGroup, ...

 

------------------------------------------------------------
revno: 7165
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-06-04 09:35:28 +0200
message:
  updated deletionhandler for attributevalue to support userGroup, orgUnitGroup, dataElementGroup, indicatorGroup
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/AttributeValueDeletionHandler.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-core/src/main/java/org/hisp/dhis/attribute/AttributeValueDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/AttributeValueDeletionHandler.java	2012-04-26 14:30:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/AttributeValueDeletionHandler.java	2012-06-04 07:35:28 +0000
@@ -23,15 +23,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Iterator;
-
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.system.deletion.DeletionHandler;
-import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
 import org.springframework.jdbc.core.JdbcTemplate;
 
+import java.util.Iterator;
+import java.util.Set;
+
 /**
  * @author Lars Helge Overland
  */
@@ -44,14 +48,14 @@
     {
         this.attributeService = attributeService;
     }
-    
+
     private JdbcTemplate jdbcTemplate;
 
     public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
         this.jdbcTemplate = jdbcTemplate;
     }
-    
+
     // -------------------------------------------------------------------------
     // DeletionHandler implementation
     // -------------------------------------------------------------------------
@@ -66,53 +70,55 @@
     public String allowDeleteAttribute( Attribute attribute )
     {
         String sql = "select count(*) from attributevalue where attributeid=" + attribute.getId();
-        
+
         return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
     }
-        
+
     @Override
     public void deleteDataElement( DataElement dataElement )
     {
-        Iterator<AttributeValue> iterator = dataElement.getAttributeValues().iterator();
+        removeAttributeValues( dataElement.getAttributeValues() );
+    }
 
-        while ( iterator.hasNext() )
-        {
-            AttributeValue attributeValue = iterator.next();
-            iterator.remove();
-            attributeService.deleteAttributeValue( attributeValue );
-        }
+    @Override
+    public void deleteDataElementGroup( DataElementGroup dataElementGroup )
+    {
+        removeAttributeValues( dataElementGroup.getAttributeValues() );
     }
 
     @Override
     public void deleteIndicator( Indicator indicator )
     {
-        Iterator<AttributeValue> iterator = indicator.getAttributeValues().iterator();
-
-        while ( iterator.hasNext() )
-        {
-            AttributeValue attributeValue = iterator.next();
-            iterator.remove();
-            attributeService.deleteAttributeValue( attributeValue );
-        }
-    }
-
-    @Override
-    public void deleteOrganisationUnit( OrganisationUnit unit )
-    {
-        Iterator<AttributeValue> iterator = unit.getAttributeValues().iterator();
-
-        while ( iterator.hasNext() )
-        {
-            AttributeValue attributeValue = iterator.next();
-            iterator.remove();
-            attributeService.deleteAttributeValue( attributeValue );
-        }
-    }
-
-    @Override
-    public void deleteUser( User user )
-    {
-        Iterator<AttributeValue> iterator = user.getAttributeValues().iterator();
+        removeAttributeValues( indicator.getAttributeValues() );
+    }
+
+    @Override
+    public void deleteIndicatorGroup( IndicatorGroup indicatorGroup )
+    {
+        removeAttributeValues( indicatorGroup.getAttributeValues() );
+    }
+
+    @Override
+    public void deleteOrganisationUnit( OrganisationUnit organisationUnit )
+    {
+        removeAttributeValues( organisationUnit.getAttributeValues() );
+    }
+
+    @Override
+    public void deleteOrganisationUnitGroup( OrganisationUnitGroup organisationUnitGroup )
+    {
+        removeAttributeValues( organisationUnitGroup.getAttributeValues() );
+    }
+
+    @Override
+    public void deleteUserGroup( UserGroup userGroup )
+    {
+        removeAttributeValues( userGroup.getAttributeValues() );
+    }
+
+    private void removeAttributeValues( Set<AttributeValue> attributeValues )
+    {
+        Iterator<AttributeValue> iterator = attributeValues.iterator();
 
         while ( iterator.hasNext() )
         {