=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2014-05-22 12:40:24 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java 2014-06-11 19:26:43 +0000 @@ -28,27 +28,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.hisp.dhis.util.ContextUtils.clearIfNotModified; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.hisp.dhis.analytics.AggregationType; import org.hisp.dhis.analytics.AnalyticsService; import org.hisp.dhis.analytics.DataQueryParams; -import org.hisp.dhis.webapi.controller.WebOptions; -import org.hisp.dhis.webapi.webdomain.GeoFeature; import org.hisp.dhis.common.DimensionalObject; import org.hisp.dhis.common.NameableObjectUtils; import org.hisp.dhis.dxf2.utils.JacksonUtils; @@ -58,48 +40,68 @@ import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter; import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.webapi.controller.WebOptions; +import org.hisp.dhis.webapi.webdomain.GeoFeature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.hisp.dhis.util.ContextUtils.clearIfNotModified; + /** * @author Lars Helge Overland */ @Controller -@RequestMapping(value = GeoFeatureController.RESOURCE_PATH) +@RequestMapping( value = GeoFeatureController.RESOURCE_PATH ) public class GeoFeatureController { public static final String RESOURCE_PATH = "/geoFeatures"; - private static final Map FEATURE_TYPE_MAP = new HashMap() { { - put( OrganisationUnit.FEATURETYPE_POINT, GeoFeature.TYPE_POINT ); - put( OrganisationUnit.FEATURETYPE_MULTIPOLYGON, GeoFeature.TYPE_POLYGON ); - put( OrganisationUnit.FEATURETYPE_POLYGON, GeoFeature.TYPE_POLYGON ); - put( null, 0 ); - } }; - + private static final Map FEATURE_TYPE_MAP = new HashMap() + { + { + put( OrganisationUnit.FEATURETYPE_POINT, GeoFeature.TYPE_POINT ); + put( OrganisationUnit.FEATURETYPE_MULTIPOLYGON, GeoFeature.TYPE_POLYGON ); + put( OrganisationUnit.FEATURETYPE_POLYGON, GeoFeature.TYPE_POLYGON ); + put( null, 0 ); + } + }; + @Autowired private AnalyticsService analyticsService; - + @Autowired private OrganisationUnitGroupService organisationUnitGroupService; - + @RequestMapping( method = RequestMethod.GET, produces = "application/json" ) public void getGeoFeatures( @RequestParam String ou, @RequestParam Map parameters, HttpServletRequest request, HttpServletResponse response ) throws IOException { WebOptions options = new WebOptions( parameters ); boolean includeGroupSets = "detailed".equals( options.getViewClass() ); - + Set set = new HashSet(); set.add( ou ); - + DataQueryParams params = analyticsService.getFromUrl( set, null, AggregationType.SUM, null, false, false, false, false, false, false, null ); - + DimensionalObject dim = params.getDimension( DimensionalObject.ORGUNIT_DIM_ID ); - + List organisationUnits = NameableObjectUtils.asTypedList( dim.getItems() ); FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() ); @@ -112,9 +114,9 @@ } Collection groupSets = includeGroupSets ? organisationUnitGroupService.getAllOrganisationUnitGroupSets() : null; - + List features = new ArrayList(); - + for ( OrganisationUnit unit : organisationUnits ) { GeoFeature feature = new GeoFeature(); @@ -128,37 +130,37 @@ feature.setPn( unit.getParent() != null ? unit.getParent().getDisplayName() : null ); feature.setTy( FEATURE_TYPE_MAP.get( unit.getFeatureType() ) ); feature.setCo( unit.getCoordinates() ); - + if ( includeGroupSets ) { for ( OrganisationUnitGroupSet groupSet : groupSets ) { OrganisationUnitGroup group = unit.getGroupInGroupSet( groupSet ); - + if ( group != null ) { feature.getDimensions().put( groupSet.getUid(), group.getUid() ); } } } - + features.add( feature ); } - + Collections.sort( features, GeoFeatureTypeComparator.INSTANCE ); - + JacksonUtils.toJson( response.getOutputStream(), features ); } - + static class GeoFeatureTypeComparator implements Comparator { public static final GeoFeatureTypeComparator INSTANCE = new GeoFeatureTypeComparator(); - + @Override public int compare( GeoFeature o1, GeoFeature o2 ) { return Integer.valueOf( o1.getTy() ).compareTo( Integer.valueOf( o2.getTy() ) ); - } + } } }