Search in sources :

Example 86 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormDefinitionGeneratorImplTest method checkSingleSelectedTaskFormGenerated.

private void checkSingleSelectedTaskFormGenerated(String taskId, String taskName) {
    generator.generateSelectedForms(diagram, taskId);
    verify(generator, times(1)).createFormForModel(formModelArgumentCaptor.capture(), any());
    verify(formDefinitionSerializer, times(1)).serialize(formDefinitionArgumentCaptor.capture());
    verify(ioService, times(1)).startBatch(any());
    verify(ioService, times(1)).getFileSystem(any());
    verify(ioService, times(1)).createFile(any());
    verify(ioService, times(1)).write(any(), anyString());
    verify(ioService, times(1)).endBatch();
    JBPMFormModel formModel = formModelArgumentCaptor.getValue();
    FormDefinition taskForm = formDefinitionArgumentCaptor.getValue();
    Assertions.assertThat(formModel).isNotNull().isInstanceOf(TaskFormModel.class);
    checkTaskFormGenerated((TaskFormModel) formModel, taskName, taskForm);
}
Also used : JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 87 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class AbstractMigrationStep method persist.

private void persist(MigrationContext migrationContext) {
    FormSerializationManager oldFormSerializer = new FormSerializationManagerImpl();
    FormDefinitionSerializer formDefinitionSerializer = migrationContext.getCDIWrapper().getFormDefinitionSerializer();
    Function<Resource<Form>, String> originaldFormSerializationFunction = formResource -> {
        Form originalForm = formResource.get();
        originalForm.setMigrationStep(getStep());
        return oldFormSerializer.generateFormXML(originalForm, migrationContext.getSystem());
    };
    Function<Resource<FormDefinition>, String> newFormSerializationFuncion = formResource -> formDefinitionSerializer.serialize(formResource.get());
    migrationContext.getSummaries().forEach(summary -> {
        if (summary.getResult().isSuccess()) {
            serializeResource(summary.getOriginalForm().getPath(), originaldFormSerializationFunction.apply(summary.getOriginalForm()), migrationContext);
            serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
        }
    });
    migrationContext.getExtraSummaries().forEach(summary -> {
        serializeResource(summary.getNewForm().getPath(), newFormSerializationFuncion.apply(summary.getNewForm()), migrationContext);
    });
}
Also used : Resource(org.kie.workbench.common.forms.migration.tool.Resource) FormSerializationManager(org.kie.workbench.common.forms.migration.legacy.services.FormSerializationManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) Function(java.util.function.Function) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) Path(org.uberfire.backend.vfs.Path) FormSerializationManagerImpl(org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) FormSerializationManagerImpl(org.kie.workbench.common.forms.migration.legacy.services.impl.FormSerializationManagerImpl) Resource(org.kie.workbench.common.forms.migration.tool.Resource) FormSerializationManager(org.kie.workbench.common.forms.migration.legacy.services.FormSerializationManager)

Example 88 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition 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 89 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class AbstractFormDefinitionGeneratorTest method verifyLineForm.

protected void verifyLineForm(FormMigrationSummary summary) {
    Form originalForm = summary.getOriginalForm().get();
    Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(4);
    FormDefinition newForm = summary.getNewForm().get();
    Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(4);
    Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", LINE_MODEL).isInstanceOf(DataObjectFormModel.class);
    IntStream indexStream = IntStream.range(0, newForm.getFields().size());
    LayoutTemplate formLayout = newForm.getLayoutTemplate();
    assertNotNull(formLayout);
    Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(1);
    LayoutRow fieldRow = formLayout.getRows().get(0);
    indexStream.forEach(index -> {
        FieldDefinition fieldDefinition = newForm.getFields().get(index);
        switch(index) {
            case 0:
                checkFieldDefinition(fieldDefinition, LINE_PRODUCT, "product", "product", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 1:
                checkFieldDefinition(fieldDefinition, LINE_PRICE, "price", "price", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 2:
                checkFieldDefinition(fieldDefinition, LINE_QUANTITY, "quantity", "quantity", IntegerBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
            case 3:
                checkFieldDefinition(fieldDefinition, LINE_TOTAL, "total", "total", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
                break;
        }
        assertNotNull(fieldRow);
        Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(4);
        LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(index);
        assertNotNull(fieldColumn);
        assertEquals("3", fieldColumn.getSpan());
        Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
        checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
    });
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Form(org.kie.workbench.common.forms.migration.legacy.model.Form) LayoutRow(org.uberfire.ext.layout.editor.api.editor.LayoutRow) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntStream(java.util.stream.IntStream)

Aggregations

FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)89 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)30 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)16 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)14 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)14 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)13 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)12 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)12 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)10 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)10 List (java.util.List)9 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)8 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)8 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)8 Person (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person)7 FormModel (org.kie.workbench.common.forms.model.FormModel)7 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)7 Date (java.util.Date)6