← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19293: Program indicator validation, using WebMessageService

 

------------------------------------------------------------
revno: 19293
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-06-05 13:12:14 +0200
message:
  Program indicator validation, using WebMessageService
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/AbstractCrudController.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-api/src/main/java/org/hisp/dhis/webapi/service/WebMessageService.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
=== 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-06-05 10:48:21 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/webmessage/WebMessage.java	2015-06-05 11:12:14 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.common.DxfNamespaces;
+import org.springframework.http.HttpStatus;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -61,7 +62,7 @@
     /**
      * HTTP status code.
      */
-    protected Integer httpStatusCode = 200;
+    protected Integer httpStatusCode = HttpStatus.OK.value();
 
     /**
      * Non-technical message, should be simple and could possibly be used to display message
@@ -90,11 +91,13 @@
     public WebMessage()
     {
         this.status = WebMessageStatus.OK;
+        this.httpStatusCode = HttpStatus.OK.value();
     }
 
     public WebMessage( WebMessageStatus status )
     {
         this.status = status;
+        this.httpStatusCode = HttpStatus.OK.value();
     }
 
     public WebMessage( WebMessageStatus status, Integer httpStatusCode )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2015-06-05 10:48:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2015-06-05 11:12:14 +0000
@@ -35,6 +35,7 @@
 import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
+
 import org.hisp.dhis.acl.AclService;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -91,6 +92,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
@@ -146,7 +148,7 @@
 
     @Autowired
     protected QueryService queryService;
-
+    
     @Autowired
     protected WebMessageService webMessageService;
 

=== 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-05 10:40:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramIndicatorController.java	2015-06-05 11:12:14 +0000
@@ -32,7 +32,7 @@
 
 import javax.servlet.http.HttpServletResponse;
 
-import org.hisp.dhis.dxf2.render.RenderService;
+import org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage;
 import org.hisp.dhis.dxf2.webmessage.WebMessageStatus;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nManager;
@@ -40,7 +40,6 @@
 import org.hisp.dhis.program.ProgramIndicatorService;
 import org.hisp.dhis.schema.descriptors.ProgramIndicatorSchemaDescriptor;
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
-import org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
@@ -57,9 +56,6 @@
     private ProgramIndicatorService programIndicatorService;
 
     @Autowired
-    private RenderService renderService;
-    
-    @Autowired
     private I18nManager i18nManager;
 
     @RequestMapping( value = "/expression/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
@@ -70,19 +66,18 @@
         
         String result = programIndicatorService.expressionIsValid( expression );
         
-        DescriptiveWebMessage validation = new DescriptiveWebMessage();
-        validation.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
-        validation.setMessage( i18n.getString( result ) );
+        DescriptiveWebMessage message = new DescriptiveWebMessage();
+        message.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
+        message.setMessage( i18n.getString( result ) );
         
-        if ( validation.okStatus() )
+        if ( message.okStatus() )
         {
             String description = programIndicatorService.getExpressionDescription( expression );
             
-            validation.setDescription( description );
+            message.setDescription( description );
         }
         
-        response.setContentType( MediaType.APPLICATION_JSON_VALUE );
-        renderService.toJson( response.getOutputStream(), validation, DescriptiveWebMessage.class );
+        webMessageService.sendJson( message, response );
     }
 
     @RequestMapping( value = "/filter/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE )
@@ -93,18 +88,17 @@
         
         String result = programIndicatorService.filterIsValid( expression );
         
-        DescriptiveWebMessage validation = new DescriptiveWebMessage();
-        validation.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
-        validation.setMessage( i18n.getString( result ) );
+        DescriptiveWebMessage message = new DescriptiveWebMessage();
+        message.setStatus( ProgramIndicator.VALID.equals( result ) ? WebMessageStatus.OK : WebMessageStatus.ERROR );
+        message.setMessage( i18n.getString( result ) );
         
-        if ( validation.okStatus() )
+        if ( message.okStatus() )
         {
             String description = programIndicatorService.getExpressionDescription( expression );
             
-            validation.setDescription( description );
+            message.setDescription( description );
         }
         
-        response.setContentType( MediaType.APPLICATION_JSON_VALUE );
-        renderService.toJson( response.getOutputStream(), validation, DescriptiveWebMessage.class );
+        webMessageService.sendJson( message, response );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/WebMessageService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/WebMessageService.java	2015-06-05 10:48:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/service/WebMessageService.java	2015-06-05 11:12:14 +0000
@@ -28,6 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.webmessage.WebMessage;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,10 +40,6 @@
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
 /**
  * WebMessage service methods.
  *