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;
}
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";
}
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);
}
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));
}
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);
}
Aggregations