Search in sources :

Example 21 with Project

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with Project

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with Project

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";
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with Project

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";
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with Project

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21