← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9360: FRED-API: fixes to hierarchy format

 

------------------------------------------------------------
revno: 9360
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-18 19:21:05 +0100
message:
  FRED-API: fixes to hierarchy format
modified:
  dhis-2/dhis-web/dhis-web-api-fred/pom.xml
  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/webapp/WEB-INF/web.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/WEB-INF/web.xml


--
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/pom.xml'
--- dhis-2/dhis-web/dhis-web-api-fred/pom.xml	2012-12-14 13:46:47 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/pom.xml	2012-12-18 18:21:05 +0000
@@ -30,12 +30,10 @@
       <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-api</artifactId>
     </dependency>
-    <!--
-        <dependency>
-          <groupId>org.hisp.dhis</groupId>
-          <artifactId>dhis-web-api</artifactId>
-        </dependency>
-    -->
+    <dependency>
+      <groupId>org.hisp.dhis</groupId>
+      <artifactId>dhis-web-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-dxf2</artifactId>

=== 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-18 17:57:10 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-18 18:21:05 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.apache.commons.lang3.StringEscapeUtils;
+import org.hisp.dhis.api.controller.organisationunit.OrganisationUnitLevelController;
 import org.hisp.dhis.common.DeleteNotAllowedException;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.dataset.DataSet;
@@ -300,20 +301,7 @@
         {
             Facility facility = conversionService.convert( organisationUnit, Facility.class );
             filterFacility( facility, allProperties, fields );
-
-            // TODO this probably belongs in "meta": {}
-            List<Map<String, Object>> hierarchy = new ArrayList<Map<String, Object>>();
-            facility.getProperties().put( "hierarchy", hierarchy );
-
-            for ( OrganisationUnitLevel organisationUnitLevel : organisationUnitLevels )
-            {
-                Map<String, Object> level = new HashMap<String, Object>();
-
-                level.put( "name", organisationUnitLevel.getName() );
-                level.put( "level", organisationUnitLevel.getLevel() );
-
-                hierarchy.add( level );
-            }
+            addHierarchyPropertyToFacility( organisationUnitLevels, organisationUnit, facility );
 
             facilities.getFacilities().add( facility );
         }
@@ -335,9 +323,11 @@
         @RequestParam( value = "fields", required = false ) String fields )
     {
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
+        List<OrganisationUnitLevel> organisationUnitLevels = organisationUnitService.getOrganisationUnitLevels();
 
         Facility facility = conversionService.convert( organisationUnit, Facility.class );
         filterFacility( facility, allProperties, fields );
+        addHierarchyPropertyToFacility( organisationUnitLevels, organisationUnit, facility );
 
         setAccessRights( model );
 
@@ -365,6 +355,29 @@
         model.addAttribute( "canDelete", authorities.contains( "F_FRED_DELETE" ) || currentUserService.currentUserIsSuper() );
     }
 
+    private void addHierarchyPropertyToFacility( List<OrganisationUnitLevel> organisationUnitLevels, OrganisationUnit organisationUnit, Facility facility )
+    {
+        // TODO this probably belongs in "meta": {}
+        List<Map<String, Object>> hierarchy = new ArrayList<Map<String, Object>>();
+        facility.getProperties().put( "hierarchy", hierarchy );
+
+        for ( OrganisationUnitLevel organisationUnitLevel : organisationUnitLevels )
+        {
+            Map<String, Object> level = new HashMap<String, Object>();
+
+            level.put( "id", organisationUnitLevel.getUid() );
+
+            // temporary fix since ControllerLinkBuilder can't handle cross-servlet controllers
+            level.put( "url", linkTo( OrganisationUnitLevelController.class ).slash( organisationUnitLevel.getUid() ).toString()
+                .replace( "/api-fred", "/api" ) );
+
+            level.put( "name", organisationUnitLevel.getName() );
+            level.put( "level", organisationUnitLevel.getLevel() );
+
+            hierarchy.add( level );
+        }
+    }
+
     //--------------------------------------------------------------------------
     // POST JSON
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/web.xml	2012-12-11 09:34:15 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/web.xml	2012-12-18 18:21:05 +0000
@@ -104,6 +104,16 @@
     <load-on-startup>1</load-on-startup>
   </servlet>
 
+  <servlet>
+    <servlet-name>webapiServlet</servlet-name>
+    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+    <init-param>
+      <param-name>contextConfigLocation</param-name>
+      <param-value>classpath*:/META-INF/dhis/servlet.xml</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
   <!-- Web API -->
 
   <servlet-mapping>
@@ -116,4 +126,13 @@
     <url-pattern>/api-fred/*</url-pattern>
   </servlet-mapping>
 
+  <servlet-mapping>
+    <servlet-name>webapiServlet</servlet-name>
+    <url-pattern>/api</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>webapiServlet</servlet-name>
+    <url-pattern>/api/*</url-pattern>
+  </servlet-mapping>
+
 </web-app>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/WEB-INF/web.xml	2012-11-27 13:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/WEB-INF/web.xml	2012-12-18 18:21:05 +0000
@@ -1,102 +1,102 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-        "http://java.sun.com/dtd/web-app_2_3.dtd";>
+  "http://java.sun.com/dtd/web-app_2_3.dtd";>
 <web-app>
-    <display-name>DHIS Web Light</display-name>
-
-    <context-param>
-        <param-name>contextConfigLocation</param-name>
-        <param-value>classpath*:/META-INF/dhis/beans.xml</param-value>
-    </context-param>
-    <context-param>
-        <param-name>automaticAccessType</param-name>
-        <param-value>ghostAdmin</param-value>
-    </context-param>
-
-    <filter>
-        <filter-name>RedirectFilter</filter-name>
-        <filter-class>org.hisp.dhis.servlet.filter.HttpRedirectFilter</filter-class>
-        <init-param>
-            <param-name>redirectPath</param-name>
-            <param-value>light/index.action</param-value>
-        </init-param>
-    </filter>
-    <filter>
-        <filter-name>OpenSessionInViewFilter</filter-name>
-        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
-    </filter>
-    <filter>
-        <filter-name>springSecurityFilterChain</filter-name>
-        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
-    </filter>
-    <filter>
-        <filter-name>Struts</filter-name>
-        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
-    </filter>
-    <filter>
-        <filter-name>encodingFilter</filter-name>
-        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
-        <init-param>
-            <param-name>encoding</param-name>
-            <param-value>UTF-8</param-value>
-        </init-param>
-        <init-param>
-            <param-name>forceEncoding</param-name>
-            <param-value>true</param-value>
-        </init-param>
-    </filter>
-
-    <filter-mapping>
-        <filter-name>encodingFilter</filter-name>
-        <url-pattern>/*</url-pattern>
-    </filter-mapping>
-    <filter-mapping>
-        <filter-name>RedirectFilter</filter-name>
-        <url-pattern>/</url-pattern>
-    </filter-mapping>
-    <filter-mapping>
-        <filter-name>OpenSessionInViewFilter</filter-name>
-        <url-pattern>*.action</url-pattern>
-    </filter-mapping>
-    <filter-mapping>
-        <filter-name>OpenSessionInViewFilter</filter-name>
-        <url-pattern>/api/*</url-pattern>
-    </filter-mapping>
-    <filter-mapping>
-        <filter-name>springSecurityFilterChain</filter-name>
-        <url-pattern>/*</url-pattern>
-    </filter-mapping>
-    <filter-mapping>
-        <filter-name>Struts</filter-name>
-        <url-pattern>*.action</url-pattern>
-    </filter-mapping>
-
-    <listener>
-        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-    </listener>
-    <listener>
-        <listener-class>org.hisp.dhis.system.startup.StartupListener</listener-class>
-    </listener>
-
-    <!-- Web API -->
-
-    <servlet>
-        <servlet-name>webapiServlet</servlet-name>
-        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
-        <init-param>
-            <param-name>contextConfigLocation</param-name>
-            <param-value>classpath*:/META-INF/dhis/servlet.xml</param-value>
-        </init-param>
-        <load-on-startup>1</load-on-startup>
-    </servlet>
-
-    <servlet-mapping>
-        <servlet-name>webapiServlet</servlet-name>
-        <url-pattern>/api</url-pattern>
-    </servlet-mapping>
-    <servlet-mapping>
-        <servlet-name>webapiServlet</servlet-name>
-        <url-pattern>/api/*</url-pattern>
-    </servlet-mapping>
+  <display-name>DHIS Web Light</display-name>
+
+  <context-param>
+    <param-name>contextConfigLocation</param-name>
+    <param-value>classpath*:/META-INF/dhis/beans.xml</param-value>
+  </context-param>
+  <context-param>
+    <param-name>automaticAccessType</param-name>
+    <param-value>ghostAdmin</param-value>
+  </context-param>
+
+  <filter>
+    <filter-name>RedirectFilter</filter-name>
+    <filter-class>org.hisp.dhis.servlet.filter.HttpRedirectFilter</filter-class>
+    <init-param>
+      <param-name>redirectPath</param-name>
+      <param-value>light/index.action</param-value>
+    </init-param>
+  </filter>
+  <filter>
+    <filter-name>OpenSessionInViewFilter</filter-name>
+    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
+  </filter>
+  <filter>
+    <filter-name>springSecurityFilterChain</filter-name>
+    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+  </filter>
+  <filter>
+    <filter-name>Struts</filter-name>
+    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
+  </filter>
+  <filter>
+    <filter-name>encodingFilter</filter-name>
+    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+    <init-param>
+      <param-name>encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+    <init-param>
+      <param-name>forceEncoding</param-name>
+      <param-value>true</param-value>
+    </init-param>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>encodingFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>RedirectFilter</filter-name>
+    <url-pattern>/</url-pattern>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>OpenSessionInViewFilter</filter-name>
+    <url-pattern>*.action</url-pattern>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>OpenSessionInViewFilter</filter-name>
+    <url-pattern>/api/*</url-pattern>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>springSecurityFilterChain</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+  <filter-mapping>
+    <filter-name>Struts</filter-name>
+    <url-pattern>*.action</url-pattern>
+  </filter-mapping>
+
+  <listener>
+    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+  </listener>
+  <listener>
+    <listener-class>org.hisp.dhis.system.startup.StartupListener</listener-class>
+  </listener>
+
+  <!-- Web API -->
+
+  <servlet>
+    <servlet-name>webapiServlet</servlet-name>
+    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+    <init-param>
+      <param-name>contextConfigLocation</param-name>
+      <param-value>classpath*:/META-INF/dhis/servlet.xml</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>webapiServlet</servlet-name>
+    <url-pattern>/api</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>webapiServlet</servlet-name>
+    <url-pattern>/api/*</url-pattern>
+  </servlet-mapping>
 
 </web-app>