Search in sources :

Example 11 with Sample

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);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with Sample

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);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ImmutableList(com.google.common.collect.ImmutableList)

Example 13 with 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;
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with Sample

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

Example 15 with Sample

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

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