use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeController method createDataSource.
@ApiOperation("Create new data source of datanode.")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}/data-sources", method = RequestMethod.POST)
public JsonResult createDataSource(@PathVariable("dataNodeId") Long id, @RequestBody C_DS_DTO commonDataSourceDTO) throws FieldException, NotExistException, ValidationException, IOException, SolrServerException, NoSuchFieldException, IllegalAccessException, BindException {
// we validate only two fields, because we don't want to validate another fields, because they always are null
validate(commonDataSourceDTO);
JsonResult<CommonDataSourceDTO> result;
DataNode dataNode = baseDataNodeService.getById(id);
if (dataNode == null) {
throw new IllegalArgumentException("Unable to find datanode by ID " + id);
}
DS dataSource = convertCommonDataSourceDtoToDataSource(commonDataSourceDTO);
dataSource.setDataNode(dataNode);
dataSource = dataSourceService.createOrRestoreDataSource(dataSource);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(genericConversionService.convert(dataSource, CommonDataSourceDTO.class));
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeController method createDataNode.
@ApiOperation("Create new data node.")
@RequestMapping(value = "/api/v1/data-nodes", method = RequestMethod.POST)
public JsonResult<CommonDataNodeCreationResponseDTO> createDataNode(Principal principal) throws PermissionDeniedException, AlreadyExistException {
final IUser user = getUser(principal);
final DN dataNode = buildEmptyDN();
CommonDataNodeCreationResponseDTO responseDTO = createDataNode(dataNode, principal);
final JsonResult<CommonDataNodeCreationResponseDTO> result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(responseDTO);
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseDataNodeController method updateDataNode.
@ApiOperation("Update data node info")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}", method = RequestMethod.PUT)
public JsonResult<CommonDataNodeDTO> updateDataNode(@PathVariable("dataNodeId") Long dataNodeId, @RequestBody @Valid CommonDataNodeRegisterDTO commonDataNodeRegisterDTO, Principal principal) throws PermissionDeniedException, NotExistException {
final IUser user = getUser(principal);
final DN dataNode = conversionService.convert(commonDataNodeRegisterDTO, getDataNodeDNClass());
dataNode.setId(dataNodeId);
final DN updatedDataNode = baseDataNodeService.update(dataNode);
final CommonDataNodeDTO dataNodeRegisterResponseDTO = conversionService.convert(updatedDataNode, CommonDataNodeDTO.class);
final JsonResult<CommonDataNodeDTO> result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(dataNodeRegisterResponseDTO);
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseDataSourceController method updateDataSource.
private JsonResult<DTO> updateDataSource(Principal principal, Long dataSourceId, DTO commonDataSourceDTO, BindingResult bindingResult) throws PermissionDeniedException, IllegalAccessException, IOException, NoSuchFieldException, SolrServerException, ValidationException {
JsonResult result;
if (bindingResult.hasErrors()) {
result = setValidationErrors(bindingResult);
} else {
IUser user = getUser(principal);
final DS exist = dataSourceService.getNotDeletedByIdInAnyTenant(dataSourceId);
DS dataSource = convertDTOToDataSource(commonDataSourceDTO);
dataSource.setId(dataSourceId);
dataSource.setDataNode(exist.getDataNode());
dataSource.setPublished(true);
dataSource = dataSourceService.updateInAnyTenant(dataSource);
result = new JsonResult<>(NO_ERROR);
result.setResult(convertDataSourceToDTO(dataSource));
}
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseStudyController method addParticipant.
@ApiOperation("Add participant to the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/participants", method = POST)
public JsonResult<Boolean> addParticipant(Principal principal, @PathVariable("studyId") Long studyId, @RequestBody @Valid AddStudyParticipantDTO addParticipantDTO, BindingResult binding) throws PermissionDeniedException, NotExistException, AlreadyExistException {
JsonResult<Boolean> result;
if (binding.hasErrors()) {
return setValidationErrors(binding);
}
final IUser createdBy = getUser(principal);
IUser participant = Optional.ofNullable(userService.getByUuid(addParticipantDTO.getUserId())).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
UserStudy userStudy = studyService.addParticipant(createdBy, studyId, participant.getId(), addParticipantDTO.getRole());
wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
Aggregations