use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method addParticipant.
@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_CONTRIBUTOR)")
public UserStudy addParticipant(IUser createdBy, Long studyId, Long participantId, ParticipantRole role) throws NotExistException, AlreadyExistException {
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 = userStudyRepository.findOneByStudyIdAndUserId(study.getId(), participant.getId());
if (studyLink == null) {
// If user is invited for first time - create new link
studyLink = new UserStudy();
} else if (studyLink.getStatus().isPendingOrApproved()) {
// Otherwise - invitation is pending or was already accepted. Cannot change or recreate
throw new AlreadyExistException(EX_PARTICIPANT_EXISTS);
}
studyLink.setCreatedBy(createdBy);
studyLink.setUser(participant);
studyLink.setStudy(study);
studyLink.setRole(role);
studyLink.setCreated(new Date());
studyLink.setStatus(ParticipantStatus.PENDING);
studyLink.setDeletedAt(null);
studyLink.setComment(null);
studyLink.setToken(UUID.randomUUID().toString().replace("-", ""));
userStudyRepository.save(studyLink);
arachneMailSender.send(new InvitationCollaboratorMailSender(WebSecurityConfig.getDefaultPortalURI(), participant, studyLink));
return studyLink;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionController method deleteSubmissionResultsByUuid.
@ApiOperation("Delete manually uploaded submission result file")
@DeleteMapping("/api/v1/analysis-management/submissions/{submissionId}/result/{fileUuid}")
public JsonResult<Boolean> deleteSubmissionResultsByUuid(@PathVariable("submissionId") Long id, @PathVariable("fileUuid") String fileUuid) {
LOGGER.info("deleting result file for submission with id={} having uuid={}", id, fileUuid);
JsonResult.ErrorCode errorCode;
Boolean hasResult;
try {
ResultFile resultFile = submissionService.getResultFileByPath(contentStorageService.getFileByIdentifier(fileUuid).getPath());
hasResult = submissionService.deleteSubmissionResultFile(id, resultFile);
errorCode = JsonResult.ErrorCode.NO_ERROR;
} catch (NotExistException e) {
LOGGER.warn("Submission was not found, id: {}", id);
errorCode = JsonResult.ErrorCode.VALIDATION_ERROR;
hasResult = false;
} catch (ValidationException e) {
LOGGER.warn("Result file was not deleted", e);
errorCode = JsonResult.ErrorCode.VALIDATION_ERROR;
hasResult = false;
}
JsonResult<Boolean> result = new JsonResult<>(errorCode);
result.setResult(hasResult);
return result;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionController method createSubmission.
@ApiOperation("Create and send submission.")
@PostMapping("/api/v1/analysis-management/{analysisId}/submissions")
public JsonResult<List<DTO>> createSubmission(Principal principal, @RequestBody @Validated CreateSubmissionsDTO createSubmissionsDTO, @PathVariable("analysisId") Long analysisId) throws PermissionDeniedException, NotExistException, IOException, NoExecutableFileException, ValidationException {
final JsonResult<List<DTO>> result;
if (principal == null) {
throw new PermissionDeniedException();
}
IUser user = userService.getByUsername(principal.getName());
if (user == null) {
throw new PermissionDeniedException();
}
Analysis analysis = analysisService.getById(analysisId);
final List<Submission> submissions = AnalysisHelper.createSubmission(submissionService, createSubmissionsDTO.getDataSources(), user, analysis);
final List<DTO> submissionDTOs = submissions.stream().map(s -> conversionService.convert(s, getSubmissionDTOClass())).collect(Collectors.toList());
result = new JsonResult<>(NO_ERROR);
result.setResult(submissionDTOs);
return result;
}
use of com.odysseusinc.arachne.portal.exception.NotExistException 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(), addParticipantDTO.getMessage());
wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyController method suggest.
@ApiOperation("Suggest study.")
@RequestMapping(value = "/api/v1/study-management/studies/search", method = GET)
public JsonResult<List<StudyDTO>> suggest(Principal principal, @RequestParam("id") String requestId, @RequestParam("query") String query, @RequestParam("region") SuggestSearchRegion region) throws PermissionDeniedException {
JsonResult<List<StudyDTO>> result;
IUser owner = getUser(principal);
Long id;
switch(region) {
case DATASOURCE:
id = Long.valueOf(requestId);
break;
case PARTICIPANT:
IUser participant = Optional.ofNullable(userService.getByUuid(requestId)).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
id = participant.getId();
break;
default:
id = 0L;
break;
}
Iterable<T> studies = studyService.suggestStudy(query, owner, id, region);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
List<StudyDTO> studiesDTOs = new LinkedList<>();
for (Study study : studies) {
studiesDTOs.add(conversionService.convert(study, StudyDTO.class));
}
result.setResult(studiesDTOs);
return result;
}
Aggregations