Search in sources :

Example 1 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin 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 2 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin 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 3 with ProjectSampleJoin

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

the class SearchController method searchSamples.

/**
 * Search all {@link Sample}s in projects for a user based on a query string
 *
 * @param query  the query string
 * @param global Whether to perform an admin
 *               global search
 * @param params parameters for a datatables response
 * @return a {@link DataTablesResponse} to display search results
 */
@RequestMapping("/search/ajax/samples")
@ResponseBody
public DataTablesResponse searchSamples(@RequestParam String query, @RequestParam(required = false, defaultValue = "false") boolean global, @DataTablesRequest DataTablesParams params) {
    Sort originalSort = params.getSort();
    List<Sort.Order> orders = Lists.newArrayList();
    originalSort.forEach(o -> {
        orders.add(new Sort.Order(o.getDirection(), "sample." + o.getProperty()));
    });
    Sort newSort = new Sort(orders);
    Page<ProjectSampleJoin> samplePage;
    if (global) {
        samplePage = sampleService.searchAllSamples(query, params.getCurrentPage(), params.getLength(), newSort);
    } else {
        samplePage = sampleService.searchSamplesForUser(query, params.getCurrentPage(), params.getLength(), newSort);
    }
    List<DataTablesResponseModel> samples = samplePage.getContent().stream().map(this::createDataTablesSample).collect(Collectors.toList());
    return new DataTablesResponse(params, samplePage, samples);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Sort(org.springframework.data.domain.Sort) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with ProjectSampleJoin

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

the class ProjectServiceImplTest method testAddSampleToProjectNoSamplePersisted.

@Test
public void testAddSampleToProjectNoSamplePersisted() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> noViolations = new HashSet<>();
    when(validator.validate(s)).thenReturn(noViolations);
    when(sampleRepository.save(s)).thenReturn(s);
    projectService.addSampleToProject(p, s, true);
    verify(sampleRepository).save(s);
    verify(psjRepository).save(new ProjectSampleJoin(p, s, true));
}
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) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ProjectSampleJoin

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

the class ProjectServiceImplTest method testRemoveSamplesFromProject.

@Test
public void testRemoveSamplesFromProject() {
    Project project = new Project();
    List<Sample> samples = ImmutableList.of(new Sample("s1"), new Sample("s2"));
    ProjectSampleJoin psj0 = new ProjectSampleJoin(project, samples.get(0), true);
    ProjectSampleJoin psj1 = new ProjectSampleJoin(project, samples.get(1), true);
    when(psjRepository.readSampleForProject(project, samples.get(0))).thenReturn(psj0);
    when(psjRepository.readSampleForProject(project, samples.get(1))).thenReturn(psj1);
    projectService.removeSamplesFromProject(project, samples);
    verify(psjRepository).delete(psj0);
    verify(psjRepository).delete(psj1);
}
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) Test(org.junit.Test)

Aggregations

ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)59 Project (ca.corefacility.bioinformatics.irida.model.project.Project)51 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)51 Test (org.junit.Test)43 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)15 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)15 ArrayList (java.util.ArrayList)11 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Authentication (org.springframework.security.core.Authentication)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)6 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)5 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)5 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)5