Search in sources :

Example 6 with NotUniqueException

use of com.odysseusinc.arachne.portal.exception.NotUniqueException in project ArachneCentralAPI by OHDSI.

the class StudyTypeController method update.

@ApiOperation(value = "Edit study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types/{studyTypeId}", method = RequestMethod.PUT)
public JsonResult update(@PathVariable("studyTypeId") Long id, @RequestBody @Valid StudyTypeDTO studyTypeDTO, BindingResult binding) {
    JsonResult result = null;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        try {
            StudyType studyType = conversionService.convert(studyTypeDTO, StudyType.class);
            studyType = studyTypeService.update(studyType);
            result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
            result.setResult(studyType);
        } catch (ConverterNotFoundException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        } catch (NotExistException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put("id", "Status with id=" + id + " not found");
            result.setErrorMessage(ex.getMessage());
        } catch (NotUniqueException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put(ex.getField(), ex.getMessage());
            result.setErrorMessage(ex.getMessage());
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        }
    }
    return result;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FieldError(org.springframework.validation.FieldError) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)4 Date (java.util.Date)3 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)2 StudyType (com.odysseusinc.arachne.portal.model.StudyType)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ConverterNotFoundException (org.springframework.core.convert.ConverterNotFoundException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 FieldError (org.springframework.validation.FieldError)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)1 PostAuthorize (org.springframework.security.access.prepost.PostAuthorize)1