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;
}
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;
}
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;
}
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());
}
}
}
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;
}
Aggregations