← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21624: Impl BaseAnalyticalObject.removeDataDimensionItem

 

------------------------------------------------------------
revno: 21624
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-06 15:52:32 +0100
message:
  Impl BaseAnalyticalObject.removeDataDimensionItem
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DataDimensionItem.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.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/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java	2016-01-06 14:52:32 +0000
@@ -268,6 +268,21 @@
     }
 
     /**
+     * Removes a data dimension object.
+     * 
+     * @return true if a data dimension was removed, false if not.
+     */
+    public boolean removeDataDimensionItem( DimensionalItemObject object )
+    {
+        if ( object != null && DataDimensionItem.DATA_DIMENSION_CLASSES.contains( object.getClass() ) )
+        {
+            return dataDimensionItems.remove( DataDimensionItem.create( object ) );
+        }
+        
+        return false;
+    }
+
+    /**
      * Adds all given data dimension objects.
      */
     public void addAllDataDimensionItems( Collection<? extends DimensionalItemObject> objects )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DataDimensionItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DataDimensionItem.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DataDimensionItem.java	2016-01-06 14:52:32 +0000
@@ -208,6 +208,56 @@
         
         return null;
     }
+
+    // -------------------------------------------------------------------------
+    // Equals and hashCode
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( getDimensionalItemObject() == null ) ? 0 : getDimensionalItemObject().hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+        
+        if ( obj == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != obj.getClass() )
+        {
+            return false;
+        }
+        
+        DataDimensionItem other = (DataDimensionItem) obj;
+        
+        DimensionalItemObject object = getDimensionalItemObject();
+        
+        if ( object == null )
+        {
+            if ( other.getDimensionalItemObject() != null )
+            {
+                return false;
+            }
+        }
+        else if ( !object.equals( other.getDimensionalItemObject() ) )
+        {
+            return false;
+        }
+        
+        return true;
+    }
     
     // -------------------------------------------------------------------------
     // Get and set methods

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/common/BaseAnalyticalObjectTest.java	2016-01-06 14:52:32 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.eventchart.EventChart;
+import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension;
 import org.junit.Test;
@@ -189,4 +190,38 @@
         assertFalse( deA.equals( dsD ) );
         assertFalse( dsA.equals( dsD ) );        
     }
+    
+    @Test
+    public void testAddDataDimensionItem()
+    {        
+        DataElement deA = new DataElement();
+        deA.setAutoFields();
+
+        MapView mv = new MapView( MapView.LAYER_THEMATIC1 );
+        
+        mv.addDataDimensionItem( deA );
+        
+        assertEquals( 1, mv.getDataDimensionItems().size() );        
+    }
+
+    @Test
+    public void testRemoveDataDimensionItem()
+    {        
+        DataElement deA = new DataElement();
+        DataElement deB = new DataElement();
+        deA.setAutoFields();
+        deB.setAutoFields();
+
+        MapView mv = new MapView( MapView.LAYER_THEMATIC1 );
+        
+        mv.addDataDimensionItem( deA );
+        mv.addDataDimensionItem( deB );
+        
+        assertEquals( 2, mv.getDataDimensionItems().size() );
+        
+        mv.removeDataDimensionItem( deA );
+
+        assertEquals( 1, mv.getDataDimensionItems().size() );
+        assertEquals( deB, mv.getDataDimensionItems().get( 0 ).getDataElement() );        
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java	2016-01-06 14:25:55 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java	2016-01-06 14:52:32 +0000
@@ -64,24 +64,27 @@
     }
     
     @Override
+    public void deleteIndicator( Indicator indicator )
+    {
+        for ( ReportTable reportTable : reportTableService.getAnalyticalObjects( indicator ) )
+        {
+            reportTableService.deleteReportTable( reportTable );
+        }
+    }
+    
+    @Override
+    public String allowDeleteDataElement( DataElement dataElement )
+    {
+        return reportTableService.countAnalyticalObjects( dataElement ) == 0 ? null : ERROR;
+    }
+
+    @Override
     public String allowDeleteDataSet( DataSet dataSet )
     {
         return reportTableService.countAnalyticalObjects( dataSet ) == 0 ? null : ERROR;
     }
     
     @Override
-    public String allowDeleteIndicator( Indicator indicator )
-    {
-        return reportTableService.countAnalyticalObjects( indicator ) == 0 ? null : ERROR;
-    }
-    
-    @Override
-    public String allowDeleteDataElement( DataElement dataElement )
-    {
-        return reportTableService.countAnalyticalObjects( dataElement ) == 0 ? null : ERROR;
-    }
-    
-    @Override
     public String allowDeletePeriod( Period period )
     {
         return reportTableService.countAnalyticalObjects( period ) == 0 ? null : ERROR;