use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesController method copySampleToProject.
/**
* Copy an existing sample to a project.
*
* @param projectId
* the project to copy the sample to.
* @param sampleIds
* the collection of sample IDs to copy.
* @param response
* a reference to the servlet response.
* @return the response indicating that the sample was joined to the
* project.
*/
@RequestMapping(value = "/api/projects/{projectId}/samples", method = RequestMethod.POST, consumes = "application/idcollection+json")
public ModelMap copySampleToProject(@PathVariable final Long projectId, @RequestBody final List<Long> sampleIds, HttpServletResponse response) {
ModelMap modelMap = new ModelMap();
Project p = projectService.read(projectId);
ResourceCollection<LabelledRelationshipResource<Project, Sample>> labeledProjectSampleResources = new ResourceCollection<>(sampleIds.size());
for (final long sampleId : sampleIds) {
Sample sample = sampleService.read(sampleId);
Join<Project, Sample> r = projectService.addSampleToProject(p, sample, false);
LabelledRelationshipResource<Project, Sample> resource = new LabelledRelationshipResource<Project, Sample>(r.getLabel(), r);
// add a labeled relationship resource to the resource collection
// that will fill the body of the response.
resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sample.getId())).withSelfRel());
resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, sample.getId())).withRel(REL_PROJECT_SAMPLE));
resource.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sample.getId())).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES));
resource.add(linkTo(RESTProjectsController.class).slash(projectId).withRel(REL_PROJECT));
labeledProjectSampleResources.add(resource);
final String location = linkTo(methodOn(RESTProjectSamplesController.class).getProjectSample(projectId, sampleId)).withSelfRel().getHref();
response.addHeader(HttpHeaders.LOCATION, location);
}
// add a link to the project that was copied to.
labeledProjectSampleResources.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSamples(projectId)).withSelfRel());
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, labeledProjectSampleResources);
response.setStatus(HttpStatus.CREATED.value());
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesController method getProjectSampleBySequencerId.
/**
* Get samples by a given string name
*
* @param projectId the Project to get samples from
* @param seqeuncerId the string id of the sample
* @return The found sample
*/
@RequestMapping(value = "/api/projects/{projectId}/samples/bySequencerId/{seqeuncerId}", method = RequestMethod.GET)
public ModelAndView getProjectSampleBySequencerId(@PathVariable Long projectId, @PathVariable String seqeuncerId) {
Project p = projectService.read(projectId);
Sample sampleBySampleId = sampleService.getSampleBySampleName(p, seqeuncerId);
Link withSelfRel = linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleBySampleId.getId())).withSelfRel();
String href = withSelfRel.getHref();
RedirectView redirectView = new RedirectView(href);
return new ModelAndView(redirectView);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesController method removeSampleFromProject.
/**
* Remove a specific {@link Sample} from the collection of {@link Sample}s
* associated with a {@link Project}.
*
* @param projectId
* the {@link Project} identifier.
* @param sampleId
* the {@link Sample} identifier.
* @return a response including links back to the specific {@link Project}
* and collection of {@link Sample}.
*/
@RequestMapping(value = "/api/projects/{projectId}/samples/{sampleId}", method = RequestMethod.DELETE)
public ModelMap removeSampleFromProject(@PathVariable Long projectId, @PathVariable Long sampleId) {
ModelMap modelMap = new ModelMap();
// load the sample and project
Project p = projectService.read(projectId);
Sample s = sampleService.read(sampleId);
// remove the relationship.
projectService.removeSampleFromProject(p, s);
// respond to the client.
RootResource resource = new RootResource();
// add links back to the collection of samples and to the project
// itself.
resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSamples(projectId)).withRel(REL_PROJECT_SAMPLES));
resource.add(linkTo(RESTProjectsController.class).slash(projectId).withRel(RESTProjectsController.REL_PROJECT));
// add the links to the response.
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resource);
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTSampleMetadataController method saveSampleMetadata.
/**
* Save new metadata for a {@link Sample}. Note this will overwrite the
* existing metadata
*
* @param sampleId
* the id of the {@link Sample} to save new metadata
* @param metadataMap
* the metadata to save to the {@link Sample}
* @return the updated {@link Sample}
*/
@RequestMapping(value = "/api/samples/{sampleId}/metadata", method = RequestMethod.POST)
public ModelMap saveSampleMetadata(@PathVariable Long sampleId, @RequestBody Map<String, MetadataEntry> metadataMap) {
Sample s = sampleService.read(sampleId);
Map<MetadataTemplateField, MetadataEntry> metadata = metadataTemplateService.getMetadataMap(metadataMap);
s.setMetadata(metadata);
sampleService.update(s);
return getSampleMetadata(sampleId);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTSampleMetadataController method getSampleMetadata.
/**
* Get the metadata for a given {@link Sample}
*
* @param sampleId
* the id of the {@link Sample} to get metadata for
* @return the metadata for the sample
*/
@RequestMapping(value = "/api/samples/{sampleId}/metadata", method = RequestMethod.GET)
public ModelMap getSampleMetadata(@PathVariable Long sampleId) {
logger.trace("Getting sample metadata for " + sampleId);
ModelMap modelMap = new ModelMap();
Sample s = sampleService.read(sampleId);
SampleMetadataResponse response = buildSampleMetadataResponse(s);
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, response);
return modelMap;
}
Aggregations