=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapStore.java 2013-10-30 12:51:03 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapStore.java 2013-12-13 13:03:25 +0000 @@ -36,4 +36,5 @@ public interface MapStore extends GenericIdentifiableObjectStore { + int countMapViewMaps( MapView 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-10-30 12:51:03 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2013-12-13 13:03:25 +0000 @@ -55,7 +55,7 @@ final String MAP_LAYER_TYPE_BASELAYER = "baselayer"; final String MAP_LAYER_TYPE_OVERLAY = "overlay"; - + // ------------------------------------------------------------------------- // MapLegend // ------------------------------------------------------------------------- @@ -63,7 +63,7 @@ void addOrUpdateMapLegend( String name, Double startValue, Double endValue, String color, String image ); int addMapLegend( MapLegend mapLegend ); - + void deleteMapLegend( MapLegend legend ); MapLegend getMapLegend( int id ); @@ -99,21 +99,21 @@ // ------------------------------------------------------------------------- int addMap( Map map ); - + void updateMap( Map map ); - + Map getMap( int id ); - + Map getMap( String uid ); - + Map getMapNoAcl( String uid ); - + void deleteMap( Map map ); - + List getMapsBetweenLikeName( String name, int first, int max ); - + List getAllMaps(); - + // ------------------------------------------------------------------------- // MapView // ------------------------------------------------------------------------- @@ -133,7 +133,7 @@ MapView getIndicatorLastYearMapView( String indicatorUid, String organisationUnitUid, int level ); Collection getAllMapViews(); - + Collection getMapViewsBetweenByName( String name, int first, int max ); // ------------------------------------------------------------------------- @@ -145,7 +145,7 @@ void updateMapLayer( MapLayer mapLayer ); void addOrUpdateMapLayer( String name, String type, String url, String layers, String time, String fillColor, - double fillOpacity, String strokeColor, int strokeWidth ); + double fillOpacity, String strokeColor, int strokeWidth ); void deleteMapLayer( MapLayer mapLayer ); @@ -160,4 +160,6 @@ MapLayer getMapLayerByMapSource( String mapSource ); Collection getAllMapLayers(); + + int countMapViewMaps( MapView mapView ); } \ No newline at end of file === 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-10-25 19:53:21 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2013-12-13 13:03:25 +0000 @@ -28,11 +28,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.indicator.Indicator; @@ -44,6 +39,11 @@ import org.hisp.dhis.period.RelativePeriods; import org.springframework.transaction.annotation.Transactional; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * @author Jan Henrik Overland */ @@ -273,7 +273,7 @@ { return mapStore.getAll(); } - + public List getMapsBetweenLikeName( String name, int first, int max ) { return mapStore.getAllLikeNameOrderedName( name, first, max ); @@ -450,4 +450,10 @@ { return mapLayerStore.getAll(); } + + @Override + public int countMapViewMaps( MapView mapView ) + { + return mapStore.countMapViewMaps( mapView ); + } } === 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-09-17 16:22:09 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2013-12-13 13:03:25 +0000 @@ -28,14 +28,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Iterator; - import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.system.deletion.DeletionHandler; +import java.util.Iterator; + /** * @author Lars Helge Overland * @version $Id$ @@ -53,7 +53,7 @@ { this.mappingService = mappingService; } - + // ------------------------------------------------------------------------- // DeletionHandler implementation // ------------------------------------------------------------------------- @@ -63,7 +63,7 @@ { return MapView.class.getName(); } - + @Override public String allowDeletePeriod( Period period ) { @@ -74,19 +74,19 @@ return mapView.getName(); } } - + return null; } - + @Override public void deleteIndicator( Indicator indicator ) { Iterator mapViews = mappingService.getAllMapViews().iterator(); - + while ( mapViews.hasNext() ) { MapView mapView = mapViews.next(); - + if ( mapView.getIndicators() != null && mapView.getIndicators().contains( indicator ) ) { mapViews.remove(); @@ -94,16 +94,16 @@ } } } - + @Override public void deleteDataElement( DataElement dataElement ) { Iterator mapViews = mappingService.getAllMapViews().iterator(); - + while ( mapViews.hasNext() ) { MapView mapView = mapViews.next(); - + if ( mapView.getDataElements() != null && mapView.getDataElements().contains( dataElement ) ) { mapViews.remove(); @@ -111,16 +111,16 @@ } } } - + @Override public void deleteOrganisationUnit( OrganisationUnit organisationUnit ) { Iterator mapViews = mappingService.getAllMapViews().iterator(); - + while ( mapViews.hasNext() ) { MapView mapView = mapViews.next(); - + if ( mapView.getOrganisationUnits() != null && mapView.getOrganisationUnits().contains( organisationUnit ) ) { mapViews.remove(); @@ -128,16 +128,16 @@ } } } - + @Override public void deleteMapLegendSet( MapLegendSet mapLegendSet ) { Iterator mapViews = mappingService.getAllMapViews().iterator(); - + while ( mapViews.hasNext() ) { MapView mapView = mapViews.next(); - + if ( mapView.getLegendSet() != null && mapView.getLegendSet().equals( mapLegendSet ) ) { mapViews.remove(); @@ -145,4 +145,10 @@ } } } + + @Override + public String allowDeleteMapView( MapView mapView ) + { + return mappingService.countMapViewMaps( mapView ) == 0 ? null : ERROR; + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapStore.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapStore.java 2013-12-13 13:03:25 +0000 @@ -28,9 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hibernate.Query; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.mapping.Map; import org.hisp.dhis.mapping.MapStore; +import org.hisp.dhis.mapping.MapView; /** * @author Lars Helge Overland @@ -38,4 +40,12 @@ public class HibernateMapStore extends HibernateIdentifiableObjectStore implements MapStore { + @Override + public int countMapViewMaps( MapView mapView ) + { + Query query = getQuery( "select count(distinct c) from Map c where :mapView in elements(c.mapViews)" ); + query.setEntity( "mapView", mapView ); + + return ((Long) query.uniqueResult()).intValue(); + } }