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