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 validateSamples(Array array, List<ValidationError> errors) { array.getSamples().forEach((pos, sam) -> { if (sam == null) { // wasn't found during #loadChildEntities errors.add(new ValidationError("Invalid Sample in position " + pos)); } else if (isDetailedSample(sam) && !isAliquotSample(sam)) { errors.add(new ValidationError("Sample in position " + pos + " must be an aliquot")); } }); }
private void loadChildEntities(Array array) throws IOException { if (array.getArrayModel() != null) { array.setArrayModel(getArrayModel(array.getArrayModel().getId())); } Map<String, Sample> samples = new HashMap<>(); for (Entry<String, Sample> entry : array.getSamples().entrySet()) { // samples not found will end up as null mapped to a position, which will cause validation error samples.put(entry.getKey(), sampleService.get(entry.getValue().getId())); } array.setSamples(samples); }
public static ArrayDto asDto(@Nonnull Array from) { ArrayDto dto = new ArrayDto(); dto.setId(from.getId()); dto.setAlias(from.getAlias()); if (from.getArrayModel() != null) { dto.setArrayModelId(from.getArrayModel().getId()); dto.setArrayModelAlias(from.getArrayModel().getAlias()); dto.setRows(from.getArrayModel().getRows()); dto.setColumns(from.getArrayModel().getColumns()); } dto.setSerialNumber(from.getSerialNumber()); dto.setDescription(from.getDescription()); if (from.getSamples() != null) { dto.setSamples(asArraySampleDtos(from.getSamples())); } if (from.getLastModified() != null) { dto.setLastModified(formatDate(from.getLastModified())); } return dto; }