Search in sources :

Example 1 with SubmissionGroup

use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.

the class ArachnePermissionEvaluator method addPermissions.

public boolean addPermissions(ArachneUser user, HasArachnePermissions hasPermissionsObj) {
    Set<ArachnePermission> allPermissions = getAllPermissions(hasPermissionsObj, user);
    hasPermissionsObj.setPermissions(allPermissions);
    if (hasPermissionsObj instanceof Analysis) {
        final Analysis analysis = (Analysis) hasPermissionsObj;
        final List<SubmissionGroup> submissionGroups = analysis.getSubmissionGroups();
        if (!CollectionUtils.isEmpty(submissionGroups)) {
            submissionGroups.forEach(submissionGroup -> submissionGroup.getSubmissions().forEach(submission -> {
                final Set<ArachnePermission> submissionPermissions = getAllPermissions(submission, user);
                submission.setPermissions(submissionPermissions);
            }));
        }
        final List<AnalysisFile> files = analysis.getFiles();
        if (!CollectionUtils.isEmpty(files)) {
            files.forEach(file -> {
                final Set<ArachnePermission> filePermissions = getAllPermissions(file, user);
                file.setPermissions(filePermissions);
            });
        }
    }
    return true;
}
Also used : Arrays(java.util.Arrays) DomainObjectLoaderFactory(com.odysseusinc.arachne.portal.service.domain.DomainObjectLoaderFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PermissionDsl.domainObject(com.odysseusinc.arachne.portal.component.PermissionDsl.domainObject) Submission(com.odysseusinc.arachne.portal.model.Submission) Paper(com.odysseusinc.arachne.portal.model.Paper) HashSet(java.util.HashSet) DataSource(com.odysseusinc.arachne.portal.model.DataSource) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) BaseArachneSecureService(com.odysseusinc.arachne.portal.service.BaseArachneSecureService) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) ArachneUser(com.odysseusinc.arachne.portal.model.security.ArachneUser) DELETE_ANALYSIS_FILES(com.odysseusinc.arachne.portal.security.ArachnePermission.DELETE_ANALYSIS_FILES) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) LinkedList(java.util.LinkedList) PermissionDslPredicates.analysisAuthorIs(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.analysisAuthorIs) HasArachnePermissions(com.odysseusinc.arachne.portal.security.HasArachnePermissions) User(com.odysseusinc.arachne.portal.model.User) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) PermissionDslPredicates.analysisFileAuthorIs(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.analysisFileAuthorIs) PublishState(com.odysseusinc.arachne.portal.model.PublishState) UserStudyGrouped(com.odysseusinc.arachne.portal.model.UserStudyGrouped) Set(java.util.Set) DELETE_DATASOURCE(com.odysseusinc.arachne.portal.security.ArachnePermission.DELETE_DATASOURCE) Page(org.springframework.data.domain.Page) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) Serializable(java.io.Serializable) Objects(java.util.Objects) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) List(java.util.List) Component(org.springframework.stereotype.Component) RawDataSource(com.odysseusinc.arachne.portal.model.RawDataSource) CollectionUtils(org.springframework.util.CollectionUtils) PermissionDslPredicates.userIsLeadInvestigator(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.userIsLeadInvestigator) DataNode(com.odysseusinc.arachne.portal.model.DataNode) PermissionDslPredicates.hasRole(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.hasRole) PermissionDslPredicates.instanceOf(com.odysseusinc.arachne.portal.component.PermissionDslPredicates.instanceOf) Authentication(org.springframework.security.core.Authentication) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) ArachnePermission(com.odysseusinc.arachne.portal.security.ArachnePermission) Collections(java.util.Collections) Study(com.odysseusinc.arachne.portal.model.Study) HashSet(java.util.HashSet) Set(java.util.Set) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) Analysis(com.odysseusinc.arachne.portal.model.Analysis) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArachnePermission(com.odysseusinc.arachne.portal.security.ArachnePermission)

Example 2 with SubmissionGroup

use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.

the class AnalysisHelper method createSubmission.

public static List<Submission> createSubmission(BaseSubmissionService submissionService, List<Long> datasourceIds, IUser user, Analysis analysis) throws IOException, NotExistException, NoExecutableFileException, ValidationException {
    final List<Submission> submissions = new LinkedList<>();
    // removes datasourceId duplicates
    Set<Long> datasourceIdSet = new HashSet<>(datasourceIds);
    SubmissionGroup submissionGroup = submissionService.createSubmissionGroup(user, analysis);
    for (Long datasourceId : datasourceIdSet) {
        submissions.add(submissionService.createSubmission(user, analysis, datasourceId, submissionGroup));
    }
    return submissions;
}
Also used : Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 3 with SubmissionGroup

use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method createSubmissionGroup.

@Override
public SubmissionGroup createSubmissionGroup(IUser user, Analysis analysis) throws IOException, NoExecutableFileException {
    checkBeforeCreateSubmissionGroup(analysis);
    List<SubmissionFile> files = new LinkedList<>();
    SubmissionGroup submissionGroup = new SubmissionGroup();
    submissionGroup.setAnalysis(analysis);
    submissionGroup.setAnalysisType(analysis.getType());
    submissionGroup.setAuthor(user);
    Date now = new Date();
    submissionGroup.setCreated(now);
    submissionGroup.setUpdated(now);
    submissionGroup.setFiles(files);
    submissionGroup = submissionGroupRepository.save(submissionGroup);
    Path submissionGroupFolder = analysisHelper.getSubmissionGroupFolder(submissionGroup);
    if (Files.notExists(submissionGroupFolder)) {
        Files.createDirectories(submissionGroupFolder);
    }
    for (AnalysisFile analysisFile : analysis.getFiles()) {
        SubmissionFile submissionFile = new SubmissionFile();
        String storeFilesPath = fileStorePath + File.separator + "content";
        String uuid = UUID.randomUUID().toString();
        submissionFile.setSubmissionGroup(submissionGroup);
        submissionFile.setContentType(analysisFile.getContentType());
        submissionFile.setCreated(analysisFile.getCreated());
        submissionFile.setUpdated(analysisFile.getUpdated());
        submissionFile.setLabel(analysisFile.getLabel());
        submissionFile.setRealName(analysisFile.getRealName());
        submissionFile.setEntryPoint(analysisFile.getEntryPoint());
        submissionFile.setUuid(uuid);
        submissionFile.setAuthor(analysisFile.getAuthor());
        submissionFile.setVersion(analysisFile.getVersion());
        submissionFile.setAntivirusStatus(analysisFile.getAntivirusStatus());
        submissionFile.setAntivirusDescription(analysisFile.getAntivirusDescription());
        Boolean isExecutable = analysisFile.getExecutable();
        submissionFile.setExecutable(isExecutable != null && isExecutable);
        Path analysisFileContent = Paths.get(storeFilesPath, analysis.getStudy().getId().toString(), analysis.getId().toString(), analysisFile.getUuid());
        Path submissionFileContent = submissionGroupFolder.resolve(uuid);
        Path target = Files.copy(analysisFileContent, submissionFileContent, StandardCopyOption.REPLACE_EXISTING);
        try (InputStream in = Files.newInputStream(target)) {
            String checksum = DigestUtils.md5DigestAsHex(in);
            submissionFile.setChecksum(checksum);
        }
        files.add(submissionFile);
    }
    submissionFileRepository.save(files);
    submissionGroup.setChecksum(calculateMD5Hash(submissionGroupFolder, files));
    submissionGroupRepository.save(submissionGroup);
    return submissionGroup;
}
Also used : Path(java.nio.file.Path) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) LinkedList(java.util.LinkedList) Date(java.util.Date) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Example 4 with SubmissionGroup

use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method getSubmissionAllFiles.

@Override
public void getSubmissionAllFiles(Long submissionGroupId, String archiveName, OutputStream os) throws IOException {
    SubmissionGroup submissionGroup = submissionGroupRepository.findOne(submissionGroupId);
    Path storeFilesPath = analysisHelper.getSubmissionGroupFolder(submissionGroup);
    try (ZipOutputStream zos = new ZipOutputStream(os)) {
        for (SubmissionFile submissionFile : submissionGroup.getFiles()) {
            String realName = submissionFile.getRealName();
            Path file = storeFilesPath.resolve(submissionFile.getUuid());
            if (Files.notExists(file)) {
                file = legacyAnalysisHelper.getOldSubmissionFile(submissionFile).orElseThrow(FileNotFoundException::new);
            }
            if (Files.exists(file)) {
                ZipUtil.addZipEntry(zos, realName, file);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) ZipOutputStream(java.util.zip.ZipOutputStream) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Example 5 with SubmissionGroup

use of com.odysseusinc.arachne.portal.model.SubmissionGroup in project ArachneCentralAPI by OHDSI.

the class BaseSubmissionServiceImpl method getSubmissionGroups.

@Override
@PreAuthorize("hasPermission(#submissoinGroupSearch.analysisId,  'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).ACCESS_STUDY)")
@PostAuthorize("@ArachnePermissionEvaluator.addPermissionsToSubmissions(principal, returnObject )")
public Page<SubmissionGroup> getSubmissionGroups(SubmissionGroupSearch submissoinGroupSearch) {
    final SubmissionGroupSpecification submissionGroupSpecification = new SubmissionGroupSpecification(submissoinGroupSearch);
    final Integer page = submissoinGroupSearch.getPage();
    final PageRequest pageRequest = new PageRequest(page == null ? 0 : page - 1, submissoinGroupSearch.getPageSize(), new Sort(Sort.Direction.DESC, "created"));
    final Page<SubmissionGroup> submissionGroups = submissionGroupRepository.findAll(submissionGroupSpecification, pageRequest);
    final List<SubmissionGroup> content = submissionGroups.getContent();
    final Map<Long, SubmissionGroup> submissionGroupMap = content.stream().collect(Collectors.toMap(SubmissionGroup::getId, sg -> {
        sg.setSubmissions(new ArrayList<>());
        return sg;
    }));
    final Set<Long> submissionGroupIds = submissionGroupMap.keySet();
    if (!CollectionUtils.isEmpty(submissionGroupIds)) {
        final SubmissionSpecification<T> submissionSpecification = SubmissionSpecification.<T>builder(submissionGroupIds).withStatuses(submissoinGroupSearch.getSubmissionStatuses()).withDataSourceIds(submissoinGroupSearch.getDataSourceIds()).hasInsight(submissoinGroupSearch.getHasInsight()).showHidden(submissoinGroupSearch.getShowHidden()).build();
        submissionRepository.findAll(submissionSpecification).forEach(s -> submissionGroupMap.get(s.getSubmissionGroup().getId()).getSubmissions().add(s));
    }
    return submissionGroups;
}
Also used : Arrays(java.util.Arrays) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) FileSaveRequest(com.odysseusinc.arachne.storage.util.FileSaveRequest) FAILED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_PUBLISHED) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Map(java.util.Map) Sort(org.springframework.data.domain.Sort) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) SubmissionStatusHistoryElement(com.odysseusinc.arachne.portal.model.SubmissionStatusHistoryElement) SubmissionHelper(com.odysseusinc.arachne.portal.util.SubmissionHelper) EXECUTE(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType.EXECUTE) ArachneMailSender(com.odysseusinc.arachne.portal.service.mail.ArachneMailSender) BaseSubmissionRepository(com.odysseusinc.arachne.portal.repository.submission.BaseSubmissionRepository) Transactional(javax.transaction.Transactional) SubmissionGroupRepository(com.odysseusinc.arachne.portal.repository.SubmissionGroupRepository) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IUser(com.odysseusinc.arachne.portal.model.IUser) SubmissionInsightRepository(com.odysseusinc.arachne.portal.repository.SubmissionInsightRepository) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) ZipOutputStream(java.util.zip.ZipOutputStream) PENDING(com.odysseusinc.arachne.portal.model.SubmissionStatus.PENDING) FAILED_REJECTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED_REJECTED) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) InvitationApprovalSubmissionArachneMailMessage(com.odysseusinc.arachne.portal.service.mail.InvitationApprovalSubmissionArachneMailMessage) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) UserService(com.odysseusinc.arachne.portal.service.UserService) SubmissionFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionFileRepository) Files(java.nio.file.Files) SubmissionGroupSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSpecification) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) DataNodeUtils(com.odysseusinc.arachne.portal.util.DataNodeUtils) File(java.io.File) ContentStorageHelper(com.odysseusinc.arachne.portal.util.ContentStorageHelper) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) QuerySpec(com.odysseusinc.arachne.storage.model.QuerySpec) Paths(java.nio.file.Paths) FAILED(com.odysseusinc.arachne.portal.model.SubmissionStatus.FAILED) PUBLISH(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType.PUBLISH) DataNodeUtils.isDataNodeOwner(com.odysseusinc.arachne.portal.util.DataNodeUtils.isDataNodeOwner) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EXECUTED_PUBLISHED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_PUBLISHED) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) SubmissionStatusHistoryRepository(com.odysseusinc.arachne.portal.repository.SubmissionStatusHistoryRepository) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) ContentStorageService(com.odysseusinc.arachne.storage.service.ContentStorageService) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) UUIDGenerator(com.odysseusinc.arachne.portal.util.UUIDGenerator) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) SubmissionSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionSpecification) List(java.util.List) Optional(java.util.Optional) SubmissionActionType(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionActionType) NOT_APPROVED(com.odysseusinc.arachne.portal.model.SubmissionStatus.NOT_APPROVED) EntityGraph(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph) SubmissionStatus.valueOf(com.odysseusinc.arachne.portal.model.SubmissionStatus.valueOf) DigestUtils(org.springframework.util.DigestUtils) EntityGraphUtils(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils) LegacyAnalysisHelper(com.odysseusinc.arachne.portal.util.LegacyAnalysisHelper) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ResultFileRepository(com.odysseusinc.arachne.portal.repository.ResultFileRepository) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) EXECUTED_REJECTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED_REJECTED) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) ObjectUtils(org.apache.commons.lang3.ObjectUtils) EXECUTED(com.odysseusinc.arachne.portal.model.SubmissionStatus.EXECUTED) UserDetails(org.springframework.security.core.userdetails.UserDetails) LinkedList(java.util.LinkedList) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) SubmissionResultFileRepository(com.odysseusinc.arachne.portal.repository.SubmissionResultFileRepository) SequenceInputStream(java.io.SequenceInputStream) SubmissionAction(com.odysseusinc.arachne.portal.service.impl.submission.SubmissionAction) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) WebSecurityConfig(com.odysseusinc.arachne.portal.config.WebSecurityConfig) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) EntityUtils(com.odysseusinc.arachne.portal.util.EntityUtils) MultipartFile(org.springframework.web.multipart.MultipartFile) IN_PROGRESS(com.odysseusinc.arachne.portal.model.SubmissionStatus.IN_PROGRESS) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) Collections(java.util.Collections) InputStream(java.io.InputStream) SubmissionGroup(com.odysseusinc.arachne.portal.model.SubmissionGroup) ArrayList(java.util.ArrayList) PageRequest(org.springframework.data.domain.PageRequest) SubmissionGroupSpecification(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSpecification) Sort(org.springframework.data.domain.Sort) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

SubmissionGroup (com.odysseusinc.arachne.portal.model.SubmissionGroup)7 Submission (com.odysseusinc.arachne.portal.model.Submission)4 LinkedList (java.util.LinkedList)4 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)3 SubmissionFile (com.odysseusinc.arachne.portal.model.SubmissionFile)3 Path (java.nio.file.Path)3 List (java.util.List)3 Map (java.util.Map)3 Analysis (com.odysseusinc.arachne.portal.model.Analysis)2 IDataSource (com.odysseusinc.arachne.portal.model.IDataSource)2 InputStream (java.io.InputStream)2 SequenceInputStream (java.io.SequenceInputStream)2 Date (java.util.Date)2 Collectors (java.util.stream.Collectors)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 EntityGraph (com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph)1 EntityGraphUtils (com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils)1 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)1 SubmissionDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO)1 SubmissionGroupDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO)1