use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method addDataSource.
@Override
// ordering annotations is important to check current participants before method invoke
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_DATANODE)")
public StudyDataSourceLink addDataSource(IUser createdBy, Long studyId, Long dataSourceId) throws NotExistException, AlreadyExistException {
T study = studyRepository.findOne(studyId);
if (study == null) {
throw new NotExistException("study not exist", Study.class);
}
DS dataSource = dataSourceService.getNotDeletedById(dataSourceId);
if (dataSource == null) {
throw new NotExistException("dataSource not exist", DataSource.class);
}
StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByDataSourceIdAndStudyId(dataSource.getId(), study.getId());
if (studyDataSourceLink == null) {
studyDataSourceLink = new StudyDataSourceLink();
} else if (studyDataSourceLink.getStatus().isPendingOrApproved()) {
throw new AlreadyExistException();
}
studyDataSourceLink.setStudy(study);
studyDataSourceLink.setDataSource(dataSource);
studyDataSourceLink.setCreated(new Date());
studyDataSourceLink.setToken(UUID.randomUUID().toString());
studyDataSourceLink.setCreatedBy(createdBy);
studyDataSourceLink.setDeletedAt(null);
AddDataSourceStrategy<DS> strategy = addDataSourceStrategyFactory.getStrategy(dataSource);
strategy.addDataSourceToStudy(createdBy, dataSource, studyDataSourceLink);
return studyDataSourceLink;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method updateParticipantRole.
@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_CONTRIBUTOR)")
public UserStudy updateParticipantRole(Long studyId, Long participantId, ParticipantRole role) throws NotExistException, AlreadyExistException, ValidationException {
Study study = Optional.ofNullable(studyRepository.findOne(studyId)).orElseThrow(() -> new NotExistException(EX_STUDY_NOT_EXISTS, Study.class));
IUser participant = Optional.ofNullable(userService.findOne(participantId)).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
UserStudy studyLink = Optional.ofNullable(userStudyRepository.findOneByStudyAndUser(study, participant)).orElseThrow(() -> new NotExistException(UserStudy.class));
checkLastLeadInvestigator(studyLink, study);
studyLink.setRole(role);
return userStudyRepository.save(studyLink);
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method list.
@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
JsonResult<List<D>> result;
IUser user = userService.getByEmail(principal.getName());
if (user == null) {
result = new JsonResult<>(PERMISSION_DENIED);
return result;
}
Iterable<T> analyses = analysisService.list(user, studyId);
result = new JsonResult<>(NO_ERROR);
List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
result.setResult(analysisDTOs);
return result;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException 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.portal.exception.NotExistException 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;
}
Aggregations