@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); }
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 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; }
/** * 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()); }
v.setDilutionName(dilution.getName()); v.setDilutionVolume(dilution.getVolume()); v.setDilutionVolumeUsed(dilution.getVolumeUsed()); v.setLastModified(dilution.getLastModified()); v.setPreMigrationId(dilution.getPreMigrationId());