← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21741: Deletion, handling of data elements linked to event reports/event charts

 

------------------------------------------------------------
revno: 21741
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-01-14 23:01:36 +0100
message:
  Deletion, handling of data elements linked to event reports/event charts
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.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/common/AnalyticalObjectService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectService.java	2016-01-06 15:52:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectService.java	2016-01-14 22:01:36 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 /**
  * @author Lars Helge Overland
@@ -49,6 +50,10 @@
     
     List<T> getAnalyticalObjects( DataElement dataElement );
     
+    List<T> getAnalyticalObjectsByDataDimension( DataElement dataElement );
+    
+    List<T> getAnalyticalObjectsByDataDimension( TrackedEntityAttribute attribute );
+    
     List<T> getAnalyticalObjects( DataSet dataSet );
 
     List<T> getAnalyticalObjects( ProgramIndicator programIndicator );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java	2016-01-06 15:52:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java	2016-01-14 22:01:36 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -48,6 +49,10 @@
     
     List<T> getAnalyticalObjects( DataElement dataElement );
     
+    List<T> getAnalyticalObjectsByDataDimension( DataElement dataElement );
+    
+    List<T> getAnalyticalObjectsByDataDimension( TrackedEntityAttribute attribute );
+    
     List<T> getAnalyticalObjects( DataSet dataSet );
 
     List<T> getAnalyticalObjects( ProgramIndicator programIndicator );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectDeletionHandler.java	2016-01-06 18:40:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectDeletionHandler.java	2016-01-14 22:01:36 +0000
@@ -83,7 +83,7 @@
         removeItem( getAnalyticalObjectService().getAnalyticalObjects( categoryOptionGroup ), categoryOptionGroup, ( ao, di ) -> ao.getCategoryOptionGroups().remove( di ) );
     }
     
-    private void removeItem( List<T> analyticalObjects, DimensionalItemObject itemObject, BiConsumer<AnalyticalObject, DimensionalItemObject> updateOperation )
+    protected void removeItem( List<T> analyticalObjects, DimensionalItemObject itemObject, BiConsumer<AnalyticalObject, DimensionalItemObject> updateOperation )
     {
         for ( T analyticalObject : analyticalObjects )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectService.java	2016-01-06 15:52:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/GenericAnalyticalObjectService.java	2016-01-14 22:01:36 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 /**
  * @author Lars Helge Overland
@@ -64,6 +65,18 @@
     }
 
     @Override
+    public List<T> getAnalyticalObjectsByDataDimension( DataElement dataElement )
+    {
+        return getAnalyticalObjectStore().getAnalyticalObjectsByDataDimension( dataElement );
+    }
+
+    @Override
+    public List<T> getAnalyticalObjectsByDataDimension( TrackedEntityAttribute attribute )
+    {
+        return getAnalyticalObjectStore().getAnalyticalObjectsByDataDimension( attribute );
+    }
+    
+    @Override
     public List<T> getAnalyticalObjects( DataSet dataSet )
     {
         return getAnalyticalObjectStore().getAnalyticalObjects( dataSet );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java	2016-01-06 18:40:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java	2016-01-14 22:01:36 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 
 import java.util.List;
 
@@ -67,6 +68,22 @@
 
     @Override
     @SuppressWarnings("unchecked")
+    public List<T> getAnalyticalObjectsByDataDimension( DataElement dataElement )
+    {
+        String hql = "select distinct c from " + clazz.getName() + " c join c.dataElementDimensions d where d.dataElement = :dataElement";
+        return getQuery( hql ).setEntity( "dataElement", dataElement ).list();        
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public List<T> getAnalyticalObjectsByDataDimension( TrackedEntityAttribute attribute )
+    {
+        String hql = "select distinct c from " + clazz.getName() + " c join c.attributeDimensions d where d.attribute = :attribute";
+        return getQuery( hql ).setEntity( "attribute", attribute ).list();        
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
     public List<T> getAnalyticalObjects( DataSet dataSet )
     {
         String hql = "select distinct c from " + clazz.getName() + " c join c.dataDimensionItems d where d.dataSet = :dataSet";

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java	2016-01-06 19:08:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventchart/EventChartDeletionHandler.java	2016-01-14 22:01:36 +0000
@@ -29,6 +29,8 @@
  */
 
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
 
 import org.hisp.dhis.common.AnalyticalObjectService;
 import org.hisp.dhis.common.GenericAnalyticalObjectDeletionHandler;
@@ -37,6 +39,7 @@
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
 import org.springframework.beans.factory.annotation.Autowired;
 
 /**
@@ -71,19 +74,34 @@
     @Override
     public void deleteIndicator( Indicator indicator )
     {
-        //TODO
+        // Ignore default implementation
     }
-    
+
     @Override
     public void deleteDataElement( DataElement dataElement )
     {
-        //TODO
+        List<EventChart> eventCharts = getAnalyticalObjectService().getAnalyticalObjectsByDataDimension( dataElement );
+        
+        for ( EventChart chart : eventCharts )
+        {
+            Iterator<TrackedEntityDataElementDimension> dimensions = chart.getDataElementDimensions().iterator();
+            
+            while ( dimensions.hasNext() )
+            {
+                if ( dimensions.next().getDataElement().equals( dataElement ) )
+                {
+                    dimensions.remove();
+                }
+            }
+            
+            eventChartService.update( chart );
+        }
     }
 
     @Override
     public void deleteDataSet( DataSet dataSet )
     {
-        //TODO
+        // Ignore default implementation
     }
 
     @Override
@@ -91,7 +109,7 @@
     {
         Collection<EventChart> charts = eventChartService.getAllEventCharts();
         
-        for( EventChart chart : charts )
+        for ( EventChart chart : charts )
         {
             if( chart.getProgramStage().equals( programStage ))
             {
@@ -105,9 +123,9 @@
     {
         Collection<EventChart> charts = eventChartService.getAllEventCharts();
         
-        for( EventChart chart : charts )
+        for ( EventChart chart : charts )
         {
-            if( chart.getProgram().equals( program ))
+            if ( chart.getProgram().equals( program ))
             {
                 eventChartService.deleteEventChart( chart );
             }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java	2016-01-06 19:08:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/eventreport/EventReportDeletionHandler.java	2016-01-14 22:01:36 +0000
@@ -29,6 +29,8 @@
  */
 
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
 
 import org.hisp.dhis.common.AnalyticalObjectService;
 import org.hisp.dhis.common.GenericAnalyticalObjectDeletionHandler;
@@ -37,6 +39,7 @@
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension;
 import org.springframework.beans.factory.annotation.Autowired;
 
 /**
@@ -71,19 +74,34 @@
     @Override
     public void deleteIndicator( Indicator indicator )
     {
-        //TODO
+        // Ignore default implementation
     }
     
     @Override
     public void deleteDataElement( DataElement dataElement )
     {
-        //TODO
+        List<EventReport> eventReports = getAnalyticalObjectService().getAnalyticalObjectsByDataDimension( dataElement );
+        
+        for ( EventReport report : eventReports )
+        {
+            Iterator<TrackedEntityDataElementDimension> dimensions = report.getDataElementDimensions().iterator();
+            
+            while ( dimensions.hasNext() )
+            {
+                if ( dimensions.next().getDataElement().equals( dataElement ) )
+                {
+                    dimensions.remove();
+                }
+            }
+            
+            eventReportService.update( report );
+        }
     }
 
     @Override
     public void deleteDataSet( DataSet dataSet )
     {
-        //TODO
+        // Ignore default implementation
     }
 
     @Override
@@ -93,7 +111,7 @@
         
         for ( EventReport chart : charts )
         {
-            if( chart.getProgramStage().equals( programStage ))
+            if ( chart.getProgramStage().equals( programStage ))
             {
                eventReportService.deleteEventReport( chart );
             }