=== 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 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 { + @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 @@ - - - - - - plainTextError - - - /dhis-web-commons/ajax/jsonResponseSuccess.vm - - - /dhis-web-commons/ajax/jsonResponseError.vm - - - - + @@ -43,7 +43,7 @@ - #foreach( $programAttribute in $program.programAttributes ) #if( $programAttribute.attribute.valueType=='number' ) @@ -65,7 +65,7 @@ - @@ -89,7 +89,7 @@ - #foreach( $constant in $constants ) #end