← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13245: meta-data deletion, wip (added mapview store)

 

------------------------------------------------------------
revno: 13245
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-16 11:07:07 +0100
message:
  meta-data deletion, wip (added mapview store)
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapViewStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.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/configuration/ConfigurationDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.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/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2013-12-13 16:03:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2013-12-16 10:07:07 +0000
@@ -115,4 +115,8 @@
     Collection<Chart> getChartsByUser( User user );
 
     int countDataSetCharts( DataSet dataSet );
+
+    int countIndicatorCharts( Indicator indicator );
+
+    int countDataElementCharts( DataElement dataElement );
 }

=== 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	2013-12-13 16:50:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticalObjectStore.java	2013-12-16 10:07:07 +0000
@@ -28,7 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.indicator.Indicator;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -37,4 +39,8 @@
     extends GenericIdentifiableObjectStore<T>
 {
     int countDataSetAnalyticalObject( DataSet dataSet );
+
+    int countIndicatorAnalyticalObject( Indicator indicator );
+
+    int countDataElementAnalyticalObject( DataElement dataElement );
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapViewStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapViewStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapViewStore.java	2013-12-16 10:07:07 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.mapping;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.AnalyticalObjectStore;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface MapViewStore
+    extends AnalyticalObjectStore<MapView>
+{
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2013-12-13 13:03:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2013-12-16 10:07:07 +0000
@@ -28,6 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.indicator.Indicator;
+
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -162,4 +166,10 @@
     Collection<MapLayer> getAllMapLayers();
 
     int countMapViewMaps( MapView mapView );
+
+    int countDataSetCharts( DataSet dataSet );
+
+    int countIndicatorCharts( Indicator indicator );
+
+    int countDataElementCharts( DataElement dataElement );
 }
\ No newline at end of file

=== 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	2013-12-13 16:50:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateAnalyticalObjectStore.java	2013-12-16 10:07:07 +0000
@@ -31,7 +31,9 @@
 import org.hibernate.Query;
 import org.hisp.dhis.common.AnalyticalObjectStore;
 import org.hisp.dhis.common.BaseAnalyticalObject;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.indicator.Indicator;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -47,4 +49,22 @@
 
         return ((Long) query.uniqueResult()).intValue();
     }
+
+    @Override
+    public int countIndicatorAnalyticalObject( Indicator indicator )
+    {
+        Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where :indicator in elements(c.indicators)" );
+        query.setEntity( "indicator", indicator );
+
+        return ((Long) query.uniqueResult()).intValue();
+    }
+
+    @Override
+    public int countDataElementAnalyticalObject( DataElement dataElement )
+    {
+        Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where :dataElement in elements(c.dataElements)" );
+        query.setEntity( "dataElement", dataElement );
+
+        return ((Long) query.uniqueResult()).intValue();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/ConfigurationDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/ConfigurationDeletionHandler.java	2013-09-04 13:52:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/configuration/ConfigurationDeletionHandler.java	2013-12-16 10:07:07 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.hisp.dhis.user.UserGroup;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -66,4 +68,12 @@
 
         return jdbcTemplate.queryForObject( sql, Integer.class ) == 0 ? null : ERROR;
     }
+
+    @Override
+    public String allowDeleteDataElementGroup( DataElementGroup dataElementGroup )
+    {
+        String sql = "SELECT COUNT(*) FROM configuration where infrastructuraldataelementsid=" + dataElementGroup.getId();
+
+        return jdbcTemplate.queryForObject( sql, Integer.class ) == 0 ? null : ERROR;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2013-12-13 13:03:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2013-12-16 10:07:07 +0000
@@ -28,8 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -37,6 +37,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.RelativePeriods;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Collection;
@@ -62,9 +63,10 @@
         this.mapStore = mapStore;
     }
 
-    private GenericIdentifiableObjectStore<MapView> mapViewStore;
+    private MapViewStore mapViewStore;
 
-    public void setMapViewStore( GenericIdentifiableObjectStore<MapView> mapViewStore )
+    @Autowired
+    public void setMapViewStore( MapViewStore mapViewStore )
     {
         this.mapViewStore = mapViewStore;
     }
@@ -456,4 +458,22 @@
     {
         return mapStore.countMapViewMaps( mapView );
     }
+
+    @Override
+    public int countDataSetCharts( DataSet dataSet )
+    {
+        return mapViewStore.countDataSetAnalyticalObject( dataSet );
+    }
+
+    @Override
+    public int countIndicatorCharts( Indicator indicator )
+    {
+        return mapViewStore.countIndicatorAnalyticalObject( indicator );
+    }
+
+    @Override
+    public int countDataElementCharts( DataElement dataElement )
+    {
+        return mapViewStore.countDataElementAnalyticalObject( dataElement );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java	2013-12-13 13:03:25 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java	2013-12-16 10:07:07 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
@@ -151,4 +152,22 @@
     {
         return mappingService.countMapViewMaps( mapView ) == 0 ? null : ERROR;
     }
+
+    @Override
+    public String allowDeleteDataSet( DataSet dataSet )
+    {
+        return mappingService.countDataSetCharts( dataSet ) == 0 ? null : ERROR;
+    }
+
+    @Override
+    public String allowDeleteIndicator( Indicator indicator )
+    {
+        return mappingService.countIndicatorCharts( indicator ) == 0 ? null : ERROR;
+    }
+
+    @Override
+    public String allowDeleteDataElement( DataElement dataElement )
+    {
+        return mappingService.countDataElementCharts( dataElement ) == 0 ? null : ERROR;
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java	2013-12-16 10:07:07 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.mapping.hibernate;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.hibernate.HibernateAnalyticalObjectStore;
+import org.hisp.dhis.mapping.MapView;
+import org.hisp.dhis.mapping.MapViewStore;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class HibernateMapViewStore
+    extends HibernateAnalyticalObjectStore<MapView> implements MapViewStore
+{
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-12-13 16:03:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2013-12-16 10:07:07 +0000
@@ -318,7 +318,7 @@
   </bean>
 
   <bean id="org.hisp.dhis.mapping.MapViewStore"
-    class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+    class="org.hisp.dhis.mapping.hibernate.HibernateMapViewStore">
     <property name="clazz" value="org.hisp.dhis.mapping.MapView" />
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="cacheable" value="true" />

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2013-12-13 16:03:24 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2013-12-16 10:07:07 +0000
@@ -73,6 +73,18 @@
     }
 
     @Override
+    public String allowDeleteIndicator( Indicator indicator )
+    {
+        return chartService.countIndicatorCharts( indicator ) == 0 ? null : ERROR;
+    }
+
+    @Override
+    public String allowDeleteDataElement( DataElement dataElement )
+    {
+        return chartService.countDataElementCharts( dataElement ) == 0 ? null : ERROR;
+    }
+
+    @Override
     public String allowDeletePeriod( Period period )
     {
         for ( Chart chart : chartService.getAllCharts() )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-12-13 16:50:58 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-12-16 10:07:07 +0000
@@ -850,4 +850,16 @@
     {
         return chartStore.countDataSetAnalyticalObject( dataSet );
     }
+
+    @Override
+    public int countIndicatorCharts( Indicator indicator )
+    {
+        return chartStore.countIndicatorAnalyticalObject( indicator );
+    }
+
+    @Override
+    public int countDataElementCharts( DataElement dataElement )
+    {
+        return chartStore.countDataElementAnalyticalObject( dataElement );
+    }
 }