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; }
@Override public boolean isSaved() { return getId() != UNSAVED_ID; }
v.setDilutionConcentrationUnits(dilution.getConcentrationUnits()); v.setDilutionNgUsed(dilution.getNgUsed()); v.setDilutionId(dilution.getId()); v.setDilutionName(dilution.getName()); v.setDilutionVolume(dilution.getVolume());
@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 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); } }
@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; }
@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; } }
@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 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; }