dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38453
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19587: updated ValidationController to use WebMessage
------------------------------------------------------------
revno: 19587
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 15:33:42 +0700
message:
updated ValidationController to use WebMessage
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationController.java 2015-02-09 17:53:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/validation/ValidationController.java 2015-07-08 08:33:42 +0000
@@ -28,23 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-
-import javax.servlet.http.HttpServletResponse;
-
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.validation.ValidationResult;
import org.hisp.dhis.validation.ValidationRuleService;
import org.hisp.dhis.validation.ValidationSummary;
-import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -53,6 +48,9 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+
/**
* @author Lars Helge Overland
*/
@@ -62,61 +60,56 @@
{
@Autowired
private ValidationRuleService validationRuleService;
-
- @Autowired
- private DataSetService dataSetService;
-
- @Autowired
- private PeriodService periodService;
-
+
+ @Autowired
+ private DataSetService dataSetService;
+
@Autowired
private OrganisationUnitService organisationUnitService;
-
+
@Autowired
private DataElementCategoryService categoryService;
-
+
@RequestMapping( value = "/dataSet/{ds}", method = RequestMethod.GET )
- public String validate( @PathVariable String ds, @RequestParam String pe,
- @RequestParam String ou, @RequestParam( required = false ) String aoc,
- HttpServletResponse response, Model model )
+ public String validate( @PathVariable String ds, @RequestParam String pe,
+ @RequestParam String ou, @RequestParam( required = false ) String aoc,
+ HttpServletResponse response, Model model ) throws WebMessageException
{
DataSet dataSet = dataSetService.getDataSet( ds );
-
+
if ( dataSet == null )
{
- ContextUtils.conflictResponse( response, "Data set does not exist: " + ds );
- return null;
+ throw new WebMessageException( WebMessageUtils.conflict( "Data set does not exist: " + ds ) );
}
-
+
Period period = PeriodType.getPeriodFromIsoString( pe );
-
+
if ( period == null )
{
- ContextUtils.conflictResponse( response, "Period does not exist: " + pe );
- return null;
+ throw new WebMessageException( WebMessageUtils.conflict( "Period does not exist: " + pe ) );
}
-
+
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ou );
-
+
if ( orgUnit == null )
{
- ContextUtils.conflictResponse( response, "Organisation unit does not exist: " + pe );
- return null;
+ throw new WebMessageException( WebMessageUtils.conflict( "Organisation unit does not exist: " + ou ) );
}
-
+
DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo( aoc );
-
+
if ( attributeOptionCombo == null )
{
attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
-
+
ValidationSummary summary = new ValidationSummary();
-
- summary.setValidationRuleViolations( new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, orgUnit, attributeOptionCombo ) ) );
+
+ summary.setValidationRuleViolations( new ArrayList<>( validationRuleService.validate( dataSet, period, orgUnit, attributeOptionCombo ) ) );
summary.setCommentRequiredViolations( validationRuleService.validateRequiredComments( dataSet, period, orgUnit, attributeOptionCombo ) );
-
+
model.addAttribute( "model", summary );
- return "summary";
+
+ return "summary";
}
}