Search in sources :

Example 6 with ProjectAnalysisSubmissionJoin

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

the class ReadAnalysisSubmissionPermissionTest method testPermitProjectShare.

@Test
public void testPermitProjectShare() {
    String username = "aaron";
    User u = new User();
    u.setUsername(username);
    Authentication auth = new UsernamePasswordAuthenticationToken("aaron", "password1");
    Project p = new Project();
    AnalysisSubmission analysisSubmission = AnalysisSubmission.builder(workflowId).name("test").inputFiles(inputSingleFiles).referenceFile(referenceFile).build();
    analysisSubmission.setSubmitter(new User());
    when(pasRepository.getProjectsForSubmission(analysisSubmission)).thenReturn(ImmutableList.of(new ProjectAnalysisSubmissionJoin(p, analysisSubmission)));
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(analysisSubmissionRepository.findOne(1L)).thenReturn(analysisSubmission);
    when(readProjectPermission.customPermissionAllowed(auth, p)).thenReturn(true);
    assertTrue("permission should be granted.", readAnalysisSubmissionPermission.isAllowed(auth, 1L));
    verify(userRepository).loadUserByUsername(username);
    verify(analysisSubmissionRepository).findOne(1L);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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 7 with ProjectAnalysisSubmissionJoin

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

the class ReadAnalysisSubmissionPermissionTest method testPermitSISTR.

@Test
public void testPermitSISTR() {
    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.setSistrTyping(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 8 with ProjectAnalysisSubmissionJoin

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

the class ProjectServiceImplIT method testGetProjectForAnalysisSubmissionAsUser.

@Test
@WithMockUser(username = "analysisuser", password = "password1", roles = "USER")
public void testGetProjectForAnalysisSubmissionAsUser() {
    AnalysisSubmission analysis = analysisSubmissionService.read(1L);
    List<ProjectAnalysisSubmissionJoin> projects = projectService.getProjectsForAnalysisSubmission(analysis);
    assertEquals("should have found 1 project", 1, projects.size());
    ProjectAnalysisSubmissionJoin project = projects.iterator().next();
    assertEquals("should have found project 2", new Long(2L), project.getSubject().getId());
}
Also used : 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 9 with ProjectAnalysisSubmissionJoin

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

the class ProjectServiceImplIT method testGetProjectForAnalysisSubmissionAsAdmin.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetProjectForAnalysisSubmissionAsAdmin() {
    AnalysisSubmission analysis = analysisSubmissionService.read(1L);
    List<ProjectAnalysisSubmissionJoin> projects = projectService.getProjectsForAnalysisSubmission(analysis);
    assertEquals("should have found 2 projects", 2, projects.size());
}
Also used : 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 10 with ProjectAnalysisSubmissionJoin

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

the class AnalysisController method getSharedProjectsForAnalysis.

/**
 * Get the status of projects that can be shared with the given analysis
 *
 * @param submissionId
 *            the {@link AnalysisSubmission} id
 * @return a list of {@link AnalysisController.SharedProjectResponse}
 */
@RequestMapping(value = "/ajax/{submissionId}/share", method = RequestMethod.GET)
@ResponseBody
public List<SharedProjectResponse> getSharedProjectsForAnalysis(@PathVariable Long submissionId) {
    AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
    // Input files
    // - Paired
    Set<SequenceFilePair> inputFilePairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class);
    // get projects already shared with submission
    Set<Project> projectsShared = projectService.getProjectsForAnalysisSubmission(submission).stream().map(ProjectAnalysisSubmissionJoin::getSubject).collect(Collectors.toSet());
    // get available projects
    Set<Project> projectsInAnalysis = projectService.getProjectsForSequencingObjects(inputFilePairs);
    List<SharedProjectResponse> projectResponses = projectsShared.stream().map(p -> new SharedProjectResponse(p, true)).collect(Collectors.toList());
    // Create response for shared projects
    projectResponses.addAll(projectsInAnalysis.stream().filter(p -> !projectsShared.contains(p)).map(p -> new SharedProjectResponse(p, false)).collect(Collectors.toList()));
    projectResponses.sort(new Comparator<SharedProjectResponse>() {

        @Override
        public int compare(SharedProjectResponse p1, SharedProjectResponse p2) {
            return p1.getProject().getName().compareTo(p2.getProject().getName());
        }
    });
    return projectResponses;
}
Also used : PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) FileUtilities(ca.corefacility.bioinformatics.irida.ria.utilities.FileUtilities) Model(org.springframework.ui.Model) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) AnalysisSubmissionService(ca.corefacility.bioinformatics.irida.service.AnalysisSubmissionService) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) MediaType(org.springframework.http.MediaType) Collectors(java.util.stream.Collectors) AnalysesListingService(ca.corefacility.bioinformatics.irida.ria.web.services.AnalysesListingService) Principal(java.security.Principal) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Authentication(org.springframework.security.core.Authentication) java.util(java.util) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) UpdateAnalysisSubmissionPermission(ca.corefacility.bioinformatics.irida.security.permissions.analysis.UpdateAnalysisSubmissionPermission) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Controller(org.springframework.stereotype.Controller) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateService(ca.corefacility.bioinformatics.irida.service.sample.MetadataTemplateService) ToolExecution(ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) Files(java.nio.file.Files) AnalysisState(ca.corefacility.bioinformatics.irida.model.enums.AnalysisState) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) AnalysisOutputFileInfo(ca.corefacility.bioinformatics.irida.ria.web.analysis.dto.AnalysisOutputFileInfo) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) java.io(java.io) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) JobError(ca.corefacility.bioinformatics.irida.model.workflow.analysis.JobError) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)

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