Search in sources :

Example 1 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class AnalysisSubmissionServiceImplIT method shareAnalysisSubmissionWithProject.

@Test
@WithMockUser(username = "aaron", roles = "USER")
public void shareAnalysisSubmissionWithProject() {
    AnalysisSubmission read = analysisSubmissionService.read(3L);
    Project project2 = projectService.read(2L);
    ProjectAnalysisSubmissionJoin shareAnalysisSubmissionWithProject = analysisSubmissionService.shareAnalysisSubmissionWithProject(read, project2);
    assertNotNull(shareAnalysisSubmissionWithProject.getId());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 2 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class ReadAnalysisSubmissionPermissionTest method testPermitAutoAssembly.

@Test
public void testPermitAutoAssembly() {
    String username = "aaron";
    User u = new User();
    u.setUsername(username);
    Authentication auth = new UsernamePasswordAuthenticationToken("aaron", "password1");
    Project p = new Project();
    SequenceFilePair pair = new SequenceFilePair();
    AnalysisSubmission analysisSubmission = AnalysisSubmission.builder(workflowId).name("test").inputFiles(ImmutableSet.of(pair)).referenceFile(referenceFile).build();
    analysisSubmission.setSubmitter(new User());
    pair.setAutomatedAssembly(analysisSubmission);
    /*
		 * testing that analysis is shared with a project that user isn't a part
		 * of
		 */
    when(pasRepository.getProjectsForSubmission(analysisSubmission)).thenReturn(ImmutableList.of(new ProjectAnalysisSubmissionJoin(p, analysisSubmission)));
    when(readProjectPermission.customPermissionAllowed(auth, p)).thenReturn(false);
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(analysisSubmissionRepository.findOne(1L)).thenReturn(analysisSubmission);
    when(seqObjectPermission.customPermissionAllowed(auth, pair)).thenReturn(true);
    when(sequencingObjectRepository.findSequencingObjectsForAnalysisSubmission(analysisSubmission)).thenReturn(ImmutableSet.of(pair));
    assertTrue("permission should be granted.", readAnalysisSubmissionPermission.isAllowed(auth, 1L));
    verify(userRepository).loadUserByUsername(username);
    verify(analysisSubmissionRepository).findOne(1L);
    verify(seqObjectPermission).customPermissionAllowed(auth, pair);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 3 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class AnalysisSubmissionServiceImpl method createSingleSampleSubmission.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_USER')")
public Collection<AnalysisSubmission> createSingleSampleSubmission(IridaWorkflow workflow, Long ref, List<SingleEndSequenceFile> sequenceFiles, List<SequenceFilePair> sequenceFilePairs, Map<String, String> params, IridaWorkflowNamedParameters namedParameters, String name, String analysisDescription, List<Project> projectsToShare, boolean writeResultsToSamples) {
    final Collection<AnalysisSubmission> createdSubmissions = new HashSet<AnalysisSubmission>();
    // Single end reads
    IridaWorkflowDescription description = workflow.getWorkflowDescription();
    if (description.acceptsSingleSequenceFiles()) {
        final Map<Sample, SingleEndSequenceFile> samplesMap = sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFiles));
        for (final Map.Entry<Sample, SingleEndSequenceFile> entry : samplesMap.entrySet()) {
            Sample s = entry.getKey();
            SingleEndSequenceFile file = entry.getValue();
            // Build the analysis submission
            AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
            builder.name(name + "_" + s.getSampleName());
            builder.inputFiles(ImmutableSet.of(file));
            builder.updateSamples(writeResultsToSamples);
            builder.priority(AnalysisSubmission.Priority.MEDIUM);
            // Add reference file
            if (ref != null && description.requiresReference()) {
                // Note: This cannot be empty if through the UI if the
                // pipeline required a reference file.
                ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
                builder.referenceFile(referenceFile);
            }
            if (description.acceptsParameters()) {
                if (namedParameters != null) {
                    builder.withNamedParameters(namedParameters);
                } else {
                    if (!params.isEmpty()) {
                        // Note: This cannot be empty if through the UI if
                        // the pipeline required params.
                        builder.inputParameters(params);
                    }
                }
            }
            // Create the submission
            createdSubmissions.add(create(builder.build()));
        }
    }
    // Paired end reads
    if (description.acceptsPairedSequenceFiles()) {
        final Map<Sample, SequenceFilePair> samplesMap = sequencingObjectService.getUniqueSamplesForSequencingObjects(Sets.newHashSet(sequenceFilePairs));
        for (final Map.Entry<Sample, SequenceFilePair> entry : samplesMap.entrySet()) {
            Sample s = entry.getKey();
            SequenceFilePair filePair = entry.getValue();
            // Build the analysis submission
            AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
            builder.name(name + "_" + s.getSampleName());
            builder.inputFiles(ImmutableSet.of(filePair));
            builder.updateSamples(writeResultsToSamples);
            // Add reference file
            if (ref != null && description.requiresReference()) {
                ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
                builder.referenceFile(referenceFile);
            }
            if (description.acceptsParameters()) {
                if (namedParameters != null) {
                    builder.withNamedParameters(namedParameters);
                } else {
                    if (!params.isEmpty()) {
                        // Note: This cannot be empty if through the UI if
                        // the pipeline required params.
                        builder.inputParameters(params);
                    }
                }
            }
            // Add description to submission, can be null
            builder.analysisDescription(analysisDescription);
            // Create the submission
            createdSubmissions.add(create(builder.build()));
        }
    }
    // Share with the required projects
    for (AnalysisSubmission submission : createdSubmissions) {
        for (Project project : projectsToShare) {
            pasRepository.save(new ProjectAnalysisSubmissionJoin(project, submission));
        }
    }
    return createdSubmissions;
}
Also used : ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) ImmutableMap(com.google.common.collect.ImmutableMap) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Example 4 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class AnalysisSubmissionServiceImpl method createMultipleSampleSubmission.

/**
 * {@inheritDoc}
 */
@Transactional
@PreAuthorize("hasRole('ROLE_USER')")
public AnalysisSubmission createMultipleSampleSubmission(IridaWorkflow workflow, Long ref, List<SingleEndSequenceFile> sequenceFiles, List<SequenceFilePair> sequenceFilePairs, Map<String, String> params, IridaWorkflowNamedParameters namedParameters, String name, String newAnalysisDescription, List<Project> projectsToShare, boolean writeResultsToSamples) {
    AnalysisSubmission.Builder builder = AnalysisSubmission.builder(workflow.getWorkflowIdentifier());
    builder.name(name);
    builder.priority(AnalysisSubmission.Priority.MEDIUM);
    builder.updateSamples(writeResultsToSamples);
    IridaWorkflowDescription description = workflow.getWorkflowDescription();
    // Add reference file
    if (ref != null && description.requiresReference()) {
        ReferenceFile referenceFile = referenceFileRepository.findOne(ref);
        builder.referenceFile(referenceFile);
    }
    // Add any single end sequencing files.
    if (description.acceptsSingleSequenceFiles()) {
        if (!sequenceFiles.isEmpty()) {
            builder.inputFiles(Sets.newHashSet(sequenceFiles));
        }
    }
    // Add any paired end sequencing files.
    if (description.acceptsPairedSequenceFiles()) {
        if (!sequenceFilePairs.isEmpty()) {
            builder.inputFiles(Sets.newHashSet(sequenceFilePairs));
        }
    }
    if (description.acceptsParameters()) {
        if (namedParameters != null) {
            builder.withNamedParameters(namedParameters);
        } else {
            if (!params.isEmpty()) {
                // Note: This cannot be empty if through the UI if
                // the pipeline required params.
                builder.inputParameters(params);
            }
        }
    }
    // Add description to submission, can be null
    builder.analysisDescription(newAnalysisDescription);
    // Create the submission
    AnalysisSubmission submission = create(builder.build());
    // Share with the required projects
    for (Project project : projectsToShare) {
        pasRepository.save(new ProjectAnalysisSubmissionJoin(project, submission));
    }
    return submission;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Example 5 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class AnalysisSubmissionServiceImpl method removeAnalysisProjectShare.

/**
 * {@inheritDoc}
 */
@PreAuthorize("hasPermission(#submission, 'canUpdateAnalysisSubmission') AND hasPermission(#project, 'canReadProject')")
@Override
public void removeAnalysisProjectShare(AnalysisSubmission submission, Project project) {
    ProjectAnalysisSubmissionJoin projectSubmissionShare = pasRepository.getProjectSubmissionShare(submission, project);
    pasRepository.delete(projectSubmissionShare);
}
Also used : ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 Test (org.junit.Test)6 User (ca.corefacility.bioinformatics.irida.model.user.User)5 Authentication (org.springframework.security.core.Authentication)5 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)2 Transactional (javax.transaction.Transactional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)1 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1