Search in sources :

Example 1 with UnSupportedFieldAdapter

use of org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter 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)

Example 2 with UnSupportedFieldAdapter

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

the class AbstractFormAdapter method registerAdapter.

protected void registerAdapter(final FieldAdapter adapter) {
    Stream.of(adapter.getLegacyFieldTypeCodes()).forEach(code -> adaptersRegistry.put(code, adapter));
    if (adapter instanceof UnSupportedFieldAdapter) {
        UnSupportedFieldAdapter unSupportedFieldAdapter = (UnSupportedFieldAdapter) adapter;
        Stream.of(unSupportedFieldAdapter.getLegacySupportedFieldTypeCodes()).forEach(code -> unSupportedAdapters.put(code, unSupportedFieldAdapter));
    }
}
Also used : UnSupportedFieldAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter)

Aggregations

UnSupportedFieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.UnSupportedFieldAdapter)2 Formatter (java.util.Formatter)1 FieldAdapter (org.kie.workbench.common.forms.migration.tool.pipelines.basic.FieldAdapter)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