Search in sources :

Example 16 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectSamplesController method getAllProjectSampleIds.

/**
 * Get a list of all {@link Sample} ids in a {@link Project}
 *
 * @param projectId            Identifier for the current project
 * @param sampleNames          {@link List} of sample names that the {@link Project} {@link Sample}s is currently filtered by.
 * @param associatedProjectIds {@link List} of associated {@link Project} identifiers
 * @param search               The global filter for the table
 * @param filter               The specific attribute filters applied to the table.
 * @return {@link Map} of {@link Project} identifiers and associated {@link Sample} identifiers available.
 */
@RequestMapping(value = "/projects/{projectId}/ajax/sampleIds", method = RequestMethod.POST)
@ResponseBody
public Map<String, List<String>> getAllProjectSampleIds(@PathVariable Long projectId, @RequestParam(required = false, defaultValue = "", value = "sampleNames[]") List<String> sampleNames, @RequestParam(value = "associated[]", required = false, defaultValue = "") List<Long> associatedProjectIds, @RequestParam(required = false, defaultValue = "") String search, UISampleFilter filter) {
    // Add the current project to the associatedProjectIds list.
    associatedProjectIds.add(projectId);
    // Get the actual projects.
    List<Project> projects = new ArrayList<>((Collection<? extends Project>) projectService.readMultiple(associatedProjectIds));
    Sort sort = new Sort(Direction.ASC, "id");
    final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), search, filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), 0, Integer.MAX_VALUE, sort);
    // Converting everything to a string for consumption by the UI.
    Map<String, List<String>> result = new HashMap<>();
    for (ProjectSampleJoin join : page) {
        String pId = join.getSubject().getId().toString();
        if (!result.containsKey(pId)) {
            result.put(pId, new ArrayList<>());
        }
        result.get(pId).add(join.getObject().getId().toString());
    }
    return result;
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sort(org.springframework.data.domain.Sort)

Example 17 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectSamplesController method getMergeSamplesInProjectModal.

/**
 * Create a modal dialog to merge samples in a project.
 *
 * @param projectId current {@link Project} identifier
 * @param ids       {@link List} List of {@link Long} identifiers for {@link Sample} to merge.
 * @param model     UI Model
 * @return Path to merge modal template
 */
@RequestMapping(value = "/projects/{projectId}/templates/merge-modal", produces = MediaType.TEXT_HTML_VALUE)
public String getMergeSamplesInProjectModal(@PathVariable Long projectId, @RequestParam(name = "sampleIds[]") List<Long> ids, Model model) {
    Project project = projectService.read(projectId);
    List<Sample> samples = new ArrayList<>();
    List<Sample> locked = new ArrayList<>();
    // check for locked samples
    ids.forEach(i -> {
        ProjectSampleJoin join = sampleService.getSampleForProject(project, i);
        samples.add(join.getObject());
        if (!join.isOwner()) {
            locked.add(join.getObject());
        }
    });
    model.addAttribute("project", project);
    model.addAttribute("samples", samples);
    model.addAttribute("locked", locked);
    return PROJECT_TEMPLATE_DIR + "merge-modal.tmpl";
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample)

Example 18 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectSamplesController method getSampleNamesNotInProject.

/**
 * Get a listing of sample names not found in the current project based on a list.
 *
 * @param projectId   {@link Project} identifier for project
 * @param sampleNames {@link List} of sample names
 * @param projects    List of associated {@link Project} identifiers
 * @param locale      {@link Locale} local of current user
 * @return {@link Map} of Samples not in the current project
 */
@RequestMapping("/projects/{projectId}/ajax/samples/missing")
@ResponseBody
public Map<String, Object> getSampleNamesNotInProject(@PathVariable Long projectId, @RequestParam(value = "projects[]", defaultValue = "") List<Long> projects, @RequestParam(value = "sampleNames[]") List<String> sampleNames, Locale locale) {
    // Need to keep the count for comparison after.
    int originalCount = sampleNames.size();
    // Get a list of all samples for all projects
    projects.add(0, projectId);
    for (Long id : projects) {
        List<Join<Project, Sample>> psj = sampleService.getSamplesForProject(projectService.read(id));
        // See if the name is there
        for (Join<Project, Sample> join : psj) {
            Sample sample = join.getObject();
            if (sampleNames.contains(sample.getLabel())) {
                sampleNames.remove(sample.getLabel());
            }
            if (sampleNames.size() == 0) {
                break;
            }
        }
        if (sampleNames.size() == 0) {
            break;
        }
    }
    Map<String, Object> result = new HashMap<>();
    if (sampleNames.size() > 0) {
        result.put("missingNames", sampleNames);
        result.put("message", messageSource.getMessage("project.sample.filterByFile.error", new Object[] { originalCount - sampleNames.size(), originalCount }, locale));
    } else {
        result.put("success", messageSource.getMessage("project.sample.filterByFile.success", new Object[] {}, locale));
    }
    return result;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)

Example 19 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project 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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sort(org.springframework.data.domain.Sort) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectSettingsAssociatedProjectsController method removeAssociatedProject.

/**
 * Delete an associated project to a project
 *
 * @param projectId           The subject project id
 * @param associatedProjectId The associated project id
 * @param locale              Locale of the logged in user
 * @return "success" if the request was successful
 */
@RequestMapping(value = "", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> removeAssociatedProject(@PathVariable Long projectId, @RequestParam Long associatedProjectId, Locale locale) {
    Project project = projectService.read(projectId);
    Project associatedProject = projectService.read(associatedProjectId);
    projectService.removeRelatedProject(project, associatedProject);
    return ImmutableMap.of("result", "success", "message", messageSource.getMessage("project.associated.removed", new Object[] {}, locale));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) 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