Search in sources :

Example 1 with LayoutColumn

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

the class LayoutGeneratorTest method checkTwoColumnsRowWraps.

protected void checkTwoColumnsRowWraps(LayoutRow row) {
    assertNotNull(row);
    assertNotNull(row.getLayoutColumns());
    assertEquals(2, row.getLayoutColumns().size());
    LayoutColumn column = row.getLayoutColumns().get(0);
    assertNotNull(column);
    assertEquals("6", column.getSpan());
    assertNotNull(column.getLayoutComponents());
    assertEquals(1, column.getLayoutComponents().size());
    assertTrue(settingsMap.containsKey(column.getLayoutComponents().get(0)));
    // the first element is wrapped so check if the next column is empty
    column = row.getLayoutColumns().get(1);
    assertNotNull(column);
    assertEquals("6", column.getSpan());
    assertNotNull(column.getLayoutComponents());
    assertNotNull(column.getLayoutComponents());
    assertEquals(0, column.getLayoutComponents().size());
}
Also used : LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn)

Example 2 with LayoutColumn

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

the class AbstractFormGenerationTest method testGeneratedForm.

protected void testGeneratedForm(FormDefinition form, String modelName) {
    assertNotNull(form);
    FormDefinitionSettings settings = resourcesProvider.getDefinitionSettings().get(modelName);
    assertEquals(settings.getModelType(), form.getId());
    assertEquals(settings.getModelType(), form.getName());
    assertEquals(settings.getFormElements().size(), form.getFields().size());
    settings.getFormElements().forEach(element -> {
        FieldElement fieldElement = (FieldElement) element;
        FieldDefinition field = form.getFieldByBinding(fieldElement.getBinding());
        assertNotNull(field);
        assertEquals(fieldElement.getName(), field.getName());
        if (!fieldElement.getPreferredType().equals(FieldType.class)) {
            assertEquals(fieldElement.getPreferredType(), field.getFieldType().getClass());
        }
        assertEquals(fieldElement.getTypeInfo().getClassName(), field.getStandaloneClassName());
        assertEquals(fieldElement.isReadOnly(), field.getReadOnly());
        assertEquals(fieldElement.isRequired(), field.getRequired());
        assertEquals(fieldElement.getBinding(), field.getBinding());
        verify(i18nHelper, atLeast(1)).getTranslation(field.getName() + ".label");
    });
    assertNotNull(form.getLayoutTemplate());
    assertEquals(settings.getFormElements().size(), form.getLayoutTemplate().getRows().size());
    form.getLayoutTemplate().getRows().forEach(row -> {
        assertNotNull(row);
        assertEquals(1, row.getLayoutColumns().size());
        LayoutColumn column = row.getLayoutColumns().get(0);
        assertNotNull(column);
        assertEquals("12", column.getSpan());
        assertEquals(1, column.getLayoutComponents().size());
        LayoutComponent layoutComponent = column.getLayoutComponents().get(0);
        String formId = layoutComponent.getProperties().get(FormLayoutComponent.FORM_ID);
        assertNotNull(formId);
        assertEquals(form.getId(), formId);
        String fieldId = layoutComponent.getProperties().get(FormLayoutComponent.FIELD_ID);
        assertNotNull(fieldId);
        FieldDefinition field = form.getFieldById(fieldId);
        assertNotNull(field);
    });
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FieldElement(org.kie.workbench.common.forms.adf.service.definitions.elements.FieldElement) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) FormDefinitionSettings(org.kie.workbench.common.forms.adf.service.definitions.FormDefinitionSettings) FieldType(org.kie.workbench.common.forms.model.FieldType)

Example 3 with LayoutColumn

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

the class AllFieldTypesFormGenerationTest method checkRow.

private LayoutComponent checkRow(LayoutRow row) {
    Assertions.assertThat(row.getLayoutColumns()).isNotEmpty().hasSize(1);
    LayoutColumn column = row.getLayoutColumns().get(0);
    assertEquals("12", column.getSpan());
    Assertions.assertThat(column.getLayoutComponents()).isNotEmpty().hasSize(1);
    return column.getLayoutComponents().get(0);
}
Also used : LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn)

Example 4 with LayoutColumn

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

the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method verifyBPMNForm.

private void verifyBPMNForm(FormMigrationSummary summary, Class<? extends JBPMFormModel> modelType) {
    Form originalForm = summary.getOriginalForm().get();
    Assertions.assertThat(originalForm.getFormFields()).hasSize(5);
    Field originalInvoiceUser = originalForm.getField(INVOICE_USER);
    Field originalLines = originalForm.getField(INVOICE_LINES);
    Field originalTotal = originalForm.getField(INVOICE_TOTAL);
    DataHolder originalDataHolder = originalForm.getHolders().iterator().next();
    String expectedExtraForm = summary.getBaseFormName() + "-" + originalDataHolder.getUniqeId();
    checkMovedField(originalInvoiceUser, expectedExtraForm);
    checkMovedField(originalLines, expectedExtraForm);
    checkMovedField(originalTotal, expectedExtraForm);
    Field invoiceField = originalForm.getField("invoice");
    Assertions.assertThat(invoiceField).isNotNull().hasFieldOrPropertyWithValue("bag", INVOICE_MODEL).hasFieldOrPropertyWithValue("sourceLink", summary.getBaseFormName() + "-" + invoiceField.getFieldName()).hasFieldOrPropertyWithValue("inputBinding", originalDataHolder.getInputId()).hasFieldOrPropertyWithValue("outputBinding", originalDataHolder.getOuputId()).extracting("defaultSubform").isNotNull();
    assertNotNull(invoiceField);
    assertEquals(FieldTypeBuilder.SUBFORM, invoiceField.getFieldType().getCode());
    FormDefinition newFormDefinition = summary.getNewForm().get();
    Assertions.assertThat(newFormDefinition.getModel()).isNotNull().isInstanceOf(modelType);
    Assertions.assertThat(newFormDefinition.getModel().getProperties()).hasSize(1).extracting("typeInfo.className").contains(INVOICE_MODEL);
    Assertions.assertThat(newFormDefinition.getFields()).isNotNull().hasSize(1);
    FieldDefinition newInvoiceField = newFormDefinition.getFieldByName("invoice");
    Assertions.assertThat(newInvoiceField).isNotNull().isInstanceOf(SubFormFieldDefinition.class).hasFieldOrPropertyWithValue("standaloneClassName", INVOICE_MODEL);
    LayoutTemplate newFormLayout = newFormDefinition.getLayoutTemplate();
    assertNotNull(newFormLayout);
    Assertions.assertThat(newFormLayout.getRows()).isNotEmpty().hasSize(1);
    LayoutRow newLayoutRow = newFormLayout.getRows().get(0);
    assertNotNull(newLayoutRow);
    Assertions.assertThat(newLayoutRow.getLayoutColumns()).isNotEmpty().hasSize(1);
    LayoutColumn newLayoutColumn = newLayoutRow.getLayoutColumns().get(0);
    assertNotNull(newLayoutColumn);
    assertEquals("12", newLayoutColumn.getSpan());
    Assertions.assertThat(newLayoutColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
    checkLayoutFormField(newLayoutColumn.getLayoutComponents().get(0), newInvoiceField, newFormDefinition);
    FormMigrationSummary extraSummary = context.getExtraSummaries().stream().filter(extra -> extra.getBaseFormName().equals(expectedExtraForm)).findAny().orElse(null);
    FormDefinition newExtraFormDefinition = extraSummary.getNewForm().get();
    checkInvoiceFormDefinition(newExtraFormDefinition, originalForm);
}
Also used : Field(org.kie.workbench.common.forms.migration.legacy.model.Field) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) 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) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerMultipleInputFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.lists.input.impl.IntegerMultipleInputFieldDefinition) 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) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 5 with LayoutColumn

use of org.uberfire.ext.layout.editor.api.editor.LayoutColumn 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) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) 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) 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) 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) List(java.util.List) 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) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.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)

Aggregations

LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)16 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)12 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)8 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)6 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)6 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)5 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)5 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)5 IntStream (java.util.stream.IntStream)4 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)4 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)4 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)3 Test (org.junit.Test)2 ColSpan (org.kie.workbench.common.forms.adf.definitions.settings.ColSpan)2 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)2 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)2