Search in sources :

Example 6 with ResourceCollection

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.

the class RESTSampleSequenceFilesController method getSampleSequenceFiles.

/**
 * Get the {@link SequenceFile} entities associated with a specific
 * {@link Sample}.
 *
 * @param sampleId
 *            the identifier for the {@link Sample}.
 * @return the {@link SequenceFile} entities associated with the
 *         {@link Sample}.
 */
@RequestMapping(value = "/api/samples/{sampleId}/sequenceFiles", method = RequestMethod.GET)
public ModelMap getSampleSequenceFiles(@PathVariable Long sampleId) {
    ModelMap modelMap = new ModelMap();
    logger.debug("Reading seq files for sample " + sampleId);
    Sample sample = sampleService.read(sampleId);
    Collection<SampleSequencingObjectJoin> sequencingObjectsForSample = sequencingObjectService.getSequencingObjectsForSample(sample);
    ResourceCollection<SequenceFile> resources = new ResourceCollection<>();
    /*
		 * Note: This is a kind of antiquated seeing we should be referencing
		 * sequencing objects instead. At the very least the link we're pointing
		 * to here should be going through the sequencing object
		 */
    for (SampleSequencingObjectJoin r : sequencingObjectsForSample) {
        for (SequenceFile sf : r.getObject().getFiles()) {
            String fileLabel = objectLabels.get(r.getObject().getClass());
            sf.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, fileLabel, r.getObject().getId(), sf.getId())).withSelfRel());
            resources.add(sf);
        }
    }
    // add a link to this collection
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withSelfRel());
    // add a link back to the sample
    resources.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(RESTSampleSequenceFilesController.REL_SAMPLE));
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).listSequencingObjectsOfTypeForSample(sample.getId(), RESTSampleSequenceFilesController.objectLabels.get(SequenceFilePair.class))).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_PAIRS));
    resources.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).listSequencingObjectsOfTypeForSample(sample.getId(), RESTSampleSequenceFilesController.objectLabels.get(SingleEndSequenceFile.class))).withRel(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_UNPAIRED));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return modelMap;
}
Also used : SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ResourceCollection

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.

the class RESTAnalysisSubmissionController method getAnalysisInputUnpairedFiles.

/**
 * get the {@link SequenceFile}s not in {@link SequenceFilePair}s used for
 * the {@link AnalysisSubmission}
 *
 * @param identifier
 *            the {@link AnalysisSubmission} id
 * @return list of {@link SequenceFile}s
 */
@RequestMapping("/{identifier}/sequenceFiles/unpaired")
public ModelMap getAnalysisInputUnpairedFiles(@PathVariable Long identifier) {
    ModelMap map = new ModelMap();
    AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
    Set<SingleEndSequenceFile> inputFilesSingleEnd = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SingleEndSequenceFile.class);
    ResourceCollection<SequencingObject> resources = new ResourceCollection<>(inputFilesSingleEnd.size());
    for (SingleEndSequenceFile file : inputFilesSingleEnd) {
        SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(file);
        if (join != null) {
            SequencingObject sequencingObject = join.getObject();
            RESTSampleSequenceFilesController.addSequencingObjectLinks(sequencingObject, join.getSubject().getId());
            resources.add(sequencingObject);
        }
    }
    resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputUnpairedFiles(identifier)).withSelfRel());
    map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return map;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ResourceCollection

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.

the class RESTGenericController method listAllResources.

/**
 * Get all resources in the application.
 *
 * @return a model containing all resources of the specified type in the
 *         application.
 */
@RequestMapping(method = RequestMethod.GET)
public ModelMap listAllResources() {
    Iterable<Type> entities = crudService.findAll();
    ResourceCollection<Type> resources = new ResourceCollection<>();
    for (Type entity : entities) {
        entity.add(constructCustomResourceLinks(entity));
        entity.add(linkTo(getClass()).slash(entity.getId()).withSelfRel());
        resources.add(entity);
    }
    resources.add(linkTo(getClass()).withSelfRel());
    ModelMap model = new ModelMap();
    // get custom links for the collection
    Collection<Link> constructCollectionResourceLinks = constructCollectionResourceLinks(resources);
    resources.add(constructCollectionResourceLinks);
    model.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
    return model;
}
Also used : MediaType(org.springframework.http.MediaType) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ResourceCollection

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.

the class RESTProjectAnalysisController method getProjectAnalyses.

/**
 * Get the list of {@link AnalysisSubmission}s associated with this
 * {@link Project}.
 *
 * @param projectId
 *            the identifier of the {@link Project} to get the
 *            {@link AnalysisSubmission}s for.
 * @return the list of {@link AnalysisSubmission}s associated with this
 *         {@link Project}.
 */
@RequestMapping(value = "/api/projects/{projectId}/analyses", method = RequestMethod.GET)
public ModelMap getProjectAnalyses(@PathVariable Long projectId) {
    logger.debug("Loading analyses for project [" + projectId + "]");
    ModelMap modelMap = new ModelMap();
    Project p = projectService.read(projectId);
    Collection<AnalysisSubmission> analysisSubmissions = analysisSubmissionService.getAnalysisSubmissionsSharedToProject(p);
    ResourceCollection<AnalysisSubmission> analysisResources = new ResourceCollection<>(analysisSubmissions.size());
    for (AnalysisSubmission submission : analysisSubmissions) {
        submission.add(linkTo(methodOn(RESTAnalysisSubmissionController.class, Long.class).getResource(submission.getId())).withSelfRel());
        analysisResources.add(submission);
    }
    analysisResources.add(linkTo(methodOn(RESTProjectsController.class, Long.class).getResource(projectId)).withRel(PROJECT_REL));
    analysisResources.add(linkTo(methodOn(RESTProjectAnalysisController.class, Long.class).getProjectAnalyses(projectId)).withSelfRel());
    modelMap.addAttribute(ANALYSIS_RESOURCES, analysisResources);
    return modelMap;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ResourceCollection

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.

the class RESTProjectAnalysisController method getProjectAnalysesByType.

/**
 * Get the list of {@link AnalysisSubmission}s for this {@link Project} by
 * type of analysis.
 *
 * @param projectId
 *            The {@link Project} to search.
 * @param type
 *            The analysis type to search for.
 * @return A list of {@link AnalysisSubmission}s for the given
 *         {@link Project} by the given type.
 * @throws IridaWorkflowNotFoundException
 *             If the {@link AnalysisSubmission} is linked to a workflow not
 *             found in IRIDA.
 */
@RequestMapping(value = "/api/projects/{projectId}/analyses/{type}", method = RequestMethod.GET)
public ModelMap getProjectAnalysesByType(@PathVariable Long projectId, @PathVariable String type) throws IridaWorkflowNotFoundException {
    logger.debug("Loading analyses for project [" + projectId + "] by type [" + type + "]");
    if (!RESTAnalysisSubmissionController.ANALYSIS_TYPES.containsKey(type)) {
        throw new EntityNotFoundException("Analysis type [" + type + "] not found");
    }
    AnalysisType analysisType = RESTAnalysisSubmissionController.ANALYSIS_TYPES.get(type);
    ModelMap modelMap = new ModelMap();
    Project p = projectService.read(projectId);
    Collection<AnalysisSubmission> analysisSubmissions = analysisSubmissionService.getAnalysisSubmissionsSharedToProject(p);
    ResourceCollection<AnalysisSubmission> analysisResources = new ResourceCollection<>(analysisSubmissions.size());
    for (AnalysisSubmission submission : analysisSubmissions) {
        IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(submission.getWorkflowId());
        AnalysisType submissionAnalysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
        if (analysisType.equals(submissionAnalysisType)) {
            submission.add(linkTo(methodOn(RESTAnalysisSubmissionController.class, Long.class).getResource(submission.getId())).withSelfRel());
            analysisResources.add(submission);
        }
    }
    analysisResources.add(linkTo(methodOn(RESTProjectsController.class, Long.class).getResource(projectId)).withRel(PROJECT_REL));
    analysisResources.add(linkTo(methodOn(RESTProjectAnalysisController.class, Long.class).getProjectAnalysesByType(projectId, type)).withSelfRel());
    modelMap.addAttribute(ANALYSIS_RESOURCES, analysisResources);
    return modelMap;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResourceCollection (ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection)18 ModelMap (org.springframework.ui.ModelMap)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)7 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)6 Test (org.junit.Test)6 Link (org.springframework.hateoas.Link)6 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)5 User (ca.corefacility.bioinformatics.irida.model.user.User)5 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)5 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)2 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)2 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2 LabelledRelationshipResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.LabelledRelationshipResource)2 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1