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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations