if (LibraryDilution.UNSAVED_ID == getId() || LibraryDilution.UNSAVED_ID == them.getId()) { if (name == null) { if (them.getName() != null) return false; } else if (!name.equals(them.getName())) { return false; if (them.getIdentificationBarcode() != null) return false; } else if (!identificationBarcode.equals(them.getIdentificationBarcode())) { return false; if (them.getConcentration() != null) return false; } else if (!concentration.equals(them.getConcentration())) { return false; if (them.getCreationDate() != null) return false; } else if (!creationDate.equals(them.getCreationDate())) { return false; if (them.getCreator() != null) return false; } else if (!creator.equals(them.getCreator())) { return false; if (them.getLibrary() != null) return false;
@Override public void beforeDelete(LibraryDilution object) throws IOException { List<Workset> worksets = worksetService.listByDilution(object.getId()); for (Workset workset : worksets) { workset.getDilutions().removeIf(ldi -> ldi.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
/** * Copies modifiable fields from the source LibraryDilution into the target LibraryDilution to be persisted * * @param target the persisted LibraryDilution to modify * @param source the modified LibraryDilution to copy modifiable fields from * @throws IOException */ private void applyChanges(LibraryDilution target, LibraryDilution source) { target.setTargetedSequencing(source.getTargetedSequencing()); target.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(source.getIdentificationBarcode())); target.setVolume(source.getVolume()); target.setVolumeUnits(target.getVolume() == null ? null : source.getVolumeUnits()); target.setConcentration(source.getConcentration()); target.setConcentrationUnits(target.getConcentration() == null ? null : source.getConcentrationUnits()); target.setNgUsed(source.getNgUsed()); target.setVolumeUsed(source.getVolumeUsed()); }
@Override public String getBarcodeSizeInfo() { return LimsUtils.makeVolumeAndConcentrationLabel(getVolume(), getConcentration(), getVolumeUnits(), getConcentrationUnits()); }
@CoverageIgnore @Override public int hashCode() { if (LibraryDilution.UNSAVED_ID != getId()) { return (int) getId(); } else { final int PRIME = 37; int hashcode = 1; if (getCreationDate() != null) hashcode = PRIME * hashcode + getCreationDate().hashCode(); if (getCreator() != null) hashcode = PRIME * hashcode + getCreator().hashCode(); if (getConcentration() != null) hashcode = PRIME * hashcode + getConcentration().hashCode(); return hashcode; } }
private static DilutionDto asDto(@Nonnull LibraryDilution from, @Nonnull LibraryDto libraryDto, boolean includeBoxPositions) { DilutionDto dto = new DilutionDto(); dto.setId(from.getId()); dto.setName(from.getName()); dto.setDilutionUserName(from.getCreator().getFullName()); dto.setConcentration(from.getConcentration() == null ? null : from.getConcentration().toString()); dto.setConcentrationUnits(from.getConcentrationUnits()); dto.setVolume(from.getVolume() == null ? null : from.getVolume().toString()); dto.setVolumeUnits(from.getVolumeUnits()); dto.setNgUsed(from.getNgUsed() == null ? null : from.getNgUsed().toString()); dto.setVolumeUsed(from.getVolumeUsed() == null ? null : from.getVolumeUsed().toString()); if (from.getCreationDate() != null) { dto.setCreationDate(formatDate(from.getCreationDate())); } dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setLocationLabel(BoxUtils.makeLocationLabel(from)); if (from.getTargetedSequencing() != null) { dto.setTargetedSequencingId(from.getTargetedSequencing().getId()); } dto.setLibrary(libraryDto); if (from.getBox() != null) { dto.setBox(asDto(from.getBox(), includeBoxPositions)); dto.setBoxPosition(from.getBoxPosition()); } dto.setDiscarded(from.isDiscarded()); return dto; }
public static PoolableElementView fromDilution(LibraryDilution dilution) { PoolableElementView v = new PoolableElementView(); v.setDilutionBarcode(dilution.getIdentificationBarcode()); v.setDilutionConcentration(dilution.getConcentration()); v.setDilutionConcentrationUnits(dilution.getConcentrationUnits()); v.setDilutionNgUsed(dilution.getNgUsed()); v.setDilutionId(dilution.getId()); v.setDilutionName(dilution.getName()); v.setDilutionVolume(dilution.getVolume()); v.setDilutionVolumeUsed(dilution.getVolumeUsed()); v.setLastModified(dilution.getLastModified()); v.setPreMigrationId(dilution.getPreMigrationId()); if (dilution.getBox() != null) { v.setBoxName(dilution.getBox().getName()); v.setBoxAlias(dilution.getBox().getAlias()); v.setBoxIdentificationBarcode(dilution.getBox().getIdentificationBarcode()); v.setBoxLocationBarcode(dilution.getBox().getLocationBarcode()); Library lib = dilution.getLibrary(); if (lib != null) { v.setIndices(lib.getIndices());
public static LibraryDilution to(@Nonnull DilutionDto from) { LibraryDilution to = new LibraryDilution(); if (from.getId() != null) to.setId(from.getId()); if (!isStringEmptyOrNull(from.getName())) { to.setName(from.getName()); } to.setIdentificationBarcode(from.getIdentificationBarcode()); to.setConcentration(from.getConcentration() == null ? null : Double.valueOf(from.getConcentration())); to.setConcentrationUnits(from.getConcentrationUnits()); to.setNgUsed(from.getNgUsed() == null ? null : Double.valueOf(from.getNgUsed())); to.setVolume(from.getVolume() == null ? null : Double.valueOf(from.getVolume())); to.setVolumeUnits(from.getVolumeUnits()); to.setVolumeUsed(from.getVolumeUsed() == null ? null : Double.valueOf(from.getVolumeUsed())); to.setLibrary(to(from.getLibrary())); to.setCreationDate(parseDate(from.getCreationDate())); if (from.getTargetedSequencingId() != null) { to.setTargetedSequencing(new TargetedSequencing()); to.getTargetedSequencing().setId(from.getTargetedSequencingId()); } to.setBoxPosition((DilutionBoxPosition) makeBoxablePosition(from, to)); to.setDiscarded(from.isDiscarded()); return to; }
@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; }
/** * 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())); } }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getId()); sb.append(" : "); sb.append(getName()); sb.append(" : "); sb.append(getCreationDate()); sb.append(" : "); sb.append(getConcentration()); return sb.toString(); }
@Override public void update(LibraryDilution dilution) throws IOException { LibraryDilution managed = get(dilution.getId()); authorizationManager.throwIfNotWritable(managed); boxService.throwIfBoxPositionIsFilled(dilution); Library library = dilution.getLibrary(); if (library.getVolume() != null) { if (dilution.getVolumeUsed() != null && managed.getVolumeUsed() != null) { library.setVolume(library.getVolume() + managed.getVolumeUsed() - dilution.getVolumeUsed()); } else if (managed.getVolumeUsed() != null) { library.setVolume(library.getVolume() + managed.getVolumeUsed()); } else if (dilution.getVolumeUsed() != null) { library.setVolume(library.getVolume() - dilution.getVolumeUsed()); } } validateChange(dilution, managed); applyChanges(managed, dilution); managed.setChangeDetails(authorizationManager.getCurrentUser()); loadChildEntities(managed); save(managed); libraryService.update(library); boxService.updateBoxableLocation(dilution); }
@Override public String getDeleteDescription() { return getName() + (getLibrary() == null || getLibrary().getAlias() == null ? "" : " (" + getLibrary().getAlias() + ")"); }
@Override public long save(LibraryDilution dilution) throws IOException { long id; if (dilution.getId() == LibraryDilution.UNSAVED_ID) { id = (long) currentSession().save(dilution); } else { if (dilution.isDiscarded()) { boxStore.removeBoxableFromBox(dilution); } currentSession().update(dilution); id = dilution.getId(); } return id; }
private void validateTargetedSequencing(LibraryDilution dilution) { TargetedSequencing ts = dilution.getTargetedSequencing(); Library library = dilution.getLibrary(); if (ts == null) { if (isTargetedSequencingRequired(library)) { throw new IllegalArgumentException("Targeted sequencing value is required"); } } else { if (!isTargetedSequencingCompatible(ts, library)) { throwTargetedSequencingIncompatible(ts, library.getKitDescriptor()); } } }
/** * Generates a unique barcode for a Nameable entity, and sets the identificationBarcode property for Boxables and LibraryDilutions. * * @param nameable Nameable object * @throws IOException */ public static void generateAndSetIdBarcode(Nameable nameable) throws IOException { String barcode = null; if (nameable instanceof LibraryDilution && nameable.getName() != null) { barcode = nameable.getName(); if (((LibraryDilution) nameable).getLibrary() != null && ((LibraryDilution) nameable).getLibrary().getAlias() != null) { barcode += "::" + ((LibraryDilution) nameable).getLibrary().getAlias(); } ((LibraryDilution) nameable).setIdentificationBarcode(barcode); } else if (nameable instanceof Boxable && nameable.getName() != null) { barcode = nameable.getName(); if (((Boxable) nameable).getAlias() != null) { barcode += "::" + ((Boxable) nameable).getAlias(); } ((Boxable) nameable).setIdentificationBarcode(barcode); } else { throw new IOException("Error generating barcode"); } }
private LibraryDilution save(LibraryDilution dilution) throws IOException { validateTargetedSequencing(dilution); dilution.setLastModifier(authorizationManager.getCurrentUser()); try { Long newId = dilutionDao.save(dilution); LibraryDilution managed = dilutionDao.get(newId); // post-save field generation boolean needsUpdate = false; if (hasTemporaryName(dilution)) { managed.setName(namingScheme.generateNameFor(managed)); validateNameOrThrow(managed, namingScheme); needsUpdate = true; } if (autoGenerateIdBarcodes && isStringEmptyOrNull(managed.getIdentificationBarcode())) { // if !autoGenerateIdBarcodes then the identificationBarcode is set by the user generateAndSetIdBarcode(managed); needsUpdate = true; } if (needsUpdate) dilutionDao.save(managed); return managed; } catch (MisoNamingException e) { throw new IllegalArgumentException("Name generator failed to generate valid name for library"); } catch (ConstraintViolationException e) { // Send the nested root cause message to the user, since it contains the actual error. throw new ConstraintViolationException(e.getMessage() + " " + ExceptionUtils.getRootCauseMessage(e), e.getSQLException(), e.getConstraintName()); } }
private static String listIndices(LibraryDilution dilution) { return dilution.getLibrary().getIndices().stream().map(Index::getSequence).collect(Collectors.joining(", ")); }
@Override public ValidationResult validateDeletion(LibraryDilution object) { ValidationResult result = new ValidationResult(); if (object.getPools() != null && !object.getPools().isEmpty()) { result.addError(new ValidationError(object.getName() + " is included in " + object.getPools().size() + " pool" + (object.getPools().size() > 1 ? "s" : ""))); } return result; }