Search in sources :

Example 1 with FormMigrationSummary

use of org.kie.workbench.common.forms.migration.tool.FormMigrationSummary in project kie-wb-common by kiegroup.

the class AllFieldTypesFormGenerationTest method doInit.

@Override
protected void doInit() throws Exception {
    fieldMappings.put("subform", SubFormFieldDefinition.class);
    fieldMappings.put("multiple", MultipleSubFormFieldDefinition.class);
    fieldMappings.put("text", TextBoxBaseDefinition.class);
    fieldMappings.put("textarea", TextAreaFieldDefinition.class);
    fieldMappings.put("character", CharacterBoxFieldDefinition.class);
    fieldMappings.put("float", DecimalBoxFieldDefinition.class);
    fieldMappings.put("double", DecimalBoxFieldDefinition.class);
    fieldMappings.put("bigDecimal", DecimalBoxFieldDefinition.class);
    fieldMappings.put("bigInteger", IntegerBoxFieldDefinition.class);
    fieldMappings.put("byte", IntegerBoxFieldDefinition.class);
    fieldMappings.put("short", IntegerBoxFieldDefinition.class);
    fieldMappings.put("integer", IntegerBoxFieldDefinition.class);
    fieldMappings.put("long", IntegerBoxFieldDefinition.class);
    fieldMappings.put("email", TextBoxFieldDefinition.class);
    fieldMappings.put("boolean", CheckBoxFieldDefinition.class);
    fieldMappings.put("html", TextAreaFieldDefinition.class);
    fieldMappings.put("date", DatePickerFieldDefinition.class);
    fieldMappings.put("shortDate", DatePickerFieldDefinition.class);
    fieldMappings.put("document", DocumentFieldDefinition.class);
    fieldMappings.put("select", StringListBoxFieldDefinition.class);
    fieldMappings.put("radio", StringRadioGroupFieldDefinition.class);
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, ALL_FIELD_TYPES, userFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(userForm, userFormPath)));
    context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArrayList(java.util.ArrayList) Resource(org.kie.workbench.common.forms.migration.tool.Resource)

Example 2 with FormMigrationSummary

use of org.kie.workbench.common.forms.migration.tool.FormMigrationSummary 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 3 with FormMigrationSummary

use of org.kie.workbench.common.forms.migration.tool.FormMigrationSummary in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorForBPMNForWrongTaskFormNameTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> wrongProcessForm = form, BPMN_RESOURCES, WRONG_PROCESS_FORM, wrongProcessPath);
    summaries.add(new FormMigrationSummary(new Resource<>(wrongProcessForm, wrongProcessPath)));
    initForm(form -> wrontTaskForm = form, BPMN_RESOURCES, WRONG_TASK_FORM, wrongTaskPath);
    summaries.add(new FormMigrationSummary(new Resource<>(wrontTaskForm, wrongTaskPath)));
    context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
    generator = new FormDefinitionGenerator(DataObjectFormAdapter::new, this::getBPMNAdapter);
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArrayList(java.util.ArrayList) Resource(org.kie.workbench.common.forms.migration.tool.Resource)

Example 4 with FormMigrationSummary

use of org.kie.workbench.common.forms.migration.tool.FormMigrationSummary 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 5 with FormMigrationSummary

use of org.kie.workbench.common.forms.migration.tool.FormMigrationSummary in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, USER_FORM, userFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(userForm, userFormPath)));
    initForm(form -> lineForm = form, DATAOBJECTS_RESOURCES, LINE_FORM, lineFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(lineForm, lineFormPath)));
    initForm(form -> processForm = form, BPMN_RESOURCES, PROCESS_FORM, processFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(processForm, processFormPath)));
    initForm(form -> taskForm = form, BPMN_RESOURCES, TASK_FORM, taskFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(taskForm, taskFormPath)));
    context = new MigrationContext(workspaceProject, weldContainer, migrationServicesCDIWrapper, new RealSystemAccess(), summaries);
    generator = new FormDefinitionGenerator(DataObjectFormAdapter::new, this::getBPMNAdapter);
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) RealSystemAccess(org.kie.workbench.common.migration.cli.RealSystemAccess) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) ArrayList(java.util.ArrayList) Resource(org.kie.workbench.common.forms.migration.tool.Resource)

Aggregations

FormMigrationSummary (org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)12 MigrationContext (org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext)9 ArrayList (java.util.ArrayList)8 Resource (org.kie.workbench.common.forms.migration.tool.Resource)8 RealSystemAccess (org.kie.workbench.common.migration.cli.RealSystemAccess)7 Field (org.kie.workbench.common.forms.migration.legacy.model.Field)5 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)5 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)5 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)4 List (java.util.List)3 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)3 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)3 Predicate (java.util.function.Predicate)2 Test (org.junit.Test)2 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)2 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)2 BPMNFormAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.BPMNFormAdapter)2 DataObjectFormAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.DataObjectFormAdapter)2