@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 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; }
public static SampleClass to(@Nonnull SampleClassDto from) { SampleClass to = new SampleClassImpl(); to.setAlias(from.getAlias()); to.setSampleCategory(from.getSampleCategory()); to.setSuffix(from.getSuffix()); to.setArchived(from.isArchived()); to.setDirectCreationAllowed(from.isDirectCreationAllowed()); to.setDNAseTreatable(from.getDNAseTreatable()); return to; }
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)); }
@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 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; }
@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 SampleClass singleResult(Collection<SampleClass> classes, SampleClass child, String parentCategory) { switch (classes.size()) { case 0: return null; case 1: return classes.iterator().next(); default: throw new IllegalStateException( String.format("SampleClass %s has multiple %s parents.", child.getAlias(), parentCategory)); } }
lai.setLibraryDesignCode(design.getLibraryDesignCode()); SampleClass sampleClass = ((DetailedSample) library.getSample()).getSampleClass(); if (!sampleClass.getId().equals(design.getSampleClass().getId())) { throw new IllegalArgumentException( "Cannot use design " + design.getName() + " for a library from a sample of type " + sampleClass.getAlias());
private static boolean safeCategoryCheck(Sample sample, String category) { DetailedSample detailedSample = (DetailedSample) sample; if (detailedSample.getSampleClass() == null) return false; return category.equals(detailedSample.getSampleClass().getSampleCategory()); }
private String addSiblingTag(String parentAlias, DetailedSample sample) throws IOException { SampleClass sc = sample.getSampleClass(); if (sc == null || sc.getSuffix() == null) { throw new InvalidParameterException("Unexpected null SampleClass or suffix"); } String partialAlias = parentAlias + SEPARATOR + sc.getSuffix(); if (sample.getSiblingNumber() == null) { if (siblingNumberGenerator == null) { throw new IllegalStateException("No SiblingNumberGenerator configured"); } sample.setSiblingNumber(siblingNumberGenerator.getNextSiblingNumber(SampleImpl.class, partialAlias)); } String siblingNum = sample.getSiblingNumber().toString(); // Sibling number is only padded for Tissue Processing if (isTissueProcessingSample(sample)) { while (siblingNum.length() < 2) siblingNum = "0" + siblingNum; } return partialAlias + siblingNum; }
@Override public List<LibraryDesign> getLibraryDesignByClass(SampleClass sampleClass) throws IOException { if (sampleClass == null) return Collections.emptyList(); Criteria criteria = currentSession().createCriteria(LibraryDesign.class); criteria.createAlias("sampleClass", "sampleClass"); criteria.add(Restrictions.eq("sampleClass.id", sampleClass.getId())); @SuppressWarnings("unchecked") List<LibraryDesign> rules = criteria.list(); return rules; }
.filter(sampleClass -> { try { return sampleClass.getSampleCategory().equals("Aliquot") && sampleValidRelationshipService.getAll().stream() .anyMatch( validRelationship -> !validRelationship.getArchived() && validRelationship.getChild().getId().equals(sampleClass.getId()) && validRelationship.getParent().getId().equals(sample.getSampleClass().getId())); } catch (IOException e) { log.error("Error getting SampleValidRelationship", e);
public static boolean isSampleSlide(DetailedSample sample) { return sample instanceof SampleSlide || sample.getSampleClass().getAlias().equals(SampleSlide.SAMPLE_CLASS_NAME); }
@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; }
public boolean validate(Library library) { if (!(library.getSample() instanceof DetailedSample)) return true; if (((DetailedSample) library.getSample()).getSampleClass().getId() != sampleClass.getId()) return false; if (library.getLibrarySelectionType().getId() != librarySelectionType.getId()) return false; if (library.getLibraryStrategyType().getId() != libraryStrategyType.getId()) return false; return true; }
private void validateHierarchy(DetailedSample sample) throws IOException { Set<SampleValidRelationship> sampleValidRelationships = sampleValidRelationshipService.getAll(); if (!isValidRelationship(sampleValidRelationships, sample.getParent(), sample)) { throw new IllegalArgumentException("Parent " + sample.getParent().getSampleClass().getAlias() + " not permitted to have a child of type " + sample.getSampleClass().getAlias()); } }
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 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; }
private SampleAliquot buildAliquot() { SampleAliquot aliquot = null; if (sampleClass.getAlias().equals(SampleAliquotSingleCell.SAMPLE_CLASS_NAME)) { SampleAliquotSingleCell sc = new SampleAliquotSingleCellImpl(); sc.setInputIntoLibrary(inputIntoLibrary); aliquot = sc; } else { aliquot = new SampleAliquotImpl(); } aliquot.setSamplePurpose(samplePurpose); return aliquot; }