Search in sources :

Example 56 with FieldError

use of org.springframework.validation.FieldError in project ArachneCentralAPI by OHDSI.

the class StudyStatusController method create.

@ApiOperation(value = "Register new study status.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-statuses", method = RequestMethod.POST)
public JsonResult<StudyStatusDTO> create(@RequestBody @Valid CreateStudyStatusDTO studyStatusDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
    JsonResult<StudyStatusDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        StudyStatus studyStatus = conversionService.convert(studyStatusDTO, StudyStatus.class);
        studyStatus = studyStatusService.create(studyStatus);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(studyStatus, StudyStatusDTO.class));
    }
    return result;
}
Also used : StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) CreateStudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyStatusDTO) StudyStatus(com.odysseusinc.arachne.portal.model.StudyStatus) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with FieldError

use of org.springframework.validation.FieldError in project production_ssm by megagao.

the class OrderController method insert.

@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid COrder cOrder, BindingResult bindingResult) throws Exception {
    CustomResult result;
    if (bindingResult.hasErrors()) {
        FieldError fieldError = bindingResult.getFieldError();
        System.out.println(fieldError.getDefaultMessage());
        return CustomResult.build(100, fieldError.getDefaultMessage());
    }
    if (orderService.get(cOrder.getOrderId()) != null) {
        result = new CustomResult(0, "该订单编号已经存在,请更换订单编号!", null);
    } else {
        result = orderService.insert(cOrder);
    }
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) CustomResult(com.megagao.production.ssm.domain.customize.CustomResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 58 with FieldError

use of org.springframework.validation.FieldError in project production_ssm by megagao.

the class UserController method updateAll.

@RequestMapping(value = "/update_all")
@ResponseBody
private CustomResult updateAll(@Valid SysUser user, BindingResult bindingResult) throws Exception {
    CustomResult result;
    if (bindingResult.hasErrors()) {
        FieldError fieldError = bindingResult.getFieldError();
        return CustomResult.build(100, fieldError.getDefaultMessage());
    }
    if (userService.findByUserNameAndId(user.getUsername(), user.getId()).size() > 0) {
        return CustomResult.build(101, "该用户名已经存在,请更换用户名!");
    }
    result = userService.updateAll(user);
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) CustomResult(com.megagao.production.ssm.domain.customize.CustomResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 59 with FieldError

use of org.springframework.validation.FieldError in project production_ssm by megagao.

the class UserController method insert.

@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid SysUser user, BindingResult bindingResult) throws Exception {
    CustomResult result;
    if (bindingResult.hasErrors()) {
        FieldError fieldError = bindingResult.getFieldError();
        return CustomResult.build(100, fieldError.getDefaultMessage());
    }
    if (userService.findByUserNameAndId(user.getUsername(), user.getId()).size() > 0) {
        return CustomResult.build(101, "该用户名已经存在,请更换用户名!");
    } else if (userService.get(user.getId()) != null) {
        return CustomResult.build(101, "该用户编号已经存在,请更换用户编号!");
    }
    result = userService.insert(user);
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) CustomResult(com.megagao.production.ssm.domain.customize.CustomResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 60 with FieldError

use of org.springframework.validation.FieldError in project production_ssm by megagao.

the class PMeasureCheckController method insert.

/*
	 *此处的method可以取两个值,
	 *一个是RequestMethod.GET,一个是RequestMethod.POST,
	 *就是请求该方法使用的模式,是get还是post,即参数提交的方法
	 *ajax或者form表单提交数据有两种方法,即get和post。
	 */
@RequestMapping(value = "/insert", method = RequestMethod.POST)
@ResponseBody
private CustomResult insert(@Valid ProcessMeasureCheck processMeasureCheck, BindingResult bindingResult) throws Exception {
    CustomResult result;
    if (bindingResult.hasErrors()) {
        FieldError fieldError = bindingResult.getFieldError();
        return CustomResult.build(100, fieldError.getDefaultMessage());
    }
    result = pMeasureCheckService.insert(processMeasureCheck);
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) CustomResult(com.megagao.production.ssm.domain.customize.CustomResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FieldError (org.springframework.validation.FieldError)92 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ObjectError (org.springframework.validation.ObjectError)19 Test (org.junit.jupiter.api.Test)17 BindingResult (org.springframework.validation.BindingResult)16 ApiOperation (io.swagger.annotations.ApiOperation)14 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)12 Errors (org.springframework.validation.Errors)11 ArrayList (java.util.ArrayList)7 BindException (org.springframework.validation.BindException)6 CustomResult (com.megagao.production.ssm.domain.customize.CustomResult)5 Locale (java.util.Locale)5 Test (org.junit.Test)5 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 HashMap (java.util.HashMap)4 UserProfileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO)3 LinkedHashSet (java.util.LinkedHashSet)3 MapBindingResult (org.springframework.validation.MapBindingResult)3