dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20312
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9213: FRED-API: minor change
------------------------------------------------------------
revno: 9213
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-07 22:54:25 +0300
message:
FRED-API: minor change
removed:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java
added:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java
modified:
dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-07 19:21:53 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2012-12-07 19:54:25 +0000
@@ -34,7 +34,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.web.webapi.v1.domain.Facilities;
import org.hisp.dhis.web.webapi.v1.domain.Facility;
-import org.hisp.dhis.web.webapi.v1.utils.OrganisationUnitToFacilityConverter;
+import org.hisp.dhis.web.webapi.v1.utils.ToFacilityConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.convert.converter.Converter;
@@ -66,7 +66,7 @@
@Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
private OrganisationUnitService organisationUnitService;
- private Converter<OrganisationUnit, Facility> convertToFacility = new OrganisationUnitToFacilityConverter();
+ private static Converter<OrganisationUnit, Facility> toFacility = new ToFacilityConverter();
//--------------------------------------------------------------------------
// GET HTML
@@ -82,7 +82,8 @@
for ( OrganisationUnit organisationUnit : allOrganisationUnits )
{
- Facility facility = convertToFacility.convert( organisationUnit );
+ Facility facility = toFacility.convert( organisationUnit );
+
facilities.getFacilities().add( facility );
}
@@ -98,7 +99,8 @@
public String readFacility( Model model, @PathVariable String id )
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
- Facility facility = convertToFacility.convert( organisationUnit );
+
+ Facility facility = toFacility.convert( organisationUnit );
model.addAttribute( "entity", facility );
model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );
=== removed file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java 2012-12-07 19:21:53 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java 1970-01-01 00:00:00 +0000
@@ -1,96 +0,0 @@
-package org.hisp.dhis.web.webapi.v1.utils;
-
-/*
- * 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.dataset.DataSet;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.web.webapi.v1.controller.FacilityController;
-import org.hisp.dhis.web.webapi.v1.domain.Facility;
-import org.springframework.core.convert.converter.Converter;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class OrganisationUnitToFacilityConverter implements Converter<OrganisationUnit, Facility>
-{
- @Override
- public Facility convert( OrganisationUnit organisationUnit )
- {
- Facility facility = new Facility();
- facility.setId( organisationUnit.getUid() );
- facility.setName( organisationUnit.getDisplayName() );
- facility.setActive( organisationUnit.isActive() );
- facility.setCreatedAt( organisationUnit.getLastUpdated() );
- facility.setUpdatedAt( organisationUnit.getLastUpdated() );
- facility.setUrl( linkTo( FacilityController.class ).slash( facility.getId() ).toString() );
-
- if ( organisationUnit.getFeatureType() != null && organisationUnit.getFeatureType().equalsIgnoreCase( "POINT" )
- && organisationUnit.getCoordinates() != null )
- {
- GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( organisationUnit.getCoordinates() );
- facility.getCoordinates().add( coordinates.lat );
- facility.getCoordinates().add( coordinates.lng );
- }
-
- if ( organisationUnit.getParent() != null )
- {
- facility.getProperties().put( "parent", organisationUnit.getParent().getUid() );
- }
-
- if ( organisationUnit.getCode() != null )
- {
- Map<String, String> codeMap = new HashMap<String, String>();
- codeMap.put( "agency", "DHIS2" );
- codeMap.put( "context", "DHIS2_CODE" );
- codeMap.put( "id", organisationUnit.getCode() );
-
- facility.getIdentifiers().add( codeMap );
- }
-
- if ( !organisationUnit.getDataSets().isEmpty() )
- {
- List<String> dataSets = new ArrayList<String>();
-
- for ( DataSet dataSet : organisationUnit.getDataSets() )
- {
- dataSets.add( dataSet.getUid() );
- }
-
- facility.getProperties().put( "dataSets", dataSets );
- }
-
- return facility;
- }
-}
=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToFacilityConverter.java 2012-12-07 19:54:25 +0000
@@ -0,0 +1,96 @@
+package org.hisp.dhis.web.webapi.v1.utils;
+
+/*
+ * 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.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.web.webapi.v1.controller.FacilityController;
+import org.hisp.dhis.web.webapi.v1.domain.Facility;
+import org.springframework.core.convert.converter.Converter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ToFacilityConverter implements Converter<OrganisationUnit, Facility>
+{
+ @Override
+ public Facility convert( OrganisationUnit organisationUnit )
+ {
+ Facility facility = new Facility();
+ facility.setId( organisationUnit.getUid() );
+ facility.setName( organisationUnit.getDisplayName() );
+ facility.setActive( organisationUnit.isActive() );
+ facility.setCreatedAt( organisationUnit.getLastUpdated() );
+ facility.setUpdatedAt( organisationUnit.getLastUpdated() );
+ facility.setUrl( linkTo( FacilityController.class ).slash( facility.getId() ).toString() );
+
+ if ( organisationUnit.getFeatureType() != null && organisationUnit.getFeatureType().equalsIgnoreCase( "POINT" )
+ && organisationUnit.getCoordinates() != null )
+ {
+ GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( organisationUnit.getCoordinates() );
+ facility.getCoordinates().add( coordinates.lat );
+ facility.getCoordinates().add( coordinates.lng );
+ }
+
+ if ( organisationUnit.getParent() != null )
+ {
+ facility.getProperties().put( "parent", organisationUnit.getParent().getUid() );
+ }
+
+ if ( organisationUnit.getCode() != null )
+ {
+ Map<String, String> codeMap = new HashMap<String, String>();
+ codeMap.put( "agency", "DHIS2" );
+ codeMap.put( "context", "DHIS2_CODE" );
+ codeMap.put( "id", organisationUnit.getCode() );
+
+ facility.getIdentifiers().add( codeMap );
+ }
+
+ if ( !organisationUnit.getDataSets().isEmpty() )
+ {
+ List<String> dataSets = new ArrayList<String>();
+
+ for ( DataSet dataSet : organisationUnit.getDataSets() )
+ {
+ dataSets.add( dataSet.getUid() );
+ }
+
+ facility.getProperties().put( "dataSets", dataSets );
+ }
+
+ return facility;
+ }
+}