Search in sources :

Example 76 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class CoverageFileProcessorTest method testRemoveExistingEntry.

@Test
public void testRemoveExistingEntry() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    QCEntry existingQc = new CoverageQCEntry();
    o.setQcEntries(Sets.newHashSet(existingQc));
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository).delete(existingQc);
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 77 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class CoverageFileProcessorTest method testGoodCoverage.

@Test
public void testGoodCoverage() {
    Project p = new Project();
    p.setGenomeSize(100L);
    p.setMinimumCoverage(2);
    SequenceFile file = new SequenceFile();
    SequencingObject o = new SingleEndSequenceFile(file);
    AnalysisFastQC fqc = mock(AnalysisFastQC.class);
    Long baseCount = 300L;
    when(analysisRepository.findFastqcAnalysisForSequenceFile(file)).thenReturn(fqc);
    when(fqc.getTotalBases()).thenReturn(baseCount);
    processor.process(o);
    ArgumentCaptor<CoverageQCEntry> qcCaptor = ArgumentCaptor.forClass(CoverageQCEntry.class);
    verify(qcEntryRepository, times(0)).delete(any(QCEntry.class));
    verify(qcEntryRepository).save(qcCaptor.capture());
    CoverageQCEntry qc = qcCaptor.getValue();
    qc.addProjectSettings(p);
    assertEquals("should show 3 times coverage", 3, qc.getCoverage());
    assertEquals("should be positive coverage", QCEntryStatus.POSITIVE, qc.getStatus());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) CoverageQCEntry(ca.corefacility.bioinformatics.irida.model.sample.CoverageQCEntry) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) Test(org.junit.Test)

Example 78 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class RESTUsersController method getUserProjects.

/**
 * Get the collection of projects for a specific user.
 *
 * @param username
 *            the username for the desired user.
 * @return a model containing the collection of projects for that user.
 */
@RequestMapping(value = "/api/{username}/projects", method = RequestMethod.GET)
public ModelMap getUserProjects(@PathVariable String username) {
    logger.debug("Loading projects for user [" + username + "]");
    ModelMap mav = new ModelMap();
    // get the appropriate user from the database
    User u = userService.getUserByUsername(username);
    // get all of the projects that this user belongs to
    ResourceCollection<Project> resources = new ResourceCollection<>();
    List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
    ControllerLinkBuilder linkBuilder = linkTo(RESTProjectsController.class);
    // add the project and a self-rel link to the project representation
    for (Join<Project, User> join : projects) {
        Project project = join.getSubject();
        project.add(linkBuilder.slash(project.getId()).withSelfRel());
        resources.add(project);
    }
    // add the resources to the response
    mav.addAttribute("projectResources", resources);
    // respond to the user
    return mav;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ControllerLinkBuilder(org.springframework.hateoas.mvc.ControllerLinkBuilder) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project 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 80 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project 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)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21