=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java 2013-08-23 15:56:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorService.java 2013-12-16 12:27:12 +0000 @@ -28,6 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.mapping.MapLegend; +import org.hisp.dhis.mapping.MapLegendSet; + import java.util.Collection; import java.util.List; @@ -176,4 +179,6 @@ int getIndicatorGroupSetCount(); int getIndicatorGroupSetCountByName( String name ); + + int countMapLegendSetIndicators( MapLegendSet mapLegendSet ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java 2013-08-23 15:56:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/IndicatorStore.java 2013-12-16 12:27:12 +0000 @@ -31,6 +31,8 @@ import java.util.Collection; import org.hisp.dhis.common.GenericNameableObjectStore; +import org.hisp.dhis.mapping.MapLegend; +import org.hisp.dhis.mapping.MapLegendSet; /** * @author Lars Helge Overland @@ -46,4 +48,6 @@ Collection getIndicatorsWithoutGroups(); Collection getIndicatorsWithDataSets(); + + int countMapLegendSetIndicators( MapLegendSet mapLegendSet ); } === modified 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 2013-12-16 10:07:07 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapViewStore.java 2013-12-16 12:27:12 +0000 @@ -36,4 +36,5 @@ public interface MapViewStore extends AnalyticalObjectStore { + int countMapLegendSetMapViews( MapLegendSet mapLegendSet ); } === 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-16 10:07:07 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2013-12-16 12:27:12 +0000 @@ -172,4 +172,6 @@ int countIndicatorCharts( Indicator indicator ); int countDataElementCharts( DataElement dataElement ); + + int countMapLegendSetMapViews( MapLegendSet mapLegendSet ); } \ No newline at end of file === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java 2013-12-16 12:27:12 +0000 @@ -30,6 +30,8 @@ import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.i18n.I18nService; +import org.hisp.dhis.mapping.MapLegend; +import org.hisp.dhis.mapping.MapLegendSet; import org.hisp.dhis.system.util.Filter; import org.hisp.dhis.system.util.FilterUtils; import org.springframework.transaction.annotation.Transactional; @@ -195,6 +197,12 @@ return getObjectsBetweenByName( i18nService, indicatorStore, name, first, max ); } + @Override + public int countMapLegendSetIndicators( MapLegendSet mapLegendSet ) + { + return indicatorStore.countMapLegendSetIndicators( mapLegendSet ); + } + // ------------------------------------------------------------------------- // IndicatorType // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2013-12-16 12:27:12 +0000 @@ -28,16 +28,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Iterator; -import java.util.Set; - import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.mapping.MapLegend; +import org.hisp.dhis.mapping.MapLegendSet; import org.hisp.dhis.system.deletion.DeletionHandler; +import java.util.Iterator; +import java.util.Set; + /** * @author Lars Helge Overland * @version $Id$ @@ -91,7 +93,7 @@ public void deleteIndicatorGroup( IndicatorGroup group ) { Iterator iterator = group.getMembers().iterator(); - + while ( iterator.hasNext() ) { Indicator indicator = iterator.next(); @@ -104,7 +106,7 @@ public void deleteDataSet( DataSet dataSet ) { Iterator iterator = dataSet.getIndicators().iterator(); - + while ( iterator.hasNext() ) { Indicator indicator = iterator.next(); @@ -161,4 +163,10 @@ return null; } + + @Override + public String allowDeleteMapLegendSet( MapLegendSet mapLegendSet ) + { + return indicatorService.countMapLegendSetIndicators( mapLegendSet ) == 0 ? null : ERROR; + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/hibernate/HibernateIndicatorStore.java 2013-12-16 12:27:12 +0000 @@ -28,11 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; - +import org.hibernate.Query; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.indicator.IndicatorStore; +import org.hisp.dhis.mapping.MapLegendSet; + +import java.util.Collection; /** * @author Lars Helge Overland @@ -46,7 +48,7 @@ // Indicator // ------------------------------------------------------------------------- - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getIndicatorsWithGroupSets() { final String hql = "from Indicator d where d.groupSets.size > 0"; @@ -54,7 +56,7 @@ return getQuery( hql ).setCacheable( true ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getIndicatorsWithoutGroups() { final String hql = "from Indicator d where d.groups.size = 0"; @@ -62,11 +64,20 @@ return getQuery( hql ).setCacheable( true ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getIndicatorsWithDataSets() { final String hql = "from Indicator d where d.dataSets.size > 0"; return getQuery( hql ).setCacheable( true ).list(); } + + @Override + public int countMapLegendSetIndicators( MapLegendSet mapLegendSet ) + { + Query query = getQuery( "select count(distinct c) from Indicator c where c.legendSet=:mapLegendSet" ); + query.setEntity( "mapLegendSet", mapLegendSet ); + + return ((Long) query.uniqueResult()).intValue(); + } } === 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-16 10:07:07 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2013-12-16 12:27:12 +0000 @@ -476,4 +476,10 @@ { return mapViewStore.countDataElementAnalyticalObject( dataElement ); } + + @Override + public int countMapLegendSetMapViews( MapLegendSet mapLegendSet ) + { + return mapViewStore.countMapLegendSetMapViews( mapLegendSet ); + } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2013-12-16 12:27:12 +0000 @@ -57,7 +57,7 @@ { return MapLegendSet.class.getSimpleName(); } - + @Override public void deleteMapLegend( MapLegend mapLegend ) { === 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-16 10:07:07 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2013-12-16 12:27:12 +0000 @@ -170,4 +170,10 @@ { return mappingService.countDataElementCharts( dataElement ) == 0 ? null : ERROR; } + + @Override + public String allowDeleteMapLegendSet( MapLegendSet mapLegendSet ) + { + return mappingService.countMapLegendSetMapViews( mapLegendSet ) == 0 ? null : ERROR; + } } === modified 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 2013-12-16 10:07:07 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java 2013-12-16 12:27:12 +0000 @@ -28,7 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hibernate.Query; import org.hisp.dhis.common.hibernate.HibernateAnalyticalObjectStore; +import org.hisp.dhis.mapping.MapLegendSet; import org.hisp.dhis.mapping.MapView; import org.hisp.dhis.mapping.MapViewStore; @@ -38,4 +40,12 @@ public class HibernateMapViewStore extends HibernateAnalyticalObjectStore implements MapViewStore { + @Override + public int countMapLegendSetMapViews( MapLegendSet mapLegendSet ) + { + Query query = getQuery( "select count(distinct c) from MapView c where c.legendSet=:mapLegendSet" ); + query.setEntity( "mapLegendSet", mapLegendSet ); + + return ((Long) query.uniqueResult()).intValue(); + } } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2013-12-16 11:49:45 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java 2013-12-16 12:27:12 +0000 @@ -32,10 +32,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.SessionFactory; +import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.cache.HibernateCacheManager; +import org.hisp.dhis.concept.Concept; +import org.hisp.dhis.constant.Constant; +import org.hisp.dhis.document.Document; import org.hisp.dhis.dxf2.timer.SystemNanoTimer; import org.hisp.dhis.dxf2.timer.Timer; +import org.hisp.dhis.option.OptionSet; import org.hisp.dhis.scheduling.TaskId; +import org.hisp.dhis.sqlview.SqlView; import org.hisp.dhis.system.notification.NotificationLevel; import org.hisp.dhis.system.notification.Notifier; import org.hisp.dhis.system.util.ReflectionUtils; @@ -67,7 +73,7 @@ // Dependencies //------------------------------------------------------------------------------------------------------- - @Autowired(required = false) + @Autowired( required = false ) private Set importerClasses = new HashSet(); @Autowired @@ -136,6 +142,16 @@ types = Lists.newArrayList( ExchangeClasses.getImportMap().values() ); } + /* + types.clear(); + types.add( "attributeTypes" ); + types.add( "optionSets" ); + types.add( "documents" ); + types.add( "constants" ); + types.add( "concepts" ); + types.add( "sqlViews" ); + */ + for ( String type : types ) { Object value = ReflectionUtils.invokeGetterMethod( type, metaData );