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 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; }
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); }
@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); }
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; }
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; }
public static LibraryDesignDto asDto(@Nonnull LibraryDesign from) { LibraryDesignDto dto = new LibraryDesignDto(); dto.setId(from.getId()); dto.setName(from.getName()); dto.setDesignCodeId(from.getLibraryDesignCode().getId()); dto.setSampleClassId(from.getSampleClass().getId()); dto.setSelectionId(from.getLibrarySelectionType().getId()); dto.setStrategyId(from.getLibraryStrategyType().getId()); return dto; }
@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 SampleDto asMinimalDto(@Nonnull Sample from) { DetailedSampleDto dto = new DetailedSampleDto(); copySampleFields(from, dto, false); if (isDetailedSample(from)) { DetailedSample detailed = (DetailedSample) from; dto.setSampleClassId(detailed.getSampleClass().getId()); dto.setCreationDate(detailed.getCreationDate() == null ? "" : formatDate(detailed.getCreationDate())); dto.setIdentityConsentLevel(getIdentityConsentLevelString(detailed)); if (detailed.getSubproject() != null) { dto.setSubprojectAlias(detailed.getSubproject().getAlias()); dto.setSubprojectPriority(detailed.getSubproject().getPriority()); } } return dto; }
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; }
throw new IllegalArgumentException(); dto.setSampleClassId(from.getSampleClass().getId()); if (from.getDetailedQcStatus() != null) { dto.setDetailedQcStatusId(from.getDetailedQcStatus().getId()); dto.setParentId(from.getParent().getId()); dto.setParentAlias(from.getParent().getAlias()); dto.setParentTissueSampleClassId(from.getParent().getSampleClass().getId()); dto.setIdentityConsentLevel(getIdentityConsentLevelString(from));
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());
dto.setParentSampleProjectId(from.getSample().getProject().getId()); if (from.getSample() instanceof DetailedSample) { dto.setParentSampleClassId(((DetailedSample) from.getSample()).getSampleClass().getId());