Search in sources :

Example 1 with FormModelSynchronizationResult

use of org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult in project kie-wb-common by kiegroup.

the class BPMNVFSFormDefinitionGeneratorService method createRootFormDefinition.

public FormDefinition createRootFormDefinition(GenerationContext<Path> context) {
    FormModelHandler modelHandler = formModelHandlerManager.getFormModelHandler(context.getFormModel().getClass());
    modelHandler.init(context.getFormModel(), context.getSource());
    final FormDefinition form;
    org.uberfire.java.nio.file.Path kiePath = Paths.convert(context.getSource());
    logger.info("Started form generation for '{}'", kiePath);
    if (ioService.exists(kiePath)) {
        form = formSerializer.deserialize(ioService.readAllString(kiePath));
        logger.warn("Already exists form '{}'. Synchronizing form fields:", kiePath);
        // If the form exists on the VFS let's synchronize form fields
        FormModelSynchronizationResult synchronizationResult = modelHandler.synchronizeFormModelProperties(form.getModel(), context.getFormModel().getProperties());
        formModelSynchronizationUtil.init(form, synchronizationResult);
        if (synchronizationResult.hasRemovedProperties()) {
            logger.warn("Process/Task has removed variables, checking fields:");
            formModelSynchronizationUtil.fixRemovedFields();
        }
        if (synchronizationResult.hasConflicts()) {
            logger.warn("Process/Task has some variables which type has changed. Checking fields:");
            formModelSynchronizationUtil.resolveConflicts();
        }
        if (synchronizationResult.hasNewProperties()) {
            logger.warn("Process/Task has new variables. Adding them to form:");
            formModelSynchronizationUtil.addNewFields(fieldManager::getDefinitionByModelProperty);
        }
        form.setModel(context.getFormModel());
    } else {
        form = new FormDefinition(context.getFormModel());
        form.setId(UIDGenerator.generateUID());
        form.setName(context.getSource().getFileName());
        form.getFields().addAll(context.getFormModel().getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList()));
    }
    form.setModel(context.getFormModel());
    return form;
}
Also used : FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with FormModelSynchronizationResult

use of org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult 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)

Example 3 with FormModelSynchronizationResult

use of org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult in project kie-wb-common by kiegroup.

the class FormEditorServiceImpl method constructContent.

@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
    try {
        org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
        FormDefinition form = findForm(kiePath);
        FormModelerContent formModelConent = new FormModelerContent();
        formModelConent.setDefinition(form);
        formModelConent.setPath(path);
        formModelConent.setOverview(overview);
        FormEditorRenderingContext context = createRenderingContext(form, path);
        formModelConent.setRenderingContext(context);
        if (Optional.ofNullable(form.getModel()).isPresent()) {
            FormModel formModel = form.getModel();
            Optional<FormModelHandler> modelHandlerOptional = getHandlerForForm(form, path);
            if (modelHandlerOptional.isPresent()) {
                FormModelHandler formModelHandler = modelHandlerOptional.get();
                FormModelSynchronizationResult synchronizationResult = formModelHandler.synchronizeFormModel();
                formModel.getProperties().forEach(property -> {
                    Optional<FieldDefinition> fieldOptional = Optional.ofNullable(form.getFieldByBinding(property.getName()));
                    if (!fieldOptional.isPresent()) {
                        synchronizationResult.resolveConflict(property.getName());
                    }
                });
                formModelConent.setSynchronizationResult(synchronizationResult);
            }
        }
        resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
        return formModelConent;
    } catch (Exception e) {
        log.warn("Error loading form " + path.toURI(), e);
    }
    return null;
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FormModel(org.kie.workbench.common.forms.model.FormModel) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 4 with FormModelSynchronizationResult

use of org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult in project kie-wb-common by kiegroup.

the class ChangesNotificationDisplayer method checkNewModelFields.

protected void checkNewModelFields() {
    FormModelSynchronizationResult synchronizationResult = content.getSynchronizationResult();
    if (synchronizationResult != null && synchronizationResult.hasNewProperties()) {
        Set<FieldDefinition> modelFields = synchronizationResult.getNewProperties().stream().filter(modelProperty -> content.getDefinition().getFieldByBinding(modelProperty.getName()) == null).map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toSet());
        if (!modelFields.isEmpty()) {
            this.canDisplay = true;
            newPropertiesDisplayer.showAvailableFields(modelFields);
            view.getElement().appendChild(newPropertiesDisplayer.getElement());
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)

Example 5 with FormModelSynchronizationResult

use of org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult in project kie-wb-common by kiegroup.

the class FormModelConflictHandler method checkConflicts.

@Override
public boolean checkConflicts(FormModelerContent content, Consumer<ConflictElement> conflictElementConsumer) {
    init(content, conflictElementConsumer);
    this.removed = false;
    this.conflicts = false;
    FormDefinition formDefinition = content.getDefinition();
    FormModelSynchronizationResult synchronizationResult = content.getSynchronizationResult();
    if (synchronizationResult == null) {
        return false;
    }
    checkRemovedProperties(formDefinition, synchronizationResult);
    checkConflictProperties(formDefinition, synchronizationResult);
    return removed || conflicts;
}
Also used : FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Aggregations

FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)5 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)3 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)3 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 FormModel (org.kie.workbench.common.forms.model.FormModel)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)1 FormModelSynchronizationResultImpl (org.kie.workbench.common.forms.editor.model.impl.FormModelSynchronizationResultImpl)1 TypeConflictImpl (org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl)1 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)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 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)1