Search in sources :

Example 21 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class HibernateSampleClassDaoIT method testCreate.

@Test
public void testCreate() throws IOException {
    String alias = "New SampleClass";
    SampleClass sampleClass = new SampleClassImpl();
    sampleClass.setAlias(alias);
    sampleClass.setSampleCategory(SampleTissue.CATEGORY_NAME);
    User user = (User) currentSession().get(UserImpl.class, 1L);
    Date now = new Date();
    sampleClass.setCreator(user);
    sampleClass.setCreationTime(now);
    sampleClass.setLastModifier(user);
    sampleClass.setLastModified(now);
    long savedId = sut.create(sampleClass);
    clearSession();
    SampleClass saved = (SampleClass) getSessionFactory().getCurrentSession().get(SampleClassImpl.class, savedId);
    assertEquals(alias, saved.getAlias());
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) User(com.eaglegenomics.simlims.core.User) UserImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.UserImpl) Date(java.util.Date) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 22 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class HibernateSampleClassDaoIT method testGetUsage.

@Test
public void testGetUsage() throws IOException {
    SampleClass sampleClass = (SampleClass) getSessionFactory().getCurrentSession().get(SampleClassImpl.class, 2L);
    assertEquals("Primary Tumor Tissue", sampleClass.getAlias());
    assertEquals(5L, sut.getUsage(sampleClass));
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 23 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class HibernateSampleClassDaoIT method testGet.

@Test
public void testGet() throws IOException {
    long id = 1L;
    SampleClass sampleClass = sut.get(id);
    assertNotNull(sampleClass);
    assertEquals(id, sampleClass.getId());
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 24 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class HibernateSampleValidRelationshipDaoIT method testGetByClasses.

@Test
public void testGetByClasses() throws Exception {
    SampleClass parent = (SampleClass) currentSession().get(SampleClassImpl.class, 1L);
    SampleClass child = (SampleClass) currentSession().get(SampleClassImpl.class, 2L);
    SampleValidRelationship relationship = sut.getByClasses(parent, child);
    assertNotNull(relationship);
    assertEquals(parent.getId(), relationship.getParent().getId());
    assertEquals(child.getId(), relationship.getChild().getId());
}
Also used : SampleValidRelationship(uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) AbstractDAOTest(uk.ac.bbsrc.tgac.miso.AbstractDAOTest) Test(org.junit.Test)

Example 25 with SampleClass

use of uk.ac.bbsrc.tgac.miso.core.data.SampleClass in project miso-lims by miso-lims.

the class DefaultSampleClassService method validateParentRelationships.

private void validateParentRelationships(SampleClass sampleClass, List<ValidationError> errors) {
    Set<String> allowedParents = null;
    switch(sampleClass.getSampleCategory()) {
        case SampleIdentity.CATEGORY_NAME:
            allowedParents = Collections.emptySet();
            break;
        case SampleTissue.CATEGORY_NAME:
            allowedParents = Sets.newHashSet(SampleIdentity.CATEGORY_NAME, SampleTissue.CATEGORY_NAME);
            validateSingleParentRequirement(sampleClass, SampleIdentity.CATEGORY_NAME, errors);
            break;
        case SampleTissueProcessing.CATEGORY_NAME:
            allowedParents = Sets.newHashSet(SampleTissue.CATEGORY_NAME, SampleTissueProcessing.CATEGORY_NAME);
            long tissueParents = sampleClass.getParentRelationships().stream().filter(relationship -> SampleTissue.CATEGORY_NAME.equals(relationship.getParent().getSampleCategory()) && !relationship.isArchived()).count();
            if (tissueParents > 1L) {
                errors.add(new ValidationError("parentRelationships", String.format("%s classes cannot have multiple %s parents", SampleTissueProcessing.CATEGORY_NAME, SampleTissue.CATEGORY_NAME)));
            } else if (tissueParents == 0L && !hasPathToIdentity(sampleClass)) {
                errors.add(new ValidationError("parentRelationships", String.format("Must have a direct or indirect link to the %s class", SampleIdentity.CATEGORY_NAME)));
            }
            break;
        case SampleStock.CATEGORY_NAME:
            allowedParents = Sets.newHashSet(SampleTissue.CATEGORY_NAME, SampleTissueProcessing.CATEGORY_NAME, SampleStock.CATEGORY_NAME);
            if (SampleStockSingleCell.SUBCATEGORY_NAME.equals(sampleClass.getSampleSubcategory())) {
                // Single Cell Stocks need to be parented to a Single Cell (tissue processing) class instead of a tissue class
                if (sampleClass.getParentRelationships().stream().filter(relationship -> SampleTissueProcessing.CATEGORY_NAME.equals(relationship.getParent().getSampleCategory()) && SampleSingleCell.SUBCATEGORY_NAME.equals(relationship.getParent().getSampleSubcategory()) && !relationship.isArchived()).count() != 1L) {
                    errors.add(makeSingleParentRequirementError(sampleClass.getSampleSubcategory(), SampleSingleCell.SUBCATEGORY_NAME));
                }
            } else {
                validateSingleParentRequirement(sampleClass, SampleTissue.CATEGORY_NAME, errors);
            }
            break;
        case SampleAliquot.CATEGORY_NAME:
            allowedParents = Sets.newHashSet(SampleStock.CATEGORY_NAME, SampleAliquot.CATEGORY_NAME);
            validateSingleParentRequirement(sampleClass, SampleStock.CATEGORY_NAME, errors);
            break;
        default:
            throw new IllegalArgumentException("Unhandled sample category: " + sampleClass.getSampleCategory());
    }
    for (SampleValidRelationship relationship : sampleClass.getParentRelationships()) {
        if (!allowedParents.contains(relationship.getParent().getSampleCategory())) {
            errors.add(new ValidationError("parentRelationships", String.format("%s (%s) cannot be a parent of %s classes", relationship.getParent().getAlias(), relationship.getParent().getSampleCategory(), sampleClass.getSampleCategory())));
        }
    }
    List<SampleClass> parents = sampleClass.getParentRelationships().stream().map(SampleValidRelationship::getParent).collect(Collectors.toList());
    for (int i = 0; i < parents.size(); i++) {
        for (int j = i + 1; j < parents.size(); j++) {
            if (parents.get(i).getId() == parents.get(j).getId()) {
                errors.add(new ValidationError("parentRelationships", String.format("Cannot have multiple parent relationships to the same sample class (%s)", parents.get(i).getAlias())));
                break;
            }
        }
    }
}
Also used : User(com.eaglegenomics.simlims.core.User) AuthorizationManager(uk.ac.bbsrc.tgac.miso.core.security.AuthorizationManager) SampleTissueProcessing(uk.ac.bbsrc.tgac.miso.core.data.SampleTissueProcessing) SampleValidRelationship(uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship) SampleSingleCell(uk.ac.bbsrc.tgac.miso.core.data.SampleSingleCell) SampleClassService(uk.ac.bbsrc.tgac.miso.core.service.SampleClassService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashSet(java.util.HashSet) SampleValidRelationshipService(uk.ac.bbsrc.tgac.miso.core.service.SampleValidRelationshipService) SampleClassDao(uk.ac.bbsrc.tgac.miso.persistence.SampleClassDao) Service(org.springframework.stereotype.Service) SampleStockSingleCell(uk.ac.bbsrc.tgac.miso.core.data.SampleStockSingleCell) Pluralizer(uk.ac.bbsrc.tgac.miso.core.util.Pluralizer) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) SampleAliquot(uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot) SampleTypeService(uk.ac.bbsrc.tgac.miso.core.service.SampleTypeService) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) ValidationResult(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationResult) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) DeletionStore(uk.ac.bbsrc.tgac.miso.core.store.DeletionStore) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock) AbstractSaveService(uk.ac.bbsrc.tgac.miso.service.AbstractSaveService) Collections(java.util.Collections) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SaveDao(uk.ac.bbsrc.tgac.miso.persistence.SaveDao) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) Transactional(org.springframework.transaction.annotation.Transactional) SampleValidRelationship(uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Aggregations

SampleClass (uk.ac.bbsrc.tgac.miso.core.data.SampleClass)41 SampleClassImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl)27 SampleStock (uk.ac.bbsrc.tgac.miso.core.data.SampleStock)10 SampleTissue (uk.ac.bbsrc.tgac.miso.core.data.SampleTissue)10 Test (org.junit.Test)8 AbstractDAOTest (uk.ac.bbsrc.tgac.miso.AbstractDAOTest)8 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)8 SampleStockImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleStockImpl)8 SampleAliquot (uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot)6 SampleIdentity (uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity)5 SampleValidRelationship (uk.ac.bbsrc.tgac.miso.core.data.SampleValidRelationship)5 SampleTissueImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleTissueImpl)4 User (com.eaglegenomics.simlims.core.User)3 HashSet (java.util.HashSet)3 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)3 SampleTissuePiece (uk.ac.bbsrc.tgac.miso.core.data.SampleTissuePiece)3 SampleAliquotImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleAliquotImpl)3 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)2 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)2 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)2