← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2745: Improved in creating/updating a validation rule by showing feedback to user if the specified peri...

 

------------------------------------------------------------
revno: 2745
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-01-25 23:29:50 +0700
message:
  Improved in creating/updating a validation rule by showing feedback to user if the specified period type selected. It should be being used in data set where contains data element.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/ValidateValidationRuleAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module_vi_VN.properties
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/validationForm.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.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/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2010-12-22 04:05:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java	2011-01-25 16:29:50 +0000
@@ -278,4 +278,11 @@
     
     Collection<DataSet> getDataSetsBetween(int first, int max );
 
+    /**
+     * Retrieves true/false with data set has members for a given PeriodType.
+     * 
+     * @param periodType the PeriodType.
+     * @return true or false.
+     */
+    boolean dataSetHasMembers( PeriodType periodType );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java	2010-12-22 04:05:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java	2011-01-25 16:29:50 +0000
@@ -189,5 +189,7 @@
     int getDataSetCount();
     
     Collection<DataSet> getDataSetsBetween(int first, int max );
+    
+    boolean dataSetHasMembers( PeriodType periodType );
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2010-12-22 04:05:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2011-01-25 16:29:50 +0000
@@ -344,4 +344,10 @@
     {
         return dataSetStore.getDataSetsBetweenByName( name, first, max );
     }
+
+    @Override
+    public boolean dataSetHasMembers( PeriodType periodType )
+    {
+        return dataSetStore.dataSetHasMembers( periodType );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java	2011-01-06 13:33:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java	2011-01-25 16:29:50 +0000
@@ -358,4 +358,15 @@
     {
         return getBetweenByName( name, first, max );
     }
+    
+    public boolean dataSetHasMembers( PeriodType periodType )
+    {
+        periodType = periodStore.getPeriodType( periodType.getClass() );
+        
+        String hql = "select count(*) from DataSet d where d.dataElements.size > 0 and d.periodType = :periodType";
+        Query query = sessionFactory.getCurrentSession().createQuery( hql );
+        Number rs = (Number)query.setEntity( "periodType", periodType ).uniqueResult();
+
+        return rs == null ? false : rs.intValue() > 0;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/ValidateValidationRuleAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/ValidateValidationRuleAction.java	2010-09-18 09:50:09 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/ValidateValidationRuleAction.java	2011-01-25 16:29:50 +0000
@@ -27,15 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
 
 import com.opensymphony.xwork2.ActionSupport;
 
-/** 
+/**
  * @author Margrethe Store
- * @version $Id: ValidateValidationRuleAction.java 3868 2007-11-08 15:11:12Z larshelg $
+ * @version $Id: ValidateValidationRuleAction.java 3868 2007-11-08 15:11:12Z
+ *          larshelg $
  */
 public class ValidateValidationRuleAction
     extends ActionSupport
@@ -50,7 +53,21 @@
     {
         this.validationRuleService = validationRuleService;
     }
-    
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -61,7 +78,7 @@
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
-    
+
     private Integer id;
 
     public void setId( Integer id )
@@ -75,7 +92,14 @@
     {
         this.name = validationName;
     }
-    
+
+    private String periodTypeName;
+
+    public void setPeriodTypeName( String periodTypeName )
+    {
+        this.periodTypeName = periodTypeName;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -93,33 +117,46 @@
 
     public String execute()
     {
-        if ( name == null )
-        {
-            message = i18n.getString( "specify_name" );
-            
-            return INPUT;
-        }
-        else
+        if ( name != null )
         {
             name = name.trim();
 
             if ( name.length() == 0 )
             {
                 message = i18n.getString( "specify_name" );
-                
+
                 return INPUT;
             }
 
             ValidationRule match = validationRuleService.getValidationRuleByName( name );
 
-            if ( match != null && ( id == null || match.getId() != id ) )
+            if ( match != null && (id == null || match.getId() != id) )
             {
                 message = i18n.getString( "name_in_use" );
 
                 return INPUT;
             }
         }
-                
+
+        if ( periodTypeName != null )
+        {
+            periodTypeName = periodTypeName.trim();
+
+            if ( periodTypeName.length() == 0 )
+            {
+                message = i18n.getString( "specify_period_type" );
+
+                return INPUT;
+            }
+
+            if ( !dataSetService.dataSetHasMembers( periodService.getPeriodTypeByName( periodTypeName ) ) )
+            {
+                message = i18n.getString( "specify_period_type_used_in_dataset_has_member" );
+
+                return INPUT;
+            }
+        }
+
         message = i18n.getString( "everything_is_ok" );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml	2010-12-27 00:21:07 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml	2011-01-25 16:29:50 +0000
@@ -71,6 +71,12 @@
     <property name="validationRuleService">
       <ref bean="org.hisp.dhis.validation.ValidationRuleService"/>
     </property>
+    <property name="periodService">
+      <ref bean="org.hisp.dhis.period.PeriodService"/>
+    </property>
+    <property name="dataSetService">
+      <ref bean="org.hisp.dhis.dataset.DataSetService"/>
+    </property>
   </bean>
   
   <bean id="org.hisp.dhis.validationrule.action.SetupTreeAction"

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2010-12-27 00:21:07 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2011-01-25 16:29:50 +0000
@@ -145,4 +145,5 @@
 specify_organisationunit_has_children = Please specify an organisationunit which has children.
 get_report_as_xls = Download as Excel
 get_report_as_csv = Download as CSV
-get_report_as_pdf = Download as PDF
\ No newline at end of file
+get_report_as_pdf = Download as PDF
+specify_period_type_used_in_dataset_has_member = Please specify a period type which being used in data set has elements.
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module_vi_VN.properties	2010-12-09 06:15:40 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module_vi_VN.properties	2011-01-25 16:29:50 +0000
@@ -49,4 +49,5 @@
 source= \u0110\u01a1n v\u1ecb
 period= Th\u1eddi \u0111i\u1ec3m
 value= Gi\u00e1 tr\u1ecb
-data_quality_report = B\u00e1o c\u00e1o ch\u1ea5t l\u01b0\u1ee3ng d\u1eef li\u1ec7u
\ No newline at end of file
+data_quality_report = B\u00e1o c\u00e1o ch\u1ea5t l\u01b0\u1ee3ng d\u1eef li\u1ec7u
+specify_period_type_used_in_dataset_has_member = Vui lo\u0300ng cho\u0323n ki\u00ea\u0309u th\u01a1\u0300i \u0111i\u00ea\u0309m \u0111ang \u0111\u01b0\u01a1\u0323c s\u01b0\u0309 du\u0323ng trong t\u00e2\u0323p d\u01b0\u0303 li\u00ea\u0323u ma\u0300 co\u0301 ch\u01b0\u0301a ph\u00e2\u0300n t\u01b0\u0309 d\u01b0\u0303 li\u00ea\u0323u.
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm	2011-01-22 23:46:22 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/addValidationRuleForm.vm	2011-01-25 16:29:50 +0000
@@ -14,6 +14,7 @@
 				});
 				
 				checkValueIsExist( "name", "validateValidationRule.action");
+				changePeriodType();
 			}
 	);
 
@@ -34,9 +35,9 @@
 		<td><textarea name="description" style="width:20em; height:6em" class="{validate:{maxlength:255}}"></textarea></td>
 	</tr>
 	<tr>
-		<td><label for="periodType">$encoder.htmlEncode( $i18n.getString( "period_type" ) )<em title="$i18n.getString( "required" )" class="required">*</em></label></td>
+		<td><label for="periodType">$encoder.htmlEncode( $i18n.getString( "period_type" ) )<em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
-			<select type="text" id="periodTypeName" name="periodTypeName" style="min-width:20em" >
+			<select type="text" id="periodTypeName" name="periodTypeName" style="min-width:20em" onchange="changePeriodType()">
 				#foreach ( $periodType in $periodTypes )
 				 <option value="$periodType.name" #if( $periodType.name.equals( ${monthlyPeriodTypeName} ) ) selected #end>$i18n.getString($periodType.name)</option>
 				#end						
@@ -45,7 +46,7 @@
 		</td>
 	</tr>
 	<tr>
-		<td><label for="operatorId">$encoder.htmlEncode( $i18n.getString( "operator" ) ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
+		<td><label for="operatorId">$encoder.htmlEncode( $i18n.getString( "operator" ) ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
 			<select id="operator" name="operator" style="width:20em" class="{validate:{required:true}}">
 				<option value="">[ $i18n.getString( "select_operator" ) ]</option>

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/validationForm.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/validationForm.js	2010-05-28 19:17:07 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/validationForm.js	2011-01-25 16:29:50 +0000
@@ -90,8 +90,30 @@
 }
 
 // ---------------------------------------------------------------------
-// disabled PeriodType field
+// PeriodType field
 // ---------------------------------------------------------------------
+
+function changePeriodType()
+{
+	$.getJSON(
+		"validateValidationRule.action",
+		{
+			"periodTypeName": getFieldValue("periodTypeName")   
+		},
+		function( json )
+		{
+			if ( json.response == "input" )
+			{ 
+				showWarningMessage( json.message );
+			}
+		}
+	);
+}
+
+/**
+ * Disabled PeriodType field
+ */
+
 function disabledPeriodTypeField(){
 	if(getFieldValue( 'leftSideExpression' ) == '' &&
 	   getFieldValue( 'rightSideExpression' ) == '') {

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm	2011-01-22 23:46:22 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/updateValidationRuleForm.vm	2011-01-25 16:29:50 +0000
@@ -12,12 +12,9 @@
 				validation( 'updateValidationRuleForm', function( form ){
 					form.submit();			
 				});
-				/* validation( 'updateValidationRuleForm', function( form ){			
-							form.submit();
-						},function(){
-							validateExpression();
-						});	 */				
-				checkValueIsExist( "name", "validateValidationRule.action", {id:getFieldValue('id')});				
+			
+				checkValueIsExist( "name", "validateValidationRule.action", {id:getFieldValue('id')});
+				changePeriodType();				
 			}
 	);
 
@@ -44,8 +41,8 @@
 		<td><textarea name="description" style="width:20em; height:6em" class="{validate:{maxlength:255}}">$!encoder.htmlEncode( $validationRule.description )</textarea></td>
 	</tr>
 	<tr>
-		<td><label for="periodType">$encoder.htmlEncode( $i18n.getString( "period_type" ) )<em title="$i18n.getString( "required" )" class="required">*</em></label></td>
-		<td><select type="text" id="periodTypeName" name="periodTypeName" style="min-width:20em" disabled>
+		<td><label for="periodType">$encoder.htmlEncode( $i18n.getString( "period_type" ) )<em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
+		<td><select type="text" id="periodTypeName" name="periodTypeName" style="min-width:20em" onchange="changePeriodType()" disabled>
 					#foreach ( $periodType in $periodTypes )
              		 <option value="$periodType.name" #if( $validationRule.periodType.name.equals($periodType.name ) ) selected #end>$i18n.getString($periodType.name)</option>
             		#end						
@@ -54,7 +51,7 @@
 		</td>
 	</tr>
 	<tr>
-		<td><label for="operatorId">$encoder.htmlEncode( $i18n.getString( "operator" ) ) <em title="$i18n.getString( "required" )" class="required">*</em></label></td>
+		<td><label for="operatorId">$encoder.htmlEncode( $i18n.getString( "operator" ) ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
 		<td>
 			<select id="operator" name="operator" style="width:20em">
 				<option value="equal_to" #if ( $validationRule.operator == 'equal_to' )selected="selected"#end>$encoder.htmlEncode( $i18n.getString( "equal_to" ) )</option>