Search in sources :

Example 81 with FieldDefinition

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

the class FormDefinitionGeneratorImplTest method checkGeneratedForm.

private void checkGeneratedForm(FormDefinition formDefinition, JBPMFormModel expectedFormModel, boolean readOnly) {
    Assertions.assertThat(formDefinition).isNotNull().hasFieldOrPropertyWithValue("name", expectedFormModel.getFormName() + ".frm");
    Assertions.assertThat(formDefinition.getFields()).isNotEmpty().hasSize(VARIABLES.size());
    assertEquals(expectedFormModel, formDefinition.getModel());
    VARIABLES.forEach((key, value) -> {
        FieldDefinition field = formDefinition.getFieldByBinding(key);
        switch(key) {
            case STRING_VARIABLE:
                checkStringField(field, readOnly);
                break;
            case INTEGER_VARIABLE:
                checkIntegerField(field, readOnly);
                break;
            case BOOLEAN_VARIABLE:
                checkBooleanField(field, readOnly);
                break;
            case FLOAT_VARIABLE:
                checkFloatField(field, readOnly);
                break;
            case OBJECT_VARIABLE:
                checkObjectField(field, readOnly);
                break;
        }
    });
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)

Example 82 with FieldDefinition

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

the class FormDefinitionGenerator method maybeArrangeNestedForms.

private void maybeArrangeNestedForms(FormMigrationSummary summary, List<FormMigrationSummary> modelForms) {
    final Form originalForm = summary.getOriginalForm().get();
    final FormDefinition formDefinition = summary.getNewForm().get();
    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof HasNestedForm).map(fieldDefinition -> (HasNestedForm) fieldDefinition).forEach(hasNestedForm -> {
        modelForms.stream().filter(modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(hasNestedForm.getNestedForm())).findFirst().ifPresent(modelSummary -> {
            hasNestedForm.setNestedForm(modelSummary.getNewForm().get().getId());
            updateNestedFormsModelProperties(formDefinition, (FieldDefinition) hasNestedForm, modelSummary.getOriginalForm().get());
        });
    });
    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof IsCRUDDefinition).map(fieldDefinition -> (IsCRUDDefinition) fieldDefinition).forEach(crudDefinition -> {
        // update Creation Form
        updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getCreationForm()), modelSummary -> crudDefinition.setCreationForm(modelSummary.getNewForm().get().getId()));
        // update Edition Form
        updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getEditionForm()), modelSummary -> crudDefinition.setEditionForm(modelSummary.getNewForm().get().getId()));
        // update Table Columns Form
        updateCrudDefinitionForms(modelForms, modelSummary -> {
            Field originalField = originalForm.getField(((FieldDefinition) crudDefinition).getName());
            return modelSummary.getOriginalForm().getPath().getFileName().equals(StringUtils.defaultIfBlank(originalField.getTableSubform(), originalField.getDefaultSubform()));
        }, modelSummary -> {
            FormDefinition modelFormDefinition = modelSummary.getNewForm().get();
            modelFormDefinition.getFields().forEach(fieldDefinition -> {
                if (!(fieldDefinition instanceof EmbedsForm)) {
                    crudDefinition.getColumnMetas().add(new TableColumnMeta(fieldDefinition.getLabel(), fieldDefinition.getBinding()));
                }
            });
            updateNestedFormsModelProperties(formDefinition, (FieldDefinition) crudDefinition, modelSummary.getOriginalForm().get());
        });
    });
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) Predicate(java.util.function.Predicate) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) BPMNFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.BPMNFormAdapter) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) Consumer(java.util.function.Consumer) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) AbstractMigrationStep(org.kie.workbench.common.forms.migration.tool.pipelines.AbstractMigrationStep) DataObjectFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.DataObjectFormAdapter) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm)

Example 83 with FieldDefinition

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

the class AbstractFieldAdapter method parseField.

@Override
public void parseField(Field originalField, FormMigrationSummary formSummary, FormDefinition newFormDefinition, Consumer<LayoutComponent> layoutElementConsumer) {
    FieldDefinition fieldDefinition = getFieldDefinition(originalField);
    fieldDefinition.setId(String.valueOf(originalField.getId()));
    fieldDefinition.setName(originalField.getFieldName());
    fieldDefinition.setLabel(lookupI18nValue(originalField.getLabel()));
    fieldDefinition.setHelpMessage(lookupI18nValue(originalField.getTitle()));
    fieldDefinition.setStandaloneClassName(StringUtils.defaultIfBlank(originalField.getBag(), originalField.getFieldType().getFieldClass()));
    fieldDefinition.setReadOnly(originalField.getReadonly());
    fieldDefinition.setRequired(originalField.getFieldRequired());
    String binding = StringUtils.defaultString(StringUtils.defaultIfBlank(originalField.getInputBinding(), originalField.getOutputBinding()));
    if (!StringUtils.isEmpty(binding)) {
        if (binding.contains("/")) {
            binding = binding.substring(binding.indexOf("/") + 1);
        }
        ModelPropertyImpl property = new ModelPropertyImpl(binding, fieldDefinition.getFieldTypeInfo());
        newFormDefinition.getModel().getProperties().add(property);
    }
    fieldDefinition.setBinding(binding);
    newFormDefinition.getFields().add(fieldDefinition);
    LayoutComponent component = new LayoutComponent(DRAGGABLE_TYPE);
    component.addProperty(FormLayoutComponent.FORM_ID, newFormDefinition.getId());
    component.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
    layoutElementConsumer.accept(component);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Example 84 with FieldDefinition

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

the class AbstractFormDefinitionGeneratorTest method verifyLineForm.

protected void verifyLineForm(FormMigrationSummary summary) {
    Form originalForm = summary.getOriginalForm().get();
    Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(4);
    FormDefinition newForm = summary.getNewForm().get();
    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(4);
    Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", LINE_MODEL).isInstanceOf(DataObjectFormModel.class);
    IntStream indexStream = IntStream.range(0, newForm.getFields().size());
    LayoutTemplate formLayout = newForm.getLayoutTemplate();
    assertNotNull(formLayout);
    Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(1);
    LayoutRow fieldRow = formLayout.getRows().get(0);
    indexStream.forEach(index -> {
        FieldDefinition fieldDefinition = newForm.getFields().get(index);
        switch(index) {
            case 0:
                checkFieldDefinition(fieldDefinition, LINE_PRODUCT, "product", "product", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 1:
                checkFieldDefinition(fieldDefinition, LINE_PRICE, "price", "price", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 2:
                checkFieldDefinition(fieldDefinition, LINE_QUANTITY, "quantity", "quantity", IntegerBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 3:
                checkFieldDefinition(fieldDefinition, LINE_TOTAL, "total", "total", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
        }
        assertNotNull(fieldRow);
        Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(4);
        LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(index);
        assertNotNull(fieldColumn);
        assertEquals("3", fieldColumn.getSpan());
        Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
        checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntStream(java.util.stream.IntStream)

Example 85 with FieldDefinition

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

the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method checkInvoiceFormDefinition.

protected void checkInvoiceFormDefinition(FormDefinition invoiceForm, Form originalForm) {
    assertNotNull(invoiceForm);
    Assertions.assertThat(invoiceForm.getModel()).isNotNull().isInstanceOf(DataObjectFormModel.class).hasFieldOrPropertyWithValue("className", INVOICE_MODEL);
    Assertions.assertThat(invoiceForm.getFields()).isNotEmpty().hasSize(3);
    IntStream indexStream = IntStream.range(0, invoiceForm.getFields().size());
    LayoutTemplate formLayout = invoiceForm.getLayoutTemplate();
    assertNotNull(formLayout);
    Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(3);
    indexStream.forEach(index -> {
        FieldDefinition fieldDefinition = invoiceForm.getFields().get(index);
        switch(index) {
            case 0:
                checkFieldDefinition(fieldDefinition, "invoice_user", "User Data:", "user", SubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 1:
                checkFieldDefinition(fieldDefinition, "lines", "Invoice Lines", "lines", MultipleSubFormFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 2:
                checkFieldDefinition(fieldDefinition, "invoice_total", "Invoice Total:", "total", DecimalBoxFieldDefinition.class, invoiceForm, originalForm.getField(fieldDefinition.getName()));
                break;
        }
        LayoutRow fieldRow = formLayout.getRows().get(index);
        assertNotNull(fieldRow);
        Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
        LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
        assertNotNull(fieldColumn);
        assertEquals("12", fieldColumn.getSpan());
        Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
        checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, invoiceForm);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) IntStream(java.util.stream.IntStream) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)

Aggregations

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7