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);
}
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);
}
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());
}
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());
}
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;
}
Aggregations