use of org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl in project kie-wb-common by kiegroup.
the class FormEditorPresenterFieldSynchronizationTest method serviceLoad.
@Override
public FormModelerContent serviceLoad() {
FormModelerContent content = super.serviceLoad();
if (syncMode.equals(SyncMode.NEW_FIELDS)) {
synchronizationResult.getNewProperties().addAll(modelProperties);
} else if (syncMode.equals(SyncMode.CONFLICTS)) {
modelProperties.stream().map(property -> new TypeConflictImpl(property.getName(), property.getTypeInfo(), property.getTypeInfo())).forEach(typeConflict -> {
synchronizationResult.getConflicts().put(typeConflict.getPropertyName(), typeConflict);
});
} else if (syncMode.equals(SyncMode.REMOVED_FIELDS)) {
content.getDefinition().getFields().addAll(employeeFields);
synchronizationResult.getRemovedProperties().addAll(modelProperties);
}
return content;
}
use of org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl in project kie-wb-common by kiegroup.
the class FormModelSynchronizationUtilImplTest method testTypeConflictProperties.
@Test
public void testTypeConflictProperties() {
Map<String, TypeConflictImpl> conflicts = formModelSynchronizationResult.getConflicts();
ModelProperty name = formModel.getProperty("name");
assertNotNull(name);
conflicts.put("name", new TypeConflictImpl("name", name.getTypeInfo(), new TypeInfoImpl(Boolean.class.getName())));
ModelProperty surname = formModel.getProperty("surname");
assertNotNull(surname);
conflicts.put("surname", new TypeConflictImpl("surname", name.getTypeInfo(), new TypeInfoImpl(Long.class.getName())));
ModelProperty birthday = formModel.getProperty("birthday");
assertNotNull(birthday);
conflicts.put("birthday", new TypeConflictImpl("birthday", name.getTypeInfo(), new TypeInfoImpl(String.class.getName())));
synchronizationUtil.init(form, formModelSynchronizationResult);
int originalFormFields = form.getFields().size();
synchronizationUtil.resolveConflicts();
assertEquals(originalFormFields, form.getFields().size());
checkConflictedFieldDefinition(conflicts.get("name"), CheckBoxFieldDefinition.class);
checkConflictedFieldDefinition(conflicts.get("surname"), IntegerBoxFieldDefinition.class);
checkConflictedFieldDefinition(conflicts.get("birthday"), TextBoxFieldDefinition.class);
}
use of org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl 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