@Override public SampleClass getRequiredTissueProcessingClass(Long childClassId) throws IOException { SampleClass stockClass = getNotNullClass(childClassId); List<SampleValidRelationship> relationships = sampleValidRelationshipDao.getSampleValidRelationship(); if (relationships.stream().anyMatch(relationship -> !relationship.getArchived() && relationship.getChild().getId().equals(childClassId) && relationship.getParent().getSampleCategory().equals(SampleTissue.CATEGORY_NAME))) { return null; } List<SampleClass> parentClasses = relationships.stream().filter(relationship -> !relationship.getArchived() && relationship.getChild().getId().equals(childClassId) && relationship.getParent().getSampleCategory().equals(SampleTissueProcessing.CATEGORY_NAME)) .map(SampleValidRelationship::getParent) .collect(Collectors.toList()); return singleResult(parentClasses, stockClass, SampleTissueProcessing.CATEGORY_NAME); }
@Override public SampleClass inferParentFromChild(long childClassId, String childCategory, String parentCategory) { 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 = sampleValidRelationshipDao.getSampleValidRelationship().stream() .filter(relationship -> !relationship.getArchived() && !relationship.getParent().isArchived() && relationship.getChild().getId() == childClass.getId() && relationship.getParent().getSampleCategory().equals(parentCategory)) .map(SampleValidRelationship::getParent).collect(Collectors.toList()); return singleResult(parentClasses, childClass, parentCategory); }
private static boolean hasPathToDnaseTreatable(SampleClass from, Set<Long> checked, Collection<SampleValidRelationship> relationships) { if (from.getDNAseTreatable()) { return true; } // stop at tissue level, or if circling into a class hierarchy that has already been checked if (from.getSampleCategory().equals(SampleTissue.CATEGORY_NAME) || !checked.add(from.getId())) { return false; } return relationships.stream() .filter(relationship -> !relationship.getArchived() && !relationship.getParent().isArchived() && relationship.getChild().getId().equals(from.getId()) && !checked.contains(relationship.getParent().getId())) .anyMatch(relationship -> hasPathToDnaseTreatable(relationship.getParent(), checked, relationships)); }
private static boolean isValidRelationship(Iterable<SampleValidRelationship> relations, SampleClass parent, SampleClass child) { for (SampleValidRelationship relation : relations) { if (relation.getParent().getId() == parent.getId() && relation.getChild().getId() == child.getId()) { return true; } } return false; }
.anyMatch( validRelationship -> !validRelationship.getArchived() && validRelationship.getChild().getId().equals(sampleClass.getId()) && validRelationship.getParent().getId().equals(sample.getSampleClass().getId())); } catch (IOException e) {
public static SampleValidRelationshipDto asDto(@Nonnull SampleValidRelationship from) { SampleValidRelationshipDto dto = new SampleValidRelationshipDto(); dto.setId(from.getId()); dto.setParentId(from.getParent().getId()); dto.setChildId(from.getChild().getId()); dto.setCreatedById(from.getCreatedBy().getUserId()); dto.setCreationDate(formatDateTime(from.getCreationDate())); dto.setUpdatedById(from.getUpdatedBy().getUserId()); dto.setLastUpdated(formatDateTime(from.getLastUpdated())); dto.setArchived(from.getArchived()); return dto; }