Search in sources :

Example 6 with FormMigrationSummary

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

the class FormDefinitionGeneratorForDataObjectsTest 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 -> invoiceForm = form, DATAOBJECTS_RESOURCES, INVOICE_FORM, invoiceFormPath);
    summaries.add(new FormMigrationSummary(new Resource<>(invoiceForm, invoiceFormPath)));
    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 7 with FormMigrationSummary

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

the class FormDefinitionGeneratorForDataObjectsWithErrorsTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> basicDataHolderForm = form, DATAOBJECTS_RESOURCES, USER_BASIC_TYPE_DATA_HOLDER_FORM, basicDataHolderPath);
    summaries.add(new FormMigrationSummary(new Resource<>(basicDataHolderForm, basicDataHolderPath)));
    initForm(form -> noDataHoldersForm = form, DATAOBJECTS_RESOURCES, USER_NO_DATA_HOLDERS_FORM, noDataHoldersPath);
    summaries.add(new FormMigrationSummary(new Resource<>(noDataHoldersForm, noDataHoldersPath)));
    initForm(form -> multipleDataHoldersForm = form, DATAOBJECTS_RESOURCES, USER_MULTIPLE_DATA_HOLDERS_FORM, multipleDataHoldersPath);
    summaries.add(new FormMigrationSummary(new Resource<>(multipleDataHoldersForm, multipleDataHoldersPath)));
    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 8 with FormMigrationSummary

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

the class FormDefinitionGeneratorWithUnsupportedFieldsTest method doInit.

@Override
protected void doInit() throws Exception {
    List<FormMigrationSummary> summaries = new ArrayList<>();
    initForm(form -> userForm = form, DATAOBJECTS_RESOURCES, USER_WITH_UNSUPPORTED_FIELDS, 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 9 with FormMigrationSummary

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

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

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