Search in sources :

Example 11 with FormMigrationSummary

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

the class FormDefinitionGenerator method maybeArrangeNestedForms.

private void maybeArrangeNestedForms(FormMigrationSummary summary, List<FormMigrationSummary> modelForms) {
    final Form originalForm = summary.getOriginalForm().get();
    final FormDefinition formDefinition = summary.getNewForm().get();
    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof HasNestedForm).map(fieldDefinition -> (HasNestedForm) fieldDefinition).forEach(hasNestedForm -> {
        modelForms.stream().filter(modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(hasNestedForm.getNestedForm())).findFirst().ifPresent(modelSummary -> {
            hasNestedForm.setNestedForm(modelSummary.getNewForm().get().getId());
            updateNestedFormsModelProperties(formDefinition, (FieldDefinition) hasNestedForm, modelSummary.getOriginalForm().get());
        });
    });
    formDefinition.getFields().stream().filter(fieldDefinition -> fieldDefinition instanceof IsCRUDDefinition).map(fieldDefinition -> (IsCRUDDefinition) fieldDefinition).forEach(crudDefinition -> {
        // update Creation Form
        updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getCreationForm()), modelSummary -> crudDefinition.setCreationForm(modelSummary.getNewForm().get().getId()));
        // update Edition Form
        updateCrudDefinitionForms(modelForms, modelSummary -> modelSummary.getOriginalForm().getPath().getFileName().equals(crudDefinition.getEditionForm()), modelSummary -> crudDefinition.setEditionForm(modelSummary.getNewForm().get().getId()));
        // update Table Columns Form
        updateCrudDefinitionForms(modelForms, modelSummary -> {
            Field originalField = originalForm.getField(((FieldDefinition) crudDefinition).getName());
            return modelSummary.getOriginalForm().getPath().getFileName().equals(StringUtils.defaultIfBlank(originalField.getTableSubform(), originalField.getDefaultSubform()));
        }, modelSummary -> {
            FormDefinition modelFormDefinition = modelSummary.getNewForm().get();
            modelFormDefinition.getFields().forEach(fieldDefinition -> {
                if (!(fieldDefinition instanceof EmbedsForm)) {
                    crudDefinition.getColumnMetas().add(new TableColumnMeta(fieldDefinition.getLabel(), fieldDefinition.getBinding()));
                }
            });
            updateNestedFormsModelProperties(formDefinition, (FieldDefinition) crudDefinition, modelSummary.getOriginalForm().get());
        });
    });
}
Also used : MigrationContext(org.kie.workbench.common.forms.migration.tool.pipelines.MigrationContext) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) Predicate(java.util.function.Predicate) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) BPMNFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.BPMNFormAdapter) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) Consumer(java.util.function.Consumer) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) AbstractMigrationStep(org.kie.workbench.common.forms.migration.tool.pipelines.AbstractMigrationStep) DataObjectFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.DataObjectFormAdapter) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Field(org.kie.workbench.common.forms.migration.legacy.model.Field) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) EmbedsForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm)

Example 12 with FormMigrationSummary

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

the class FormDefinitionGenerator method doExecute.

@Override
public void doExecute(MigrationContext migrationContext) {
    migrationContext.getSummaries().removeIf(this::basicSummaryCheck);
    DataObjectFormAdapter dataObjectAdapter = dataObjectFormAdapterFunction.apply(migrationContext);
    List<FormMigrationSummary> possibleDataObjectForms = dataObjectAdapter.migrateSummaries();
    if (!possibleDataObjectForms.isEmpty()) {
        arrangeNestedForms(possibleDataObjectForms, possibleDataObjectForms);
    }
    BPMNFormAdapter bpmFormAdapter = bpmFormAdapterFunction.apply(migrationContext);
    List<FormMigrationSummary> possibleBPMNForms = bpmFormAdapter.migrateSummaries();
    if (!possibleBPMNForms.isEmpty() && !possibleDataObjectForms.isEmpty()) {
        arrangeNestedForms(possibleDataObjectForms, possibleDataObjectForms);
    }
    if (!migrationContext.getExtraSummaries().isEmpty() && !possibleDataObjectForms.isEmpty()) {
        arrangeNestedForms(migrationContext.getExtraSummaries(), possibleDataObjectForms);
    }
}
Also used : BPMNFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.BPMNFormAdapter) DataObjectFormAdapter(org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.DataObjectFormAdapter) FormMigrationSummary(org.kie.workbench.common.forms.migration.tool.FormMigrationSummary)

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