Search in sources :

Example 11 with RelatedProjectJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testRemoveRelatedProject2ProjectArgs.

@Test
public void testRemoveRelatedProject2ProjectArgs() {
    Project x = new Project("projectx");
    Project y = new Project("projecty");
    RelatedProjectJoin join = new RelatedProjectJoin(x, y);
    when(relatedProjectRepository.getRelatedProjectJoin(x, y)).thenReturn(join);
    projectService.removeRelatedProject(x, y);
    verify(relatedProjectRepository).getRelatedProjectJoin(x, y);
    verify(relatedProjectRepository).delete(join);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Test(org.junit.Test)

Example 12 with RelatedProjectJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testAddRelatedProject.

@Test
public void testAddRelatedProject() {
    Project p1 = new Project("project 1");
    Project p2 = new Project("project 2");
    RelatedProjectJoin rp = new RelatedProjectJoin(p1, p2);
    when(relatedProjectRepository.save(any(RelatedProjectJoin.class))).thenReturn(rp);
    RelatedProjectJoin returned = projectService.addRelatedProject(p1, p2);
    assertNotNull(returned);
    assertEquals(rp, returned);
    verify(relatedProjectRepository).save(any(RelatedProjectJoin.class));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Test(org.junit.Test)

Example 13 with RelatedProjectJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testGetRelatedProjects.

@Test
public void testGetRelatedProjects() {
    Project p1 = new Project("project 1");
    Project p2 = new Project("project 2");
    Project p3 = new Project("project 3");
    List<RelatedProjectJoin> relatedProjectList = Lists.newArrayList(new RelatedProjectJoin(p1, p2), new RelatedProjectJoin(p1, p3));
    when(relatedProjectRepository.getRelatedProjectsForProject(p1)).thenReturn(relatedProjectList);
    List<RelatedProjectJoin> relatedProjects = projectService.getRelatedProjects(p1);
    assertFalse(relatedProjects.isEmpty());
    for (RelatedProjectJoin rp : relatedProjects) {
        assertEquals(p1, rp.getSubject());
    }
    verify(relatedProjectRepository).getRelatedProjectsForProject(p1);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Test(org.junit.Test)

Example 14 with RelatedProjectJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.

the class ProjectServiceImpl method removeRelatedProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#subject,'isProjectOwner')")
public void removeRelatedProject(Project subject, Project relatedProject) {
    RelatedProjectJoin relatedProjectJoin = relatedProjectRepository.getRelatedProjectJoin(subject, relatedProject);
    removeRelatedProject(relatedProjectJoin);
}
Also used : RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with RelatedProjectJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.

the class ProjectSamplesController method getProjectSamplesPage.

/**
 * Get the samples for a given project
 *
 * @param model
 * 		A model for the sample list view
 * @param principal
 * 		The user reading the project
 * @param projectId
 * 		The ID of the project
 * @param httpSession
 * 		The user's session
 *
 * @return Name of the project samples list view
 */
@RequestMapping(value = { "/projects/{projectId}", "/projects/{projectId}/samples" })
public String getProjectSamplesPage(final Model model, final Principal principal, @PathVariable long projectId, HttpSession httpSession) {
    Project project = projectService.read(projectId);
    model.addAttribute("project", project);
    // Set up the template information
    projectControllerUtils.getProjectTemplateDetails(model, principal, project);
    // Exporting functionality
    boolean haveGalaxyCallbackURL = (httpSession.getAttribute(ProjectsController.GALAXY_CALLBACK_VARIABLE_NAME) != null);
    model.addAttribute("linkerAvailable", LINKER_AVAILABLE);
    model.addAttribute("galaxyCallback", haveGalaxyCallbackURL);
    // Add the associated projects
    List<RelatedProjectJoin> associatedJoin = projectService.getRelatedProjects(project);
    List<Project> associated = associatedJoin.stream().map(RelatedProjectJoin::getObject).collect(Collectors.toList());
    model.addAttribute("associatedProjects", associated);
    model.addAttribute(ACTIVE_NAV, ACTIVE_NAV_SAMPLES);
    return PROJECT_SAMPLES_PAGE;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)

Aggregations

RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)16 Project (ca.corefacility.bioinformatics.irida.model.project.Project)14 Test (org.junit.Test)10 User (ca.corefacility.bioinformatics.irida.model.user.User)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Principal (java.security.Principal)3 Map (java.util.Map)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)3 List (java.util.List)2 PageImpl (org.springframework.data.domain.PageImpl)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Sort (org.springframework.data.domain.Sort)1 Transactional (org.springframework.transaction.annotation.Transactional)1