use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseUserController method linkUserToDataNode.
@ApiOperation("Link U to DataNode")
@RequestMapping(value = "/api/v1/user-management/datanodes/{datanodeSid}/users", method = POST)
public JsonResult linkUserToDataNode(@PathVariable("datanodeSid") Long datanodeId, @RequestBody CommonLinkUserToDataNodeDTO linkUserToDataNode) throws NotExistException, AlreadyExistException {
final DN dataNode = Optional.ofNullable(baseDataNodeService.getById(datanodeId)).orElseThrow(() -> new NotExistException(String.format(DATA_NODE_NOT_FOUND_EXCEPTION, datanodeId), DataNode.class));
final U user = userService.getByUnverifiedEmailInAnyTenant(linkUserToDataNode.getUserName());
baseDataNodeService.linkUserToDataNode(dataNode, user);
return new JsonResult(NO_ERROR);
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class StudyTypeController method create.
@ApiOperation(value = "Register new study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types", method = RequestMethod.POST)
public JsonResult create(@RequestBody @Valid CreateStudyTypeDTO studyTypeDTO, BindingResult binding) {
JsonResult result;
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.create(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 (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;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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);
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class ExceptionHandlingController method exceptionHandler.
@ExceptionHandler(Exception.class)
public ResponseEntity<JsonResult> exceptionHandler(Exception ex) {
LOGGER.error(ex.getMessage(), ex);
JsonResult result = new JsonResult<>(SYSTEM_ERROR);
result.setErrorMessage(ex.getMessage());
return new ResponseEntity<>(result, HttpStatus.OK);
}
Aggregations