Search in sources :

Example 51 with FormDefinition

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

the class FormGenerationIntegrationTest method ProcessFormIsCorrectlyGenerated.

/**
 * Tests if all form definitions are generated correctly when you hit generate all in the designer.
 */
@Test
public void ProcessFormIsCorrectlyGenerated() {
    when(module.getRootPath()).thenReturn(rootPathWithNestedForms);
    final FormGenerationResult formGenerationResult = generateForm("new_formmodeler.FormGenerationTest_Process-taskform.frm", processFormModel);
    final List<String> expectedProcessFormFields = Arrays.asList("boolean", CHECKBOX_FIELDTYPE, "dataObject", SUBFORM_FIELDTYPE, "document", DOCUMENT_FIELDTYPE, "float", DECIMALBOX_FIELDTYPE, "integer", INTEGERBOX_FIELDTYPE, "object", TEXTAREA_FIELDTYPE, "string", TEXTBOX_FIELDTYPE);
    final FormDefinition rootForm = formGenerationResult.getRootForm();
    testFormDefinition(rootForm, expectedProcessFormFields);
    testNestedFormsHaveCorrectId(rootForm, "dataObject", DATAOBJECT_FORM_ID);
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 52 with FormDefinition

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

the class AbstractBPMNFormGeneratorService method generateForms.

@Override
public FormGenerationResult generateForms(JBPMFormModel formModel, SOURCE source) {
    if (formModel == null) {
        throw new IllegalArgumentException("FormModel cannot be null");
    }
    GenerationContext<SOURCE> context = new GenerationContext<>(formModel, source);
    FormDefinition rootForm = createRootFormDefinition(context);
    if (rootForm == null) {
        throw new IllegalStateException("Impossible to generate form for: " + formModel.getFormName());
    }
    if (rootForm.getLayoutTemplate() == null) {
        createFormLayout(rootForm);
    }
    context.setRootForm(rootForm);
    processFormDefinition(rootForm, context);
    return new FormGenerationResult(context.getRootForm(), new ArrayList<>(context.getContextForms().values()));
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 53 with FormDefinition

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

the class BPMNVFSFormDefinitionGeneratorService method createModelFormDefinition.

@Override
protected FormDefinition createModelFormDefinition(String modelType, GenerationContext<Path> context) {
    FormDefinition form = super.createModelFormDefinition(modelType, context);
    org.uberfire.java.nio.file.Path path = Paths.convert(context.getSource()).getParent().resolve(form.getName() + "." + FormResourceTypeDefinition.EXTENSION);
    ioService.write(path, formSerializer.serialize(form), commentedOptionFactory.makeCommentedOption("Automatically generated form"));
    return form;
}
Also used : FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 54 with FormDefinition

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

the class BPMNVFSFormDefinitionGeneratorService method findFormDefinitionForModelType.

@Override
protected FormDefinition findFormDefinitionForModelType(String modelType, GenerationContext<Path> context) {
    FormDefinition form = super.findFormDefinitionForModelType(modelType, context);
    if (form != null) {
        return form;
    }
    List<FormDefinition> foundForms = formFinderService.findFormsForType(modelType, context.getSource());
    Optional<FormDefinition> validForm = foundForms.stream().filter(formDefinition -> !formDefinition.getFields().isEmpty()).findFirst();
    return validForm.orElse(foundForms.stream().findFirst().orElse(null));
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LoggerFactory(org.slf4j.LoggerFactory) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FieldManager(org.kie.workbench.common.forms.service.shared.FieldManager) Named(javax.inject.Named) GenerationContext(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.impl.GenerationContext) VFSFormFinderService(org.kie.workbench.common.forms.editor.service.shared.VFSFormFinderService) Path(org.uberfire.backend.vfs.Path) Logger(org.slf4j.Logger) UIDGenerator(org.kie.workbench.common.forms.services.backend.util.UIDGenerator) FormModelSynchronizationUtil(org.kie.workbench.common.forms.editor.service.shared.model.FormModelSynchronizationUtil) AbstractBPMNFormGeneratorService(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.impl.AbstractBPMNFormGeneratorService) Collectors(java.util.stream.Collectors) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) List(java.util.List) FormResourceTypeDefinition(org.kie.workbench.common.forms.editor.type.FormResourceTypeDefinition) Dependent(javax.enterprise.context.Dependent) IOService(org.uberfire.io.IOService) Optional(java.util.Optional) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandlerManager(org.kie.workbench.common.forms.editor.service.backend.FormModelHandlerManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 55 with FormDefinition

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

the class FormGenerationWithSynchronizationTest method testAddModelProperties.

@Test
public void testAddModelProperties() {
    List<ModelProperty> modelProperties = new ArrayList<>();
    modelProperties.add(new ModelPropertyImpl(NAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
    modelProperties.add(new ModelPropertyImpl(LASTNAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
    modelProperties.add(new ModelPropertyImpl(AGE_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
    modelProperties.add(new ModelPropertyImpl(MARRIED_PROPERTY, new TypeInfoImpl(Boolean.class.getName())));
    modelProperties.add(new ModelPropertyImpl(ADDRESS_PROPERTY, new TypeInfoImpl(String.class.getName())));
    modelProperties.add(new ModelPropertyImpl(JOB_PROPERTY, new TypeInfoImpl(String.class.getName())));
    modelProperties.add(new ModelPropertyImpl(HOBBIES_PROPERTY, new TypeInfoImpl(String.class.getName())));
    newFormModel = new TaskFormModel(PROCESS_ID, TASK_NAME, modelProperties);
    FormGenerationResult generationResult = service.generateForms(newFormModel, source);
    assertNotNull(generationResult);
    assertNotNull(generationResult.getRootForm());
    FormDefinition formDefinition = generationResult.getRootForm();
    assertEquals(newFormModel, formDefinition.getModel());
    assertEquals(ALL_FORM_FIELDS, Integer.valueOf(formDefinition.getFields().size()));
    FieldDefinition field = formDefinition.getFieldByBinding(NAME_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(AGE_PROPERTY);
    assertEquals(field.getStandaloneClassName(), Integer.class.getName());
    assertTrue(field instanceof IntegerBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(MARRIED_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), Boolean.class.getName());
    assertTrue(field instanceof CheckBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(ADDRESS_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(JOB_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(HOBBIES_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
}
Also used : TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) ArrayList(java.util.ArrayList) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) Test(org.junit.Test)

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