Search in sources :

Example 1 with ModelProperty

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());
}
Also used : ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Example 2 with ModelProperty

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());
    });
}
Also used : ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Example 3 with ModelProperty

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);
}
Also used : JsonObject(com.google.gson.JsonObject) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) GsonBuilder(com.google.gson.GsonBuilder) MetaDataEntryManager(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryManager) Inject(javax.inject.Inject) JsonElement(com.google.gson.JsonElement) FormModel(org.kie.workbench.common.forms.model.FormModel) Dependent(javax.enterprise.context.Dependent) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Gson(com.google.gson.Gson) JsonDeserializer(com.google.gson.JsonDeserializer) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry) ModelMetaDataImpl(org.kie.workbench.common.forms.model.impl.meta.ModelMetaDataImpl) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 4 with ModelProperty

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);
}
Also used : TypeConflictImpl(org.kie.workbench.common.forms.editor.model.impl.TypeConflictImpl) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Test(org.junit.Test)

Example 5 with ModelProperty

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;
}
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

ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)24 ArrayList (java.util.ArrayList)11 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)11 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)11 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)8 Test (org.junit.Test)7 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)7 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)5 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)4 HashMap (java.util.HashMap)3 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)3 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)3 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)3 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)3 FormModel (org.kie.workbench.common.forms.model.FormModel)3 FieldReadOnlyEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry)3 List (java.util.List)2 Optional (java.util.Optional)2 Dependent (javax.enterprise.context.Dependent)2 Inject (javax.inject.Inject)2