Search in sources :

Example 31 with JsonResult

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

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(AlreadyExistException.class)
public ResponseEntity<JsonResult> exceptionHandler(AlreadyExistException ex) {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(ALREADY_EXIST);
    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 32 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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 33 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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 34 with JsonResult

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

the class ProfessionalTypeController method update.

@ApiOperation(value = "Update professional type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/professional-types/{professionalTypeId}", method = RequestMethod.PUT)
public JsonResult<CommonProfessionalTypeDTO> update(@PathVariable("professionalTypeId") Long id, @RequestBody @Valid CommonProfessionalTypeDTO professionalTypeDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    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 {
        ProfessionalType professionalType = conversionService.convert(professionalTypeDTO, ProfessionalType.class);
        professionalType.setId(id);
        professionalType = professionalTypeService.update(professionalType);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(professionalType);
    }
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with JsonResult

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

the class ProfessionalTypeController method get.

@ApiOperation("Get professional type.")
@RequestMapping(value = "/api/v1/user-management/professional-types/{professionalTypeId}", method = RequestMethod.GET)
public JsonResult<CommonProfessionalTypeDTO> get(@PathVariable("professionalTypeId") Long id) throws NotExistException {
    JsonResult result;
    if (id == null) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("professionalTypeId", "cannot be null");
    } else {
        ProfessionalType skill = professionalTypeService.getById(id);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(skill);
    }
    return result;
}
Also used : ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)71 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)58 ApiOperation (io.swagger.annotations.ApiOperation)55 IUser (com.odysseusinc.arachne.portal.model.IUser)22 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)17 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)17 ResponseEntity (org.springframework.http.ResponseEntity)16 GET (org.springframework.web.bind.annotation.RequestMethod.GET)10 POST (org.springframework.web.bind.annotation.RequestMethod.POST)10 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)10 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 FieldError (org.springframework.validation.FieldError)6 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)5 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)5 DataNode (com.odysseusinc.arachne.portal.model.DataNode)5 IOException (java.io.IOException)5 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)4 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)4