Search in sources :

Example 1 with FieldAdapter

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());
}
Also used : CharacterFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CharacterFieldAdapter) IntegerTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.IntegerTextFieldAdapter) DecimalTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DecimalTextFieldAdapter) SelectBoxFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SelectBoxFieldAdapter) InputTextFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.InputTextFieldAdapter) MultipleSubformFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.MultipleSubformFieldAdapter) SubformFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SubformFieldAdapter) TextAreaFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.TextAreaFieldAdapter) UnSupportedFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter) CheckBoxFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CheckBoxFieldAdapter) RadioGroupFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.RadioGroupFieldAdapter) DecoratorFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.decorators.DecoratorFieldAdapter) DocumentFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DocumentFieldAdapter) DatesFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DatesFieldAdapter) FieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.FieldAdapter) Formatter(java.util.Formatter) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) UnSupportedFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter)

Aggregations

Formatter (java.util.Formatter)1 FieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.FieldAdapter)1 UnSupportedFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter)1 DecoratorFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.decorators.DecoratorFieldAdapter)1 CharacterFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CharacterFieldAdapter)1 CheckBoxFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.CheckBoxFieldAdapter)1 DatesFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DatesFieldAdapter)1 DecimalTextFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DecimalTextFieldAdapter)1 DocumentFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.DocumentFieldAdapter)1 InputTextFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.InputTextFieldAdapter)1 IntegerTextFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.IntegerTextFieldAdapter)1 MultipleSubformFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.MultipleSubformFieldAdapter)1 RadioGroupFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.RadioGroupFieldAdapter)1 SelectBoxFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SelectBoxFieldAdapter)1 SubformFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.SubformFieldAdapter)1 TextAreaFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.TextAreaFieldAdapter)1 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)1