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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations