use of org.kie.workbench.common.forms.model.ModelProperty in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method checkFieldDefinition.
protected void checkFieldDefinition(FieldDefinition fieldDefinition, String name, String label, String binding, Class<? extends FieldDefinition> expectedClass, FormDefinition formDefinition, Field field) {
Assertions.assertThat(fieldDefinition).isNotNull().hasFieldOrPropertyWithValue("name", name).hasFieldOrPropertyWithValue("label", label).hasFieldOrPropertyWithValue("binding", binding).hasFieldOrPropertyWithValue("id", String.valueOf(field.getId())).hasFieldOrPropertyWithValue("required", field.getFieldRequired()).hasFieldOrPropertyWithValue("readOnly", field.getReadonly()).isInstanceOf(expectedClass);
ModelProperty property = formDefinition.getModel().getProperty(fieldDefinition.getBinding());
Assertions.assertThat(property).isNotNull().hasFieldOrPropertyWithValue("typeInfo", fieldDefinition.getFieldTypeInfo());
}
use of org.kie.workbench.common.forms.model.ModelProperty in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImplTest method checkProcessFormModel.
private void checkProcessFormModel(BusinessProcessFormModel formModel) {
Assertions.assertThat(formModel).hasFieldOrPropertyWithValue("processId", PROCESS_ID).hasFieldOrPropertyWithValue("processName", PROCESS_NAME);
Assertions.assertThat(formModel.getProperties()).isNotEmpty().hasSize(VARIABLES.size());
VARIABLES.forEach((key, value) -> {
ModelProperty property = formModel.getProperty(key);
assertNotNull(property);
assertEquals(value, property.getTypeInfo().getClassName());
});
}
use of org.kie.workbench.common.forms.model.ModelProperty in project kie-wb-common by kiegroup.
the class FormDefinitionSerializerImpl method deserialize.
@Override
public FormDefinition deserialize(String serializedForm) {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(FormModel.class, formModelSerializer);
builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer);
builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class));
builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class));
builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class));
builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> {
JsonObject jsonField = json.getAsJsonObject();
JsonElement jsonName = jsonField.get("name");
return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString()));
});
Gson gson = builder.create();
return gson.fromJson(serializedForm, FormDefinition.class);
}
use of org.kie.workbench.common.forms.model.ModelProperty 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.model.ModelProperty 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