use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getPotentialAssociatedProjects.
/**
* Get {@link Project}s that could be associated with this project
*
* @param projectId
* The current project ID
* @param principal
* The logged in user
* @param page
* The page to request
* @param count
* The number of elements in the page
* @param sortedBy
* The property to sort by
* @param sortDir
* The direction to sort in
* @param projectName
* The project name to search for
*
* @return A {@code Map<String,Object>} of elements for a datatable
*/
@RequestMapping("/ajax/available")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#projectId, 'isProjectOwner')")
@ResponseBody
public Map<String, Object> getPotentialAssociatedProjects(@PathVariable Long projectId, final Principal principal, @RequestParam Integer page, @RequestParam Integer count, @RequestParam String sortedBy, @RequestParam String sortDir, @RequestParam(value = "name", required = false, defaultValue = "") String projectName) {
Project project = projectService.read(projectId);
Sort.Direction sortDirection = sortDir.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC;
List<RelatedProjectJoin> relatedProjectJoins = projectService.getRelatedProjects(project);
List<Project> projects;
long totalElements;
int totalPages;
final Page<Project> search = projectService.getUnassociatedProjects(project, projectName, page, count, sortDirection, sortedBy);
totalElements = search.getTotalElements();
totalPages = search.getTotalPages();
projects = search.getContent();
Map<String, Object> map = getProjectsDataMap(projects, relatedProjectJoins);
map.put("totalAssociated", totalElements);
map.put("totalPages", totalPages);
return map;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getAssociatedProjectsForProject.
/**
* Find all projects that have been associated with a project.
*
* @param currentProject
* The project to find the associated projects of.
* @param currentUser
* The currently logged in user.
*
* @return List of Maps containing information about the associated projects.
*/
private List<Map<String, String>> getAssociatedProjectsForProject(Project currentProject, User currentUser, boolean isAdmin) {
List<RelatedProjectJoin> relatedProjectJoins = projectService.getRelatedProjects(currentProject);
List<Map<String, String>> projects = new ArrayList<>();
for (RelatedProjectJoin rpj : relatedProjectJoins) {
Project project = rpj.getObject();
Map<String, String> map = new HashMap<>();
map.put("name", project.getLabel());
map.put("id", project.getId().toString());
map.put("auth", "authorized");
projects.add(map);
}
return projects;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectServiceImplTest method testRemoveRelatedProject.
@Test
public void testRemoveRelatedProject() {
RelatedProjectJoin join = new RelatedProjectJoin();
projectService.removeRelatedProject(join);
verify(relatedProjectRepository).delete(join);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsControllerTest method testGetAssociatedProjectsPage.
@Test
public void testGetAssociatedProjectsPage() {
ExtendedModelMap model = new ExtendedModelMap();
Principal principal = () -> USER_NAME;
Long projectId = 1L;
User u = new User();
u.setSystemRole(Role.ROLE_ADMIN);
Project p = new Project("my project");
p.setId(projectId);
Project o = new Project("other project");
o.setId(2L);
List<RelatedProjectJoin> relatedProjects = Lists.newArrayList(new RelatedProjectJoin(p, o));
when(projectService.read(projectId)).thenReturn(p);
when(userService.getUserByUsername(USER_NAME)).thenReturn(u);
when(projectService.getRelatedProjects(p)).thenReturn(relatedProjects);
controller.getAssociatedProjectsPage(projectId, model, principal);
assertTrue(model.containsAttribute("isAdmin"));
assertTrue(model.containsAttribute("associatedProjects"));
verify(projectService).read(projectId);
verify(userService, times(2)).getUserByUsername(USER_NAME);
verify(projectService).getRelatedProjects(p);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsControllerTest method testGetPotentialAssociatedProjectsAsAdmin.
@SuppressWarnings("unchecked")
@Test
public void testGetPotentialAssociatedProjectsAsAdmin() {
Long projectId = 1L;
Principal principal = () -> USER_NAME;
int page = 1;
int count = 10;
String sortedBy = "id";
String sortDir = "asc";
String projectName = "";
Project p1 = new Project("p1");
when(projectService.read(projectId)).thenReturn(p1);
User user = new User();
user.setSystemRole(Role.ROLE_ADMIN);
when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
// (specification, page, count, sortDirection, sortedBy);
Project p2 = new Project("p2");
p2.setId(2L);
Project p3 = new Project("p3");
p3.setId(3L);
List<RelatedProjectJoin> relatedJoins = Lists.newArrayList(new RelatedProjectJoin(p1, p2));
when(projectService.getRelatedProjects(p1)).thenReturn(relatedJoins);
Page<Project> projectPage = new PageImpl<>(Lists.newArrayList(p2, p3));
when(projectService.getUnassociatedProjects(p1, projectName, page, count, Direction.ASC, sortedBy)).thenReturn(projectPage);
Map<String, Object> potentialAssociatedProjects = controller.getPotentialAssociatedProjects(projectId, principal, page, count, sortedBy, sortDir, projectName);
assertTrue(potentialAssociatedProjects.containsKey("associated"));
List<Map<String, String>> associated = (List<Map<String, String>>) potentialAssociatedProjects.get("associated");
assertEquals(2, associated.size());
for (Map<String, String> pmap : associated) {
if (pmap.get("id").equals("2")) {
assertTrue(pmap.containsKey("associated"));
}
}
verify(projectService).read(projectId);
verify(projectService).getRelatedProjects(p1);
verify(projectService).getUnassociatedProjects(p1, projectName, page, count, Direction.ASC, sortedBy);
}
Aggregations