use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SamplesController method getSampleListByIdList.
/**
* Utility method to get a l{@link List} of {@link Sample}s based on their
* ids.
*
* @param sampleIds
* {@link List} of {@link Sample} ids
* @param projectId
* {@link Long} identifier for the current {@link Project}
*
* @return {@link List}
*/
@RequestMapping(value = "/samples/idList", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getSampleListByIdList(@RequestParam(value = "sampleIds[]") List<Long> sampleIds, @RequestParam Long projectId) {
List<Sample> list = (List<Sample>) sampleService.readMultiple(sampleIds);
List<Map<String, String>> result = new ArrayList<>();
for (Sample sample : list) {
result.add(ImmutableMap.of("label", sample.getSampleName(), "href", linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, sample.getId())).withSelfRel().getHref()));
}
return ImmutableMap.of("samples", result);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class SamplesController method uploadSequenceFiles.
/**
* Upload {@link SequenceFile}'s to a sample
*
* @param sampleId
* The {@link Sample} id to upload to
* @param files
* A list of {@link MultipartFile} sequence files.
* @param response
* HTTP response object to update response status if there's an
* error.
* @throws IOException
* on upload failure
*/
@RequestMapping(value = { "/samples/{sampleId}/sequenceFiles/upload" }, method = RequestMethod.POST)
public void uploadSequenceFiles(@PathVariable Long sampleId, @RequestParam(value = "files") List<MultipartFile> files, HttpServletResponse response) throws IOException {
Sample sample = sampleService.read(sampleId);
final Map<String, List<MultipartFile>> pairedFiles = SamplePairer.getPairedFiles(files);
final List<MultipartFile> singleFiles = SamplePairer.getSingleFiles(files);
for (String key : pairedFiles.keySet()) {
List<MultipartFile> list = pairedFiles.get(key);
createSequenceFilePairsInSample(list, sample);
}
for (MultipartFile file : singleFiles) {
createSequenceFileInSample(file, sample);
}
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class CartController method getSamplesAsList.
/**
* Get the set of given {@link Sample}s as a List for JSON serialization
*
* @param samples
* The {@link Sample} set
* @return A List<Map<String,Object>> containing the relevant Sample
* information
*/
private List<Map<String, Object>> getSamplesAsList(Set<Sample> samples, Long projectId) {
List<Map<String, Object>> sampleList = new ArrayList<>();
for (Sample s : samples) {
String sampleHref = linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, s.getId())).withSelfRel().getHref();
Map<String, Object> sampleMap = ImmutableMap.of("id", s.getId(), "label", s.getLabel(), "createdDate", s.getCreatedDate(), "sequenceFiles", getSequenceFileList(s), "href", sampleHref);
sampleList.add(sampleMap);
}
return sampleList;
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class CartController method removeProjectSamples.
/**
* Delete a {@link Sample} from the cart from a given {@link Project}
*
* @param projectId
* The {@link Project} ID
* @param sampleIds
* The {@link Sample} ID
* @return a map stating success
*/
@RequestMapping(value = "/project/{projectId}/samples", method = RequestMethod.DELETE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> removeProjectSamples(@PathVariable Long projectId, @RequestBody Set<Long> sampleIds) {
Project project = projectService.read(projectId);
Set<Sample> samples = loadSamplesForProject(project, sampleIds);
Set<Sample> selectedSamplesForProject = getSelectedSamplesForProject(project);
selectedSamplesForProject.removeAll(samples);
if (selectedSamplesForProject.isEmpty()) {
selected.remove(project);
}
return ImmutableMap.of("success", true);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class CartController method getProjectsAsList.
/**
* Get the {@link Project}s in the cart as a List for JSON serialization
*
* @return A List<Map<String,Object>> containing the relevant Project and
* Sample information
*/
private List<Map<String, Object>> getProjectsAsList() {
Set<Project> projects = selected.keySet();
List<Map<String, Object>> projectList = new ArrayList<>();
for (Project p : projects) {
Set<Sample> selectedSamplesForProject = selected.get(p);
List<Map<String, Object>> samples = getSamplesAsList(selectedSamplesForProject, p.getId());
Map<String, Object> projectMap = ImmutableMap.of("id", p.getId(), "label", p.getLabel(), "samples", samples);
projectList.add(projectMap);
}
return projectList;
}
Aggregations