Search in sources :

Example 6 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 7 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(PasswordValidationException.class)
public ResponseEntity<JsonResult> exceptionHandler(PasswordValidationException ex) {
    LOGGER.error("User tried to register with weak password");
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage("You have provided a weak password");
    final ArachnePasswordInfoDTO passwordInfoDTO = conversionService.convert(ex.getPasswordInfo(), ArachnePasswordInfoDTO.class);
    result.getValidatorErrors().put("password", passwordInfoDTO);
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArachnePasswordInfoDTO(com.odysseusinc.arachne.commons.api.v1.dto.ArachnePasswordInfoDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 8 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 sendUnlockRequest.

@ApiOperation("Send analysis unlock request")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/unlock-request", method = POST)
public JsonResult<FileDTO> sendUnlockRequest(Principal principal, @PathVariable("analysisId") Long analysisId, @RequestBody AnalysisUnlockRequestDTO analysisUnlockRequestDTO) throws NotExistException, PermissionDeniedException, AlreadyExistException {
    JsonResult result;
    final IUser user = getUser(principal);
    final AnalysisUnlockRequest unlockRequest = new AnalysisUnlockRequest();
    unlockRequest.setUser(user);
    unlockRequest.setStatus(AnalysisUnlockRequestStatus.PENDING);
    unlockRequest.setCreated(new Date());
    unlockRequest.setToken(UUID.randomUUID().toString().replace("-", ""));
    unlockRequest.setDescription(analysisUnlockRequestDTO.getDescription());
    try {
        final AnalysisUnlockRequest analysisUnlockRequest = analysisService.sendAnalysisUnlockRequest(analysisId, unlockRequest);
        analysisService.findLeads((T) analysisUnlockRequest.getAnalysis()).forEach(lead -> wsTemplate.convertAndSendToUser(lead.getUsername(), "/topic/invitations", new UpdateNotificationDTO()));
        result = new JsonResult<>(NO_ERROR);
    } catch (AlreadyExistException ex) {
        result = new JsonResult<>(VALIDATION_ERROR);
        result.setErrorMessage("Unlock request for the analysis was already created");
    }
    return result;
}
Also used : UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) IUser(com.odysseusinc.arachne.portal.model.IUser) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 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(WrongFileFormatException.class)
public ResponseEntity<JsonResult> exceptionHandler(WrongFileFormatException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getField(), 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 10 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(FieldException.class)
public ResponseEntity<JsonResult> exceptionHandler(FieldException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage("Incorrect data");
    result.getValidatorErrors().put(ex.getField(), 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)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 ResponseEntity (org.springframework.http.ResponseEntity)9 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)9 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 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 Date (java.util.Date)1 UUID (java.util.UUID)1