dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37776
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19291: Program indicator expression validation, extending WebMessage
------------------------------------------------------------
revno: 19291
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-06-05 12:40:30 +0200
message:
Program indicator expression validation, extending WebMessage
renamed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java => dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/DescriptiveWebMessage.java
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.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/webapp/dhis-web-maintenance-program/javascript/programIndicator.js
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/DescriptiveWebMessage.java
--
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
=== renamed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java' => 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/DescriptiveWebMessage.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/ValidationResult.java 2015-06-02 15:19:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/DescriptiveWebMessage.java 2015-06-05 10:40:30 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.webapi.webdomain;
+package org.hisp.dhis.dxf2.webmessage;
/*
* Copyright (c) 2004-2015, University of Oslo
@@ -28,42 +28,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dxf2.webmessage.WebMessage;
+
import com.fasterxml.jackson.annotation.JsonProperty;
-public class ValidationResult
-{
- private Boolean valid;
-
- private String message;
-
+public class DescriptiveWebMessage
+ extends WebMessage
+{
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;
- }
-
+ public DescriptiveWebMessage()
+ {
+ super();
+ }
+
@JsonProperty
public String getDescription()
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java 2015-06-05 10:40:30 +0000
@@ -83,6 +83,10 @@
*/
protected WebMessageResponse response;
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
public WebMessage()
{
this.status = WebMessageStatus.OK;
@@ -99,6 +103,24 @@
this.httpStatusCode = httpStatusCode;
}
+ // -------------------------------------------------------------------------
+ // Logic
+ // -------------------------------------------------------------------------
+
+ public boolean okStatus()
+ {
+ return WebMessageStatus.OK.equals( status );
+ }
+
+ public boolean errorStatus()
+ {
+ return WebMessageStatus.ERROR.equals( status );
+ }
+
+ // -------------------------------------------------------------------------
+ // Get and set methods
+ // -------------------------------------------------------------------------
+
@JsonProperty
@JacksonXmlProperty( isAttribute = true )
public WebMessageStatus getStatus()
=== 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-06-02 22:11:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java 2015-06-05 10:40:30 +0000
@@ -33,13 +33,14 @@
import javax.servlet.http.HttpServletResponse;
import org.hisp.dhis.dxf2.render.RenderService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageStatus;
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.webapi.controller.AbstractCrudController;
-import org.hisp.dhis.webapi.webdomain.ValidationResult;
+import org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@@ -69,11 +70,11 @@
String result = programIndicatorService.expressionIsValid( expression );
- ValidationResult validation = new ValidationResult();
- validation.setValid( ProgramIndicator.VALID.equals( result ) );
+ DescriptiveWebMessage validation = new DescriptiveWebMessage();
+ validation.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
validation.setMessage( i18n.getString( result ) );
- if ( validation.isValid() )
+ if ( validation.okStatus() )
{
String description = programIndicatorService.getExpressionDescription( expression );
@@ -81,7 +82,7 @@
}
response.setContentType( MediaType.APPLICATION_JSON_VALUE );
- renderService.toJson( response.getOutputStream(), validation, ValidationResult.class );
+ renderService.toJson( response.getOutputStream(), validation, DescriptiveWebMessage.class );
}
@RequestMapping( value = "/filter/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
@@ -92,11 +93,11 @@
String result = programIndicatorService.filterIsValid( expression );
- ValidationResult validation = new ValidationResult();
- validation.setValid( ProgramIndicator.VALID.equals( result ) );
+ DescriptiveWebMessage validation = new DescriptiveWebMessage();
+ validation.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
validation.setMessage( i18n.getString( result ) );
- if ( validation.isValid() )
+ if ( validation.okStatus() )
{
String description = programIndicatorService.getExpressionDescription( expression );
@@ -104,6 +105,6 @@
}
response.setContentType( MediaType.APPLICATION_JSON_VALUE );
- renderService.toJson( response.getOutputStream(), validation, ValidationResult.class );
+ renderService.toJson( response.getOutputStream(), validation, DescriptiveWebMessage.class );
}
}
=== 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-06-03 16:14:07 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js 2015-06-05 10:40:30 +0000
@@ -123,7 +123,7 @@
function getExpressionDescription( type ) {
var expression = getFieldValue( type );
- if( expression == '' )
+ if( !expression || expression == '' )
{
setInnerHTML(type + '-description', '');
}
@@ -132,7 +132,7 @@
$.getJSON('../api/programIndicators/' + type + '/description', {
expression: expression
}, function( json ) {
- if( json.valid ){
+ if( 'OK' == json.status ){
setInnerHTML(type + '-description', json.description);
}
else {