Search in sources :

Example 11 with NotExistException

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);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Paper(com.odysseusinc.arachne.portal.model.Paper) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with NotExistException

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;
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) IUser(com.odysseusinc.arachne.portal.model.IUser) InvitationCollaboratorMailSender(com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with NotExistException

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);
    }
}
Also used : UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Study(com.odysseusinc.arachne.portal.model.Study) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with NotExistException

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);
}
Also used : Tenant(com.odysseusinc.arachne.portal.model.security.Tenant) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException)

Example 15 with NotExistException

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;
}
Also used : Comment(com.odysseusinc.arachne.portal.model.Comment) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)29 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 IUser (com.odysseusinc.arachne.portal.model.IUser)8 Date (java.util.Date)7 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)6 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 Study (com.odysseusinc.arachne.portal.model.Study)5 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)4 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)4 ResultFile (com.odysseusinc.arachne.portal.model.ResultFile)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 User (com.odysseusinc.arachne.portal.model.User)3 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)2 Analysis (com.odysseusinc.arachne.portal.model.Analysis)2 AnalysisUnlockRequest (com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest)2