use of org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl in project kie-wb-common by kiegroup.
the class AbstractFormModelHandler method synchronizeFormModelProperties.
@Override
public FormModelSynchronizationResult synchronizeFormModelProperties(final F formModel, final List<ModelProperty> currentProperties) {
final FormModelSynchronizationResultImpl result = new FormModelSynchronizationResultImpl();
List<ModelProperty> modelProperties = Optional.ofNullable(formModel.getProperties()).orElse(new ArrayList<>());
result.setPreviousProperties(modelProperties);
currentProperties.forEach((currentProperty) -> {
Optional<ModelProperty> optional = result.getPreviousProperties().stream().filter(oldProperty -> oldProperty.getName().equals(currentProperty.getName())).findFirst();
if (optional.isPresent()) {
ModelProperty oldProperty = optional.get();
if (!oldProperty.equals(currentProperty)) {
// currentProperty exists on the Model oldProperties but type doesn't match -> adding it to conlfict
result.getConflicts().put(oldProperty.getName(), new TypeConflictImpl(oldProperty.getName(), oldProperty.getTypeInfo(), currentProperty.getTypeInfo()));
}
} else {
// currentPproperty doesn't exist on the previous properties -> adding to new properties
result.getNewProperties().add(currentProperty);
}
});
modelProperties.forEach(oldProperty -> {
Optional<ModelProperty> optional = currentProperties.stream().filter(currentProperty -> currentProperty.getName().equals(oldProperty.getName())).findFirst();
if (!optional.isPresent()) {
result.getRemovedProperties().add(oldProperty);
}
});
formModel.getProperties().clear();
formModel.getProperties().addAll(currentProperties);
return result;
}
Aggregations