Search in sources :

Example 1 with Analysis

use of com.odysseusinc.arachne.portal.model.Analysis 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 Analysis

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

the class BaseSubmissionController method createSubmission.

@ApiOperation("Create and send submission.")
@RequestMapping(value = "/api/v1/analysis-management/{analysisId}/submissions", method = POST)
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.getByEmail(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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) Date(java.util.Date) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) LoggerFactory(org.slf4j.LoggerFactory) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ResultFileSearch(com.odysseusinc.arachne.portal.model.search.ResultFileSearch) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) Path(java.nio.file.Path) SubmissionStatusHistoryElement(com.odysseusinc.arachne.portal.model.SubmissionStatusHistoryElement) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) ContentStorageService(com.odysseusinc.arachne.storage.service.ContentStorageService) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) HttpUtils(com.odysseusinc.arachne.portal.util.HttpUtils) ArachneFileMeta(com.odysseusinc.arachne.storage.model.ArachneFileMeta) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) IUser(com.odysseusinc.arachne.portal.model.IUser) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Principal(java.security.Principal) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) SubmissionStatus(com.odysseusinc.arachne.portal.model.SubmissionStatus) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) ArrayList(java.util.ArrayList) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) RequestBody(org.springframework.web.bind.annotation.RequestBody) NoExecutableFileException(com.odysseusinc.arachne.portal.exception.NoExecutableFileException) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) POST(org.springframework.web.bind.annotation.RequestMethod.POST) LinkedList(java.util.LinkedList) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) BaseController(com.odysseusinc.arachne.portal.api.v1.controller.BaseController) Validated(org.springframework.validation.annotation.Validated) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ContentStorageHelper(com.odysseusinc.arachne.portal.util.ContentStorageHelper) HttpStatus(org.springframework.http.HttpStatus) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) StringUtils(org.springframework.util.StringUtils) Submission(com.odysseusinc.arachne.portal.model.Submission) Analysis(com.odysseusinc.arachne.portal.model.Analysis) IUser(com.odysseusinc.arachne.portal.model.IUser) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) ResultFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.ResultFileDTO) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) BaseSubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionDTO) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) SubmissionStatusHistoryElementDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionStatusHistoryElementDTO) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) CommonAnalysisExecutionStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisExecutionStatusDTO) CreateSubmissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateSubmissionsDTO) SubmissionFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO) SubmissionDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionDTO) BaseSubmissionAndAnalysisTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseSubmissionAndAnalysisTypeDTO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Analysis

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

the class BaseSubmissionToCommonAnalysisDTOConverter method convert.

@Override
public CommonAnalysisDTO convert(T source) {
    final CommonAnalysisDTO dto = createResultObject();
    dto.setId(source.getId());
    final Analysis analysis = source.getSubmissionGroup().getAnalysis();
    if (analysis != null) {
        dto.setName(analysis.getTitle());
        dto.setType(analysis.getType());
        Study study = analysis.getStudy();
        if (study != null && conversionService.canConvert(study.getClass(), CommonStudyDTO.class)) {
            dto.setStudy(conversionService.convert(study, CommonStudyDTO.class));
        }
    }
    IUser author = source.getSubmissionGroup().getAuthor();
    if (author != null && conversionService.canConvert(author.getClass(), CommonArachneUserDTO.class)) {
        CommonArachneUserDTO userDTO = conversionService.convert(author, CommonArachneUserDTO.class);
        dto.setOwner(userDTO);
    }
    dto.setUpdateSubmissionStatusPassword(source.getUpdatePassword());
    dto.setCentralDataSourceId(source.getDataSource().getId());
    for (SubmissionFile submissionFile : source.getSubmissionGroup().getFiles()) {
        if (submissionFile.getExecutable() && StringUtils.isEmpty(dto.getExecutableFileName())) {
            dto.setExecutableFileName(submissionFile.getRealName());
            dto.setInnerExecutableFilename(submissionFile.getEntryPoint());
        }
    }
    dto.setAnalysisFiles(source.getSubmissionGroup().getFiles().stream().map(file -> conversionService.convert(file, CommonAnalysisFileDTO.class)).collect(Collectors.toList()));
    proceedAdditionalFields(dto, source);
    return dto;
}
Also used : CommonAnalysisFileDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisFileDTO) Study(com.odysseusinc.arachne.portal.model.Study) CommonStudyDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonStudyDTO) CommonAnalysisDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) CommonArachneUserDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonArachneUserDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile)

Example 4 with Analysis

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

the class StudyStateMachineTest method testAnalysisListDiscriminatorChangingInfo.

@Test
public void testAnalysisListDiscriminatorChangingInfo() {
    Study activeStudy = createStudy(ACTIVE);
    activeStudy.getAnalyses().add(new Analysis());
    // now study has one analysis and transitions from Active to Initiate should have Info status
    List<StudyTransition> availableStates = stateMachine.getAvailableStates(activeStudy);
    assertEquals(2, availableStates.size());
    assertTrue(availableStates.get(0).isInfo());
    assertFalse(availableStates.get(1).isInfo());
}
Also used : Study(com.odysseusinc.arachne.portal.model.Study) StudyTransition(com.odysseusinc.arachne.portal.model.statemachine.study.StudyTransition) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Test(org.junit.Test)

Example 5 with Analysis

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

the class AnalysisHelperTest method prepareAnalysis.

private Analysis prepareAnalysis(IUser author, Study study) throws Exception {
    List<Analysis> exists = analysisRepository.findByTitleAndStudyId("AnalysisHelperTest#test", study.getId());
    if (!exists.isEmpty()) {
        analysisRepository.delete(exists);
    }
    Analysis analysis = new Analysis();
    analysis.setTitle("AnalysisHelperTest#test");
    analysis.setFiles(new ArrayList<>());
    analysis.setAuthor(author);
    analysis.setStudy(study);
    analysis.setType(CommonAnalysisType.COHORT_CHARACTERIZATION);
    Set<ArachnePermission> permissions = new HashSet<>();
    permissions.add(ArachnePermission.CREATE_SUBMISSION);
    permissions.add(ArachnePermission.CREATE_ANALYSIS);
    analysis.setPermissions(permissions);
    analysis = analysisService.create(analysis);
    AnalysisFile file = new AnalysisFile();
    file.setUuid(UUID.randomUUID().toString());
    file.setAnalysis(analysis);
    file.setContentType("text/plain");
    file.setLabel("");
    file.setAuthor(author);
    file.setUpdatedBy(author);
    file.setExecutable(Boolean.TRUE);
    file.setRealName("test.sql");
    Date created = new Date();
    file.setCreated(created);
    file.setUpdated(created);
    file.setVersion(1);
    file = analysisFileRepository.save(file);
    analysis.getFiles().add(file);
    Path dir = Paths.get(analysisHelper.getStoreFilesPath(), study.getId().toString(), analysis.getId().toString());
    Files.createDirectories(dir);
    Path path = dir.resolve(file.getUuid());
    Files.write(path, "test".getBytes());
    return analysis;
}
Also used : Path(java.nio.file.Path) Analysis(com.odysseusinc.arachne.portal.model.Analysis) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArachnePermission(com.odysseusinc.arachne.portal.security.ArachnePermission) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Analysis (com.odysseusinc.arachne.portal.model.Analysis)20 LinkedList (java.util.LinkedList)9 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)8 IUser (com.odysseusinc.arachne.portal.model.IUser)8 Study (com.odysseusinc.arachne.portal.model.Study)7 Submission (com.odysseusinc.arachne.portal.model.Submission)7 Date (java.util.Date)7 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)6 Path (java.nio.file.Path)6 List (java.util.List)6 IOException (java.io.IOException)5 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 NO_ERROR (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR)4 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)4 FileDtoContentHandler (com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler)4 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)4 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)4 BaseSubmissionService (com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService)4 InputStream (java.io.InputStream)4