private static <S extends DetailedSample, T> Function<Library, T> detailedSample(Class<S> clazz, Function<S, T> function, T defaultValue) { return l -> { if (clazz.isInstance(l.getSample())) { return function.apply(clazz.cast(l.getSample())); } if (LimsUtils.isDetailedSample(l.getSample())) { S parent = LimsUtils.getParent(clazz, (DetailedSample) l.getSample()); if (parent != null) { return function.apply(parent); } } return defaultValue; }; }
private static <S extends DetailedSample, T> Function<LibraryDilution, T> detailedSample(Class<S> clazz, Function<S, T> function, T defaultValue) { return d -> { if (clazz.isInstance(d.getLibrary().getSample())) { return function.apply(clazz.cast(d.getLibrary().getSample())); } if (LimsUtils.isDetailedSample(d.getLibrary().getSample())) { S parent = LimsUtils.getParent(clazz, (DetailedSample) d.getLibrary().getSample()); if (parent != null) { return function.apply(parent); } } return defaultValue; }; }
private void validateParentOrThrow(Library library) { if (!isDetailedLibrary(library)) return; if (!isAliquotSample(library.getSample())) { String sc = null; if (isDetailedSample(library.getSample())) { DetailedSample sample = (DetailedSample) library.getSample(); sc = sample.getSampleClass() == null ? "not set" : sample.getSampleClass().getAlias(); } else { sc = "Plain Sample"; } throw new IllegalArgumentException(String.format("Sample Class '%s' is not a valid parent for Libraries. Must be an aliquot", sc)); } }
@Override public String generate(Library library) throws MisoNamingException, IOException { if (library.getSample() != null) { Pattern samplePattern = Pattern.compile("([A-z0-9]+)_S([A-z0-9]+)_(.*)"); Matcher m = samplePattern.matcher(library.getSample().getAlias()); if (m.matches()) { Collection<Library> siblings = libraryStore.listBySampleId(library.getSample().getId()); Set<String> siblingAliases = siblings.stream() .map(Library::getAlias) .collect(Collectors.toSet()); String alias = null; long siblingNumber = siblings.stream() .filter(sibling -> sibling.getId() != library.getId()) .count(); do { siblingNumber++; alias = m.group(1) + "_" + "L" + m.group(2) + "-" + siblingNumber + "_" + m.group(3); } while (siblingAliases.contains(alias)); return alias; } else { throw new MisoNamingException( "Cannot generate Library alias for: " + library.toString() + " from supplied sample alias: " + library.getSample().getAlias()); } } else { throw new NullPointerException("This alias generation scheme requires the Library to have a parent Sample set."); } }
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; }
sampleDescriptor.setAttribute("refname", experiment.getLibrary().getSample().getAlias()); sampleDescriptor.setAttribute("refcenter", centreName); if (!isStringEmptyOrNull(experiment.getLibrary().getSample().getAccession())) { sampleDescriptor.setAttribute("accession", experiment.getLibrary().getSample().getAccession()); librarySource.setTextContent(experiment.getLibrary().getSample().getSampleType()); libraryDescriptor.appendChild(librarySource);
@Override public Library getAdjacentLibrary(long libraryId, boolean before) throws IOException { AdjacencySelector selector = before ? BEFORE : AFTER; Library lib = get(libraryId); if (lib == null) throw new IOException("Library not found"); // get library siblings Criteria criteria = currentSession().createCriteria(LibraryImpl.class); criteria.createAlias("sample", "sample"); criteria.add(Restrictions.eq("sample.id", lib.getSample().getId())); criteria.add(selector.generateCriterion("id", libraryId)); criteria.addOrder(selector.getOrder("id")); criteria.setMaxResults(1); Library library = (Library) criteria.uniqueResult(); if (library != null) return library; // get library cousins criteria = currentSession().createCriteria(LibraryImpl.class); criteria.createAlias("sample", "sample"); criteria.createAlias("sample.project", "project"); criteria.add(Restrictions.eq("project.id", lib.getSample().getProject().getId())); criteria.add(selector.generateCriterion("id", lib.getId())); criteria.addOrder(selector.getOrder("sample.id")); criteria.addOrder(selector.getOrder("id")); criteria.setMaxResults(1); library = (Library) criteria.uniqueResult(); return library; }
@Override public Long create(Library library) throws IOException { if (library.getSample() != null && library.getSample().getId() == Sample.UNSAVED_ID) { Long sampleId = sampleService.create(library.getSample()); library.getSample().setId(sampleId); } loadChildEntities(library); boxService.throwIfBoxPositionIsFilled(library); library.setChangeDetails(authorizationManager.getCurrentUser()); if (library.getSecurityProfile() == null) { library.inheritPermissions(sampleService.get(library.getSample().getId())); } authorizationManager.throwIfNotWritable(library); validateParentOrThrow(library); // pre-save field generation library.setName(generateTemporaryName()); if (isStringEmptyOrNull(library.getAlias()) && namingScheme.hasLibraryAliasGenerator()) { library.setAlias(generateTemporaryName()); } if (library.getConcentration() == null) { library.setConcentrationUnits(null); } if (library.getVolume() == null) { library.setVolumeUnits(null); } validateChange(library, null); long savedId = save(library, true).getId(); boxService.updateBoxableLocation(library); return savedId; }
dto.setParentSampleId(from.getSample().getId()); dto.setParentSampleAlias(from.getSample().getAlias()); dto.setParentSampleProjectId(from.getSample().getProject().getId()); if (from.getSample() instanceof DetailedSample) { dto.setParentSampleClassId(((DetailedSample) from.getSample()).getSampleClass().getId()); if (from.getSample().getBox() != null) { dto.setSampleBoxPositionLabel(BoxUtils.makeBoxPositionLabel(from.getSample().getBox().getAlias(), from.getSample().getBoxPosition()));
if (library.getSample() != null) { library.setSample(sampleService.get(library.getSample().getId())); lai.setLibraryStrategyType(design.getLibraryStrategyType()); lai.setLibraryDesignCode(design.getLibraryDesignCode()); SampleClass sampleClass = ((DetailedSample) library.getSample()).getSampleClass(); if (!sampleClass.getId().equals(design.getSampleClass().getId())) { throw new IllegalArgumentException(
if (from.getParentSampleId() != null) { to.setSample(new SampleImpl()); to.getSample().setId(from.getParentSampleId());
v.setPlatformType(lib.getPlatformType()); Sample sam = lib.getSample(); if (sam != null) { v.setSampleAccession(sam.getAccession());