use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BasePaperServiceImpl method delete.
@PreAuthorize("hasPermission(#id, 'Paper', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_PAPER)")
@Transactional
@Override
public void delete(Long id) throws FileNotFoundException {
final Paper paper = Optional.of(paperRepository.getOne(id)).orElseThrow(() -> new NotExistException(Paper.class));
Stream.concat(paper.getPapers().stream(), paper.getProtocols().stream()).forEach(file -> {
try {
deleteFile(id, file.getUuid(), file.getType());
} catch (FileNotFoundException ex) {
log.error("Paper file with uuid={} is not found", file.getUuid());
}
});
if (paperRepository.deleteById(id) == 0) {
throw new NotExistException(Paper.class);
}
}
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 BaseStudyServiceImpl method removeParticipant.
@Override
@PreAuthorize("hasPermission(#id, 'Study'," + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_STUDY)")
public void removeParticipant(Long id, Long participantId) throws NotExistException, PermissionDeniedException, ValidationException {
Study study = getById(id);
IUser participant = userService.findOne(participantId);
UserStudy studyLink = Optional.ofNullable(userStudyRepository.findOneByStudyAndUser(study, participant)).orElseThrow(() -> new NotExistException(UserStudy.class));
checkLastLeadInvestigator(studyLink, study);
if (userStudyRepository.hardRemoveIfNotTracked(id, participantId) == 0) {
userStudyRepository.delete(studyLink);
}
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class BaseUserServiceImpl method setActiveTenant.
@Override
public void setActiveTenant(U user, Long tenantId) {
for (Tenant t : user.getTenants()) {
if (t.getId().equals(tenantId)) {
user.setActiveTenant(t);
userRepository.save(user);
return;
}
}
throw new NotExistException(Tenant.class);
}
use of com.odysseusinc.arachne.portal.exception.NotExistException in project ArachneCentralAPI by OHDSI.
the class CommentServiceImpl method getTopic.
@Cacheable("comments")
@Override
public CommentTopic getTopic(Long id) throws NotExistException {
final CommentTopic commentTopic = commentTopicRepository.getOne(id);
if (commentTopic == null) {
final String message = String.format(TOPIC_NOT_EXIST_EXCEPTION, id);
throw new NotExistException(message, CommentTopic.class);
}
final List<Comment> comments = commentRepository.getAllByTopicIdAndParentIsNull(id);
comments.forEach(c -> Hibernate.initialize(c.getAuthor().getRoles()));
commentTopic.setComments(comments);
return commentTopic;
}
Aggregations