Search in sources :

Example 16 with Sample

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

the class CartController method addProject.

/**
 * Add an entire {@link Project} to the cart
 *
 * @param projectId
 *            The ID of the {@link Project}
 * @return a map stating success
 */
@RequestMapping(value = "/project/{projectId}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> addProject(@PathVariable Long projectId) {
    Project project = projectService.read(projectId);
    List<Join<Project, Sample>> samplesForProject = sampleService.getSamplesForProject(project);
    Set<Sample> samples = samplesForProject.stream().map((j) -> {
        return j.getObject();
    }).collect(Collectors.toSet());
    getSelectedSamplesForProject(project).addAll(samples);
    return ImmutableMap.of("success", true);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) ControllerLinkBuilder.methodOn(org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn) Controller(org.springframework.stereotype.Controller) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Scope(org.springframework.context.annotation.Scope) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ArrayList(java.util.ArrayList) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) ControllerLinkBuilder.linkTo(org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo) Model(org.springframework.ui.Model) Locale(java.util.Locale) Map(java.util.Map) RESTSampleSequenceFilesController(ca.corefacility.bioinformatics.irida.web.controller.api.samples.RESTSampleSequenceFilesController) MessageSource(org.springframework.context.MessageSource) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableMap(com.google.common.collect.ImmutableMap) RESTProjectSamplesController(ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectSamplesController) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) List(java.util.List) Principal(java.security.Principal) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with Sample

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

the class ProjectServiceImplTest method testAddSampleWithSameSequencerId.

@Test(expected = EntityExistsException.class)
public void testAddSampleWithSameSequencerId() {
    Project p = project();
    Sample s = new Sample();
    Sample otherSample = new Sample("name");
    s.setSampleName("name");
    when(sampleRepository.getSampleBySampleName(p, s.getSampleName())).thenReturn(otherSample);
    projectService.addSampleToProject(p, s, true);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Test(org.junit.Test)

Example 18 with Sample

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

the class ProjectServiceImplTest method testAddSampleToProjectNoSamplePersistedInvalidSample.

@Test(expected = ConstraintViolationException.class)
public void testAddSampleToProjectNoSamplePersistedInvalidSample() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> violations = new HashSet<>();
    violations.add(ConstraintViolationImpl.forBeanValidation(null, null, Sample.class, null, null, null, null, null, null));
    when(validator.validate(s)).thenReturn(violations);
    projectService.addSampleToProject(p, s, true);
    verifyZeroInteractions(sampleRepository, psjRepository);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with Sample

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

the class ProjectServiceImplTest method testAddSampleToProjectNoSamplePersisted.

@Test
public void testAddSampleToProjectNoSamplePersisted() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> noViolations = new HashSet<>();
    when(validator.validate(s)).thenReturn(noViolations);
    when(sampleRepository.save(s)).thenReturn(s);
    projectService.addSampleToProject(p, s, true);
    verify(sampleRepository).save(s);
    verify(psjRepository).save(new ProjectSampleJoin(p, s, true));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with Sample

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

the class ProjectServiceImplTest method testRemoveSamplesFromProject.

@Test
public void testRemoveSamplesFromProject() {
    Project project = new Project();
    List<Sample> samples = ImmutableList.of(new Sample("s1"), new Sample("s2"));
    ProjectSampleJoin psj0 = new ProjectSampleJoin(project, samples.get(0), true);
    ProjectSampleJoin psj1 = new ProjectSampleJoin(project, samples.get(1), true);
    when(psjRepository.readSampleForProject(project, samples.get(0))).thenReturn(psj0);
    when(psjRepository.readSampleForProject(project, samples.get(1))).thenReturn(psj1);
    projectService.removeSamplesFromProject(project, samples);
    verify(psjRepository).delete(psj0);
    verify(psjRepository).delete(psj1);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Test(org.junit.Test)

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