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