private void loadPoolDilutions(Collection<PoolDilution> source, Pool target) throws IOException { Set<PoolDilution> targetDilutions = target.getPoolDilutions(); targetDilutions.removeIf(notInOther(source)); Set<PoolDilution> additions = source.stream() .filter(notInOther(targetDilutions)) .collect(Collectors.toSet()); for (PoolDilution sourcePd : additions) { PoolableElementView v = poolableElementViewService.get(sourcePd.getPoolableElementView().getDilutionId()); if (v == null) { throw new IllegalStateException("Pool contains an unsaved dilution"); } targetDilutions.add(new PoolDilution(target, v, sourcePd.getProportion())); } for (PoolDilution targetPd : targetDilutions) { PoolDilution sourcePd = source.stream() .filter(spd -> spd.getPoolableElementView().getDilutionId() == targetPd.getPoolableElementView().getDilutionId()) .findFirst().orElse(null); if (sourcePd != null) { targetPd.setProportion(sourcePd.getProportion()); } } }
public static Pool to(@Nonnull PoolDto dto) { PoolImpl to = new PoolImpl(); to.setId(dto.getId() == null ? PoolImpl.UNSAVED_ID : dto.getId()); to.setAlias(dto.getAlias()); to.setConcentration(dto.getConcentration() == null ? null : Double.valueOf(dto.getConcentration())); to.setConcentrationUnits(dto.getConcentrationUnits()); to.setCreationDate(parseDate(dto.getCreationDate())); to.setDescription(dto.getDescription()); to.setIdentificationBarcode(dto.getIdentificationBarcode()); to.setDiscarded(dto.isDiscarded()); if (dto.getVolume() != null) { to.setVolume(Double.valueOf(dto.getVolume())); } to.setVolumeUnits(dto.getVolumeUnits()); to.setPlatformType(PlatformType.valueOf(dto.getPlatformType())); to.setPoolDilutions(dto.getPooledElements().stream().map(dilution -> { PoolableElementView view = new PoolableElementView(); view.setDilutionId(dilution.getId()); view.setDilutionName(dilution.getName()); view.setDilutionVolumeUsed(dilution.getVolumeUsed() == null ? null : Double.valueOf(dilution.getVolumeUsed())); PoolDilution link = new PoolDilution(to, view); if (dilution.getProportion() != null) { link.setProportion(dilution.getProportion()); } return link; }).collect(Collectors.toSet())); to.setQcPassed(dto.getQcPassed()); to.setBoxPosition((PoolBoxPosition) makeBoxablePosition(dto, to)); return to; }