private static boolean safeCategoryCheck(Sample sample, String category) { DetailedSample detailedSample = (DetailedSample) sample; if (detailedSample.getSampleClass() == null) return false; return category.equals(detailedSample.getSampleClass().getSampleCategory()); }
@Override public ProgressStep create(String input, Set<InputType> inputTypes) throws IOException { SampleProgressStep step = ((SampleProgressStep) super.create(input, inputTypes)); if (step == null) { return null; } if (((DetailedSample) step.getInput()).getSampleClass().getSampleCategory().equals("Stock")) { return step; } return null; }
@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); }
@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); }
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)); }
.filter(sampleClass -> { try { return sampleClass.getSampleCategory().equals("Aliquot") && sampleValidRelationshipService.getAll().stream() .anyMatch( validRelationship -> !validRelationship.getArchived()
@Override public void update(SampleClass sampleClass) throws IOException { authorizationManager.throwIfNonAdmin(); SampleClass updatedSampleClass = get(sampleClass.getId()); updatedSampleClass.setAlias(sampleClass.getAlias()); updatedSampleClass.setSampleCategory(sampleClass.getSampleCategory()); updatedSampleClass.setSuffix(sampleClass.getSuffix()); updatedSampleClass.setDNAseTreatable(sampleClass.getDNAseTreatable()); User user = authorizationManager.getCurrentUser(); updatedSampleClass.setUpdatedBy(user); sampleClassDao.update(updatedSampleClass); }
public DetailedSample build() { if (sampleClass == null || sampleClass.getSampleCategory() == null) { throw new NullPointerException("Missing sample class or category"); switch (sampleClass.getSampleCategory()) { case SampleIdentity.CATEGORY_NAME: SampleIdentity identity = buildIdentity(); break; default: throw new IllegalArgumentException("Unknown sample category: " + sampleClass.getSampleCategory()); } else { DetailedSample parent = null; int categoryIndex = CATEGORY_ORDER.indexOf(sampleClass.getSampleCategory()); if (categoryIndex < 0) { throw new IllegalArgumentException("Sample has no parent and cannot infer order from sample category.");
public static SampleClassDto asDto(@Nonnull SampleClass from) { SampleClassDto dto = new SampleClassDto(); dto.setId(from.getId()); dto.setAlias(from.getAlias()); dto.setSampleCategory(from.getSampleCategory()); dto.setSuffix(from.getSuffix()); dto.setArchived(from.isArchived()); dto.setDirectCreationAllowed(from.isDirectCreationAllowed()); dto.setCreatedById(from.getCreatedBy().getUserId()); dto.setCreationDate(formatDateTime(from.getCreationDate())); dto.setUpdatedById(from.getUpdatedBy().getUserId()); dto.setLastUpdated(formatDateTime(from.getLastUpdated())); dto.setDNAseTreatable(from.getDNAseTreatable()); return dto; }