@Override public Long getId() { return library.getId(); }
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); }
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"); } } }
dto.setId(from.getId()); if (from.getConcentration() != null) { dto.setConcentration(from.getConcentration().toString());
@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); } }
v.setLibraryDnaSize(lib.getDnaSize().longValue()); v.setLibraryId(lib.getId()); v.setLibraryName(lib.getName()); v.setLibraryPaired(lib.getPaired());
@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 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; }
@Override public void deleteNote(Library library, Long noteId) throws IOException { if (noteId == null || noteId.equals(Note.UNSAVED_ID)) { throw new IllegalArgumentException("Cannot delete an unsaved Note"); } Library managed = libraryDao.get(library.getId()); authorizationManager.throwIfNotWritable(managed); Note deleteNote = null; for (Note note : managed.getNotes()) { if (note.getNoteId().equals(noteId)) { deleteNote = note; break; } } if (deleteNote == null) { throw new IOException("Note " + noteId + " not found for Library " + library.getId()); } authorizationManager.throwIfNonAdminOrMatchingOwner(deleteNote.getOwner()); managed.getNotes().remove(deleteNote); libraryDao.save(managed); }
@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; }
@Override public void addNote(Library library, Note note) throws IOException { Library managed = libraryDao.get(library.getId()); authorizationManager.throwIfNotWritable(managed); note.setCreationDate(new Date()); note.setOwner(authorizationManager.getCurrentUser()); managed.addNote(note); save(managed, false); }
@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 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); }
/** * Loads persisted objects into LibraryDilution fields. Should be called before saving LibraryDilutions. Loads all member objects * <b>except</b> * <ul> * <li>creator/lastModifier User objects</li> * </ul> * * @param libraryDilution the LibraryDilution to load entities into. Must contain at least the IDs of objects to load (e.g. to load the * persisted Library * into dilution.library, dilution.library.id must be set) * @throws IOException */ private void loadChildEntities(LibraryDilution dilution) throws IOException { if (dilution.getLibrary() != null) { dilution.setLibrary(libraryService.get(dilution.getLibrary().getId())); } if (dilution.getTargetedSequencing() != null) { dilution.setTargetedSequencing(targetedSequencingService.get(dilution.getTargetedSequencing().getId())); } if (dilution.getSecurityProfile() != null && dilution.getSecurityProfile().getProfileId() != SecurityProfile.UNSAVED_ID) { dilution.setSecurityProfile(securityProfileStore.get(dilution.getSecurityProfile().getProfileId())); } }
experiment.setName(DbUtils.generateTemporaryName()); experiment.setInstrumentModel(platformService.get(experiment.getInstrumentModel().getId())); experiment.setLibrary(libraryService.get(experiment.getLibrary().getId())); experiment.setStudy(studyService.get(experiment.getStudy().getId())); experiment.setChangeDetails(authorizationManager.getCurrentUser()); original.setName(experiment.getName()); original.setInstrumentModel(platformService.get(experiment.getInstrumentModel().getId())); original.setLibrary(libraryService.get(experiment.getLibrary().getId())); original.setStudy(studyService.get(experiment.getStudy().getId())); original.setSecurityProfile(securityStore.getSecurityProfileById(experiment.getSecurityProfile().getProfileId()));
@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; }
@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; }