← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4188: wip, action for getting orgunittree

 

------------------------------------------------------------
revno: 4188
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-07-21 17:16:53 +0200
message:
  wip, action for getting orgunittree
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.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
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-07-21 15:16:53 +0000
@@ -0,0 +1,23 @@
+
+#macro( expandOrganisationUnit $organisationUnit )
+	{
+		"id": $!{organisationUnit.id},
+		"name": "$!encoder.jsonEncode( ${organisationUnit.name} )",
+		"hasChildren": #if( $organisationUnit.children.size() > 0 )true,#{else}false#end
+		#if( $organisationUnit.children.size() > 0 )
+		"children": [
+			#foreach ( $child in $organisationUnit.children )
+				#expandOrganisationUnit( $child )#if( $velocityCount < $organisationUnit.children.size() ),#end
+			#end
+		]
+		#end
+	}
+#end
+
+{ "organisationUnits": [
+	#foreach ( $organisationUnit in $organisationUnits )
+		#expandOrganisationUnit( $organisationUnit )
+		#if( $velocityCount < $organisationUnits.size() ),#end
+	#end
+	]
+}

=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-07-21 15:16:53 +0000
@@ -0,0 +1,110 @@
+package org.hisp.dhis.commons.action;
+
+/*
+ * Copyright (c) 2004-2010, 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author mortenoh
+ */
+public class GetOrganisationUnitTreeAction
+    implements Action
+{
+    private final static int ALL = 0;
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Comparator
+    // -------------------------------------------------------------------------
+
+    private Comparator<OrganisationUnit> organisationUnitComparator;
+
+    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
+    {
+        this.organisationUnitComparator = organisationUnitComparator;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private Integer level;
+
+    public void setLevel( Integer level )
+    {
+        this.level = level;
+    }
+
+    private List<OrganisationUnit> organisationUnits;
+
+    public List<OrganisationUnit> getOrganisationUnits()
+    {
+        return organisationUnits;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        if ( level == null || level == ALL )
+        {
+            organisationUnits = new ArrayList<OrganisationUnit>(
+                organisationUnitService.getOrganisationUnitsAtLevel( 1 ) );
+        }
+        else
+        {
+            organisationUnits = new ArrayList<OrganisationUnit>(
+                organisationUnitService.getOrganisationUnitsAtLevel( level ) );
+        }
+
+        Collections.sort( organisationUnits, organisationUnitComparator );
+
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-07-06 07:04:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-07-21 15:16:53 +0000
@@ -5,7 +5,7 @@
 		http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd";>
 
-	<!-- Web Portal -->
+  <!-- Web Portal -->
 
   <bean id="org.hisp.dhis.webportal.module.ModuleManager" class="org.hisp.dhis.webportal.module.DefaultModuleManager">
     <property name="moduleComparator">
@@ -88,7 +88,7 @@
     </property>
   </bean>
 
-	<!-- Organisation Unit Web Tree -->
+  <!-- Organisation Unit Web Tree -->
 
   <bean id="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" class="org.hisp.dhis.ouwt.manager.DefaultOrganisationUnitSelectionManager">
     <property name="organisationUnitService">
@@ -184,7 +184,7 @@
     </property>
   </bean>
 
-	<!-- Organisation Unit Selection Tree -->
+  <!-- Organisation Unit Selection Tree -->
 
   <bean id="org.hisp.dhis.oust.manager.SelectionTreeManager" class="org.hisp.dhis.oust.manager.DefaultSelectionTreeManager">
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
@@ -511,6 +511,11 @@
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
   </bean>
 
+  <bean id="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction" class="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction"
+    scope="prototype">
+    <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+  </bean>
+
   <bean id="org.hisp.dhis.commons.action.GetPeriodAction" class="org.hisp.dhis.commons.action.GetPeriodAction"
     scope="prototype">
     <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
@@ -531,7 +536,7 @@
     <property name="locationManager" ref="locationManager" />
     <property name="documentService" ref="org.hisp.dhis.document.DocumentService" />
   </bean>
-  
+
   <bean id="org.hisp.dhis.commons.action.GetConstantsAction" class="org.hisp.dhis.commons.action.GetConstantsAction"
     scope="prototype">
     <property name="constantService" ref="org.hisp.dhis.constant.ConstantService" />
@@ -539,7 +544,7 @@
 
   <bean id="org.hisp.dhis.commons.action.NoAction" class="org.hisp.dhis.commons.action.NoAction" />
 
-	<!-- Interceptor -->
+  <!-- Interceptor -->
 
   <bean id="org.hisp.dhis.interceptor.DisplayPropertyInterceptor" class="org.hisp.dhis.interceptor.DisplayPropertyInterceptor">
     <property name="displayPropertyManager" ref="org.hisp.dhis.options.displayproperty.DisplayPropertyManager" />

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-07-06 07:04:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-07-21 15:16:53 +0000
@@ -6,15 +6,16 @@
 
   <include file="struts-default.xml" />
 
-	<!-- Properties -->
+  <!-- Properties -->
 
   <constant name="struts.velocity.contexts" value="org.hisp.dhis.encoding.velocity.EncoderVelocityContext" />
   <constant name="struts.velocity.toolboxlocation" value="toolbox.xml" /> <!-- Work-around -->
   <constant name="struts.i18n.encoding" value="UTF-8" />
   <constant name="struts.multipart.parser" value="jakarta" />
   <constant name="struts.multipart.maxSize" value="1073741824" />
+  <constant name="struts.directive.parse.max.depth" value="30" />
 
-	<!-- DHIS Web Commons -->
+  <!-- DHIS Web Commons -->
 
   <package name="dhis-web-commons" extends="struts-default" namespace="/dhis-web-commons">
 
@@ -56,10 +57,10 @@
         <interceptor-ref name="params" />
         <interceptor-ref name="chain" />
         <interceptor-ref name="i18nInterceptor" />
-				<!--
-					The securityInterceptor is put after the i18nInterceptor so that
-					the access denied error pages can use internationalisation.
-				-->
+        <!--
+          The securityInterceptor is put after the i18nInterceptor so that
+          the access denied error pages can use internationalisation.
+        -->
         <interceptor-ref name="securityInterceptor" />
         <interceptor-ref name="loginInterceptor" />
         <interceptor-ref name="sortOrderInterceptor" />
@@ -105,7 +106,7 @@
     </global-results>
   </package>
 
-	<!-- Organisation Unit Selection Tree -->
+  <!-- Organisation Unit Selection Tree -->
 
   <package name="dhis-web-commons-oust" extends="dhis-web-commons" namespace="/dhis-web-commons/oust">
 
@@ -155,7 +156,7 @@
 
   </package>
 
-	<!-- Organisation Unit Web Tree -->
+  <!-- Organisation Unit Web Tree -->
 
   <package name="dhis-web-commons-ouwt" extends="dhis-web-commons" namespace="/dhis-web-commons/ouwt">
 
@@ -209,7 +210,7 @@
 
   </package>
 
-	<!-- Menu -->
+  <!-- Menu -->
 
   <package name="dhis-web-commons-menu" extends="dhis-web-commons" namespace="/dhis-web-commons/menu">
 
@@ -229,7 +230,7 @@
 
   </package>
 
-	<!-- i18n -->
+  <!-- i18n -->
 
   <package name="dhis-web-commons-i18n" extends="dhis-web-commons" namespace="/dhis-web-commons">
 
@@ -273,7 +274,7 @@
 
   </package>
 
-	<!-- Common actions XML -->
+  <!-- Common actions XML -->
 
   <package name="dhis-web-commons-ajax" extends="dhis-web-commons" namespace="/dhis-web-commons-ajax">
 
@@ -393,7 +394,7 @@
 
   </package>
 
-	<!-- Common actions JSON -->
+  <!-- Common actions JSON -->
 
   <package name="dhis-web-commons-ajax-json" extends="dhis-web-commons" namespace="/dhis-web-commons-ajax-json">
 
@@ -589,6 +590,12 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
+    <action name="getOrganisationUnitTree" class="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction">
+      <result name="success" type="velocity-json">
+        /dhis-web-commons/ajax/jsonOrganisationUnitTree.vm</result>
+      <param name="onExceptionReturn">plainTextError</param>
+    </action>
+
     <action name="getPeriod" class="org.hisp.dhis.commons.action.GetPeriodAction">
       <result name="success" type="velocity-json">
         /dhis-web-commons/ajax/jsonPeriod.vm</result>
@@ -612,7 +619,7 @@
         /dhis-web-commons/ajax/jsonConstants.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
     </action>
-	
+
     <action name="getExpressionText" class="org.hisp.dhis.commons.action.GetExpressionTextAction">
       <result name="success" type="velocity-json">
         /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
@@ -628,7 +635,7 @@
 
   </package>
 
-    <!-- Stream -->
+  <!-- Stream -->
 
   <package name="dhis-web-commons-stream" extends="dhis-web-commons" namespace="/dhis-web-commons-stream">
 
@@ -637,8 +644,8 @@
     </action>
 
   </package>
-	
-	<!-- About -->
+
+  <!-- About -->
 
   <package name="dhis-web-commons-about" extends="dhis-web-commons" namespace="/dhis-web-commons-about">