@CoverageIgnore @Override public int compareTo(Library l) { if (getId() != 0L && l.getId() != 0L) { if (getId() < l.getId()) return -1; if (getId() > l.getId()) return 1; } else if (getName() != null && l.getName() != null) { return getName().compareTo(l.getName()); } else if (getAlias() != null && l.getAlias() != null) { return getAlias().compareTo(l.getAlias()); } return 0; }
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; }
target.setDescription(source.getDescription()); target.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(source.getIdentificationBarcode())); target.setConcentration(source.getConcentration()); target.setConcentrationUnits(target.getConcentration() == null ? null : source.getConcentrationUnits()); target.setPlatformType(source.getPlatformType()); target.setAlias(source.getAlias()); target.setPaired(source.getPaired()); target.setLowQuality(source.isLowQuality()); target.setDiscarded(source.isDiscarded()); target.setCreationDate(source.getCreationDate()); if (target.isDiscarded()) { target.setVolume(0.0); } else { target.setVolume(source.getVolume()); target.setVolumeUnits(target.getVolume() == null ? null : source.getVolumeUnits()); target.setDnaSize(source.getDnaSize()); target.setLibraryType(source.getLibraryType()); target.setLibrarySelectionType(source.getLibrarySelectionType()); target.setLibraryStrategyType(source.getLibraryStrategyType()); target.setQcPassed(source.getQcPassed()); target.setIndices(source.getIndices()); if (source.getKitDescriptor() != null) { target.setKitDescriptor(source.getKitDescriptor()); } else { target.setKitDescriptor(null); target.setReceivedDate(source.getReceivedDate());
@Override public ValidationResult validateDeletion(Library object) { ValidationResult result = new ValidationResult(); if (object.getLibraryDilutions() != null && !object.getLibraryDilutions().isEmpty()) { result.addError(new ValidationError(object.getName() + " has " + object.getLibraryDilutions().size() + " dilution" + (object.getLibraryDilutions().size() > 1 ? "s" : ""))); } return result; }
@Override public void beforeDelete(Library object) throws IOException { List<Workset> worksets = worksetService.listByLibrary(object.getId()); for (Workset workset : worksets) { workset.getLibraries().removeIf(lib -> lib.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
dto.setAlias(from.getAlias()); dto.setName(from.getName()); 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()); dto.setCreationDate(formatDate(from.getCreationDate())); dto.setDescription(from.getDescription()); dto.setId(from.getId()); if (from.getConcentration() != null) { dto.setConcentration(from.getConcentration().toString()); dto.setConcentrationUnits(from.getConcentrationUnits()); if (from.getLibrarySelectionType() != null) { dto.setLibrarySelectionTypeId(from.getLibrarySelectionType().getId()); if (from.getLibraryStrategyType() != null) { dto.setLibraryStrategyTypeId(from.getLibraryStrategyType().getId()); if (from.getLibraryType() != null) { dto.setLibraryTypeId(from.getLibraryType().getId()); dto.setLibraryTypeAlias(from.getLibraryType().getDescription()); dto.setQcPassed(from.getQcPassed()); dto.setLowQuality(from.isLowQuality()); dto.setPaired(from.getPaired()); if (from.getPlatformType() != null) {
if (from.getId() != null) to.setId(from.getId()); to.setAlias(from.getAlias()); to.setName(from.getName()); to.setDescription(from.getDescription()); to.setIdentificationBarcode(from.getIdentificationBarcode()); to.setConcentration(from.getConcentration() == null ? null : Double.valueOf(from.getConcentration())); to.setConcentrationUnits(from.getConcentrationUnits()); to.setLowQuality(from.getLowQuality()); if (from.getPaired() != null) { to.setPaired(from.getPaired()); to.setPlatformType(PlatformType.get(from.getPlatformType())); if (from.getParentSampleId() != null) { to.setSample(new SampleImpl()); to.getSample().setId(from.getParentSampleId()); to.setLibrarySelectionType(sel); to.setLibraryStrategyType(strat); type.setId(from.getLibraryTypeId()); if (from.getLibraryTypeAlias() != null) type.setDescription(from.getLibraryTypeAlias()); to.setLibraryType(type); to.setQcPassed(from.getQcPassed()); if (from.getIndex1Id() != null) { List<Index> indices = new ArrayList<>();
v.setIndices(lib.getIndices()); v.setLibraryAlias(lib.getAlias()); v.setLibraryBarcode(lib.getIdentificationBarcode()); v.setLibraryDescription(lib.getDescription()); if (lib.getDnaSize() != null) { v.setLibraryDnaSize(lib.getDnaSize().longValue()); v.setLibraryId(lib.getId()); v.setLibraryName(lib.getName()); v.setLibraryPaired(lib.getPaired()); if (lib.getLibrarySelectionType() != null) { v.setLibrarySelectionType(lib.getLibrarySelectionType().getName()); if (lib.getLibraryStrategyType() != null) { v.setLibraryStrategyType(lib.getLibraryStrategyType().getName()); v.setLibraryLowQuality(lib.isLowQuality()); v.setPlatformType(lib.getPlatformType()); Sample sam = lib.getSample(); if (sam != null) { v.setSampleAccession(sam.getAccession());
if (library.getSample() != null) { library.setSample(sampleService.get(library.getSample().getId())); if (library.getLibraryType() != null) { library.setLibraryType(getLibraryTypeById(library.getLibraryType().getId())); if (library.getLibrarySelectionType() != null) { library.setLibrarySelectionType(getLibrarySelectionTypeById(library.getLibrarySelectionType().getId())); if (library.getLibraryStrategyType() != null) { library.setLibraryStrategyType(getLibraryStrategyTypeById(library.getLibraryStrategyType().getId())); for (Index index : library.getIndices()) { if (index != null && index.getId() != Index.UNSAVED_ID) { Index managedIndex = indexService.getIndexById(index.getId()); library.setIndices(managedIndices); if (library.getSecurityProfile() != null && library.getSecurityProfile().getProfileId() != SecurityProfile.UNSAVED_ID) { library.setSecurityProfile(securityManager.getSecurityProfileById(library.getSecurityProfile().getProfileId())); if (library.getKitDescriptor() != null) { library.setKitDescriptor(kitService.getKitDescriptorById(library.getKitDescriptor().getId())); if (library.getSpikeIn() != null) { library.setSpikeIn(getSpikeIn(library.getSpikeIn().getId())); lai.setLibraryStrategyType(design.getLibraryStrategyType()); lai.setLibraryDesignCode(design.getLibraryDesignCode()); SampleClass sampleClass = ((DetailedSample) library.getSample()).getSampleClass();
@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; }
sampleDescriptor.setAttribute("refname", experiment.getLibrary().getSample().getAlias()); sampleDescriptor.setAttribute("refcenter", centreName); if (!isStringEmptyOrNull(experiment.getLibrary().getSample().getAccession())) { sampleDescriptor.setAttribute("accession", experiment.getLibrary().getSample().getAccession()); if (!isStringEmptyOrNull(experiment.getLibrary().getAlias())) { libraryName.setTextContent(experiment.getLibrary().getAlias()); } else { libraryName.setTextContent(experiment.getLibrary().getName()); libraryStrategy.setTextContent(experiment.getLibrary().getLibraryStrategyType().getName()); libraryDescriptor.appendChild(libraryStrategy); librarySource.setTextContent(experiment.getLibrary().getSample().getSampleType()); libraryDescriptor.appendChild(librarySource); librarySelection.setTextContent(experiment.getLibrary().getLibrarySelectionType().getName()); libraryDescriptor.appendChild(librarySelection); if (experiment.getLibrary().getPaired()) { layout = xml.getOwnerDocument().createElementNS(null, "PAIRED"); if (experiment.getLibrary().getDnaSize() != null) { layout.setAttribute("NOMINAL_LENGTH", experiment.getLibrary().getDnaSize().toString()); } else { layout.setAttribute("NOMINAL_LENGTH", "0");
public static DilutionDto asDto(@Nonnull LibraryDilution from, boolean includeFullLibrary, boolean includeBoxPositions) { LibraryDto libDto = null; if (includeFullLibrary) { libDto = asDto(from.getLibrary(), false); } else { Library lib = from.getLibrary(); libDto = new LibraryDto(); libDto.setId(lib.getId()); libDto.setName(lib.getName()); libDto.setAlias(lib.getAlias()); libDto.setIdentificationBarcode(lib.getIdentificationBarcode()); if (lib.getPlatformType() != null) { libDto.setPlatformType(lib.getPlatformType().getKey()); } } return asDto(from, libDto, includeBoxPositions); }
@Override public void update(Library library) throws IOException { Library managed = get(library.getId()); managed.setChangeDetails(authorizationManager.getCurrentUser()); List<Index> originalIndices = new ArrayList<>(managed.getIndices()); authorizationManager.throwIfNotWritable(managed); maybeRemoveFromBox(library); boxService.throwIfBoxPositionIsFilled(library); boolean validateAliasUniqueness = !managed.getAlias().equals(library.getAlias()); validateChange(library, managed); applyChanges(managed, library); loadChildEntities(managed); makeChangeLogForIndices(originalIndices, managed.getIndices(), managed); save(managed, validateAliasUniqueness); boxService.updateBoxableLocation(library); }
@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."); } }
@Override public Long create(LibraryDilution dilution) throws IOException { loadChildEntities(dilution); dilution.setCreator(authorizationManager.getCurrentUser()); if (dilution.getSecurityProfile() == null) { dilution.inheritPermissions(libraryService.get(dilution.getLibrary().getId())); } authorizationManager.throwIfNotWritable(dilution); boxService.throwIfBoxPositionIsFilled(dilution); if (dilution.getConcentration() == null) { dilution.setConcentrationUnits(null); } if (dilution.getVolume() == null) { dilution.setVolumeUnits(null); } Library library = dilution.getLibrary(); if (dilution.getVolumeUsed() != null && library.getVolume() != null) { library.setVolume(library.getVolume() - dilution.getVolumeUsed()); } dilution.setChangeDetails(authorizationManager.getCurrentUser()); // pre-save field generation dilution.setName(generateTemporaryName()); validateChange(dilution, null); long savedId = save(dilution).getId(); libraryService.update(library); boxService.updateBoxableLocation(dilution); return savedId; }
private void validateAliasUniqueness(Library library) throws IOException { // duplicate aliases may be allowed via naming scheme, or with nonStandardAlias=true in the case of a DetailedLibrary if (namingScheme.duplicateLibraryAliasAllowed() || (LimsUtils.isDetailedLibrary(library) && ((DetailedLibrary) library).hasNonStandardAlias())) { return; } List<Library> potentialDupes = listByAlias(library.getAlias()); for (Library potentialDupe : potentialDupes) { if (library.getId() == AbstractLibrary.UNSAVED_ID || library.getId() != potentialDupe.getId()) { // an existing DIFFERENT library already has this alias throw new IllegalArgumentException("NEW: A library with this alias already exists in the database"); } } }
@Override public long save(Library library) throws IOException { long id; if (library.getId() == AbstractLibrary.UNSAVED_ID) { id = (long) currentSession().save(library); } else { if (library.isDiscarded()) { getBoxDao().removeBoxableFromBox(library); } currentSession().update(library); id = library.getId(); } return id; }
managed.setName(namingScheme.generateNameFor(managed)); validateNameOrThrow(managed, namingScheme); needsUpdate = true; managed.setAlias(generatedAlias); if (isDetailedLibrary(managed)) { if (autoGenerateIdBarcodes && isStringEmptyOrNull(managed.getIdentificationBarcode())) {
@Override public Long getId() { return library.getId(); }
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; }; }