← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9225: FRED-API: support update of facilities (wip)

 

------------------------------------------------------------
revno: 9225
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-12-08 19:07:13 +0300
message:
  FRED-API: support update of facilities (wip)
added:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToOrganisationUnitConverter.java
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils/
  dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtilsTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  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/utils/GeoUtils.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml
  dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm
  dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm


--
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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-12-04 15:27:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2012-12-08 16:07:13 +0000
@@ -389,7 +389,9 @@
     @Override
     public String toString()
     {
-        return "[" + name + "]";
+        return "DataSet{" +
+            "name=" + name +
+            '}';
     }
 
     // -------------------------------------------------------------------------

=== 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-08 08:31:02 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-08 16:07:13 +0000
@@ -34,21 +34,25 @@
 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.ValidationUtils;
+import org.hisp.dhis.web.webapi.v1.validation.group.UpdateSequence;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.core.convert.ConversionService;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.*;
 
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
 
@@ -69,6 +73,9 @@
     @Qualifier( "conversionService" )
     private ConversionService conversionService;
 
+    @Autowired
+    private Validator validator;
+
     //--------------------------------------------------------------------------
     // GET HTML
     //--------------------------------------------------------------------------
@@ -115,20 +122,65 @@
     // POST JSON
     //--------------------------------------------------------------------------
 
-    @RequestMapping( value = "/{id}", method = RequestMethod.POST )
-    public ResponseEntity<Void> createFacility()
+    @RequestMapping( value = "", method = RequestMethod.POST )
+    public ResponseEntity<String> createFacility( @RequestBody Facility facility ) throws IOException
     {
-        return new ResponseEntity<Void>( HttpStatus.OK );
+        OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
+
+        return new ResponseEntity<String>( "ok", HttpStatus.OK );
+
+        /*
+        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, CreateSequence.class );
+
+        String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
+
+        if ( constraintViolations.isEmpty() )
+        {
+            return new ResponseEntity<String>( json, HttpStatus.OK );
+        }
+        else
+        {
+            return new ResponseEntity<String>( json, HttpStatus.UNPROCESSABLE_ENTITY );
+        }
+        */
     }
 
     //--------------------------------------------------------------------------
     // PUT JSON
     //--------------------------------------------------------------------------
 
-    @RequestMapping( value = "/{id}", method = RequestMethod.PUT )
-    public ResponseEntity<Void> updateFacility()
+    @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
+    public ResponseEntity<String> updateFacility( @PathVariable String id, @RequestBody Facility facility ) throws IOException
     {
-        return new ResponseEntity<Void>( HttpStatus.OK );
+        facility.setId( id );
+        OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
+
+        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, UpdateSequence.class );
+
+        String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
+
+        if ( constraintViolations.isEmpty() )
+        {
+            OrganisationUnit ou = organisationUnitService.getOrganisationUnit( facility.getId() );
+
+            ou.setName( organisationUnit.getName() );
+            ou.setShortName( organisationUnit.getShortName() );
+
+            ou.setFeatureType( organisationUnit.getFeatureType() );
+            ou.setCoordinates( organisationUnit.getCoordinates() );
+            ou.setDataSets( organisationUnit.getDataSets() );
+            ou.setParent( organisationUnit.getParent() );
+
+            ou.setActive( organisationUnit.isActive() );
+
+            organisationUnitService.updateOrganisationUnit( ou );
+
+            return new ResponseEntity<String>( json, HttpStatus.OK );
+        }
+        else
+        {
+            return new ResponseEntity<String>( json, HttpStatus.UNPROCESSABLE_ENTITY );
+        }
     }
 
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtils.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtils.java	2012-12-08 11:49:49 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtils.java	2012-12-08 16:07:13 +0000
@@ -36,23 +36,68 @@
  */
 final public class GeoUtils
 {
+    public static enum CoordinateOrder
+    {
+        COORDINATE_LATLNG,
+        COORDINATE_LNGLAT
+    }
+
     public static class Coordinates
     {
         public Double lat = 0.0d;
 
         public Double lng = 0.0d;
+
+        @Override
+        public String toString()
+        {
+            return "Coordinates{" +
+                "lat=" + lat +
+                ", lng=" + lng +
+                '}';
+        }
     }
 
+    // helper for most common case, our internal lnglat to latlng
     public static Coordinates parseCoordinates( String coordinatesString )
     {
+        return parseCoordinates( coordinatesString, CoordinateOrder.COORDINATE_LNGLAT, CoordinateOrder.COORDINATE_LATLNG );
+    }
+
+    public static Coordinates parseCoordinates( String coordinatesString, CoordinateOrder from, CoordinateOrder to )
+    {
         Coordinates coordinates = new Coordinates();
 
         try
         {
             List list = new ObjectMapper().readValue( coordinatesString, List.class );
 
-            coordinates.lat = convertToDouble( list.get( 1 ) );
-            coordinates.lng = convertToDouble( list.get( 0 ) );
+            if ( from == CoordinateOrder.COORDINATE_LATLNG )
+            {
+                if ( to == CoordinateOrder.COORDINATE_LATLNG )
+                {
+                    coordinates.lat = convertToDouble( list.get( 0 ) );
+                    coordinates.lng = convertToDouble( list.get( 1 ) );
+                }
+                else if ( to == CoordinateOrder.COORDINATE_LNGLAT )
+                {
+                    coordinates.lat = convertToDouble( list.get( 1 ) );
+                    coordinates.lng = convertToDouble( list.get( 0 ) );
+                }
+            }
+            else if ( from == CoordinateOrder.COORDINATE_LNGLAT )
+            {
+                if ( to == CoordinateOrder.COORDINATE_LATLNG )
+                {
+                    coordinates.lat = convertToDouble( list.get( 0 ) );
+                    coordinates.lng = convertToDouble( list.get( 1 ) );
+                }
+                else if ( to == CoordinateOrder.COORDINATE_LNGLAT )
+                {
+                    coordinates.lat = convertToDouble( list.get( 0 ) );
+                    coordinates.lng = convertToDouble( list.get( 1 ) );
+                }
+            }
         }
         catch ( Exception ignored )
         {

=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToOrganisationUnitConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ToOrganisationUnitConverter.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/ToOrganisationUnitConverter.java	2012-12-08 16:07:13 +0000
@@ -0,0 +1,93 @@
+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.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.web.webapi.v1.domain.Facility;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Component
+public class ToOrganisationUnitConverter implements Converter<Facility, OrganisationUnit>
+{
+    @Autowired
+    @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    @Qualifier( "org.hisp.dhis.dataset.DataSetService" )
+    private DataSetService dataSetService;
+
+    @Override
+    public OrganisationUnit convert( Facility facility )
+    {
+        OrganisationUnit organisationUnit = new OrganisationUnit();
+
+        organisationUnit.setUid( facility.getId() );
+        organisationUnit.setName( facility.getName() );
+
+        if ( facility.getName().length() > 49 )
+        {
+            organisationUnit.setShortName( facility.getName().substring( 0, 49 ) );
+        }
+        else
+        {
+            organisationUnit.setShortName( facility.getName() );
+        }
+
+        organisationUnit.setActive( facility.getActive() );
+        organisationUnit.setParent( organisationUnitService.getOrganisationUnit( (String) facility.getProperties().get( "parent" ) ) );
+
+        Collection<String> dataSets = (Collection<String>) facility.getProperties().get( "dataSets" );
+
+        for ( String uid : dataSets )
+        {
+            DataSet dataSet = dataSetService.getDataSet( uid );
+            organisationUnit.getDataSets().add( dataSet );
+        }
+
+        organisationUnit.setFeatureType( OrganisationUnit.FEATURETYPE_POINT );
+
+        GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates(
+            facility.getCoordinates().toString(), GeoUtils.CoordinateOrder.COORDINATE_LATLNG, GeoUtils.CoordinateOrder.COORDINATE_LNGLAT );
+
+        organisationUnit.setCoordinates( String.format( "[%f, %f]", coordinates.lng, coordinates.lat ) );
+
+        return organisationUnit;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml	2012-12-08 08:31:02 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml	2012-12-08 16:07:13 +0000
@@ -15,6 +15,7 @@
     <property name="converters">
       <set>
         <ref bean="toFacilityConverter" />
+        <ref bean="toOrganisationUnitConverter" />
       </set>
     </property>
   </bean>

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm	2012-12-07 14:16:37 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm	2012-12-08 16:07:13 +0000
@@ -53,9 +53,7 @@
 <table class="table table-bordered table-striped table-condensed">
     <thead>
     <tr>
-        <th>ID</th>
         <th>Name</th>
-        <th>Active</th>
         <th>Actions</th>
     </tr>
     </thead>
@@ -63,26 +61,20 @@
     <tbody>
         #foreach( $facility in $entity.facilities )
         <tr>
-            <td class="facility-id" style="width: 1px;">$facility.id</td>
             <td class="facility-name"><a href="$facility.url">$facility.name</a></td>
-            <td class="facility-active" style="width: 1px;">
-                #if( $facility.active )
-                    <button style="width: 44px;" class="deactivateButton btn btn-mini btn-success">
-                        <span class="icon-white icon-ok-circle"> </span>
-                    </button>
-                #else
-                    <button style="width: 44px;" class="activateButton btn btn-mini btn-inverse">
-                        <span class="icon-white icon-ban-circle"> </span>
-                    </button>
-                #end
-            </td>
 
             <td class="facility-actions" style="width: 1px;">
                 <div class="btn-group">
-                    <button disabled="disabled" style="width: 42px;" class="editButton btn btn-mini btn-info">
-                        <span class="icon-white icon-edit"> </span>
-                    </button>
-                    <button disabled="disabled" style="width: 42px;" class="deleteButton btn btn-mini btn-danger">
+                    #if( $facility.active )
+                        <button style="width: 44px;" class="deactivateButton btn btn-mini btn-success" title="Deactivate Facility">
+                            <span class="icon-white icon-ok-circle"> </span>
+                        </button>
+                    #else
+                        <button style="width: 44px;" class="activateButton btn btn-mini btn-inverse" title="Activate Facility">
+                            <span class="icon-white icon-ban-circle"> </span>
+                        </button>
+                    #end
+                    <button disabled="disabled" style="width: 42px;" class="deleteButton btn btn-mini btn-danger" title="Delete Facility">
                         <span class="icon-white icon-trash"> </span>
                     </button>
                 </div>

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm	2012-12-08 11:50:26 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm	2012-12-08 16:07:13 +0000
@@ -1,6 +1,24 @@
-<script src="http://maps.google.com/maps/api/js?sensor=false";></script>
+<script src="//maps.google.com/maps/api/js?sensor=false"></script>
 
 <script>
+    function updateMap(coordinates) {
+        var latlng = new google.maps.LatLng(coordinates[0], coordinates[1]);
+
+        var options = {
+            zoom: 12,
+            center: latlng,
+            mapTypeId: google.maps.MapTypeId.HYBRID
+        };
+
+        var map = new google.maps.Map(document.getElementById('mapTarget'), options);
+
+        var marker = new google.maps.Marker({
+            position: latlng,
+            map: map,
+            title: '$entity.name'
+        });
+    }
+
     $(function () {
         var coordinates = JSON.parse("$entity.coordinates");
 
@@ -8,33 +26,54 @@
             $('#facilityLatitude').val(coordinates[0]);
             $('#facilityLongitude').val(coordinates[1]);
 
-            var latlng = new google.maps.LatLng(coordinates[0], coordinates[1]);
-
-            var options = {
-                zoom: 12,
-                center: latlng,
-                mapTypeId: google.maps.MapTypeId.HYBRID
-            };
-
-            var map = new google.maps.Map(document.getElementById("mapTarget"), options);
-
-            var marker = new google.maps.Marker({
-                position: latlng,
-                map: map,
-                title: "$entity.name"
+            updateMap(coordinates);
+        } else {
+            $('#mapTarget').html('<div style="text-align: center;">No coordinates provided.</div>')
+                .parent().addClass('hidden-phone');
+        }
+
+        $('#facilityForm').submit(function (e) {
+            e.preventDefault();
+
+            $.get('$baseUrl/facilities/${entity.id}.json').success(function (data) {
+
+                delete data.createdAt;
+                delete data.updatedAt;
+                delete data.url;
+
+                data.name = $('#facilityName').val();
+                data.active = JSON.parse($('#facilityActive').val());
+
+                var lat = $('#facilityLatitude').val();
+                var lng = $('#facilityLongitude').val();
+
+                data.coordinates = [ lat, lng ];
+
+                $.ajax({
+                    url: '$baseUrl/facilities/${entity.id}',
+                    contentType: 'application/json; charset=UTF-8',
+                    type: 'PUT',
+                    data: JSON.stringify(data),
+                    dataType: 'json'
+                }).success(function (data) {
+                    console.log("save success!", data);
+                }).error(function (data) {
+                    console.log("could not update!", data);
+                });
             });
-        }
+        });
     });
 </script>
 
 <div class="container-fluid">
-    <div class="span4">
+    <div class="span5 well" style="padding: 4px;">
         <div style="height: 320px;" id="mapTarget"></div>
     </div>
 
-    <div class="span4">
+    <div class="span6">
         <form id="facilityForm">
             #set( $inputSize = "span12")
+            #set( $canEdit = true )
 
             <fieldset>
                 <legend>Facility</legend>
@@ -43,24 +82,30 @@
                 <input id="facilityID" disabled="disabled" type="text" class="$inputSize" value="$entity.id"/>
 
                 <label for="facilityName">Name</label>
-                <input #if(true)disabled#end id="facilityName" type="text" class="$inputSize" value="$entity.name"/>
+                <input #if(!$canEdit)disabled#end id="facilityName" type="text" class="$inputSize" value="$entity.name"/>
 
                 <label for="facilityActive">Active</label>
 
-                <select id="facilityActive" #if(true)disabled#end class="$inputSize">
+                <select id="facilityActive" #if(!$canEdit)disabled#end class="$inputSize">
                     <option value="true" #if($entity.active)selected#end>Yes</option>
                     <option value="false" #if(!$entity.active)selected#end>No</option>
                 </select>
 
                 <label for="facilityLatitude">Latitude</label>
-                <input #if(true)disabled#end id="facilityLatitude" type="text" class="$inputSize" value=""/>
+                <input #if(!$canEdit)disabled#end id="facilityLatitude" type="text" class="$inputSize" value=""/>
 
                 <label for="facilityLongitude">Longitude</label>
-                <input #if(true)disabled#end id="facilityLongitude" type="text" class="$inputSize" value=""/>
+                <input #if(!$canEdit)disabled#end id="facilityLongitude" type="text" class="$inputSize" value=""/>
             </fieldset>
 
-            <button #if(true)disabled#end type="submit" class="btn btn-info">Update</button>
+            <button #if(!$canEdit)disabled#end type="submit" class="btn btn-info">Update</button>
         </form>
     </div>
+
+    <div class="span1">
+        <button disabled="disabled" style="width: 42px;" class="deleteButton btn btn-mini btn-danger pull-right" title="Delete Facility">
+            <span class="icon-white icon-trash"> </span>
+        </button>
+    </div>
 </div>
 

=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1'
=== added directory 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils'
=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtilsTest.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtilsTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/utils/GeoUtilsTest.java	2012-12-08 16:07:13 +0000
@@ -0,0 +1,97 @@
+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.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class GeoUtilsTest
+{
+    @Test
+    public void latToLat()
+    {
+        Double lat = 1.0d;
+        Double lng = 2.0d;
+
+        String coordinatesString = String.format( "[%f, %f]", lat, lng );
+
+        GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( coordinatesString, GeoUtils.CoordinateOrder.COORDINATE_LATLNG,
+            GeoUtils.CoordinateOrder.COORDINATE_LATLNG );
+
+        Assert.assertEquals( lat, coordinates.lat );
+        Assert.assertEquals( lng, coordinates.lng );
+    }
+
+    @Test
+    public void lngToLng()
+    {
+        Double lat = 1.0d;
+        Double lng = 2.0d;
+
+        String coordinatesString = String.format( "[%f, %f]", lat, lng );
+
+        GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( coordinatesString, GeoUtils.CoordinateOrder.COORDINATE_LNGLAT,
+            GeoUtils.CoordinateOrder.COORDINATE_LNGLAT );
+
+        Assert.assertEquals( lng, coordinates.lng );
+        Assert.assertEquals( lat, coordinates.lat );
+    }
+
+    @Test
+    public void latToLng()
+    {
+        Double lat = 1.0d;
+        Double lng = 2.0d;
+
+        String coordinatesString = String.format( "[%f, %f]", lat, lng );
+
+        GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( coordinatesString, GeoUtils.CoordinateOrder.COORDINATE_LATLNG,
+            GeoUtils.CoordinateOrder.COORDINATE_LNGLAT );
+
+        Assert.assertEquals( lat, coordinates.lng );
+        Assert.assertEquals( lng, coordinates.lat );
+    }
+
+    @Test
+    public void lngToLat()
+    {
+        Double lat = 1.0d;
+        Double lng = 2.0d;
+
+        String coordinatesString = String.format( "[%f, %f]", lng, lat );
+
+        GeoUtils.Coordinates coordinates = GeoUtils.parseCoordinates( coordinatesString, GeoUtils.CoordinateOrder.COORDINATE_LNGLAT,
+            GeoUtils.CoordinateOrder.COORDINATE_LATLNG );
+
+        Assert.assertEquals( lng, coordinates.lat );
+        Assert.assertEquals( lat, coordinates.lng );
+    }
+}