Search in sources :

Example 26 with SampleClass

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

the class DefaultSampleClassService method collectValidationErrors.

@Override
protected void collectValidationErrors(SampleClass object, SampleClass beforeChange, List<ValidationError> errors) throws IOException {
    long usage = beforeChange == null ? 0L : sampleClassDao.getUsage(beforeChange);
    if (beforeChange == null && SampleIdentity.CATEGORY_NAME.equals(object.getSampleCategory()) && list().stream().anyMatch(sampleClass -> SampleIdentity.CATEGORY_NAME.equals(sampleClass.getSampleCategory()))) {
        errors.add(new ValidationError("sampleCategory", "There can be only one identity class"));
    }
    if (usage > 0L) {
        if (ValidationUtils.isSetAndChanged(SampleClass::getSampleCategory, object, beforeChange)) {
            errors.add(new ValidationError("sampleCategory", String.format("Cannot change because this sample class is already used by %d samples", usage)));
        }
    }
    if (!SampleClass.CATEGORIES.contains(object.getSampleCategory())) {
        errors.add(new ValidationError("sampleCategory", "Invalid category"));
    } else if (object.getSampleSubcategory() != null && !SampleClass.SUBCATEGORIES.get(object.getSampleCategory()).contains(object.getSampleSubcategory())) {
        errors.add(new ValidationError("sampleSubcategory", "Invalid subcategory"));
    }
    if (beforeChange == null && !object.getChildRelationships().isEmpty()) {
        errors.add(new ValidationError("Cannot specify child relationships for new sample class"));
    }
    validateParentRelationships(object, errors);
    if (object.isArchived()) {
        if (object.getParentRelationships().stream().anyMatch(relationship -> relationship.isArchived())) {
            errors.add(new ValidationError("archived", "Cannot archive class due to unarchived parent relationships"));
        }
        if (object.getChildRelationships().stream().anyMatch(relationship -> relationship.isArchived())) {
            errors.add(new ValidationError("archived", "Cannot archive class due to unarchived child relationships"));
        }
    }
}
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) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError)

Example 27 with SampleClass

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

the class DefaultSampleClassService method inferParentFromChild.

@Override
public SampleClass inferParentFromChild(long childClassId, String childCategory, String parentCategory) throws IOException {
    SampleClass childClass = getNotNullClass(childClassId);
    if (!childClass.getSampleCategory().equals(childCategory)) {
        throw new IllegalArgumentException(String.format("Sample class %s is not a valid %s class.", childClassId, childCategory));
    }
    List<SampleClass> parentClasses = sampleValidRelationshipService.getAll().stream().filter(relationship -> !relationship.isArchived() && !relationship.getParent().isArchived() && relationship.getChild().getId() == childClass.getId() && relationship.getParent().getSampleCategory().equals(parentCategory)).map(SampleValidRelationship::getParent).collect(Collectors.toList());
    return singleResult(parentClasses, childClass, parentCategory);
}
Also used : SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass)

Example 28 with SampleClass

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

the class OicrSampleAliasGeneratorTest method makeAliquotFromStock.

private SampleAliquot makeAliquotFromStock() throws Exception {
    DetailedSample lcm = makeLcmTube();
    lcm.setAlias("PROJ_0001_nn_n_nn_1-1_LCM02");
    SampleStock stock = new SampleStockImpl();
    stock.setParent(lcm);
    SampleClass stockSc = new SampleClassImpl();
    stockSc.setSampleCategory(SampleStock.CATEGORY_NAME);
    stockSc.setSuffix("R_S");
    stock.setSampleClass(stockSc);
    stock.setSiblingNumber(4);
    stock.setAlias("PROJ_0001_nn_n_nn_1-1_R_S4");
    SampleAliquot aliquot = new SampleAliquotImpl();
    aliquot.setParent(stock);
    SampleClass aliquotSc = new SampleClassImpl();
    aliquotSc.setSuffix("R_");
    aliquotSc.setSampleCategory(SampleAliquot.CATEGORY_NAME);
    aliquot.setSampleClass(aliquotSc);
    aliquot.setSiblingNumber(12);
    return aliquot;
}
Also used : SampleAliquot(uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) SampleAliquotImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleAliquotImpl) SampleStockImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleStockImpl) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock)

Example 29 with SampleClass

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

the class OicrSampleAliasGeneratorTest method makeLcmTube.

private SampleTissuePiece makeLcmTube() {
    SampleTissuePiece lcmTube = new SampleTissuePieceImpl();
    SampleTissue tissue = makeMinimalTissue();
    tissue.setAlias("PROJ_0001_nn_n_nn_1-1");
    lcmTube.setParent(tissue);
    lcmTube.setSiblingNumber(2);
    SampleClass sc = new SampleClassImpl();
    sc.setSampleCategory(SampleTissueProcessing.CATEGORY_NAME);
    sc.setSuffix("LCM");
    lcmTube.setSampleClass(sc);
    return lcmTube;
}
Also used : SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) SampleTissuePiece(uk.ac.bbsrc.tgac.miso.core.data.SampleTissuePiece) SampleTissuePieceImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleTissuePieceImpl)

Example 30 with SampleClass

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

the class OicrSampleAliasGeneratorTest method makeIdentity.

private SampleIdentity makeIdentity() {
    SampleIdentity identity = new SampleIdentityImpl();
    identity.setId(1L);
    identity.setAlias("PROJ_0001");
    SampleClass sc = new SampleClassImpl();
    sc.setSampleCategory(SampleIdentity.CATEGORY_NAME);
    identity.setSampleClass(sc);
    Project proj = new ProjectImpl();
    proj.setId(1L);
    proj.setAlias("PROJ");
    proj.setShortName("PROJ");
    identity.setProject(proj);
    return identity;
}
Also used : Project(uk.ac.bbsrc.tgac.miso.core.data.Project) SampleIdentityImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleIdentityImpl) SampleClass(uk.ac.bbsrc.tgac.miso.core.data.SampleClass) SampleClassImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleClassImpl) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) ProjectImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.ProjectImpl)

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