Search in sources :

Example 1 with FormModelSynchronizationResultImpl

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;
}
Also used : TypeConflictImpl(org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl) ModuleClassLoaderHelper(org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormModelSynchronizationResultImpl(org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl) ArrayList(java.util.ArrayList) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) ModelPropertiesGenerator(org.kie.workbench.common.forms.service.backend.util.ModelPropertiesGenerator) Optional(java.util.Optional) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) Path(org.uberfire.backend.vfs.Path) TypeConflictImpl(org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl) FormModelSynchronizationResultImpl(org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)1 FormModelSynchronizationResultImpl (org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl)1 TypeConflictImpl (org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl)1 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)1 FormModel (org.kie.workbench.common.forms.model.FormModel)1 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)1 ModelPropertiesGenerator (org.kie.workbench.common.forms.service.backend.util.ModelPropertiesGenerator)1 ModuleClassLoaderHelper (org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper)1 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)1 Path (org.uberfire.backend.vfs.Path)1