use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class StudyTypeController method get.
@ApiOperation("Get study type.")
@RequestMapping(value = "/api/v1/study-management/study-types/{studyTypeId}", method = RequestMethod.GET)
public JsonResult get(@PathVariable("studyTypeId") Long id) {
JsonResult result = null;
try {
StudyType studyType = studyTypeService.getById(id);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(studyType);
} catch (NotExistException ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
result.getValidatorErrors().put("studyTypeId", "Status with id=" + id + " not found");
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;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class StudyTypeController method delete.
@ApiOperation(value = "Delete study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types/{studyTypeId}", method = RequestMethod.DELETE)
public JsonResult delete(@PathVariable("studyTypeId") Long id) {
JsonResult result = null;
if (id == null) {
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
result.getValidatorErrors().put("studyTypeId", "cannot be null");
} else {
try {
studyTypeService.delete(id);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(Boolean.TRUE);
} catch (NotExistException ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
result.getValidatorErrors().put("studyTypeId", "Status with id=" + id + " not found");
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;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class StudyTypeController method list.
@ApiOperation("List study types.")
@RequestMapping(value = "/api/v1/study-management/study-types", method = RequestMethod.GET)
public JsonResult<List<StudyTypeDTO>> list() {
JsonResult result;
try {
Iterable<StudyType> studyTypees = studyTypeService.list();
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
List<StudyTypeDTO> studyTypeDTOs = new LinkedList<>();
for (StudyType studyType : studyTypees) {
studyTypeDTOs.add(conversionService.convert(studyType, StudyTypeDTO.class));
}
result.setResult(studyTypeDTOs);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
result.setErrorMessage(ex.getMessage());
}
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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);
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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);
}
Aggregations