use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getProjectsDataMap.
/**
* Generates a map of project information.
*
* @param projectList
* a List of {@link ProjectUserJoin} for the current user.
*
* @return Map containing the information to put the projects table
*/
private Map<String, Object> getProjectsDataMap(Iterable<Project> projectList, List<RelatedProjectJoin> relatedProjectJoins) {
Map<String, Object> map = new HashMap<>();
Map<Project, Boolean> related = new HashMap<>();
relatedProjectJoins.forEach((p) -> related.put(p.getObject(), true));
// Create the format required by DataTable
List<Map<String, String>> projectsData = new ArrayList<>();
for (Project project : projectList) {
Map<String, String> projectMap = new HashMap<>();
projectMap.put("id", project.getId().toString());
projectMap.put("name", project.getName());
projectMap.put("organism", project.getOrganism());
projectMap.put("createdDate", dateFormatter.print(project.getCreatedDate(), LocaleContextHolder.getLocale()));
if (related.containsKey(project)) {
projectMap.put("associated", "associated");
}
projectsData.add(projectMap);
}
map.put("associated", projectsData);
return map;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project 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.project.Project in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method editAssociatedProjectsForProject.
/**
* Get the edit associated projects page
*
* @param projectId
* The ID of the current project
* @param model
* Model object to be passed to the view
* @param principal
* The logged in user
*
* @return The name of the edit associated projects view
*/
@RequestMapping("/edit")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#projectId, 'isProjectOwner')")
public String editAssociatedProjectsForProject(@PathVariable Long projectId, Model model, Principal principal) {
Project project = projectService.read(projectId);
model.addAttribute("project", project);
projectControllerUtils.getProjectTemplateDetails(model, principal, project);
model.addAttribute(ProjectsController.ACTIVE_NAV, ProjectSettingsController.ACTIVE_NAV_SETTINGS);
return "projects/settings/pages/associated_edit";
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getAssociatedProjectsPage.
/**
* Get the associated projects for the given project
*
* @param projectId
* The ID of the project to get associated projects
* @param model
* A model for the view
* @param principal
* a reference to the logged in user.
*
* @return The view name of the assocated projects view
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String getAssociatedProjectsPage(@PathVariable Long projectId, Model model, Principal principal) {
Project project = projectService.read(projectId);
model.addAttribute("project", project);
User loggedInUser = userService.getUserByUsername(principal.getName());
// Determine if the user is an owner or admin.
boolean isAdmin = loggedInUser.getSystemRole().equals(Role.ROLE_ADMIN);
model.addAttribute("isAdmin", isAdmin);
// Add any associated projects
User currentUser = userService.getUserByUsername(principal.getName());
List<Map<String, String>> associatedProjects = getAssociatedProjectsForProject(project, currentUser, isAdmin);
model.addAttribute("associatedProjects", associatedProjects);
model.addAttribute("noAssociated", associatedProjects.isEmpty());
model.addAttribute(ProjectsController.ACTIVE_NAV, ProjectSettingsController.ACTIVE_NAV_SETTINGS);
model.addAttribute("page", "associated");
projectControllerUtils.getProjectTemplateDetails(model, principal, project);
return "projects/settings/pages/associated";
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectSettingsController method updateAssemblySetting.
/**
* Update the project assembly setting for the {@link Project}
*
* @param projectId the ID of a {@link Project}
* @param assemble Whether or not to do automated assemblies
* @param model Model for the view
* @param locale Locale of the logged in user
* @return success message if successful
*/
@RequestMapping(value = "/assemble", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateAssemblySetting(@PathVariable Long projectId, @RequestParam boolean assemble, final Model model, Locale locale) {
Project read = projectService.read(projectId);
Map<String, Object> updates = new HashMap<>();
updates.put("assembleUploads", assemble);
projectService.updateProjectSettings(read, updates);
String message = null;
if (assemble) {
message = messageSource.getMessage("project.settings.notifications.assemble.enabled", new Object[] { read.getLabel() }, locale);
} else {
message = messageSource.getMessage("project.settings.notifications.assemble.disabled", new Object[] { read.getLabel() }, locale);
}
return ImmutableMap.of("result", message);
}
Aggregations