Search in sources :

Example 1 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class AllFieldTypesFormGenerationTest method testMigration.

@Test
public void testMigration() {
    generator.execute(context);
    Assertions.assertThat(context.getSummaries()).isNotEmpty().hasSize(1);
    Assertions.assertThat(context.getExtraSummaries()).isEmpty();
    // 1 legacyforms + 1 migrated forms
    verify(migrationServicesCDIWrapper, times(2)).write(any(Path.class), anyString(), anyString());
    FormMigrationSummary summary = context.getSummaries().iterator().next();
    Form originalForm = summary.getOriginalForm().get();
    FormDefinition newForm = summary.getNewForm().get();
    assertNotNull(newForm);
    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(fieldMappings.size());
    LayoutTemplate newLayout = newForm.getLayoutTemplate();
    assertNotNull(newLayout);
    Assertions.assertThat(newLayout.getRows()).isNotEmpty().hasSize(// fields + 2 decorators in original form
    fieldMappings.size() + 2);
    List<LayoutRow> rows = newLayout.getRows();
    checkDecoratorRow(rows.get(0));
    checkDecoratorRow(rows.get(1));
    IntStream indexStream = IntStream.range(0, fieldMappings.size());
    indexStream.forEach(index -> {
        FieldDefinition newField = newForm.getFields().get(index);
        assertNotNull(newField);
        Field originalField = originalForm.getField(newField.getName());
        assertNotNull(originalField);
        checkFieldDefinition(newField, newField.getName(), newField.getLabel(), newField.getBinding(), fieldMappings.get(newField.getName()), newForm, originalField);
        LayoutRow row = rows.get(index + 2);
        LayoutComponent component = checkRow(row);
        checkLayoutFormField(component, newField, newForm);
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) 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) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) 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) StringListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.StringListBoxFieldDefinition) StringRadioGroupFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.radioGroup.definition.StringRadioGroupFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) DocumentFieldDefinition(org.kie.workbench.common.forms.jbpm.model.authoring.document.definition.DocumentFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) IntStream(java.util.stream.IntStream) Test(org.junit.Test)

Example 2 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorWithUnsupportedFieldsTest method testMigration.

@Test
public void testMigration() {
    generator.execute(context);
    Assertions.assertThat(context.getSummaries()).isNotEmpty().hasSize(1);
    Assertions.assertThat(context.getExtraSummaries()).isEmpty();
    // 1 legacyforms + 1 migrated forms
    verify(migrationServicesCDIWrapper, times(2)).write(any(Path.class), anyString(), anyString());
    FormMigrationSummary summary = context.getSummaries().iterator().next();
    Form originalForm = summary.getOriginalForm().get();
    FormDefinition newForm = summary.getNewForm().get();
    assertNotNull(newForm);
    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(1);
    LayoutTemplate newLayout = newForm.getLayoutTemplate();
    assertNotNull(newLayout);
    Assertions.assertThat(newLayout.getRows()).isNotEmpty().hasSize(2);
    // Checking first field (login), althought the original field type isn't supported it can be migrated to a textbox
    Field originalLogin = originalForm.getField(USER_LOGIN);
    FieldDefinition newLogin = newForm.getFieldByName(USER_LOGIN);
    assertNotNull(newLogin);
    checkFieldDefinition(newLogin, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalLogin);
    LayoutRow loginRow = newLayout.getRows().get(0);
    assertNotNull(loginRow);
    Assertions.assertThat(loginRow.getLayoutColumns()).isNotEmpty().hasSize(1);
    LayoutColumn loginColumn = loginRow.getLayoutColumns().get(0);
    assertNotNull(loginColumn);
    assertEquals("12", loginColumn.getSpan());
    Assertions.assertThat(loginColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
    checkLayoutFormField(loginColumn.getLayoutComponents().get(0), newLogin, newForm);
    // Checking second field (password), the original field type isn't supported and it cannot be migrated to any
    // other form control. There shouldn't be any FieldDefinition for it but it should be an HTML component on
    // the layout warning about the error
    assertNull(newForm.getFieldByName(USER_PASSWORD));
    LayoutRow passwordRow = newLayout.getRows().get(1);
    assertNotNull(passwordRow);
    Assertions.assertThat(passwordRow.getLayoutColumns()).isNotEmpty().hasSize(1);
    LayoutColumn passwordColumn = passwordRow.getLayoutColumns().get(0);
    assertNotNull(passwordColumn);
    assertEquals("12", passwordColumn.getSpan());
    Assertions.assertThat(passwordColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
    LayoutComponent passwordComponent = passwordColumn.getLayoutComponents().get(0);
    Assertions.assertThat(passwordComponent).isNotNull().hasFieldOrPropertyWithValue("dragTypeName", FormsMigrationConstants.HTML_COMPONENT);
    Field originalPassword = originalForm.getField(USER_PASSWORD);
    Formatter formatter = new Formatter();
    formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalPassword.getFieldName(), originalPassword.getFieldType().getCode());
    final String expectedHtmlMessage = formatter.toString();
    Assertions.assertThat(passwordComponent.getProperties()).hasEntrySatisfying(FormsMigrationConstants.HTML_CODE_PARAMETER, new Condition<>(htmlMessage -> htmlMessage.equals(expectedHtmlMessage), "Invalid error HTML message"));
    formatter.close();
}
Also used : Path(org.uberfire.backend.vfs.Path) Resource(org.kie.workbench.common.forms.migration.tool.Resource) MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) FormsMigrationConstants(org.kie.workbench.common.forms.migration.tool.util.FormsMigrationConstants) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) Assertions(org.assertj.core.api.Assertions) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Path(org.uberfire.backend.vfs.Path) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert.assertNull(org.junit.Assert.assertNull) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Condition(org.assertj.core.api.Condition) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) Assert.assertEquals(org.junit.Assert.assertEquals) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) Formatter(java.util.Formatter) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) Matchers.anyString(org.mockito.Matchers.anyString) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Test(org.junit.Test)

Example 3 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class AbstractFormAdapter method migrateFields.

protected void migrateFields(final Set<Field> fields, final FormDefinition newForm, final FormMigrationSummary formSummary) {
    LayoutHelper helper = new LayoutHelper();
    fields.forEach(originalField -> {
        if (!StringUtils.isEmpty(originalField.getMovedToForm())) {
            return;
        }
        if (!Boolean.TRUE.equals(originalField.getGroupWithPrevious())) {
            helper.newRow();
        }
        String originalTypeCode = originalField.getFieldType().getCode();
        FieldAdapter adapter = adaptersRegistry.get(originalTypeCode);
        if (adapter == null) {
            // trying a backup adapter
            UnSupportedFieldAdapter unSupportedFieldAdapter = unSupportedAdapters.get(originalTypeCode);
            if (unSupportedFieldAdapter != null) {
                warn("Problems migrating field '" + originalField.getFieldName() + "': the original field has an unsupported field type '" + originalTypeCode + "'. It will be added on the new Form as a '" + unSupportedFieldAdapter.getNewFieldType() + "'");
                unSupportedFieldAdapter.parseField(originalField, formSummary, newForm, helper::add);
            } else {
                warn("Cannot migrate field '" + originalField.getFieldName() + "': Unsupported field type '" + originalTypeCode + "'");
                Formatter formatter = new Formatter();
                formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalField.getFieldName(), originalTypeCode);
                LayoutComponent component = new LayoutComponent(FormsMigrationConstants.HTML_COMPONENT);
                component.addProperty(FormsMigrationConstants.HTML_CODE_PARAMETER, formatter.toString());
                formatter.close();
                helper.add(component);
            }
        } else {
            try {
                adapter.parseField(originalField, formSummary, newForm, helper::add);
            } catch (Exception ex) {
                warn("Cannot migrate field '" + originalField.getFieldName() + "': Unexpected error, see message for details");
                ex.printStackTrace(migrationContext.getSystem().err());
            }
        }
    });
    newForm.setLayoutTemplate(helper.build());
}
Also used : CharacterFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CharacterFieldAdapter) IntegerTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.IntegerTextFieldAdapter) DecimalTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DecimalTextFieldAdapter) SelectBoxFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SelectBoxFieldAdapter) InputTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.InputTextFieldAdapter) MultipleSubformFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.MultipleSubformFieldAdapter) SubformFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SubformFieldAdapter) TextAreaFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.TextAreaFieldAdapter) UnSupportedFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter) CheckBoxFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CheckBoxFieldAdapter) RadioGroupFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.RadioGroupFieldAdapter) DecoratorFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.decorators.DecoratorFieldAdapter) DocumentFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DocumentFieldAdapter) DatesFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DatesFieldAdapter) FieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.FieldAdapter) Formatter(java.util.Formatter) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) UnSupportedFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter)

Example 4 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorPresenterTest method createLayoutComponent.

protected LayoutComponent createLayoutComponent(FormDefinition form, FieldDefinition field) {
    LayoutComponent component = new LayoutComponent("");
    component.addProperty(FieldLayoutComponent.FORM_ID, form.getId());
    component.addProperty(FieldLayoutComponent.FIELD_ID, field.getId());
    return component;
}
Also used : LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) FieldLayoutComponent(org.kie.workbench.common.forms.dynamic.client.rendering.FieldLayoutComponent)

Example 5 with LayoutComponent

use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.

the class AbstractBPMNFormGeneratorService method createFormLayout.

protected void createFormLayout(FormDefinition form) {
    LayoutGenerator layoutGenerator = new LayoutGenerator();
    layoutGenerator.init(new LayoutColumnDefinition[] { new LayoutColumnDefinition(ColSpan.SPAN_12) });
    if (form.getFields().size() > 0) {
        boolean separeateInputsAndOutputs = form.getModel() instanceof TaskFormModel;
        boolean mightAddOtuputsLabel = form.getFields().get(0).getReadOnly();
        if (separeateInputsAndOutputs) {
            if (mightAddOtuputsLabel) {
                layoutGenerator.addComponent(generateHTMLElement(INPUTS), new LayoutSettings());
            } else {
                layoutGenerator.addComponent(generateHTMLElement(OUTPUTS), new LayoutSettings());
            }
        }
        for (FieldDefinition fieldDefinition : form.getFields()) {
            if (separeateInputsAndOutputs && mightAddOtuputsLabel && !fieldDefinition.getReadOnly()) {
                mightAddOtuputsLabel = false;
                layoutGenerator.addComponent(generateHTMLElement(OUTPUTS), new LayoutSettings());
            }
            LayoutComponent fieldComponent = new LayoutComponent(StaticFormLayoutTemplateGenerator.DRAGGABLE_TYPE);
            fieldComponent.addProperty(FormLayoutComponent.FORM_ID, form.getId());
            fieldComponent.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
            layoutGenerator.addComponent(fieldComponent, new LayoutSettings());
        }
    }
    form.setLayoutTemplate(layoutGenerator.build());
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutGenerator(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Aggregations

LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)15 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)7 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)6 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 Test (org.junit.Test)4 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)4 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)4 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)3 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)3 Formatter (java.util.Formatter)2 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)2 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)2 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)2 FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 Path (org.uberfire.backend.vfs.Path)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IntStream (java.util.stream.IntStream)1 Assertions (org.assertj.core.api.Assertions)1