Search in sources :

Example 1 with IsCRUDDefinition

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition in project kie-wb-common by kiegroup.

the class AbstractBPMNFormGeneratorService method processFieldDefinition.

protected void processFieldDefinition(FieldDefinition field, GenerationContext<SOURCE> context) {
    if (field instanceof EntityRelationField) {
        if (field instanceof HasNestedForm) {
            HasNestedForm nestedFormField = (HasNestedForm) field;
            FormDefinition nestedForm = findFormDefinitionForModelType(field.getStandaloneClassName(), context);
            if (nestedForm == null) {
                nestedForm = createModelFormDefinition(field.getStandaloneClassName(), context);
            }
            nestedFormField.setNestedForm(nestedForm.getId());
        } else if (field instanceof IsCRUDDefinition) {
            IsCRUDDefinition crudField = (IsCRUDDefinition) field;
            FormDefinition nestedForm = findFormDefinitionForModelType(field.getStandaloneClassName(), context);
            if (nestedForm == null) {
                nestedForm = createModelFormDefinition(field.getStandaloneClassName(), context);
                crudField.setCreationForm(nestedForm.getId());
                crudField.setEditionForm(nestedForm.getId());
                List<TableColumnMeta> tableColumnMetas = new ArrayList<>();
                nestedForm.getFields().forEach(nestedField -> {
                    tableColumnMetas.add(new TableColumnMeta(nestedField.getLabel(), nestedField.getBinding()));
                });
                crudField.setColumnMetas(tableColumnMetas);
            }
        }
    }
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) UIDGenerator(org.kie.workbench.common.forms.services.backend.util.UIDGenerator) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) BPMNFormGeneratorService(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.BPMNFormGeneratorService) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) ArrayList(java.util.ArrayList) ColSpan(org.kie.workbench.common.forms.adf.definitions.settings.ColSpan) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) StaticFormLayoutTemplateGenerator(org.kie.workbench.common.forms.commons.shared.layout.impl.StaticFormLayoutTemplateGenerator) List(java.util.List) LayoutGenerator(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FieldManager(org.kie.workbench.common.forms.service.shared.FieldManager) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) 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) ArrayList(java.util.ArrayList) List(java.util.List) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with IsCRUDDefinition

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition in project kie-wb-common by kiegroup.

the class FormDefinitionVisitor method visit.

public void visit(FieldDefinition fieldDefinition) {
    resParts.addPart(fieldDefinition.getName(), PartType.FORM_FIELD);
    addResourceReference(fieldDefinition.getStandaloneClassName(), ResourceType.JAVA);
    if (fieldDefinition instanceof HasNestedForm) {
        HasNestedForm nestedForm = (HasNestedForm) fieldDefinition;
        addResourceReference(nestedForm.getNestedForm(), ResourceType.FORM);
    } else if (fieldDefinition instanceof IsCRUDDefinition) {
        IsCRUDDefinition crudDefinition = (IsCRUDDefinition) fieldDefinition;
        addResourceReference(crudDefinition.getCreationForm(), ResourceType.FORM);
        addResourceReference(crudDefinition.getEditionForm(), ResourceType.FORM);
    }
}
Also used : IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm)

Example 3 with IsCRUDDefinition

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition in project kie-wb-common by kiegroup.

the class NestedFormsConflictHandler method checkConflict.

protected void checkConflict(FieldDefinition fieldDefinition) {
    if (fieldDefinition instanceof HasNestedForm) {
        HasNestedForm nestedForm = (HasNestedForm) fieldDefinition;
        if (content.getRenderingContext().getAvailableForms().get(nestedForm.getNestedForm()) == null) {
            consumeConflict(getFieldText(fieldDefinition), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerNestedForm), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerFix));
            commands.add(() -> nestedForm.setNestedForm(null));
        }
    } else if (fieldDefinition instanceof IsCRUDDefinition) {
        IsCRUDDefinition crudDefinition = (IsCRUDDefinition) fieldDefinition;
        if (content.getRenderingContext().getAvailableForms().get(crudDefinition.getCreationForm()) == null) {
            consumeConflict(getFieldText(fieldDefinition), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerCreationForm), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerFix));
            commands.add(() -> crudDefinition.setCreationForm(null));
        }
        if (content.getRenderingContext().getAvailableForms().get(crudDefinition.getEditionForm()) == null) {
            consumeConflict(getFieldText(fieldDefinition), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerEditionForm), translationService.getTranslation(FormEditorConstants.NestedFormsConflictHandlerFix));
            commands.add(() -> crudDefinition.setEditionForm(null));
        }
    }
}
Also used : IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm)

Example 4 with IsCRUDDefinition

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition 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)

Aggregations

HasNestedForm (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm)4 IsCRUDDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition)4 List (java.util.List)2 TableColumnMeta (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta)2 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 ArrayList (java.util.ArrayList)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ColSpan (org.kie.workbench.common.forms.adf.definitions.settings.ColSpan)1 LayoutGenerator (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator)1 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)1 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)1 StaticFormLayoutTemplateGenerator (org.kie.workbench.common.forms.commons.shared.layout.impl.StaticFormLayoutTemplateGenerator)1 DataObjectFormModel (org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)1 EmbedsForm (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EmbedsForm)1 EntityRelationField (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField)1 JBPMFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel)1