← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4077: Replaced the referring action - list of constants - in indicator/validation rule expression build...

 

------------------------------------------------------------
revno: 4077
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-07-06 14:04:25 +0700
message:
  Replaced the referring action - list of constants - in indicator/validation rule expression builder form by a new one which placed at commons lib.
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonConstants.vm
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConstants.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetConstantsAction.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
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.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
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConstants.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConstants.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonConstants.vm	2011-07-06 07:04:25 +0000
@@ -0,0 +1,13 @@
+#set( $size = $constants.size() )
+{ "constants": [
+#foreach( $constant in $constants )
+  {
+    "constantId": "$!{constant.id}",
+    "constantName": "$!encoder.jsonEncode( ${constant.name} )"
+  }#if( $velocityCount < $size ),#end
+#end
+]
+#if( $usePaging ),
+	"paging":#parse( "/dhis-web-commons/ajax/jsonPaging.vm" )
+#end
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetConstantsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetConstantsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetConstantsAction.java	2011-07-06 07:04:25 +0000
@@ -0,0 +1,110 @@
+package org.hisp.dhis.commons.action;
+
+/*
+ * Copyright (c) 2004-2011, 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 static org.apache.commons.lang.StringUtils.isNotBlank;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.constant.ConstantService;
+import org.hisp.dhis.constant.comparator.ConstantNameComparator;
+import org.hisp.dhis.paging.ActionPagingSupport;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class GetConstantsAction
+    extends ActionPagingSupport<Constant>
+{
+    /**
+     * Determines if a de-serialized file is compatible with this class.
+     */
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ConstantService constantService;
+
+    public void setConstantService( ConstantService constantService )
+    {
+        this.constantService = constantService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private List<Constant> constants;
+
+    public List<Constant> getConstants()
+    {
+        return constants;
+    }
+
+    private String key;
+    
+    public String getKey()
+    {
+        return key;
+    }
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        if ( isNotBlank( key ) ) // Filter on key only if set
+        {
+            this.paging = createPaging( constantService.getConstantCountByName( key ) );
+            
+            constants = new ArrayList<Constant>( constantService.getConstantsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+        }
+        else
+        {
+            this.paging = createPaging( constantService.getConstantCount() );
+            
+            constants = new ArrayList<Constant>( constantService.getConstantsBetween( paging.getStartPos(), paging.getPageSize() ) );
+        }
+        
+        Collections.sort( constants, new ConstantNameComparator() );
+
+        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-06-20 14:59:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-07-06 07:04:25 +0000
@@ -531,6 +531,11 @@
     <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" />
+  </bean>
 
   <bean id="org.hisp.dhis.commons.action.NoAction" class="org.hisp.dhis.commons.action.NoAction" />
 

=== 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-06-22 06:29:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-07-06 07:04:25 +0000
@@ -607,6 +607,12 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
+    <action name="getConstants" class="org.hisp.dhis.commons.action.GetConstantsAction">
+      <result name="success" type="velocity-json">
+        /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>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantListAction.java	2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/GetConstantListAction.java	2011-07-06 07:04:25 +0000
@@ -1,7 +1,7 @@
 package org.hisp.dhis.dataadmin.action.constant;
 
 /*
- * Copyright (c) 2004-2010, University of Oslo
+ * Copyright (c) 2004-2011, University of Oslo
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2011-07-01 03:36:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2011-07-06 07:04:25 +0000
@@ -391,12 +391,6 @@
       <result name="success" type="velocity-xml">
         /dhis-web-maintenance-dataadmin/responseConstant.vm</result>
     </action>
-
-    <action name="getConstants" class="org.hisp.dhis.dataadmin.action.constant.GetConstantListAction">
-      <result name="success" type="velocity-json">
-		/dhis-web-maintenance-dataadmin/jsonConstants.vm</result>
-      <param name="onExceptionReturn">plainTextError</param>
-    </action>
 	
     <action name="constant" class="org.hisp.dhis.dataadmin.action.constant.GetConstantListAction">
       <result name="success" type="velocity">/main.vm</result>

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonConstants.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonConstants.vm	2011-07-01 03:36:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonConstants.vm	1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
-#set( $size = $constants.size() )
-{ "constants": [
-#foreach( $constant in $constants )
-  {
-    "constantId": "$!{constant.id}",
-    "constantName": "$!encoder.jsonEncode( ${constant.name} )"
-  }#if( $velocityCount < $size ),#end
-#end
-]
-#if( $usePaging ),
-	"paging":#parse( "/dhis-web-commons/ajax/jsonPaging.vm" )
-#end
-}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2011-07-06 06:40:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2011-07-06 07:04:25 +0000
@@ -62,7 +62,7 @@
 		var target = jQuery( "#indicator-expression-container select[id=constantId]" );
 		target.children().remove();
 		
-		jQuery.postJSON( '../dhis-web-maintenance-dataadmin/getConstants.action', {},
+		jQuery.postJSON( '../dhis-web-commons-ajax-json/getConstants.action', {},
 			function( json ) {
 				jQuery.each( json.constants, function(i, item) {
 					target.append( '<option value="[C'+item.constantId+']">' + item.constantName + '</option>' );

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm	2011-07-01 04:04:24 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm	2011-07-06 07:04:25 +0000
@@ -52,7 +52,7 @@
 		var target = jQuery( "#expression-container select[id=constantId]" );
 		target.children().remove();
 		
-		jQuery.postJSON( '../dhis-web-maintenance-dataadmin/getConstants.action', {},
+		jQuery.postJSON( '../dhis-web-commons-ajax-json/getConstants.action', {},
 			function( json ) {
 				if ( json.constants.length == 0 )
 				{