← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9201: FRED-API: added new controller for providing services to the facilitity API (available from /api-...

 

------------------------------------------------------------
revno: 9201
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-07 16:04:36 +0300
message:
  FRED-API: added new controller for providing services to the facilitity API (available from /api-fred/v1/facility-service/*). Also minor UI fixes for HTML rendering.
added:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java
modified:
  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/resources/META-INF/dhis/beans.xml
  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/layout.vm
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.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-06 21:41:42 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-07 13:04:36 +0000
@@ -29,6 +29,7 @@
 
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.web.webapi.v1.domain.Facilities;
@@ -124,40 +125,13 @@
     //--------------------------------------------------------------------------
 
     @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
-    public ResponseEntity<Void> deleteFacility()
-    {
-        return new ResponseEntity<Void>( HttpStatus.OK );
-    }
-
-    //--------------------------------------------------------------------------
-    // EXTRA WEB METHODS
-    //--------------------------------------------------------------------------
-
-    @RequestMapping( value = "/activate/{id}", method = RequestMethod.POST )
-    public ResponseEntity<Void> activateFacility( @PathVariable String id )
-    {
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
-
-        if ( organisationUnit != null )
-        {
-            organisationUnit.setActive( true );
-            organisationUnitService.updateOrganisationUnit( organisationUnit );
-
-            return new ResponseEntity<Void>( HttpStatus.OK );
-        }
-
-        return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
-    }
-
-    @RequestMapping( value = "/deactivate/{id}", method = RequestMethod.POST )
-    public ResponseEntity<Void> deactivateFacility( @PathVariable String id )
-    {
-        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
-
-        if ( organisationUnit != null )
-        {
-            organisationUnit.setActive( false );
-            organisationUnitService.updateOrganisationUnit( organisationUnit );
+    public ResponseEntity<Void> deleteFacility( @PathVariable String id ) throws HierarchyViolationException
+    {
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( organisationUnit != null )
+        {
+            organisationUnitService.deleteOrganisationUnit( organisationUnit );
 
             return new ResponseEntity<Void>( HttpStatus.OK );
         }
@@ -173,7 +147,7 @@
     {
         Facility facility = new Facility();
         facility.setId( organisationUnit.getUid() );
-        facility.setName( organisationUnit.getName() );
+        facility.setName( organisationUnit.getDisplayName() );
         facility.setActive( organisationUnit.isActive() );
         facility.setCreatedAt( organisationUnit.getLastUpdated() );
         facility.setUpdatedAt( organisationUnit.getLastUpdated() );
@@ -215,4 +189,16 @@
 
         return facility;
     }
+
+    //--------------------------------------------------------------------------
+    // EXCEPTION HANDLERS
+    //--------------------------------------------------------------------------
+
+/*
+    @ExceptionHandler( Exception.class )
+    public ResponseEntity<String> exceptionHandler( Exception ex )
+    {
+        return new ResponseEntity<String>( ex.getMessage(), HttpStatus.FORBIDDEN );
+    }
+*/
 }

=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.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/controller/FacilityServiceController.java	2012-12-07 13:04:36 +0000
@@ -0,0 +1,89 @@
+package org.hisp.dhis.web.webapi.v1.controller;
+
+/*
+ * 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.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller( value = "facility-service-controller-" + FredController.PREFIX )
+@RequestMapping( FacilityServiceController.RESOURCE_PATH )
+public class FacilityServiceController
+{
+    public static final String RESOURCE_PATH = "/" + FredController.PREFIX + "/facility-service";
+
+    @Autowired
+    @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
+    private OrganisationUnitService organisationUnitService;
+
+    //--------------------------------------------------------------------------
+    // EXTRA WEB METHODS
+    //--------------------------------------------------------------------------
+
+    @RequestMapping( value = "/{id}/activate", method = RequestMethod.POST )
+    public ResponseEntity<Void> activateFacility( @PathVariable String id )
+    {
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( organisationUnit != null )
+        {
+            organisationUnit.setActive( true );
+            organisationUnitService.updateOrganisationUnit( organisationUnit );
+
+            return new ResponseEntity<Void>( HttpStatus.OK );
+        }
+
+        return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
+    }
+
+    @RequestMapping( value = "/{id}/deactivate", method = RequestMethod.POST )
+    public ResponseEntity<Void> deactivateFacility( @PathVariable String id )
+    {
+        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( organisationUnit != null )
+        {
+            organisationUnit.setActive( false );
+            organisationUnitService.updateOrganisationUnit( organisationUnit );
+
+            return new ResponseEntity<Void>( HttpStatus.OK );
+        }
+
+        return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml	2012-12-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/beans.xml	2012-12-07 13:04:36 +0000
@@ -2,6 +2,6 @@
 <beans xmlns="http://www.springframework.org/schema/beans";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="
-http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd";>
+    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd";>
 
 </beans>

=== 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-06 20:06:23 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/resources/META-INF/dhis/webapi-fred.xml	2012-12-07 13:04:36 +0000
@@ -2,7 +2,8 @@
 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xmlns="http://www.springframework.org/schema/beans";
   xmlns:context="http://www.springframework.org/schema/context";
-  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+  xsi:schemaLocation="
+    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd";>
 
   <context:component-scan base-package="org.hisp.dhis.web.webapi" />

=== 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-06 22:11:44 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm	2012-12-07 13:04:36 +0000
@@ -5,7 +5,7 @@
                 var id = $(this).parent().parent().find('.facility-id').text();
 
                 $.ajax({
-                    url: 'facilities/activate/' + id,
+                    url: 'facility-service/' + id + '/activate',
                     type: 'POST',
                     async: false
                 }).complete(function () {
@@ -19,7 +19,7 @@
                 var id = $(this).parent().parent().find('.facility-id').text();
 
                 $.ajax({
-                    url: 'facilities/deactivate/' + id,
+                    url: 'facility-service/' + id + '/deactivate',
                     type: 'POST',
                     async: false
                 }).complete(function () {
@@ -31,9 +31,11 @@
 </script>
 
 <style>
+/*
     .table > tbody > tr:hover {
-        background-color: #f5f5f5;
+        background-color : #f5f5f5;
     }
+*/
 </style>
 
 <div class="btn-group pull-right">
@@ -48,7 +50,7 @@
     -->
 </div>
 
-<table class="table table-bordered">
+<table class="table table-bordered table-striped table-condensed">
     <thead>
     <tr>
         <th>ID</th>
@@ -59,25 +61,33 @@
     </thead>
 
     <tbody>
-    #foreach( $facility in $entity.facilities )
-    <tr>
-        <td class="facility-id" style="width: 1px;">$facility.id</td>
-        <td class="facility-name"><a href="facilities/$facility.id">$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>
+        #foreach( $facility in $entity.facilities )
+        <tr>
+            <td class="facility-id" style="width: 1px;">$facility.id</td>
+            <td class="facility-name"><a href="facilities/$facility.id">$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"><span class="icon-white icon-trash"> </span> </button>
-            </div>
-        </td>
-    </tr>
-    #end
+            <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">
+                        <span class="icon-white icon-trash"> </span>
+                    </button>
+                </div>
+            </td>
+        </tr>
+        #end
     </tbody>
 </table>

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm	2012-12-06 21:55:24 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/layout.vm	2012-12-07 13:04:36 +0000
@@ -12,7 +12,7 @@
     <link href="$baseUrl/api-fred-resources/css//bootstrap.min.css?v2.2.1" rel="stylesheet">
     <style>
         body {
-            padding-top: 60px;
+            padding-top : 60px;
         }
     </style>
     <link href="$baseUrl/api-fred-resources/css/bootstrap-responsive.min.css?v2.2.1" rel="stylesheet">
@@ -33,30 +33,21 @@
                 <span class="icon-bar"></span>
             </a>
 
-            <a class="brand" href="#">FRED Facility API v1.0</a>
+            <a class="brand" href="../v1">FRED Facility API v1.0</a>
 
             <div class="nav-collapse collapse">
                 <ul class="nav">
                     <li #if( $pageName == "home" )class="active"#end><a href="../"><span class="icon-home"> </span> Home</a></li>
+                    <li #if( $pageName == "facilities" )class="active"#end><a href="v1/facilities"><span class="icon-search"> </span> Facilities</a></li>
                 </ul>
             </div>
         </div>
     </div>
 </div>
 
-
 <div class="container-fluid">
     <div class="row-fluid">
-        <div class="span3">
-            <div class="well sidebar-nav">
-                <ul class="nav nav-list">
-                    <li class="nav-header">Resources</li>
-                    <li #if( $pageName == "facilities" )class="active"#end><a href="v1/facilities">Facilities</a></li>
-                </ul>
-            </div>
-        </div>
-
-        <div class="span9">
+        <div class="span12">
             #parse( $page )
         </div>
     </div>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-11-29 13:22:38 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-12-07 13:04:36 +0000
@@ -54,7 +54,7 @@
 import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_XML;
 
 @Controller
-@RequestMapping( value = DataValueSetController.RESOURCE_PATH )
+@RequestMapping(value = DataValueSetController.RESOURCE_PATH)
 public class DataValueSetController
 {
     public static final String RESOURCE_PATH = "/dataValueSets";
@@ -67,7 +67,7 @@
     @Autowired
     private IntegrationService integrationService;
 
-    @RequestMapping( method = RequestMethod.GET, produces = { "text/html", "text/plain" } )
+    @RequestMapping(method = RequestMethod.GET, produces = { "text/html", "text/plain" })
     public String getDataValueSets( Model model ) throws Exception
     {
         DataValueSets dataValueSets = new DataValueSets();
@@ -78,7 +78,7 @@
         return "dataValueSets";
     }
 
-    @RequestMapping( method = RequestMethod.GET, produces = "application/xml" )
+    @RequestMapping(method = RequestMethod.GET, produces = "application/xml")
     public void getDataValueSet( @RequestParam String dataSet, @RequestParam String period,
         @RequestParam String orgUnit, HttpServletResponse response ) throws IOException
     {
@@ -88,8 +88,8 @@
         dataValueSetService.writeDataValueSet( dataSet, period, orgUnit, response.getOutputStream() );
     }
 
-    @RequestMapping( method = RequestMethod.POST, consumes = "application/xml" )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )
+    @RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
+    @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
     public void postDxf2DataValueSet( ImportOptions importOptions,
         HttpServletResponse response, InputStream in, Model model ) throws IOException
     {
@@ -101,8 +101,8 @@
         JacksonUtils.toXml( response.getOutputStream(), summary );
     }
 
-    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )
+    @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
+    @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
     public void postJsonDataValueSet( ImportOptions importOptions,
         HttpServletResponse response, InputStream in, Model model ) throws IOException
     {
@@ -114,8 +114,8 @@
         JacksonUtils.toJson( response.getOutputStream(), summary );
     }
 
-    @RequestMapping( method = RequestMethod.POST, consumes = "application/sdmx+xml" )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )
+    @RequestMapping(method = RequestMethod.POST, consumes = "application/sdmx+xml")
+    @PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
     public void postSDMXDataValueSet( ImportOptions importOptions,
         HttpServletResponse response, InputStream in, Model model ) throws IOException
     {
@@ -127,11 +127,10 @@
         JacksonUtils.toXml( response.getOutputStream(), summary );
     }
 
-    @ExceptionHandler( IllegalArgumentException.class )
+    @ExceptionHandler(IllegalArgumentException.class)
     public void handleError( IllegalArgumentException ex, HttpServletResponse response )
         throws IOException
     {
         ContextUtils.conflictResponse( response, ex.getMessage() );
     }
 }
-                                                
\ No newline at end of file