use of org.kie.workbench.common.forms.migration.tool.pipelines.basic.FieldAdapter in project kie-wb-common by kiegroup.
the class AbstractFormAdapter method migrateFields.
protected void migrateFields(final Set<Field> fields, final FormDefinition newForm, final FormMigrationSummary formSummary) {
LayoutHelper helper = new LayoutHelper();
fields.forEach(originalField -> {
if (!StringUtils.isEmpty(originalField.getMovedToForm())) {
return;
}
if (!Boolean.TRUE.equals(originalField.getGroupWithPrevious())) {
helper.newRow();
}
String originalTypeCode = originalField.getFieldType().getCode();
FieldAdapter adapter = adaptersRegistry.get(originalTypeCode);
if (adapter == null) {
// trying a backup adapter
UnSupportedFieldAdapter unSupportedFieldAdapter = unSupportedAdapters.get(originalTypeCode);
if (unSupportedFieldAdapter != null) {
warn("Problems migrating field '" + originalField.getFieldName() + "': the original field has an unsupported field type '" + originalTypeCode + "'. It will be added on the new Form as a '" + unSupportedFieldAdapter.getNewFieldType() + "'");
unSupportedFieldAdapter.parseField(originalField, formSummary, newForm, helper::add);
} else {
warn("Cannot migrate field '" + originalField.getFieldName() + "': Unsupported field type '" + originalTypeCode + "'");
Formatter formatter = new Formatter();
formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalField.getFieldName(), originalTypeCode);
LayoutComponent component = new LayoutComponent(FormsMigrationConstants.HTML_COMPONENT);
component.addProperty(FormsMigrationConstants.HTML_CODE_PARAMETER, formatter.toString());
formatter.close();
helper.add(component);
}
} else {
try {
adapter.parseField(originalField, formSummary, newForm, helper::add);
} catch (Exception ex) {
warn("Cannot migrate field '" + originalField.getFieldName() + "': Unexpected error, see message for details");
ex.printStackTrace(migrationContext.getSystem().err());
}
}
});
newForm.setLayoutTemplate(helper.build());
}
Aggregations