Search in sources :

Example 6 with Sample

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);
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) IdentityBuilder(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleIdentityImpl.IdentityBuilder) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)

Example 7 with Sample

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();
}
Also used : User(com.eaglegenomics.simlims.core.User) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)

Example 8 with Sample

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);
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) Date(java.util.Date)

Example 9 with Sample

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);
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) Note(com.eaglegenomics.simlims.core.Note) IOException(java.io.IOException)

Example 10 with Sample

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());
}
Also used : User(com.eaglegenomics.simlims.core.User) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Note(com.eaglegenomics.simlims.core.Note) UserImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl) SampleImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl) Test(org.junit.Test)

Aggregations

Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)97 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)60 Test (org.junit.Test)55 SampleImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleImpl)37 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)24 TransferSample (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)19 SampleIdentity (uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity)11 User (com.eaglegenomics.simlims.core.User)9 ArrayList (java.util.ArrayList)9 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)9 SampleTissue (uk.ac.bbsrc.tgac.miso.core.data.SampleTissue)8 IOException (java.io.IOException)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)7 Library (uk.ac.bbsrc.tgac.miso.core.data.Library)7 SampleStock (uk.ac.bbsrc.tgac.miso.core.data.SampleStock)7 Requisition (uk.ac.bbsrc.tgac.miso.core.data.impl.Requisition)7 WorksetSample (uk.ac.bbsrc.tgac.miso.core.data.impl.workset.WorksetSample)7 Date (java.util.Date)6 Criteria (org.hibernate.Criteria)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6