Search in sources :

Example 1 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method update.

@ApiOperation("Update analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}", method = PUT)
public JsonResult<D> update(@PathVariable("analysisId") Long id, @RequestBody @Valid AnalysisUpdateDTO analysisDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    JsonResult<D> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        T analysis = conversionService.convert(analysisDTO, getAnalysisClass());
        analysis.setId(id);
        analysis = analysisService.update(analysis);
        result = new JsonResult<>(NO_ERROR);
        result.setResult(conversionService.convert(analysis, getAnalysisDTOClass()));
    }
    return result;
}
Also used : PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) UUID(java.util.UUID) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(NotExistException.class)
public ResponseEntity<JsonResult> exceptionHandler(NotExistException ex) {
    LOGGER.error(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getEntity().getSimpleName(), ex.getMessage());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 3 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(NoExecutableFileException.class)
public ResponseEntity<JsonResult> exceptionHandler(NoExecutableFileException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 4 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<JsonResult> exceptionHandler(ConstraintViolationException ex) {
    LOGGER.warn(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    if (!ex.getConstraintViolations().isEmpty()) {
        result = setValidationErrors(ex.getConstraintViolations());
    }
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 5 with VALIDATION_ERROR

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<JsonResult> exceptionHandler(UserNotFoundException ex, HttpServletResponse response) throws IOException {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getField(), ex.getMessage());
    response.sendRedirect("/auth/login?message=email-not-confirmed");
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)15 ResponseEntity (org.springframework.http.ResponseEntity)12 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)12 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 GET (org.springframework.web.bind.annotation.RequestMethod.GET)2 POST (org.springframework.web.bind.annotation.RequestMethod.POST)2 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)2 ArachnePasswordInfoDTO (com.odysseusinc.arachne.commons.api.v1.dto.ArachnePasswordInfoDTO)1 PERMISSION_DENIED (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED)1 InvitationActionWithTokenDTO (com.odysseusinc.arachne.portal.api.v1.dto.InvitationActionWithTokenDTO)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 PasswordValidationException (com.odysseusinc.arachne.portal.exception.PasswordValidationException)1 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)1 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 Collection (java.util.Collection)1 Date (java.util.Date)1