private void applyChanges(Array from, Array to) { to.setAlias(from.getAlias()); to.setSerialNumber(from.getSerialNumber()); to.setDescription(from.getDescription()); // have to add/remove samples individually to avoid unneccessary "sample removed; sample added" changelogs for non-changes Map<String, Sample> toSamples = to.getSamples(); toSamples.entrySet().removeIf(entry -> !from.getSamples().containsKey(entry.getKey())); from.getSamples().forEach((key, val) -> { Sample current = toSamples.get(key); if (toSamples.get(key) == null || current.getId() != val.getId()) { toSamples.put(key, val); } }); }
private void loadChildEntities(ArrayRun arrayRun) throws IOException { if (arrayRun.getInstrument() != null) { arrayRun.setInstrument(instrumentService.get(arrayRun.getInstrument().getId())); } if (arrayRun.getArray() != null) { Array array = arrayService.get(arrayRun.getArray().getId()); if (array == null) { // providing a way to detect "array not found" in validation arrayRun.getArray().setAlias(null); } else { arrayRun.setArray(array); } } }
public static Array to(@Nonnull ArrayDto from) { Array array = new Array(); if (from.getId() != null) { array.setId(from.getId()); } array.setAlias(from.getAlias()); array.setArrayModel(new ArrayModel()); if (from.getArrayModelId() != null) { array.getArrayModel().setId(from.getArrayModelId()); } if (from.getArrayModelAlias() != null) { array.getArrayModel().setAlias(from.getArrayModelAlias()); } array.setSerialNumber(from.getSerialNumber()); array.setDescription(nullifyStringIfBlank(from.getDescription())); array.setSamples(toArraySamples(from.getSamples())); return array; }