Search in sources :

Example 1 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition 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 FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition 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(4);
    Field originalInvoiceUser = originalForm.getField(INVOICE_USER);
    Field originalLines = originalForm.getField(INVOICE_LINES);
    Field originalTotal = originalForm.getField(INVOICE_TOTAL);
    String expectedExtraForm = summary.getBaseFormName() + "-" + originalForm.getHolders().iterator().next().getUniqeId();
    checkMovedField(originalInvoiceUser, expectedExtraForm);
    checkMovedField(originalLines, expectedExtraForm);
    checkMovedField(originalTotal, expectedExtraForm);
    Field invoiceField = originalForm.getField("invoice");
    assertNotNull(invoiceField);
    assertEquals(FieldTypeBuilder.SUBFORM, invoiceField.getFieldType().getCode());
    FormDefinition newFormDefinition = summary.getNewForm().get();
    Assertions.assertThat(newFormDefinition.getModel()).isNotNull().isInstanceOf(modelType);
    Assertions.assertThat(newFormDefinition.getFields()).isNotNull().hasSize(1);
    FieldDefinition newInvoiceField = newFormDefinition.getFieldByName("invoice");
    Assertions.assertThat(newInvoiceField).isNotNull().isInstanceOf(SubFormFieldDefinition.class);
    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) 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) 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) Matchers.anyString(org.mockito.Matchers.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 3 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition 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 4 with FormDefinition

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

the class AbstractFormAdapter method doCreateFormDefinition.

protected void doCreateFormDefinition(FormModel formModel, FormMigrationSummary formSummary) {
    Form originalForm = formSummary.getOriginalForm().get();
    FormDefinition newFormDefinition = new FormDefinition(formModel);
    newFormDefinition.setId(String.valueOf(originalForm.getId()));
    newFormDefinition.setName(formSummary.getBaseFormName());
    Path originalPath = Paths.convert(formSummary.getOriginalForm().getPath());
    Path newPath = originalPath.getParent().resolve(formSummary.getBaseFormName() + "." + FormsMigrationConstants.NEW_FOMRS_EXTENSION);
    formSummary.setNewFormResource(new Resource<>(newFormDefinition, Paths.convert(newPath)));
    migrateFields(originalForm.getFormFields(), newFormDefinition, formSummary);
}
Also used : Path(org.uberfire.java.nio.file.Path) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 5 with FormDefinition

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

the class BPMNFormAdapter method doCreateFormDefinition.

@Override
protected void doCreateFormDefinition(FormModel formModel, FormMigrationSummary formSummary) {
    Form originalForm = formSummary.getOriginalForm().get();
    Set<DataHolder> objectDataHolders = originalForm.getHolders().stream().filter(dataHolder -> !dataHolder.getType().equals(FormsMigrationConstants.DATA_HOLDER_TYPE_BASIC)).collect(Collectors.toSet());
    if (!objectDataHolders.isEmpty()) {
        FieldTypeManager fieldTypeManager = FieldTypeManager.get();
        objectDataHolders.forEach(dataHolder -> {
            Set<Field> dataHolderFields = originalForm.getFieldsForDataHolder(dataHolder);
            if (dataHolderFields.isEmpty()) {
                return;
            }
            FormModel newFormModel = createModelForDO(dataHolder);
            String formName = formSummary.getBaseFormName() + "-" + dataHolder.getUniqeId();
            String formAssetName = formName + "." + FormsMigrationConstants.NEW_FOMRS_EXTENSION;
            FormDefinition newFormDefinition = new FormDefinition(newFormModel);
            newFormDefinition.setId(UIDGenerator.generateUID());
            newFormDefinition.setName(formName);
            migrateFields(dataHolderFields, newFormDefinition, formSummary);
            dataHolderFields.forEach(field -> field.setMovedToForm(formName));
            Path newFormPath = Paths.convert(formSummary.getOriginalForm().getPath()).getParent().resolve(formAssetName);
            FormMigrationSummary extraSummary = new FormMigrationSummary(formSummary.getOriginalForm());
            extraSummary.setBaseFormName(formName);
            extraSummary.setNewFormResource(new Resource<>(newFormDefinition, Paths.convert(newFormPath)));
            migrationContext.getExtraSummaries().add(extraSummary);
            Field field = new Field();
            field.setFieldType(fieldTypeManager.getTypeByCode(FieldTypeBuilder.SUBFORM));
            field.setId(System.currentTimeMillis());
            field.setFieldName(dataHolder.getUniqeId());
            field.setInputBinding(dataHolder.getUniqeId());
            field.setLabel(new HashMap<>());
            field.getLabel().put(FormsMigrationConstants.DEFAULT_LANG, dataHolder.getUniqeId());
            field.setPosition(originalForm.getFormFields().size() + 1000);
            field.setForm(originalForm);
            originalForm.getFormFields().add(field);
        });
    }
    super.doCreateFormDefinition(formModel, formSummary);
}
Also used : Resource(org.kie.workbench.common.forms.migration.tool.Resource) MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) BPMNProcess(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNProcess) Path(org.uberfire.java.nio.file.Path) FieldTypeManager(org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager) HashMap(java.util.HashMap) Files(org.uberfire.java.nio.file.Files) ArrayList(java.util.ArrayList) Paths(org.uberfire.backend.server.util.Paths) FormsMigrationConstants(org.kie.workbench.common.forms.migration.tool.util.FormsMigrationConstants) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FileVisitResult(org.uberfire.java.nio.file.FileVisitResult) BasicFileAttributes(org.uberfire.java.nio.file.attribute.BasicFileAttributes) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) Predicate(java.util.function.Predicate) UIDGenerator(org.kie.workbench.common.forms.services.backend.util.UIDGenerator) Set(java.util.Set) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) Collectors(java.util.stream.Collectors) File(java.io.File) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) IOException(org.uberfire.java.nio.IOException) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) SimpleFileVisitor(org.uberfire.java.nio.file.SimpleFileVisitor) BPMNAnalyzer(org.kie.workbench.common.forms.migration.tool.bpmn.BPMNAnalyzer) FieldTypeBuilder(org.kie.workbench.common.forms.migration.legacy.services.impl.FieldTypeBuilder) Path(org.uberfire.java.nio.file.Path) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) FieldTypeManager(org.kie.workbench.common.forms.migration.legacy.services.FieldTypeManager) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) DataHolder(org.kie.workbench.common.forms.migration.legacy.model.DataHolder) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Aggregations

FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)89 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)30 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)16 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)14 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)14 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)13 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)12 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)12 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)10 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)10 List (java.util.List)9 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)8 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)8 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)8 Person (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person)7 FormModel (org.kie.workbench.common.forms.model.FormModel)7 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)7 Date (java.util.Date)6