dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37716
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19260: Introduced web domain class ValidationResult. Re-impl indicator expression validation using web api.
------------------------------------------------------------
revno: 19260
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-02 17:19:55 +0200
message:
Introduced web domain class ValidationResult. Re-impl indicator expression validation using web api.
removed:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorDescriptionAction.java
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.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/program/ProgramIndicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-06-02 11:13:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicator.java 2015-06-02 15:19:55 +0000
@@ -77,6 +77,7 @@
public static final String VALID = "valid";
public static final String EXPRESSION_NOT_WELL_FORMED = "expression_not_well_formed";
+ public static final String INVALID_IDENTIFIERS_IN_EXPRESSION = "invalid_identifiers_in_expression";
private Program program;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java 2015-04-27 11:16:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramIndicatorService.java 2015-06-02 15:19:55 +0000
@@ -131,18 +131,20 @@
Map<String, String> getProgramIndicatorValues( ProgramInstance programInstance );
/**
- * Get description of an indicator expression
+ * Get description of an indicator expression.
*
- * @param expression A expression string
+ * @param expression An expression string
* @return The description
*/
String getExpressionDescription( String expression );
/**
- * Get description of an indicator expression
- *
- * @param expression A expression string
- * @return The expression is valid or not
+ * Indicates whether the given program indicator expression is valid.
+ *
+ * @param expression An expression string.
+ * @return the string {@link ProgramIndicator.VALID} if valid, if not any of
+ * {@link ProgramIndicator.EXPRESSION_NOT_WELL_FORMED},
+ * {@link ProgramIndicator.INVALID_VARIABLES_IN_EXPRESSION}.
*/
String expressionIsValid( String expression );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2015-06-02 12:18:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2015-06-02 15:19:55 +0000
@@ -653,6 +653,7 @@
success=Success
waiting=Please wait
expression_not_well_formed=Expression is not well formed
+invalid_identifiers_in_expression=Invalid identifiers in expression
locate_by_code=Locate by code
select_at_level=Select at level
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-05-28 15:04:54 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramIndicatorService.java 2015-06-02 15:19:55 +0000
@@ -341,7 +341,7 @@
}
else
{
- return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
+ return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
}
else if ( ProgramIndicator.KEY_ATTRIBUTE.equals( key ) )
@@ -354,7 +354,7 @@
}
else
{
- return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
+ return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
}
else if ( ProgramIndicator.KEY_CONSTANT.equals( key ) )
@@ -367,7 +367,7 @@
}
else
{
- return ProgramIndicator.EXPRESSION_NOT_WELL_FORMED;
+ return ProgramIndicator.INVALID_IDENTIFIERS_IN_EXPRESSION;
}
}
else if ( ProgramIndicator.KEY_PROGRAM_VARIABLE.equals( key ) )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java 2015-05-14 12:28:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java 2015-06-02 15:19:55 +0000
@@ -28,15 +28,79 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.dxf2.render.RenderService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.program.ProgramIndicator;
+import org.hisp.dhis.program.ProgramIndicatorService;
import org.hisp.dhis.schema.descriptors.ProgramIndicatorSchemaDescriptor;
+import org.hisp.dhis.util.ExpressionUtils;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.hisp.dhis.webapi.webdomain.ValidationResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping( value = ProgramIndicatorSchemaDescriptor.API_ENDPOINT )
public class ProgramIndicatorController
extends AbstractCrudController<ProgramIndicator>
{
+ @Autowired
+ private ProgramIndicatorService programIndicatorService;
+
+ @Autowired
+ private RenderService renderService;
+
+ @Autowired
+ private I18nManager i18nManager;
+
+ @RequestMapping( value = "/expression/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
+ public void getExpressionDescription( @RequestParam String expression, HttpServletResponse response )
+ throws IOException
+ {
+ I18n i18n = i18nManager.getI18n();
+
+ String result = programIndicatorService.expressionIsValid( expression );
+
+ ValidationResult validation = new ValidationResult();
+ validation.setValid( ProgramIndicator.VALID.equals( result ) );
+ validation.setMessage( i18n.getString( result ) );
+
+ if ( validation.isValid() )
+ {
+ String description = programIndicatorService.getExpressionDescription( expression );
+
+ validation.setDescription( description );
+ }
+
+ response.setContentType( MediaType.APPLICATION_JSON_VALUE );
+ renderService.toJson( response.getOutputStream(), validation, ValidationResult.class );
+ }
+
+ @RequestMapping( value = "/filter/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
+ public void validateFilter( @RequestParam String filter, HttpServletResponse response )
+ throws IOException
+ {
+ Boolean result = ExpressionUtils.isBoolean( filter, null );
+
+ ValidationResult validation = new ValidationResult();
+ validation.setValid( result );
+ validation.setMessage( result ? ProgramIndicator.VALID : ProgramIndicator.EXPRESSION_NOT_WELL_FORMED );
+
+ if ( validation.isValid() )
+ {
+ validation.setDescription( "" );
+ }
+
+ response.setContentType( MediaType.APPLICATION_JSON_VALUE );
+ renderService.toJson( response.getOutputStream(), validation, ValidationResult.class );
+ }
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java 2015-06-02 15:19:55 +0000
@@ -0,0 +1,77 @@
+package org.hisp.dhis.webapi.webdomain;
+
+/*
+ * Copyright (c) 2004-2015, 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 com.fasterxml.jackson.annotation.JsonProperty;
+
+public class ValidationResult
+{
+ private Boolean valid;
+
+ private String message;
+
+ private String description;
+
+ public ValidationResult()
+ {
+ }
+
+ @JsonProperty
+ public Boolean isValid()
+ {
+ return valid;
+ }
+
+ public void setValid( Boolean valid )
+ {
+ this.valid = valid;
+ }
+
+ @JsonProperty
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setMessage( String message )
+ {
+ this.message = message;
+ }
+
+ @JsonProperty
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+}
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorDescriptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorDescriptionAction.java 2015-02-18 13:48:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorDescriptionAction.java 1970-01-01 00:00:00 +0000
@@ -1,100 +0,0 @@
-package org.hisp.dhis.trackedentity.action.programindicator;
-
-/*
- * Copyright (c) 2004-2015, 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 org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.program.ProgramIndicator;
-import org.hisp.dhis.program.ProgramIndicatorService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Chau Thu Tran
- * @version $ GetProgramIndicatorDescripttionAction.java May 30, 2013 11:09:04
- * AM $
- */
-public class GetProgramIndicatorDescriptionAction
- implements Action
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private ProgramIndicatorService programIndicatorService;
-
- public void setProgramIndicatorService( ProgramIndicatorService programIndicatorService )
- {
- this.programIndicatorService = programIndicatorService;
- }
-
- private I18n i18n;
-
- public void setI18n( I18n i18n )
- {
- this.i18n = i18n;
- }
-
- // -------------------------------------------------------------------------
- // Setters
- // -------------------------------------------------------------------------
-
- private String expression;
-
- public void setExpression( String expression )
- {
- this.expression = expression;
- }
-
- private String message;
-
- public String getMessage()
- {
- return message;
- }
-
- // -------------------------------------------------------------------------
- // Action implementation
- // -------------------------------------------------------------------------
-
- @Override
- public String execute()
- throws Exception
- {
- String valid = programIndicatorService.expressionIsValid( expression );
- if ( valid.equals( ProgramIndicator.VALID ) )
- {
- message = programIndicatorService.getExpressionDescription( expression );
- return SUCCESS;
- }
-
- message = i18n.getString( "expression_is_not_well_formed" );
-
- return ERROR;
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml 2015-05-15 04:04:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/META-INF/dhis/beans.xml 2015-06-02 15:19:55 +0000
@@ -1009,15 +1009,6 @@
</property>
</bean>
- <bean
- id="org.hisp.dhis.trackedentity.action.programindicator.GetProgramIndicatorDescriptionAction"
- class="org.hisp.dhis.trackedentity.action.programindicator.GetProgramIndicatorDescriptionAction"
- scope="prototype">
- <property name="programIndicatorService">
- <ref bean="org.hisp.dhis.program.ProgramIndicatorService" />
- </property>
- </bean>
-
<!-- Program reminder -->
<bean
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml 2015-04-23 11:59:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml 2015-06-02 15:19:55 +0000
@@ -1072,16 +1072,6 @@
<param name="onExceptionReturn">plainTextError</param>
</action>
- <action name="getProgramIndicatorDescription"
- class="org.hisp.dhis.trackedentity.action.programindicator.GetProgramIndicatorDescriptionAction">
- <result name="success" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseSuccess.vm
- </result>
- <result name="error" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseError.vm
- </result>
- </action>
-
<!-- Program reminder -->
<action name="programReminder"
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-02-18 13:48:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-06-02 15:19:55 +0000
@@ -94,26 +94,24 @@
}
function getConditionDescription() {
- var expression = getFieldValue('expression');
+ var expression = getFieldValue('expression');
if( expression == '' )
{
setInnerHTML('aggregationDescription', '');
}
else
{
- $.postJSON('getProgramIndicatorDescription.action',
- {
- expression: expression
+ $.getJSON('../api/programIndicators/expression/description', {
+ expression: expression
}, function( json ) {
- if( json.response =='error' ){
+ if( json.valid ){
+ setFieldValue('checkExpression', json.message);
+ setInnerHTML('aggregationDescription', json.description);
+ }
+ else {
setFieldValue('checkExpression','');
- $('#aggregationDescription').css('color','red');
- }
- else{
- setFieldValue('checkExpression', json.message);
- $('#aggregationDescription').css('color','black');
- }
- setInnerHTML('aggregationDescription', json.message);
+ setInnerHTML('aggregationDescription', json.message);
+ }
});
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm 2015-06-02 13:46:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm 2015-06-02 15:19:55 +0000
@@ -25,7 +25,7 @@
</tr>
<tr>
<td>
- <select multiple id="dataElements" name="dataElements" size="8" style="width:100%" ondblclick="insertDataElement(this);"></select>
+ <select multiple id="dataElements" name="dataElements" size="7" style="width:100%" ondblclick="insertDataElement(this);"></select>
</td>
</tr>
</table>
@@ -43,7 +43,7 @@
</tr>
<tr>
<td>
- <select multiple id="attributes" name="attributes" size="8" style="width:100%" ondblclick="insertData(this,'A');">
+ <select multiple id="attributes" name="attributes" size="7" style="width:100%" ondblclick="insertData(this,'A');">
#foreach( $programAttribute in $program.programAttributes )
#if( $programAttribute.attribute.valueType=='number' )
<option value='$programAttribute.attribute.uid'>$encoder.htmlEncode($programAttribute.attribute.displayName)</option>
@@ -65,7 +65,7 @@
</tr>
<tr>
<td>
- <select multiple id="programProperty" name="programProperty" size="8" style="width:100%" ondblclick="insertInfo(this, false);" >
+ <select multiple id="programProperty" name="programProperty" size="7" style="width:100%" ondblclick="insertInfo(this, false);" >
<option value="V{incident_date}">$i18n.getString( "incident_date" )</option>
<option value="V{enrollment_date}">$i18n.getString( "date_of_enrollment" )</option>
<option value="V{current_date}">$i18n.getString( "current_date" )</option>
@@ -89,7 +89,7 @@
</tr>
<tr>
<td>
- <select multiple id="constants" name="constants" size="8" style="width:100%" ondblclick="insertData(this,'C');">
+ <select multiple id="constants" name="constants" size="7" style="width:100%" ondblclick="insertData(this,'C');">
#foreach( $constant in $constants )
<option value='$constant.uid'>$encoder.htmlEncode($constant.displayName)</option>
#end