=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping' === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,691 @@ +package org.hisp.dhis.mapping; + +/* + * Copyright (c) 2004-2012, 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 java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.hisp.dhis.aggregation.AggregatedDataValueService; +import org.hisp.dhis.aggregation.AggregatedMapValue; +import org.hisp.dhis.configuration.ConfigurationService; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitLevel; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.period.RelativePeriods; +import org.hisp.dhis.system.util.ConversionUtils; +import org.hisp.dhis.system.util.MathUtils; +import org.hisp.dhis.user.CurrentUserService; +import org.hisp.dhis.user.User; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Jan Henrik Overland + */ +@Transactional +public class DefaultMappingService + implements MappingService +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MapViewStore mapViewStore; + + private MapLayerStore mapLayerStore; + + private MapLegendStore mapLegendStore; + + private MapLegendSetStore mapLegendSetStore; + + public void setMapViewStore( MapViewStore mapViewStore ) + { + this.mapViewStore = mapViewStore; + } + + public void setMapLayerStore( MapLayerStore mapLayerStore ) + { + this.mapLayerStore = mapLayerStore; + } + + public void setMapLegendStore( MapLegendStore mapLegendStore ) + { + this.mapLegendStore = mapLegendStore; + } + + public void setMapLegendSetStore( MapLegendSetStore mapLegendSetStore ) + { + this.mapLegendSetStore = mapLegendSetStore; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + private IndicatorService indicatorService; + + public void setIndicatorService( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + private AggregatedDataValueService aggregatedDataValueService; + + public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) + { + this.aggregatedDataValueService = aggregatedDataValueService; + } + + private CurrentUserService currentUserService; + + public void setCurrentUserService( CurrentUserService currentUserService ) + { + this.currentUserService = currentUserService; + } + + private ConfigurationService configurationService; + + public void setConfigurationService( ConfigurationService configurationService ) + { + this.configurationService = configurationService; + } + + // ------------------------------------------------------------------------- + // MappingService implementation + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // OrganisationUnits + // ------------------------------------------------------------------------- + + /** + * Returns the relevant OrganisationUnits for the given parent identifier + * and / or level. + * + * @param parentOrganisationUnitId the OrganisationUnit level. + * @param level the OrganisationUnit level. + * @return a collection of OrganisationUnits. + */ + private Collection getOrganisationUnits( Integer parentOrganisationUnitId, Integer level ) + { + Collection organisationUnits = null; + + if ( parentOrganisationUnitId != null && level != null ) + { + organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level, + organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ) ); + } + else if ( level != null ) + { + organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level ); + } + else if ( parentOrganisationUnitId != null ) + { + organisationUnits = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ).getChildren(); + } + + return organisationUnits; + } + + // ------------------------------------------------------------------------- + // IndicatorMapValues + // ------------------------------------------------------------------------- + + /** + * Generates a collection AggregatedMapValues. Only one of Period and + * start/end date can be specified. At least one of parent organisation unit + * and level must be specified. Period should be specified with "real time" + * aggregation strategy, any may be specified with "batch" aggregation + * strategy. + * + * @param indicatorId the Indicator identifier. + * @param periodId the Period identifier. Ignored if null. + * @param parentOrganisationUnitId the parent OrganisationUnit identifier. + * Ignored if null. + * @param level the OrganisationUnit level. Ignored if null. + * @return a collection of AggregatedMapValues. + */ + public Collection getIndicatorMapValues( int indicatorId, int periodId, + int parentOrganisationUnitId, Integer level ) + { + Collection units = getOrganisationUnits( parentOrganisationUnitId, level ); + + return getIndicatorMapValues( indicatorId, periodId, units ); + } + + public Collection getIndicatorMapValues( int indicatorId, int periodId, + Collection units ) + { + Collection values = aggregatedDataValueService.getAggregatedIndicatorMapValues( + indicatorId, periodId, ConversionUtils.getIdentifiers( OrganisationUnit.class, units ) ); + + for ( AggregatedMapValue value : values ) + { + value.setValue( MathUtils.getRounded( value.getValue(), 2 ) ); + } + + return values; + } + + // ------------------------------------------------------------------------- + // DataElementMapValues + // ------------------------------------------------------------------------- + + /** + * Generates a collection AggregatedMapValues. Only one of Period and + * start/end date can be specified. At least one of parent organisation unit + * and level must be specified. Period should be specified with "real time" + * aggregation strategy, any may be specified with "batch" aggregation + * strategy. + * + * @param dataElementId the DataElement identifier. + * @param periodId the Period identifier. Ignored if null. + * @param parentOrganisationUnitId the parent OrganisationUnit identifier. + * Ignored if null. + * @param level the OrganisationUnit level. Ignored if null. + * @return a collection of AggregatedMapValues. + */ + public Collection getDataElementMapValues( int dataElementId, int periodId, + int parentOrganisationUnitId, Integer level ) + { + Collection units = getOrganisationUnits( parentOrganisationUnitId, level ); + + return getDataElementMapValues( dataElementId, periodId, units ); + } + + public Collection getDataElementMapValues( int dataElementId, int periodId, + Collection units ) + { + Collection values = aggregatedDataValueService.getAggregatedDataMapValues( dataElementId, + periodId, ConversionUtils.getIdentifiers( OrganisationUnit.class, units ) ); + + for ( AggregatedMapValue value : values ) + { + value.setValue( MathUtils.getRounded( value.getValue(), 2 ) ); + } + + return values; + } + + public Collection getInfrastructuralDataElementMapValues( Integer periodId, + Integer organisationUnitId ) + { + DataElementGroup group = configurationService.getConfiguration().getInfrastructuralDataElements(); + + if ( group == null ) + { + return new HashSet(); + } + + Collection dataElementIds = ConversionUtils.getIdentifiers( DataElement.class, group.getMembers() ); + + return aggregatedDataValueService.getAggregatedDataMapValues( dataElementIds, periodId, organisationUnitId ); + } + + // ------------------------------------------------------------------------- + // MapLegend + // ------------------------------------------------------------------------- + + public void addOrUpdateMapLegend( String name, Double startValue, Double endValue, String color, String image ) + { + MapLegend mapLegend = getMapLegendByName( name ); + + if ( mapLegend != null ) + { + mapLegend.setName( name ); + mapLegend.setStartValue( startValue ); + mapLegend.setEndValue( endValue ); + mapLegend.setColor( color ); + mapLegend.setImage( image ); + + mapLegendStore.update( mapLegend ); + } + else + { + mapLegend = new MapLegend( name, startValue, endValue, color, image ); + + mapLegendStore.save( mapLegend ); + } + } + + public int addMapLegend( MapLegend mapLegend ) + { + return mapLegendStore.save( mapLegend ); + } + + public void deleteMapLegend( MapLegend mapLegend ) + { + mapLegendStore.delete( mapLegend ); + } + + public MapLegend getMapLegend( int id ) + { + return mapLegendStore.get( id ); + } + + @Override + public MapLegend getMapLegend( String uid ) + { + return mapLegendStore.getByUid( uid ); + } + + public MapLegend getMapLegendByName( String name ) + { + return mapLegendStore.getByName( name ); + } + + public Collection getAllMapLegends() + { + return mapLegendStore.getAll(); + } + + // ------------------------------------------------------------------------- + // MapLegendSet + // ------------------------------------------------------------------------- + + public int addMapLegendSet( MapLegendSet mapLegendSet ) + { + return mapLegendSetStore.save( mapLegendSet ); + } + + public void updateMapLegendSet( MapLegendSet mapLegendSet ) + { + mapLegendSetStore.update( mapLegendSet ); + } + + public void addOrUpdateMapLegendSet( String name, String type, String symbolizer, Set mapLegends ) + { + MapLegendSet mapLegendSet = getMapLegendSetByName( name ); + + Set indicators = new HashSet(); + + Set dataElements = new HashSet(); + + if ( mapLegendSet != null ) + { + mapLegendSet.setType( type ); + mapLegendSet.setSymbolizer( symbolizer ); + mapLegendSet.setMapLegends( mapLegends ); + mapLegendSet.setIndicators( indicators ); + mapLegendSet.setDataElements( dataElements ); + + mapLegendSetStore.update( mapLegendSet ); + } + else + { + mapLegendSet = new MapLegendSet( name, type, symbolizer, mapLegends, indicators, dataElements ); + + mapLegendSetStore.save( mapLegendSet ); + } + } + + public void deleteMapLegendSet( MapLegendSet mapLegendSet ) + { + mapLegendSetStore.delete( mapLegendSet ); + } + + public MapLegendSet getMapLegendSet( int id ) + { + return mapLegendSetStore.get( id ); + } + + @Override + public MapLegendSet getMapLegendSet( String uid ) + { + return mapLegendSetStore.getByUid( uid ); + } + + public MapLegendSet getMapLegendSetByName( String name ) + { + return mapLegendSetStore.getByName( name ); + } + + public Collection getMapLegendSetsByType( String type ) + { + return mapLegendSetStore.getMapLegendSetsByType( type ); + } + + public MapLegendSet getMapLegendSetByIndicator( int indicatorId ) + { + Indicator indicator = indicatorService.getIndicator( indicatorId ); + + Collection mapLegendSets = mapLegendSetStore.getAll(); + + for ( MapLegendSet mapLegendSet : mapLegendSets ) + { + if ( mapLegendSet.getIndicators().contains( indicator ) ) + { + return mapLegendSet; + } + } + + return null; + } + + public MapLegendSet getMapLegendSetByDataElement( int dataElementId ) + { + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + Collection mapLegendSets = mapLegendSetStore.getAll(); + + for ( MapLegendSet mapLegendSet : mapLegendSets ) + { + if ( mapLegendSet.getDataElements().contains( dataElement ) ) + { + return mapLegendSet; + } + } + + return null; + } + + public Collection getAllMapLegendSets() + { + return mapLegendSetStore.getAll(); + } + + public boolean indicatorHasMapLegendSet( int indicatorId ) + { + Indicator indicator = indicatorService.getIndicator( indicatorId ); + + Collection mapLegendSets = mapLegendSetStore.getAll(); + + for ( MapLegendSet mapLegendSet : mapLegendSets ) + { + if ( mapLegendSet.getIndicators().contains( indicator ) ) + { + return true; + } + } + + return false; + } + + // ------------------------------------------------------------------------- + // MapView + // ------------------------------------------------------------------------- + + public int addMapView( MapView mapView ) + { + return mapViewStore.save( mapView ); + } + + public void addMapView( String name, boolean system, String mapValueType, Integer indicatorGroupId, + Integer indicatorId, Integer dataElementGroupId, Integer dataElementId, String periodTypeName, + Integer periodId, Integer parentOrganisationUnitId, Integer organisationUnitLevel, String mapLegendType, + Integer method, Integer classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId, + Integer radiusLow, Integer radiusHigh, String longitude, String latitude, int zoom ) + { + User user = system ? null : currentUserService.getCurrentUser(); + + IndicatorGroup indicatorGroup = null; + + Indicator indicator = null; + + DataElementGroup dataElementGroup = null; + + DataElement dataElement = null; + + if ( mapValueType.equals( MappingService.MAP_VALUE_TYPE_INDICATOR ) ) + { + indicatorGroup = indicatorService.getIndicatorGroup( indicatorGroupId ); + indicator = indicatorService.getIndicator( indicatorId ); + } + else + { + dataElementGroup = dataElementService.getDataElementGroup( dataElementGroupId ); + dataElement = dataElementService.getDataElement( dataElementId ); + } + + PeriodType periodType = periodTypeName != null && !periodTypeName.isEmpty() ? periodService + .getPeriodTypeByClass( PeriodType.getPeriodTypeByName( periodTypeName ).getClass() ) : null; + + Period period = periodId != null ? periodService.getPeriod( periodId ) : null; + + OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ); + + OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevelByLevel( organisationUnitLevel ); + + MapLegendSet mapLegendSet = mapLegendSetId != null ? getMapLegendSet( mapLegendSetId ) : null; + + addMapView( new MapView( name, user, mapValueType, indicatorGroup, indicator, dataElementGroup, dataElement, + periodType, period, parent, level, mapLegendType, method, classes, bounds, colorLow, colorHigh, + mapLegendSet, radiusLow, radiusHigh, longitude, latitude, zoom ) ); + } + + public void updateMapView( MapView mapView ) + { + mapViewStore.update( mapView ); + } + + public void deleteMapView( MapView mapView ) + { + mapViewStore.delete( mapView ); + } + + public MapView getMapView( int id ) + { + MapView mapView = mapViewStore.get( id ); + + setMapViewLevel( mapView ); + + return mapView; + } + + public MapView getMapView( String uid ) + { + MapView mapView = mapViewStore.getByUid( uid ); + + setMapViewLevel( mapView ); + + return mapView; + } + + private void setMapViewLevel( MapView mapView ) + { + if ( mapView != null ) + { + mapView.getParentOrganisationUnit().setLevel( + organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); + } + } + + public MapView getMapViewByName( String name ) + { + return mapViewStore.getByName( name ); + } + + public MapView getIndicatorLastYearMapView( String indicatorUid, String organisationUnitUid, int level ) + { + MapView mapView = new MapView(); + + Period period = periodService.reloadPeriod( new RelativePeriods().setThisYear( true ).getRelativePeriods() + .iterator().next() ); + + Indicator indicator = indicatorService.getIndicator( indicatorUid ); + OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid ); + + mapView.setIndicator( indicator ); + mapView.setPeriod( period ); + mapView.setParentOrganisationUnit( unit ); + mapView.setOrganisationUnitLevel( new OrganisationUnitLevel( level, "" ) ); + mapView.setName( indicator.getName() ); + mapView.setMapValueType( MappingService.MAP_VALUE_TYPE_INDICATOR ); + + return mapView; + } + + public Collection getSystemAndUserMapViews() + { + User user = currentUserService.getCurrentUser(); + + return mapViewStore.getSystemAndUserMapViews( user ); + } + + public Collection getAllMapViews() + { + Collection mapViews = mapViewStore.getAll(); + + if ( mapViews.size() > 0 ) + { + for ( MapView mapView : mapViews ) + { + mapView.getParentOrganisationUnit().setLevel( + organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); + } + } + + return mapViews; + } + + public Collection getMapViewsByFeatureType( String featureType ) + { + User user = currentUserService.getCurrentUser(); + + Collection mapViews = mapViewStore.getMapViewsByFeatureType( featureType, user ); + + for ( MapView mapView : mapViews ) + { + mapView.getParentOrganisationUnit().setLevel( + organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); + } + + return mapViews; + } + + public Collection getMapViewsByUser( User user ) + { + return mapViewStore.getByUser( user ); + } + + public Collection getMapViewsBetweenByName( String name, int first, int max ) + { + return mapViewStore.getBetweenByName( name, first, max ); + } + + // ------------------------------------------------------------------------- + // MapLayer + // ------------------------------------------------------------------------- + + public int addMapLayer( MapLayer mapLayer ) + { + return mapLayerStore.save( mapLayer ); + } + + public void updateMapLayer( MapLayer mapLayer ) + { + mapLayerStore.update( mapLayer ); + } + + public void addOrUpdateMapLayer( String name, String type, String url, String layers, String time, + String fillColor, double fillOpacity, String strokeColor, int strokeWidth ) + { + MapLayer mapLayer = mapLayerStore.getByName( name ); + + if ( mapLayer != null ) + { + mapLayer.setName( name ); + mapLayer.setType( type ); + mapLayer.setUrl( url ); + mapLayer.setLayers( layers ); + mapLayer.setTime( time ); + mapLayer.setFillColor( fillColor ); + mapLayer.setFillOpacity( fillOpacity ); + mapLayer.setStrokeColor( strokeColor ); + mapLayer.setStrokeWidth( strokeWidth ); + + updateMapLayer( mapLayer ); + } + else + { + addMapLayer( new MapLayer( name, type, url, layers, time, fillColor, fillOpacity, strokeColor, strokeWidth ) ); + } + } + + public void deleteMapLayer( MapLayer mapLayer ) + { + mapLayerStore.delete( mapLayer ); + } + + public MapLayer getMapLayer( int id ) + { + return mapLayerStore.get( id ); + } + + @Override + public MapLayer getMapLayer( String uid ) + { + return mapLayerStore.getByUid( uid ); + } + + public MapLayer getMapLayerByName( String name ) + { + return mapLayerStore.getByName( name ); + } + + public Collection getMapLayersByType( String type ) + { + return mapLayerStore.getMapLayersByType( type ); + } + + public MapLayer getMapLayerByMapSource( String mapSource ) + { + return mapLayerStore.getMapLayerByMapSource( mapSource ); + } + + public Collection getAllMapLayers() + { + return mapLayerStore.getAll(); + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,97 @@ +package org.hisp.dhis.mapping; + +/* + * Copyright (c) 2004-2012, 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.dataelement.DataElement; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.system.deletion.DeletionHandler; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class MapLegendSetDeletionHandler + extends DeletionHandler +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MappingService mappingService; + + public void setMappingService( MappingService mappingService ) + { + this.mappingService = mappingService; + } + + // ------------------------------------------------------------------------- + // DeletionHandler implementation + // ------------------------------------------------------------------------- + + @Override + protected String getClassName() + { + return MapLegendSet.class.getSimpleName(); + } + + @Override + public void deleteMapLegend( MapLegend mapLegend ) + { + for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) + { + if ( legendSet.getMapLegends().remove( mapLegend ) ) + { + mappingService.updateMapLegendSet( legendSet ); + } + } + } + + @Override + public void deleteIndicator( Indicator indicator ) + { + for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) + { + if ( legendSet.getIndicators().remove( indicator ) ) + { + mappingService.updateMapLegendSet( legendSet ); + } + } + } + + @Override + public void deleteDataElement( DataElement dataElement ) + { + for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) + { + if ( legendSet.getDataElements().remove( dataElement ) ) + { + mappingService.updateMapLegendSet( legendSet ); + } + } + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,167 @@ +package org.hisp.dhis.mapping; + +/* + * Copyright (c) 2004-2012, 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 java.util.Iterator; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.system.deletion.DeletionHandler; +import org.hisp.dhis.user.User; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class MapViewDeletionHandler + extends DeletionHandler +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MappingService mappingService; + + public void setMappingService( MappingService mappingService ) + { + this.mappingService = mappingService; + } + + // ------------------------------------------------------------------------- + // DeletionHandler implementation + // ------------------------------------------------------------------------- + + @Override + protected String getClassName() + { + return MapView.class.getName(); + } + + @Override + public String allowDeletePeriod( Period period ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getPeriod().equals( period ) ) + { + return mapView.getName(); + } + } + + return null; + } + + @Override + public void deleteIndicatorGroup( IndicatorGroup indicatorGroup ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getIndicatorGroup() != null && mapView.getIndicatorGroup().equals( indicatorGroup ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteIndicator( Indicator indicator ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getIndicator() != null && mapView.getIndicator().equals( indicator ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteDataElementGroup( DataElementGroup dataElementGroup ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getDataElementGroup() != null && mapView.getDataElementGroup().equals( dataElementGroup ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteDataElement( DataElement dataElement ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getDataElement() != null && mapView.getDataElement().equals( dataElement ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteOrganisationUnit( OrganisationUnit organisationUnit ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getParentOrganisationUnit() != null && mapView.getParentOrganisationUnit().equals( organisationUnit ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteMapLegendSet( MapLegendSet mapLegendSet ) + { + for ( MapView mapView : mappingService.getAllMapViews() ) + { + if ( mapView.getMapLegendSet() != null && mapView.getMapLegendSet().equals( mapLegendSet ) ) + { + mappingService.deleteMapView( mapView ); + } + } + } + + @Override + public void deleteUser( User user ) + { + Iterator iterator = mappingService.getMapViewsByUser( user ).iterator(); + + while ( iterator.hasNext() ) + { + MapView mapView = iterator.next(); + iterator.remove(); + mappingService.deleteMapView( mapView ); + } + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,80 @@ +package org.hisp.dhis.mapping.hibernate; + +/* + * Copyright (c) 2004-2012, 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.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.mapping.MapLayer; +import org.hisp.dhis.mapping.MapLayerStore; + +import java.util.Collection; + +/** + * @author Jan Henrik Overland + */ +public class HibernateMapLayerStore + extends HibernateIdentifiableObjectStore + implements MapLayerStore +{ + @SuppressWarnings( "unchecked" ) + public Collection getMapLayersByType( String type ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapLayer.class ); + + criteria.add( Restrictions.eq( "type", type ) ); + + return criteria.list(); + } + + @SuppressWarnings( "unchecked" ) + public Collection getMapLayersByMapSourceType( String mapSourceType ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapLayer.class ); + + criteria.add( Restrictions.eq( "mapSourceType", mapSourceType ) ); + + return criteria.list(); + } + + public MapLayer getMapLayerByMapSource( String mapSource ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapLayer.class ); + + criteria.add( Restrictions.eq( "mapSource", mapSource ) ); + + return (MapLayer) criteria.uniqueResult(); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,57 @@ +package org.hisp.dhis.mapping.hibernate; + +/* + * Copyright (c) 2004-2012, 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.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.mapping.MapLegendSet; +import org.hisp.dhis.mapping.MapLegendSetStore; + +import java.util.Collection; + +/** + * @author Jan Henrik Overland + */ +public class HibernateMapLegendSetStore + extends HibernateIdentifiableObjectStore + implements MapLegendSetStore +{ + @SuppressWarnings( "unchecked" ) + public Collection getMapLegendSetsByType( String type ) + { + Session session = this.sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapLegendSet.class ); + + criteria.add( Restrictions.eq( "type", type ) ); + + return criteria.list(); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java 2012-10-24 16:19:29 +0000 @@ -0,0 +1,41 @@ +package org.hisp.dhis.mapping.hibernate; + +/* + * Copyright (c) 2004-2012, 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.HibernateIdentifiableObjectStore; +import org.hisp.dhis.mapping.MapLegend; +import org.hisp.dhis.mapping.MapLegendStore; + +/** + * @author Jan Henrik Overland + */ +public class HibernateMapLegendStore + extends HibernateIdentifiableObjectStore + implements MapLegendStore +{ +} === 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 2012-10-24 16:19:29 +0000 @@ -0,0 +1,80 @@ +package org.hisp.dhis.mapping.hibernate; + +/* + * Copyright (c) 2004-2012, 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.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; +import org.hisp.dhis.mapping.MapView; +import org.hisp.dhis.mapping.MapViewStore; +import org.hisp.dhis.user.User; + +import java.util.Collection; + +/** + * @author Jan Henrik Overland + */ +public class HibernateMapViewStore + extends HibernateIdentifiableObjectStore + implements MapViewStore +{ + @SuppressWarnings( "unchecked" ) + public Collection getSystemAndUserMapViews( User user ) + { + return getCriteria( + Restrictions.or( Restrictions.isNull( "user" ), + Restrictions.eq( "user", user ) ) ).list(); + } + + @SuppressWarnings( "unchecked" ) + public Collection getMapViewsByMapSourceType( String mapSourceType ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapView.class ); + + criteria.add( Restrictions.eq( "mapSourceType", mapSourceType ) ); + + return criteria.list(); + } + + @SuppressWarnings( "unchecked" ) + public Collection getMapViewsByFeatureType( String featureType, User user ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( MapView.class ); + + criteria.add( Restrictions.eq( "featureType", featureType ) ); + + criteria.add( Restrictions.or( Restrictions.eq( "user", user ), Restrictions.isNull( "user" ) ) ); + + return criteria.list(); + } +} === 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 2012-10-23 08:01:42 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-10-24 16:19:29 +0000 @@ -287,6 +287,30 @@ + + + + + + + + + + + + + + + + + + + + @@ -504,6 +528,20 @@ + + + + + + + + + + + + + + @@ -843,6 +881,14 @@ + + + + + + + + @@ -883,6 +929,8 @@ + + @@ -909,7 +957,10 @@ - + + + + === removed directory 'dhis-2/dhis-services/dhis-service-mapping' === removed file 'dhis-2/dhis-services/dhis-service-mapping/pom.xml' --- dhis-2/dhis-services/dhis-service-mapping/pom.xml 2012-08-22 12:45:25 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/pom.xml 1970-01-01 00:00:00 +0000 @@ -1,44 +0,0 @@ - - 4.0.0 - - - org.hisp.dhis - dhis-services - 2.10-SNAPSHOT - - - dhis-service-mapping - jar - DHIS Mapping Service Implementation - - - - - - - org.hisp.dhis - dhis-api - - - org.hisp.dhis - dhis-service-core - - - org.hisp.dhis - dhis-service-aggregationengine-default - - - - - - commons-logging - commons-logging - - - - - ../../ - - === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping' === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2012-10-24 09:11:47 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 1970-01-01 00:00:00 +0000 @@ -1,691 +0,0 @@ -package org.hisp.dhis.mapping; - -/* - * Copyright (c) 2004-2012, 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 java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.hisp.dhis.aggregation.AggregatedDataValueService; -import org.hisp.dhis.aggregation.AggregatedMapValue; -import org.hisp.dhis.configuration.ConfigurationService; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementGroup; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.indicator.IndicatorGroup; -import org.hisp.dhis.indicator.IndicatorService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitLevel; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodService; -import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.period.RelativePeriods; -import org.hisp.dhis.system.util.ConversionUtils; -import org.hisp.dhis.system.util.MathUtils; -import org.hisp.dhis.user.CurrentUserService; -import org.hisp.dhis.user.User; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Jan Henrik Overland - */ -@Transactional -public class DefaultMappingService - implements MappingService -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private MapViewStore mapViewStore; - - private MapLayerStore mapLayerStore; - - private MapLegendStore mapLegendStore; - - private MapLegendSetStore mapLegendSetStore; - - public void setMapViewStore( MapViewStore mapViewStore ) - { - this.mapViewStore = mapViewStore; - } - - public void setMapLayerStore( MapLayerStore mapLayerStore ) - { - this.mapLayerStore = mapLayerStore; - } - - public void setMapLegendStore( MapLegendStore mapLegendStore ) - { - this.mapLegendStore = mapLegendStore; - } - - public void setMapLegendSetStore( MapLegendSetStore mapLegendSetStore ) - { - this.mapLegendSetStore = mapLegendSetStore; - } - - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - private IndicatorService indicatorService; - - public void setIndicatorService( IndicatorService indicatorService ) - { - this.indicatorService = indicatorService; - } - - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - private PeriodService periodService; - - public void setPeriodService( PeriodService periodService ) - { - this.periodService = periodService; - } - - private AggregatedDataValueService aggregatedDataValueService; - - public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) - { - this.aggregatedDataValueService = aggregatedDataValueService; - } - - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - - private ConfigurationService configurationService; - - public void setConfigurationService( ConfigurationService configurationService ) - { - this.configurationService = configurationService; - } - - // ------------------------------------------------------------------------- - // MappingService implementation - // ------------------------------------------------------------------------- - - // ------------------------------------------------------------------------- - // OrganisationUnits - // ------------------------------------------------------------------------- - - /** - * Returns the relevant OrganisationUnits for the given parent identifier - * and / or level. - * - * @param parentOrganisationUnitId the OrganisationUnit level. - * @param level the OrganisationUnit level. - * @return a collection of OrganisationUnits. - */ - private Collection getOrganisationUnits( Integer parentOrganisationUnitId, Integer level ) - { - Collection organisationUnits = null; - - if ( parentOrganisationUnitId != null && level != null ) - { - organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level, - organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ) ); - } - else if ( level != null ) - { - organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level ); - } - else if ( parentOrganisationUnitId != null ) - { - organisationUnits = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ).getChildren(); - } - - return organisationUnits; - } - - // ------------------------------------------------------------------------- - // IndicatorMapValues - // ------------------------------------------------------------------------- - - /** - * Generates a collection AggregatedMapValues. Only one of Period and - * start/end date can be specified. At least one of parent organisation unit - * and level must be specified. Period should be specified with "real time" - * aggregation strategy, any may be specified with "batch" aggregation - * strategy. - * - * @param indicatorId the Indicator identifier. - * @param periodId the Period identifier. Ignored if null. - * @param parentOrganisationUnitId the parent OrganisationUnit identifier. - * Ignored if null. - * @param level the OrganisationUnit level. Ignored if null. - * @return a collection of AggregatedMapValues. - */ - public Collection getIndicatorMapValues( int indicatorId, int periodId, - int parentOrganisationUnitId, Integer level ) - { - Collection units = getOrganisationUnits( parentOrganisationUnitId, level ); - - return getIndicatorMapValues( indicatorId, periodId, units ); - } - - public Collection getIndicatorMapValues( int indicatorId, int periodId, - Collection units ) - { - Collection values = aggregatedDataValueService.getAggregatedIndicatorMapValues( - indicatorId, periodId, ConversionUtils.getIdentifiers( OrganisationUnit.class, units ) ); - - for ( AggregatedMapValue value : values ) - { - value.setValue( MathUtils.getRounded( value.getValue(), 2 ) ); - } - - return values; - } - - // ------------------------------------------------------------------------- - // DataElementMapValues - // ------------------------------------------------------------------------- - - /** - * Generates a collection AggregatedMapValues. Only one of Period and - * start/end date can be specified. At least one of parent organisation unit - * and level must be specified. Period should be specified with "real time" - * aggregation strategy, any may be specified with "batch" aggregation - * strategy. - * - * @param dataElementId the DataElement identifier. - * @param periodId the Period identifier. Ignored if null. - * @param parentOrganisationUnitId the parent OrganisationUnit identifier. - * Ignored if null. - * @param level the OrganisationUnit level. Ignored if null. - * @return a collection of AggregatedMapValues. - */ - public Collection getDataElementMapValues( int dataElementId, int periodId, - int parentOrganisationUnitId, Integer level ) - { - Collection units = getOrganisationUnits( parentOrganisationUnitId, level ); - - return getDataElementMapValues( dataElementId, periodId, units ); - } - - public Collection getDataElementMapValues( int dataElementId, int periodId, - Collection units ) - { - Collection values = aggregatedDataValueService.getAggregatedDataMapValues( dataElementId, - periodId, ConversionUtils.getIdentifiers( OrganisationUnit.class, units ) ); - - for ( AggregatedMapValue value : values ) - { - value.setValue( MathUtils.getRounded( value.getValue(), 2 ) ); - } - - return values; - } - - public Collection getInfrastructuralDataElementMapValues( Integer periodId, - Integer organisationUnitId ) - { - DataElementGroup group = configurationService.getConfiguration().getInfrastructuralDataElements(); - - if ( group == null ) - { - return new HashSet(); - } - - Collection dataElementIds = ConversionUtils.getIdentifiers( DataElement.class, group.getMembers() ); - - return aggregatedDataValueService.getAggregatedDataMapValues( dataElementIds, periodId, organisationUnitId ); - } - - // ------------------------------------------------------------------------- - // MapLegend - // ------------------------------------------------------------------------- - - public void addOrUpdateMapLegend( String name, Double startValue, Double endValue, String color, String image ) - { - MapLegend mapLegend = getMapLegendByName( name ); - - if ( mapLegend != null ) - { - mapLegend.setName( name ); - mapLegend.setStartValue( startValue ); - mapLegend.setEndValue( endValue ); - mapLegend.setColor( color ); - mapLegend.setImage( image ); - - mapLegendStore.update( mapLegend ); - } - else - { - mapLegend = new MapLegend( name, startValue, endValue, color, image ); - - mapLegendStore.save( mapLegend ); - } - } - - public int addMapLegend( MapLegend mapLegend ) - { - return mapLegendStore.save( mapLegend ); - } - - public void deleteMapLegend( MapLegend mapLegend ) - { - mapLegendStore.delete( mapLegend ); - } - - public MapLegend getMapLegend( int id ) - { - return mapLegendStore.get( id ); - } - - @Override - public MapLegend getMapLegend( String uid ) - { - return mapLegendStore.getByUid( uid ); - } - - public MapLegend getMapLegendByName( String name ) - { - return mapLegendStore.getByName( name ); - } - - public Collection getAllMapLegends() - { - return mapLegendStore.getAll(); - } - - // ------------------------------------------------------------------------- - // MapLegendSet - // ------------------------------------------------------------------------- - - public int addMapLegendSet( MapLegendSet mapLegendSet ) - { - return mapLegendSetStore.save( mapLegendSet ); - } - - public void updateMapLegendSet( MapLegendSet mapLegendSet ) - { - mapLegendSetStore.update( mapLegendSet ); - } - - public void addOrUpdateMapLegendSet( String name, String type, String symbolizer, Set mapLegends ) - { - MapLegendSet mapLegendSet = getMapLegendSetByName( name ); - - Set indicators = new HashSet(); - - Set dataElements = new HashSet(); - - if ( mapLegendSet != null ) - { - mapLegendSet.setType( type ); - mapLegendSet.setSymbolizer( symbolizer ); - mapLegendSet.setMapLegends( mapLegends ); - mapLegendSet.setIndicators( indicators ); - mapLegendSet.setDataElements( dataElements ); - - mapLegendSetStore.update( mapLegendSet ); - } - else - { - mapLegendSet = new MapLegendSet( name, type, symbolizer, mapLegends, indicators, dataElements ); - - mapLegendSetStore.save( mapLegendSet ); - } - } - - public void deleteMapLegendSet( MapLegendSet mapLegendSet ) - { - mapLegendSetStore.delete( mapLegendSet ); - } - - public MapLegendSet getMapLegendSet( int id ) - { - return mapLegendSetStore.get( id ); - } - - @Override - public MapLegendSet getMapLegendSet( String uid ) - { - return mapLegendSetStore.getByUid( uid ); - } - - public MapLegendSet getMapLegendSetByName( String name ) - { - return mapLegendSetStore.getByName( name ); - } - - public Collection getMapLegendSetsByType( String type ) - { - return mapLegendSetStore.getMapLegendSetsByType( type ); - } - - public MapLegendSet getMapLegendSetByIndicator( int indicatorId ) - { - Indicator indicator = indicatorService.getIndicator( indicatorId ); - - Collection mapLegendSets = mapLegendSetStore.getAll(); - - for ( MapLegendSet mapLegendSet : mapLegendSets ) - { - if ( mapLegendSet.getIndicators().contains( indicator ) ) - { - return mapLegendSet; - } - } - - return null; - } - - public MapLegendSet getMapLegendSetByDataElement( int dataElementId ) - { - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - - Collection mapLegendSets = mapLegendSetStore.getAll(); - - for ( MapLegendSet mapLegendSet : mapLegendSets ) - { - if ( mapLegendSet.getDataElements().contains( dataElement ) ) - { - return mapLegendSet; - } - } - - return null; - } - - public Collection getAllMapLegendSets() - { - return mapLegendSetStore.getAll(); - } - - public boolean indicatorHasMapLegendSet( int indicatorId ) - { - Indicator indicator = indicatorService.getIndicator( indicatorId ); - - Collection mapLegendSets = mapLegendSetStore.getAll(); - - for ( MapLegendSet mapLegendSet : mapLegendSets ) - { - if ( mapLegendSet.getIndicators().contains( indicator ) ) - { - return true; - } - } - - return false; - } - - // ------------------------------------------------------------------------- - // MapView - // ------------------------------------------------------------------------- - - public int addMapView( MapView mapView ) - { - return mapViewStore.save( mapView ); - } - - public void addMapView( String name, boolean system, String mapValueType, Integer indicatorGroupId, - Integer indicatorId, Integer dataElementGroupId, Integer dataElementId, String periodTypeName, - Integer periodId, Integer parentOrganisationUnitId, Integer organisationUnitLevel, String mapLegendType, - Integer method, Integer classes, String bounds, String colorLow, String colorHigh, Integer mapLegendSetId, - Integer radiusLow, Integer radiusHigh, String longitude, String latitude, int zoom ) - { - User user = system ? null : currentUserService.getCurrentUser(); - - IndicatorGroup indicatorGroup = null; - - Indicator indicator = null; - - DataElementGroup dataElementGroup = null; - - DataElement dataElement = null; - - if ( mapValueType.equals( MappingService.MAP_VALUE_TYPE_INDICATOR ) ) - { - indicatorGroup = indicatorService.getIndicatorGroup( indicatorGroupId ); - indicator = indicatorService.getIndicator( indicatorId ); - } - else - { - dataElementGroup = dataElementService.getDataElementGroup( dataElementGroupId ); - dataElement = dataElementService.getDataElement( dataElementId ); - } - - PeriodType periodType = periodTypeName != null && !periodTypeName.isEmpty() ? periodService - .getPeriodTypeByClass( PeriodType.getPeriodTypeByName( periodTypeName ).getClass() ) : null; - - Period period = periodId != null ? periodService.getPeriod( periodId ) : null; - - OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentOrganisationUnitId ); - - OrganisationUnitLevel level = organisationUnitService.getOrganisationUnitLevelByLevel( organisationUnitLevel ); - - MapLegendSet mapLegendSet = mapLegendSetId != null ? getMapLegendSet( mapLegendSetId ) : null; - - addMapView( new MapView( name, user, mapValueType, indicatorGroup, indicator, dataElementGroup, dataElement, - periodType, period, parent, level, mapLegendType, method, classes, bounds, colorLow, colorHigh, - mapLegendSet, radiusLow, radiusHigh, longitude, latitude, zoom ) ); - } - - public void updateMapView( MapView mapView ) - { - mapViewStore.update( mapView ); - } - - public void deleteMapView( MapView mapView ) - { - mapViewStore.delete( mapView ); - } - - public MapView getMapView( int id ) - { - MapView mapView = mapViewStore.get( id ); - - setMapViewLevel( mapView ); - - return mapView; - } - - public MapView getMapView( String uid ) - { - MapView mapView = mapViewStore.getByUid( uid ); - - setMapViewLevel( mapView ); - - return mapView; - } - - private void setMapViewLevel( MapView mapView ) - { - if ( mapView != null ) - { - mapView.getParentOrganisationUnit().setLevel( - organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); - } - } - - public MapView getMapViewByName( String name ) - { - return mapViewStore.getByName( name ); - } - - public MapView getIndicatorLastYearMapView( String indicatorUid, String organisationUnitUid, int level ) - { - MapView mapView = new MapView(); - - Period period = periodService.reloadPeriod( new RelativePeriods().setThisYear( true ).getRelativePeriods() - .iterator().next() ); - - Indicator indicator = indicatorService.getIndicator( indicatorUid ); - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( organisationUnitUid ); - - mapView.setIndicator( indicator ); - mapView.setPeriod( period ); - mapView.setParentOrganisationUnit( unit ); - mapView.setOrganisationUnitLevel( new OrganisationUnitLevel( level, "" ) ); - mapView.setName( indicator.getName() ); - mapView.setMapValueType( MappingService.MAP_VALUE_TYPE_INDICATOR ); - - return mapView; - } - - public Collection getSystemAndUserMapViews() - { - User user = currentUserService.getCurrentUser(); - - return mapViewStore.getSystemAndUserMapViews( user ); - } - - public Collection getAllMapViews() - { - Collection mapViews = mapViewStore.getAll(); - - if ( mapViews.size() > 0 ) - { - for ( MapView mapView : mapViews ) - { - mapView.getParentOrganisationUnit().setLevel( - organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); - } - } - - return mapViews; - } - - public Collection getMapViewsByFeatureType( String featureType ) - { - User user = currentUserService.getCurrentUser(); - - Collection mapViews = mapViewStore.getMapViewsByFeatureType( featureType, user ); - - for ( MapView mapView : mapViews ) - { - mapView.getParentOrganisationUnit().setLevel( - organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit().getId() ) ); - } - - return mapViews; - } - - public Collection getMapViewsByUser( User user ) - { - return mapViewStore.getByUser( user ); - } - - public Collection getMapViewsBetweenByName( String name, int first, int max ) - { - return mapViewStore.getBetweenByName( name, first, max ); - } - - // ------------------------------------------------------------------------- - // MapLayer - // ------------------------------------------------------------------------- - - public int addMapLayer( MapLayer mapLayer ) - { - return mapLayerStore.save( mapLayer ); - } - - public void updateMapLayer( MapLayer mapLayer ) - { - mapLayerStore.update( mapLayer ); - } - - public void addOrUpdateMapLayer( String name, String type, String url, String layers, String time, - String fillColor, double fillOpacity, String strokeColor, int strokeWidth ) - { - MapLayer mapLayer = mapLayerStore.getByName( name ); - - if ( mapLayer != null ) - { - mapLayer.setName( name ); - mapLayer.setType( type ); - mapLayer.setUrl( url ); - mapLayer.setLayers( layers ); - mapLayer.setTime( time ); - mapLayer.setFillColor( fillColor ); - mapLayer.setFillOpacity( fillOpacity ); - mapLayer.setStrokeColor( strokeColor ); - mapLayer.setStrokeWidth( strokeWidth ); - - updateMapLayer( mapLayer ); - } - else - { - addMapLayer( new MapLayer( name, type, url, layers, time, fillColor, fillOpacity, strokeColor, strokeWidth ) ); - } - } - - public void deleteMapLayer( MapLayer mapLayer ) - { - mapLayerStore.delete( mapLayer ); - } - - public MapLayer getMapLayer( int id ) - { - return mapLayerStore.get( id ); - } - - @Override - public MapLayer getMapLayer( String uid ) - { - return mapLayerStore.getByUid( uid ); - } - - public MapLayer getMapLayerByName( String name ) - { - return mapLayerStore.getByName( name ); - } - - public Collection getMapLayersByType( String type ) - { - return mapLayerStore.getMapLayersByType( type ); - } - - public MapLayer getMapLayerByMapSource( String mapSource ) - { - return mapLayerStore.getMapLayerByMapSource( mapSource ); - } - - public Collection getAllMapLayers() - { - return mapLayerStore.getAll(); - } -} === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapLegendSetDeletionHandler.java 1970-01-01 00:00:00 +0000 @@ -1,97 +0,0 @@ -package org.hisp.dhis.mapping; - -/* - * Copyright (c) 2004-2012, 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.dataelement.DataElement; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.system.deletion.DeletionHandler; - -/** - * @author Lars Helge Overland - * @version $Id$ - */ -public class MapLegendSetDeletionHandler - extends DeletionHandler -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private MappingService mappingService; - - public void setMappingService( MappingService mappingService ) - { - this.mappingService = mappingService; - } - - // ------------------------------------------------------------------------- - // DeletionHandler implementation - // ------------------------------------------------------------------------- - - @Override - protected String getClassName() - { - return MapLegendSet.class.getSimpleName(); - } - - @Override - public void deleteMapLegend( MapLegend mapLegend ) - { - for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) - { - if ( legendSet.getMapLegends().remove( mapLegend ) ) - { - mappingService.updateMapLegendSet( legendSet ); - } - } - } - - @Override - public void deleteIndicator( Indicator indicator ) - { - for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) - { - if ( legendSet.getIndicators().remove( indicator ) ) - { - mappingService.updateMapLegendSet( legendSet ); - } - } - } - - @Override - public void deleteDataElement( DataElement dataElement ) - { - for ( MapLegendSet legendSet : mappingService.getAllMapLegendSets() ) - { - if ( legendSet.getDataElements().remove( dataElement ) ) - { - mappingService.updateMapLegendSet( legendSet ); - } - } - } -} === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2012-07-01 11:33:07 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 1970-01-01 00:00:00 +0000 @@ -1,167 +0,0 @@ -package org.hisp.dhis.mapping; - -/* - * Copyright (c) 2004-2012, 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 java.util.Iterator; - -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementGroup; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.indicator.IndicatorGroup; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.system.deletion.DeletionHandler; -import org.hisp.dhis.user.User; - -/** - * @author Lars Helge Overland - * @version $Id$ - */ -public class MapViewDeletionHandler - extends DeletionHandler -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private MappingService mappingService; - - public void setMappingService( MappingService mappingService ) - { - this.mappingService = mappingService; - } - - // ------------------------------------------------------------------------- - // DeletionHandler implementation - // ------------------------------------------------------------------------- - - @Override - protected String getClassName() - { - return MapView.class.getName(); - } - - @Override - public String allowDeletePeriod( Period period ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getPeriod().equals( period ) ) - { - return mapView.getName(); - } - } - - return null; - } - - @Override - public void deleteIndicatorGroup( IndicatorGroup indicatorGroup ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getIndicatorGroup() != null && mapView.getIndicatorGroup().equals( indicatorGroup ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteIndicator( Indicator indicator ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getIndicator() != null && mapView.getIndicator().equals( indicator ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteDataElementGroup( DataElementGroup dataElementGroup ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getDataElementGroup() != null && mapView.getDataElementGroup().equals( dataElementGroup ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteDataElement( DataElement dataElement ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getDataElement() != null && mapView.getDataElement().equals( dataElement ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteOrganisationUnit( OrganisationUnit organisationUnit ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getParentOrganisationUnit() != null && mapView.getParentOrganisationUnit().equals( organisationUnit ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteMapLegendSet( MapLegendSet mapLegendSet ) - { - for ( MapView mapView : mappingService.getAllMapViews() ) - { - if ( mapView.getMapLegendSet() != null && mapView.getMapLegendSet().equals( mapLegendSet ) ) - { - mappingService.deleteMapView( mapView ); - } - } - } - - @Override - public void deleteUser( User user ) - { - Iterator iterator = mappingService.getMapViewsByUser( user ).iterator(); - - while ( iterator.hasNext() ) - { - MapView mapView = iterator.next(); - iterator.remove(); - mappingService.deleteMapView( mapView ); - } - } -} === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate' === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java 2012-03-22 12:34:46 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLayerStore.java 1970-01-01 00:00:00 +0000 @@ -1,80 +0,0 @@ -package org.hisp.dhis.mapping.hibernate; - -/* - * Copyright (c) 2004-2012, 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.hibernate.Criteria; -import org.hibernate.Session; -import org.hibernate.criterion.Restrictions; -import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; -import org.hisp.dhis.mapping.MapLayer; -import org.hisp.dhis.mapping.MapLayerStore; - -import java.util.Collection; - -/** - * @author Jan Henrik Overland - */ -public class HibernateMapLayerStore - extends HibernateIdentifiableObjectStore - implements MapLayerStore -{ - @SuppressWarnings( "unchecked" ) - public Collection getMapLayersByType( String type ) - { - Session session = sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapLayer.class ); - - criteria.add( Restrictions.eq( "type", type ) ); - - return criteria.list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection getMapLayersByMapSourceType( String mapSourceType ) - { - Session session = sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapLayer.class ); - - criteria.add( Restrictions.eq( "mapSourceType", mapSourceType ) ); - - return criteria.list(); - } - - public MapLayer getMapLayerByMapSource( String mapSource ) - { - Session session = sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapLayer.class ); - - criteria.add( Restrictions.eq( "mapSource", mapSource ) ); - - return (MapLayer) criteria.uniqueResult(); - } -} === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java 2012-03-22 12:34:46 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendSetStore.java 1970-01-01 00:00:00 +0000 @@ -1,57 +0,0 @@ -package org.hisp.dhis.mapping.hibernate; - -/* - * Copyright (c) 2004-2012, 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.hibernate.Criteria; -import org.hibernate.Session; -import org.hibernate.criterion.Restrictions; -import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; -import org.hisp.dhis.mapping.MapLegendSet; -import org.hisp.dhis.mapping.MapLegendSetStore; - -import java.util.Collection; - -/** - * @author Jan Henrik Overland - */ -public class HibernateMapLegendSetStore - extends HibernateIdentifiableObjectStore - implements MapLegendSetStore -{ - @SuppressWarnings( "unchecked" ) - public Collection getMapLegendSetsByType( String type ) - { - Session session = this.sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapLegendSet.class ); - - criteria.add( Restrictions.eq( "type", type ) ); - - return criteria.list(); - } -} === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java 2012-03-22 12:34:46 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapLegendStore.java 1970-01-01 00:00:00 +0000 @@ -1,41 +0,0 @@ -package org.hisp.dhis.mapping.hibernate; - -/* - * Copyright (c) 2004-2012, 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.HibernateIdentifiableObjectStore; -import org.hisp.dhis.mapping.MapLegend; -import org.hisp.dhis.mapping.MapLegendStore; - -/** - * @author Jan Henrik Overland - */ -public class HibernateMapLegendStore - extends HibernateIdentifiableObjectStore - implements MapLegendStore -{ -} === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java' --- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java 2012-04-29 18:04:08 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMapViewStore.java 1970-01-01 00:00:00 +0000 @@ -1,80 +0,0 @@ -package org.hisp.dhis.mapping.hibernate; - -/* - * Copyright (c) 2004-2012, 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.hibernate.Criteria; -import org.hibernate.Session; -import org.hibernate.criterion.Restrictions; -import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; -import org.hisp.dhis.mapping.MapView; -import org.hisp.dhis.mapping.MapViewStore; -import org.hisp.dhis.user.User; - -import java.util.Collection; - -/** - * @author Jan Henrik Overland - */ -public class HibernateMapViewStore - extends HibernateIdentifiableObjectStore - implements MapViewStore -{ - @SuppressWarnings( "unchecked" ) - public Collection getSystemAndUserMapViews( User user ) - { - return getCriteria( - Restrictions.or( Restrictions.isNull( "user" ), - Restrictions.eq( "user", user ) ) ).list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection getMapViewsByMapSourceType( String mapSourceType ) - { - Session session = sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapView.class ); - - criteria.add( Restrictions.eq( "mapSourceType", mapSourceType ) ); - - return criteria.list(); - } - - @SuppressWarnings( "unchecked" ) - public Collection getMapViewsByFeatureType( String featureType, User user ) - { - Session session = sessionFactory.getCurrentSession(); - - Criteria criteria = session.createCriteria( MapView.class ); - - criteria.add( Restrictions.eq( "featureType", featureType ) ); - - criteria.add( Restrictions.or( Restrictions.eq( "user", user ), Restrictions.isNull( "user" ) ) ); - - return criteria.list(); - } -} === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis' === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 2012-04-29 18:04:08 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 1970-01-01 00:00:00 +0000 @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate' === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLayer.hbm.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLayer.hbm.xml 2012-03-19 22:10:02 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLayer.hbm.xml 1970-01-01 00:00:00 +0000 @@ -1,33 +0,0 @@ - -] -> - - - - - - - - &identifiableProperties; - - - - - - - - - - - - - - - - - - - === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegend.hbm.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegend.hbm.xml 2012-03-19 18:32:42 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegend.hbm.xml 1970-01-01 00:00:00 +0000 @@ -1,25 +0,0 @@ - -] -> - - - - - - - - &identifiableProperties; - - - - - - - - - - - === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml 2012-03-19 18:32:42 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapLegendSet.hbm.xml 1970-01-01 00:00:00 +0000 @@ -1,36 +0,0 @@ - -] -> - - - - - - - - &identifiableProperties; - - - - - - - - - - - - - - - - - - - - - - === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml' --- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml 2012-03-26 13:00:42 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml 1970-01-01 00:00:00 +0000 @@ -1,69 +0,0 @@ - -] -> - - - - - - - - &identifiableProperties; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test/java' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis' === removed directory 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping' === removed file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java' --- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2012-03-26 13:00:42 +0000 +++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 1970-01-01 00:00:00 +0000 @@ -1,507 +0,0 @@ -package org.hisp.dhis.mapping; - -/* - * Copyright (c) 2004-2012, 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 static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; - -import org.hisp.dhis.DhisSpringTest; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementGroup; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.indicator.IndicatorGroup; -import org.hisp.dhis.indicator.IndicatorService; -import org.hisp.dhis.indicator.IndicatorType; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitLevel; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.period.MonthlyPeriodType; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodService; -import org.hisp.dhis.period.PeriodType; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author Lars Helge Overland - * @version $Id$ - */ -public class MappingServiceTest - extends DhisSpringTest -{ - private MappingService mappingService; - - private OrganisationUnit organisationUnit; - - private OrganisationUnitLevel organisationUnitLevel; - - private IndicatorGroup indicatorGroup; - - private IndicatorType indicatorType; - - private Indicator indicator; - - private DataElement dataElement; - - private DataElementGroup dataElementGroup; - - private PeriodType periodType; - - private Period period; - - private MapLegendSet mapLegendSet; - - // ------------------------------------------------------------------------- - // Fixture - // ------------------------------------------------------------------------- - - @Override - public void setUpTest() - { - mappingService = (MappingService) getBean( MappingService.ID ); - - organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID ); - - indicatorService = (IndicatorService) getBean( IndicatorService.ID ); - - dataElementService = (DataElementService) getBean( DataElementService.ID ); - - periodService = (PeriodService) getBean( PeriodService.ID ); - - organisationUnit = createOrganisationUnit( 'A' ); - organisationUnitLevel = new OrganisationUnitLevel( 1, "Level" ); - - organisationUnitService.addOrganisationUnit( organisationUnit ); - organisationUnitService.addOrganisationUnitLevel( organisationUnitLevel ); - - indicatorGroup = createIndicatorGroup( 'A' ); - indicatorService.addIndicatorGroup( indicatorGroup ); - - indicatorType = createIndicatorType( 'A' ); - indicatorService.addIndicatorType( indicatorType ); - - indicator = createIndicator( 'A', indicatorType ); - indicatorService.addIndicator( indicator ); - - dataElement = createDataElement( 'A' ); - dataElementService.addDataElement( dataElement ); - - dataElementGroup = createDataElementGroup( 'A' ); - dataElementGroup.getMembers().add( dataElement ); - dataElementService.addDataElementGroup( dataElementGroup ); - - periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME ); - period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) ); - periodService.addPeriod( period ); - - mapLegendSet = createMapLegendSet( 'A', indicator ); - mappingService.addMapLegendSet( mapLegendSet ); - } - - // ------------------------------------------------------------------------- - // MapLegend - // ------------------------------------------------------------------------- - - @Test - public void testGetAddOrUpdateMapLegendByName() - { - MapLegend legend = createMapLegend( 'A', 0.1, 0.2 ); - - mappingService.addOrUpdateMapLegend( legend.getName(), legend.getStartValue(), legend.getEndValue(), - legend.getColor(), legend.getImage() ); - - legend = mappingService.getMapLegendByName( legend.getName() ); - - assertNotNull( legend ); - - int id = legend.getId(); - - mappingService.addOrUpdateMapLegend( legend.getName(), legend.getStartValue(), 0.3, "ColorB", "img.png" ); - - assertEquals( "MapLegendA", mappingService.getMapLegend( id ).getName() ); - assertEquals( 0.1, mappingService.getMapLegend( id ).getStartValue() ); - assertEquals( 0.3, mappingService.getMapLegend( id ).getEndValue() ); - assertEquals( "ColorB", mappingService.getMapLegend( id ).getColor() ); - assertEquals( "img.png", mappingService.getMapLegend( id ).getImage() ); - } - - @Test - public void testDeleteMapLegend() - { - MapLegend legend = createMapLegend( 'A', 0.1, 0.2 ); - - mappingService.addOrUpdateMapLegend( legend.getName(), legend.getStartValue(), legend.getEndValue(), - legend.getColor(), legend.getImage() ); - - legend = mappingService.getMapLegendByName( legend.getName() ); - - assertNotNull( legend ); - - int id = legend.getId(); - - mappingService.deleteMapLegend( legend ); - - assertNull( mappingService.getMapLegend( id ) ); - } - - @Test - public void testGetAllMapLegends() - { - MapLegend legend1 = createMapLegend( 'A', 0.1, 0.2 ); - MapLegend legend2 = createMapLegend( 'B', 0.3, 0.4 ); - MapLegend legend3 = createMapLegend( 'C', 0.5, 0.6 ); - - mappingService.addOrUpdateMapLegend( legend1.getName(), legend1.getStartValue(), legend1.getEndValue(), - legend1.getColor(), legend1.getImage() ); - mappingService.addOrUpdateMapLegend( legend3.getName(), legend3.getStartValue(), legend3.getEndValue(), - legend3.getColor(), legend3.getImage() ); - - legend1 = mappingService.getMapLegendByName( legend1.getName() ); - legend3 = mappingService.getMapLegendByName( legend3.getName() ); - - assertNotNull( legend1 ); - assertNotNull( legend3 ); - - int idA = legend1.getId(); - int idC = legend3.getId(); - - assertEquals( legend1, mappingService.getMapLegend( idA ) ); - assertEquals( legend3, mappingService.getMapLegend( idC ) ); - assertTrue( !mappingService.getAllMapLegends().contains( legend2 ) ); - } - - // ------------------------------------------------------------------------- - // MapLegendSet - // ------------------------------------------------------------------------- - - @Test - public void testAddGetMapLegendSet() - { - MapLegendSet legendSet = createMapLegendSet( 'B', indicator ); - - int id = mappingService.addMapLegendSet( legendSet ); - - assertNotNull( mappingService.getMapLegendSet( id ) ); - } - - @Test - public void testGetUpdateMapLegendSetByName() - { - MapLegendSet legendSet = createMapLegendSet( 'C', indicator ); - - int id = mappingService.addMapLegendSet( legendSet ); - - legendSet = mappingService.getMapLegendSet( id ); - - assertNotNull( legendSet ); - - legendSet.setName( "MapLegendSetB" ); - - mappingService.updateMapLegendSet( legendSet ); - - assertEquals( "MapLegendSetB", mappingService.getMapLegendSetByName( "MapLegendSetB" ).getName() ); - } - - @Test - public void testGetMapLegendSetsByType() - { - MapLegendSet legendSet1 = createMapLegendSet( 'B', indicator ); - MapLegendSet legendSet2 = createMapLegendSet( 'C', indicator ); - MapLegendSet legendSet3 = createMapLegendSet( 'D', indicator ); - - legendSet1.setType( MappingService.MAPLEGENDSET_TYPE_AUTOMATIC ); - legendSet2.setType( MappingService.MAPLEGENDSET_TYPE_PREDEFINED ); - legendSet3.setType( MappingService.MAPLEGENDSET_TYPE_PREDEFINED ); - - int idA = mappingService.addMapLegendSet( legendSet1 ); - int idB = mappingService.addMapLegendSet( legendSet2 ); - int idC = mappingService.addMapLegendSet( legendSet3 ); - - List autoTypes = new ArrayList( - mappingService.getMapLegendSetsByType( MappingService.MAPLEGENDSET_TYPE_AUTOMATIC ) ); - - List predefinedTypes = new ArrayList( - mappingService.getMapLegendSetsByType( MappingService.MAPLEGENDSET_TYPE_PREDEFINED ) ); - - assertTrue( autoTypes.contains( mappingService.getMapLegendSet( idA ) ) ); - assertTrue( !autoTypes.contains( mappingService.getMapLegendSet( idB ) ) ); - assertTrue( !autoTypes.contains( mappingService.getMapLegendSet( idC ) ) ); - assertTrue( predefinedTypes.contains( mappingService.getMapLegendSet( idB ) ) ); - assertTrue( predefinedTypes.contains( mappingService.getMapLegendSet( idC ) ) ); - assertTrue( !predefinedTypes.contains( mappingService.getMapLegendSet( idA ) ) ); - - } - - @Test - public void testGetMapLegendSetByIndicatorOrDataElement() - { - MapLegendSet legendSet1 = createMapLegendSet( 'B', indicator ); - MapLegendSet legendSet2 = createMapLegendSet( 'C', indicator ); - - int idB = mappingService.addMapLegendSet( legendSet1 ); - int idC = mappingService.addMapLegendSet( legendSet2 ); - - assertEquals( "1", mapLegendSet, mappingService.getMapLegendSetByIndicator( indicator.getId() ) ); - - legendSet1 = mappingService.getMapLegendSet( idB ); - legendSet2 = mappingService.getMapLegendSet( idC ); - - legendSet1.getDataElements().add( dataElement ); - legendSet2.getDataElements().add( dataElement ); - - mappingService.updateMapLegendSet( legendSet1 ); - mappingService.updateMapLegendSet( legendSet2 ); - - assertEquals( "2", mappingService.getMapLegendSet( idB ), - mappingService.getMapLegendSetByDataElement( dataElement.getId() ) ); - - } - - @Test - public void testGetAllMapLegendSets() - { - MapLegendSet legendSet1 = createMapLegendSet( 'B', indicator ); - MapLegendSet legendSet2 = createMapLegendSet( 'C', indicator ); - MapLegendSet legendSet3 = createMapLegendSet( 'D', indicator ); - - Collection mapLegendSets = new HashSet(); - - mapLegendSets.add( mapLegendSet ); - mapLegendSets.add( legendSet1 ); - mapLegendSets.add( legendSet2 ); - mapLegendSets.add( legendSet3 ); - - mappingService.addMapLegendSet( legendSet1 ); - mappingService.addMapLegendSet( legendSet2 ); - mappingService.addMapLegendSet( legendSet3 ); - - assertTrue( mappingService.getAllMapLegendSets().containsAll( mapLegendSets ) ); - - } - - @Test - public void testIndicatorHasMapLegendSet() - { - MapLegendSet legendSet1 = createMapLegendSet( 'B', indicator ); - MapLegendSet legendSet2 = createMapLegendSet( 'C', indicator ); - MapLegendSet legendSet3 = createMapLegendSet( 'D', indicator ); - - mappingService.addMapLegendSet( legendSet1 ); - mappingService.addMapLegendSet( legendSet2 ); - mappingService.addMapLegendSet( legendSet3 ); - - assertTrue( mappingService.indicatorHasMapLegendSet( indicator.getId() ) ); - } - - // ------------------------------------------------------------------------- - // MapView tests - // ------------------------------------------------------------------------- - - @Test - public void testAddGetMapView() - { - MapView mapView = new MapView( "MapViewA", null, MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "1", "1", 1 ); - - int idA = mappingService.addMapView( mapView ); - - assertEquals( mapView, mappingService.getMapView( idA ) ); - assertEquals( indicatorGroup, mappingService.getMapView( idA ).getIndicatorGroup() ); - assertEquals( indicator, mappingService.getMapView( idA ).getIndicator() ); - assertEquals( periodType, mappingService.getMapView( idA ).getPeriodType() ); - assertEquals( period, mappingService.getMapView( idA ).getPeriod() ); - } - - @Test - public void testGetDeleteMapViewByName() - { - MapView mapView = new MapView( "MapViewA", null, MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "1", "1", 1 ); - - int id = mappingService.addMapView( mapView ); - - mapView = mappingService.getMapViewByName( "MapViewA" ); - - mappingService.deleteMapView( mapView ); - - assertNull( mappingService.getMapView( id ) ); - } - - @Test - public void testGetAllMapViews() - { - MapView mapView1 = new MapView( "MapViewA", null, MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "1", "1", 1 ); - - MapView mapView2 = new MapView( "MapViewB", null, MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "2", "2", 1 ); - - mappingService.addMapView( mapView1 ); - mappingService.addMapView( mapView2 ); - - assertEquals( 2, mappingService.getAllMapViews().size() ); - } - - @Test - @Ignore - // TODO - public void testGetMapViewsByFeatureType() - { - MapView mapView1 = new MapView( "MapViewA", null, MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "1", "1", 1 ); - - MapView mapView2 = new MapView( "MapViewB", null, MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "2", "2", 1 ); - - MapView mapView3 = new MapView( "MapViewC", null, MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, - indicator, dataElementGroup, dataElement, periodType, period, - organisationUnit, organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", - mapLegendSet, 5, 20, "3", "3", 1 ); - - mappingService.addMapView( mapView1 ); - mappingService.addMapView( mapView2 ); - mappingService.addMapView( mapView3 ); - - assertEquals( 1, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_POLYGON ).size() ); - assertEquals( 2, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_MULTIPOLYGON ).size() ); - } - - // ------------------------------------------------------------------------- - // MapLayer - // ------------------------------------------------------------------------- - - @Test - public void testAddGetMapLayer() - { - MapLayer mapLayer = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "A", 0.1, - "B", 1 ); - - int id = mappingService.addMapLayer( mapLayer ); - - assertEquals( "MapLayerA", mappingService.getMapLayer( id ).getName() ); - assertEquals( MappingService.MAP_LAYER_TYPE_BASELAYER, mappingService.getMapLayer( id ).getType() ); - assertEquals( "A", mappingService.getMapLayer( id ).getFillColor() ); - assertEquals( "B", mappingService.getMapLayer( id ).getStrokeColor() ); - assertEquals( 0.1, mappingService.getMapLayer( id ).getFillOpacity() ); - assertEquals( 1, mappingService.getMapLayer( id ).getStrokeWidth() ); - } - - @Test - public void testGetUpdateDeleteMapLayerByName() - { - MapLayer mapLayer = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "A", 0.1, - "B", 1 ); - - int id = mappingService.addMapLayer( mapLayer ); - - mapLayer = mappingService.getMapLayer( id ); - - mapLayer.setName( "MapLayerB" ); - mapLayer.setFillOpacity( 0.05 ); - mapLayer.setStrokeWidth( 0 ); - - mappingService.updateMapLayer( mapLayer ); - - assertEquals( "MapLayerB", mappingService.getMapLayerByName( "MapLayerB" ).getName() ); - assertEquals( 0.05, mappingService.getMapLayerByName( "MapLayerB" ).getFillOpacity() ); - assertEquals( 0, mappingService.getMapLayerByName( "MapLayerB" ).getStrokeWidth() ); - } - - @Test - public void testGetAllMapLayers() - { - MapLayer mapLayer1 = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "A", 0.1, - "B", 1 ); - MapLayer mapLayer2 = new MapLayer( "MapLayerB", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "C", 0.2, - "D", 2 ); - MapLayer mapLayer3 = new MapLayer( "MapLayerC", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "E", 0.3, - "F", 3 ); - MapLayer mapLayer4 = new MapLayer( "MapLayerD", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "G", 0.4, - "H", 4 ); - - int idA = mappingService.addMapLayer( mapLayer1 ); - int idB = mappingService.addMapLayer( mapLayer2 ); - int idC = mappingService.addMapLayer( mapLayer3 ); - - assertEquals( mapLayer1, mappingService.getMapLayer( idA ) ); - assertEquals( mapLayer2, mappingService.getMapLayer( idB ) ); - assertEquals( mapLayer3, mappingService.getMapLayer( idC ) ); - assertTrue( !mappingService.getAllMapLayers().contains( mapLayer4 ) ); - - } - - @Test - public void testGetMapLayersByTypeOrMapSource() - { - List baseLayers = new ArrayList(); - List overlayLayers = new ArrayList(); - - MapLayer mapLayer1 = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "A", 0.1, - "B", 1 ); - MapLayer mapLayer2 = new MapLayer( "MapLayerB", MappingService.MAP_LAYER_TYPE_OVERLAY, "", "", "", "C", 0.2, - "D", 2 ); - MapLayer mapLayer3 = new MapLayer( "MapLayerC", MappingService.MAP_LAYER_TYPE_OVERLAY, "", "", "", "E", 0.3, - "F", 3 ); - MapLayer mapLayer4 = new MapLayer( "MapLayerD", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "", "G", 0.4, - "H", 4 ); - - baseLayers.add( mapLayer1 ); - baseLayers.add( mapLayer4 ); - - overlayLayers.add( mapLayer2 ); - overlayLayers.add( mapLayer3 ); - - mappingService.addMapLayer( mapLayer1 ); - mappingService.addMapLayer( mapLayer2 ); - mappingService.addMapLayer( mapLayer3 ); - mappingService.addMapLayer( mapLayer4 ); - - assertEquals( baseLayers, mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_BASELAYER ) ); - assertEquals( overlayLayers, mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_OVERLAY ) ); - } -} === modified file 'dhis-2/dhis-services/dhis-service-reporting/pom.xml' --- dhis-2/dhis-services/dhis-service-reporting/pom.xml 2012-08-03 11:05:49 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/pom.xml 2012-10-24 16:19:29 +0000 @@ -29,10 +29,6 @@ org.hisp.dhis dhis-service-core - - org.hisp.dhis - dhis-service-mapping - === modified file 'dhis-2/dhis-services/pom.xml' --- dhis-2/dhis-services/pom.xml 2012-08-03 11:05:49 +0000 +++ dhis-2/dhis-services/pom.xml 2012-10-24 16:19:29 +0000 @@ -20,7 +20,6 @@ dhis-service-datamart-default dhis-service-importexport dhis-service-reporting - dhis-service-mapping dhis-service-mapgeneration dhis-service-aggregationengine-default dhis-service-patient === modified file 'dhis-2/dhis-web/dhis-web-mapping/pom.xml' --- dhis-2/dhis-web/dhis-web-mapping/pom.xml 2012-08-03 11:05:49 +0000 +++ dhis-2/dhis-web/dhis-web-mapping/pom.xml 2012-10-24 16:19:29 +0000 @@ -36,10 +36,6 @@ org.hisp.dhis - dhis-service-mapping - - - org.hisp.dhis dhis-service-reporting