← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2277: Apply pagination in ValidationRule and ValidationRuleGroup.

 

------------------------------------------------------------
revno: 2277
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Fri 2010-12-03 23:15:40 +0700
message:
  Apply pagination in ValidationRule and ValidationRuleGroup.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/GetValidationRuleListAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupListAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRule.vm
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRuleGroup.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/validation/ValidationRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-09-04 06:30:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-12-03 16:15:40 +0000
@@ -32,6 +32,7 @@
 import java.util.List;
 
 import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
@@ -235,5 +236,22 @@
      * 
      * @param name the name of the ValidationRuleGroup.
      */
-    ValidationRuleGroup getValidationRuleGroupByName( String name );    
+    ValidationRuleGroup getValidationRuleGroupByName( String name );  
+    
+    Collection<ValidationRule> getValidationRulesBetween( int first, int max );
+    
+    Collection<ValidationRule> getValidationRulesBetweenByName( String name, int first, int max );
+    
+    int getValidationRuleCount();
+    
+    int getValidationRuleCountByName( String name );
+    
+    Collection<ValidationRuleGroup> getValidationRuleGroupsBetween( int first, int max );
+    
+    Collection<ValidationRuleGroup> getValidationRuleGroupsBetweenByName( String name, int first, int max );
+    
+    int getValidationRuleGroupCount();
+    
+    int getValidationRuleGroupCountByName( String name );
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-04 06:30:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-12-03 16:15:40 +0000
@@ -443,5 +443,45 @@
     {
         return validationRuleGroupStore.getByName( name );
     }
+
+    public int getValidationRuleCount()
+    {
+        return validationRuleStore.getCount();
+    }
+
+    public int getValidationRuleCountByName( String name )
+    {
+        return validationRuleStore.getCountByName( name );
+    }
+
+    public Collection<ValidationRule> getValidationRulesBetween( int first, int max )
+    {
+        return validationRuleStore.getBetween( first, max );
+    }
+
+    public Collection<ValidationRule> getValidationRulesBetweenByName( String name, int first, int max )
+    {
+        return validationRuleStore.getBetweenByName( name, first, max );
+    }
+
+    public int getValidationRuleGroupCount()
+    {
+        return validationRuleGroupStore.getCount();
+    }
+
+    public int getValidationRuleGroupCountByName( String name )
+    {
+        return validationRuleGroupStore.getCountByName( name );
+    }
+
+    public Collection<ValidationRuleGroup> getValidationRuleGroupsBetween( int first, int max )
+    {
+        return validationRuleGroupStore.getBetween( first, max );
+    }
+
+    public Collection<ValidationRuleGroup> getValidationRuleGroupsBetweenByName( String name, int first, int max )
+    {
+        return validationRuleGroupStore.getBetweenByName( name, first, max );
+    }
     
 }

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/GetValidationRuleListAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/GetValidationRuleListAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/GetValidationRuleListAction.java	2010-12-03 16:15:40 +0000
@@ -27,22 +27,23 @@
  * 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.paging.ActionPagingSupport;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
 import org.hisp.dhis.validation.comparator.ValidationRuleNameComparator;
 
-import com.opensymphony.xwork2.ActionSupport;
-
 /**
  * @author Margrethe Store
  * @version $Id: GetValidationRuleListAction.java 5331 2008-06-04 10:59:13Z larshelg $
  */
 public class GetValidationRuleListAction 
-    extends ActionSupport
+    extends ActionPagingSupport<ValidationRule>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -56,7 +57,7 @@
     }
     
     // -------------------------------------------------------------------------
-    // Output
+    // Input & Output
     // -------------------------------------------------------------------------
     
     private List<ValidationRule> validationRulesList;
@@ -66,13 +67,36 @@
         return validationRulesList;
     }
     
+    private String key;
+    
+    public String getKey()
+    {
+        return key;
+    }
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
     
     public String execute() throws Exception
     {
-        validationRulesList = new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() );
+        if ( isNotBlank( key ) ) // Filter on key only if set
+        {
+            this.paging = createPaging( validationRuleService.getValidationRuleCountByName( key ) );
+            
+            validationRulesList = new ArrayList<ValidationRule>( validationRuleService.getValidationRulesBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+        }
+        else
+        {
+            this.paging = createPaging( validationRuleService.getValidationRuleCount() );
+            
+            validationRulesList = new ArrayList<ValidationRule>( validationRuleService.getValidationRulesBetween( paging.getStartPos(), paging.getPageSize() ) );
+        }
 
         Collections.sort( validationRulesList, new ValidationRuleNameComparator() );
         

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupListAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupListAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/validationrulegroup/GetValidationRuleGroupListAction.java	2010-12-03 16:15:40 +0000
@@ -27,10 +27,14 @@
  * 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.paging.ActionPagingSupport;
+import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleGroup;
 import org.hisp.dhis.validation.ValidationRuleService;
 import org.hisp.dhis.validation.comparator.ValidationRuleGroupNameComparator;
@@ -42,7 +46,7 @@
 * @version $Id$
 */
 public class GetValidationRuleGroupListAction
-    implements Action
+    extends ActionPagingSupport<ValidationRuleGroup>
 {
     // -------------------------------------------------------------------------
     // Dependencies
@@ -56,7 +60,7 @@
     }
 
     // -------------------------------------------------------------------------
-    // Output
+    // Input & Output
     // -------------------------------------------------------------------------
 
     private List<ValidationRuleGroup> validationRuleGroups;
@@ -65,14 +69,37 @@
     {
         return validationRuleGroups;
     }
+    
+    private String key;
+    
+    public String getKey()
+    {
+        return key;
+    }
 
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implemantation
     // -------------------------------------------------------------------------
 
     public String execute()
     {
-        validationRuleGroups = new ArrayList<ValidationRuleGroup>( validationRuleService.getAllValidationRuleGroups() );
+        if ( isNotBlank( key ) ) // Filter on key only if set
+        {
+            this.paging = createPaging( validationRuleService.getValidationRuleGroupCountByName( key ) );
+            
+            validationRuleGroups = new ArrayList<ValidationRuleGroup>( validationRuleService.getValidationRuleGroupsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+        }
+        else
+        {
+            this.paging = createPaging( validationRuleService.getValidationRuleGroupCount() );
+            
+            validationRuleGroups = new ArrayList<ValidationRuleGroup>( validationRuleService.getValidationRuleGroupsBetween( paging.getStartPos(), paging.getPageSize() ) );
+        }
         
         Collections.sort( validationRuleGroups, new ValidationRuleGroupNameComparator() );
         

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2010-12-03 05:41:34 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2010-12-03 16:15:40 +0000
@@ -22,6 +22,7 @@
       <param name="page">/dhis-web-validationrule/validationRule.vm</param>
       <param name="menu">/dhis-web-validationrule/menu.vm</param>
       <param name="javascripts">javascript/general.js</param>
+	  <param name="stylesheets">../dhis-web-commons/paging/paging.css</param>
     </action> 
     
     <action name="getValidationRule" class="org.hisp.dhis.validationrule.action.GetValidationRuleAction">
@@ -88,6 +89,7 @@
       <param name="page">/dhis-web-validationrule/validationRuleGroup.vm</param>
       <param name="menu">/dhis-web-validationrule/menu.vm</param>
       <param name="javascripts">javascript/validationRuleGroup.js</param>
+	  <param name="stylesheets">../dhis-web-commons/paging/paging.css</param>
     </action>
     
     <action name="getValidationRuleGroup" class="org.hisp.dhis.validationrule.action.validationrulegroup.GetValidationRuleGroupAction">

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRule.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRule.vm	2010-12-03 05:41:34 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRule.vm	2010-12-03 16:15:40 +0000
@@ -5,7 +5,7 @@
 		<td style="vertical-align:top">
 			<table width="100%">
 				<tr>
-					<td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
+					<td>#filterDiv( "showValidationRuleForm" )</td>
 					<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddValidationRuleForm.action'"></td>
 				</tr>	
 			</table>
@@ -34,6 +34,8 @@
 				#end
 				</tbody>               
 			</table>
+			<p></p>
+			#parse( "/dhis-web-commons/paging/paging.vm" )
 
 		</td>
 		<td style="width:20em; padding-left:2em; vertical-align:top">

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRuleGroup.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRuleGroup.vm	2010-12-03 05:41:34 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/validationRuleGroup.vm	2010-12-03 16:15:40 +0000
@@ -6,7 +6,7 @@
         <td style="vertical-align:top">
 			<table width="100%">
 				<tr>
-                    <td>$i18n.getString( "filter_by_name" ): <form style="display:inline" action="none" onsubmit="return false"><div style="inline"><input type="text" onkeyup="filterValues( this.value )"></div></form></td>
+                    <td>#filterDiv( "showValidationRuleGroupForm" )</td>
                     <td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAddValidationRuleGroupForm.action'"></td>
                 </tr>       
 			</table>
@@ -33,6 +33,8 @@
                 #end
                 </tbody>
             </table>
+			<p></p>
+			#parse( "/dhis-web-commons/paging/paging.vm" )
 
         </td>
         <td style="width:20em; padding-left:2em; vertical-align:top">