Search in sources :

Example 51 with Sample

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) LabelledRelationshipResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.LabelledRelationshipResource) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with Sample

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) Link(org.springframework.hateoas.Link) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with Sample

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;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 54 with Sample

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);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with Sample

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;
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)243 Test (org.junit.Test)162 Project (ca.corefacility.bioinformatics.irida.model.project.Project)114 WithMockUser (org.springframework.security.test.context.support.WithMockUser)71 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)62 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)53 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)53 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)41 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)33 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)33 Path (java.nio.file.Path)28 ModelMap (org.springframework.ui.ModelMap)28 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)23 ArrayList (java.util.ArrayList)22 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)17 User (ca.corefacility.bioinformatics.irida.model.user.User)14 HashMap (java.util.HashMap)14 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)13