use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.
the class DefaultSampleService method createParentIdentity.
private SampleIdentity createParentIdentity(DetailedSample sample, SampleIdentity identity) throws IOException, MisoNamingException, SQLException {
log.debug("Creating a new Identity to use as a parent.");
List<SampleClass> identityClasses = sampleClassService.listByCategory(SampleIdentity.CATEGORY_NAME);
if (identityClasses.size() != 1) {
throw new IllegalStateException("Found more or less than one SampleClass of category " + SampleIdentity.CATEGORY_NAME + ". Cannot choose which to use as root sample class.");
}
SampleClass rootSampleClass = identityClasses.get(0);
confirmExternalNameUniqueForProjectIfRequired(identity.getExternalName(), sample);
Sample identitySample = new IdentityBuilder().project(sample.getProject()).sampleType(sample.getSampleType()).scientificName(sample.getScientificName()).name(generateTemporaryName()).rootSampleClass(rootSampleClass).volume(BigDecimal.ZERO).externalName(identity.getExternalName()).donorSex(identity.getDonorSex()).consentLevel(identity.getConsentLevel()).build();
identitySample.setAlias(getNamingScheme(sample).generateSampleAlias(identitySample));
identitySample.setChangeDetails(authorizationManager.getCurrentUser());
return (SampleIdentity) save(identitySample, true);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.
the class DefaultSampleService method update.
@Override
public long update(Sample sample) throws IOException {
Sample managed = get(sample.getId());
User changeUser = authorizationManager.getCurrentUser();
managed.setChangeDetails(changeUser);
boolean validateAliasUniqueness = !managed.getAlias().equals(sample.getAlias());
maybeRemoveFromBox(sample, managed);
boxService.throwIfBoxPositionIsFilled(sample);
if (sample.getParent() != null) {
((DetailedSample) sample).setParent((DetailedSample) get(sample.getParent().getId()));
}
LimsUtils.updateParentVolume(sample, managed, changeUser);
updateParentSlides(sample, managed, changeUser);
loadChildEntities(sample);
writeRequisitionChangelogs(sample, managed);
validateChange(sample, managed);
applyChanges(managed, sample);
if (isDetailedSample(managed)) {
DetailedSample detailedUpdated = (DetailedSample) managed;
if (detailedUpdated.getParent() != null) {
detailedUpdated.setParent((DetailedSample) get(detailedUpdated.getParent().getId()));
validateHierarchy(detailedUpdated);
}
}
save(managed, validateAliasUniqueness);
if (sample.getParent() != null) {
sampleStore.update(sample.getParent());
}
boxService.updateBoxableLocation(sample);
return sample.getId();
}
use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.
the class DefaultSampleService method addNote.
@Override
public void addNote(Sample sample, Note note) throws IOException {
Sample managed = sampleStore.get(sample.getId());
note.setCreationDate(new Date());
note.setOwner(authorizationManager.getCurrentUser());
managed.addNote(note);
sampleStore.update(managed);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.
the class DefaultSampleService method deleteNote.
@Override
public void deleteNote(Sample sample, Long noteId) throws IOException {
if (noteId == null) {
throw new IllegalArgumentException("Cannot delete an unsaved Note");
}
Sample managed = sampleStore.get(sample.getId());
Note deleteNote = null;
for (Note note : managed.getNotes()) {
if (note.getId() == noteId.longValue()) {
deleteNote = note;
break;
}
}
if (deleteNote == null) {
throw new IOException("Note " + noteId + " not found for Sample " + sample.getId());
}
authorizationManager.throwIfNonAdminOrMatchingOwner(deleteNote.getOwner());
managed.getNotes().remove(deleteNote);
sampleStore.update(managed);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Sample in project miso-lims by miso-lims.
the class DefaultSampleServiceTest method testDeleteNote.
@Test
public void testDeleteNote() throws Exception {
Sample paramSample = new SampleImpl();
paramSample.setId(1L);
paramSample.setAlias("paramSample");
Sample dbSample = new SampleImpl();
dbSample.setId(paramSample.getId());
dbSample.setAlias("persistedSample");
Note note = new Note();
note.setId(3L);
User owner = new UserImpl();
owner.setId(5L);
note.setOwner(owner);
dbSample.addNote(note);
Mockito.when(sampleStore.get(paramSample.getId())).thenReturn(dbSample);
sut.deleteNote(paramSample, note.getId());
Mockito.verify(authorizationManager).throwIfNonAdminOrMatchingOwner(owner);
ArgumentCaptor<Sample> capture = ArgumentCaptor.forClass(Sample.class);
Mockito.verify(sampleStore).update(capture.capture());
Sample savedSample = capture.getValue();
assertTrue(savedSample.getNotes().isEmpty());
}
Aggregations