Search in sources :

Example 56 with FormDefinition

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

the class FormGenerationWithSynchronizationTest method testModelPropertiesConflict.

@Test
public void testModelPropertiesConflict() {
    List<ModelProperty> modelProperties = new ArrayList<>();
    modelProperties.add(new ModelPropertyImpl(NAME_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
    modelProperties.add(new ModelPropertyImpl(LASTNAME_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
    modelProperties.add(new ModelPropertyImpl(AGE_PROPERTY, new TypeInfoImpl(String.class.getName())));
    modelProperties.add(new ModelPropertyImpl(MARRIED_PROPERTY, new TypeInfoImpl(Integer.class.getName())));
    modelProperties.add(new ModelPropertyImpl(ADDRESS_PROPERTY, new TypeInfoImpl(Boolean.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(ORIGINAL_FORM_FIELDS, Integer.valueOf(formDefinition.getFields().size()));
    FieldDefinition field = formDefinition.getFieldByBinding(NAME_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), Integer.class.getName());
    assertTrue(field instanceof IntegerBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), Integer.class.getName());
    assertTrue(field instanceof IntegerBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(AGE_PROPERTY);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertTrue(field instanceof TextBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(MARRIED_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), Integer.class.getName());
    assertTrue(field instanceof IntegerBoxFieldDefinition);
    field = formDefinition.getFieldByBinding(ADDRESS_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), Boolean.class.getName());
    assertTrue(field instanceof CheckBoxFieldDefinition);
}
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)

Example 57 with FormDefinition

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

the class BPMNFormGenerationTest method checkPersonForm.

private void checkPersonForm(FormDefinition form, Map<String, FormDefinition> allForms) {
    assertNotNull(form);
    assertTrue(form.getModel() instanceof JavaFormModel);
    assertEquals(4, form.getFields().size());
    FieldDefinition field = form.getFieldByBinding("name");
    assertFieldStatus(field, "name", String.class.getName());
    field = form.getFieldByBinding("type");
    assertFieldStatus(field, "type", PersonType.class.getName());
    assertTrue(field instanceof EnumListBoxFieldDefinition);
    field = form.getFieldByBinding("personalData");
    assertFieldStatus(field, "personalData", PersonalData.class.getName());
    assertTrue(field instanceof SubFormFieldDefinition);
    SubFormFieldDefinition subForm = (SubFormFieldDefinition) field;
    assertNotNull(subForm.getNestedForm());
    assertNotNull(allForms.get(subForm.getNestedForm()));
    field = form.getFieldByBinding("log");
    assertFieldStatus(field, "log", LogEntry.class.getName());
    assertTrue(field instanceof MultipleSubFormFieldDefinition);
    MultipleSubFormFieldDefinition multipleSubForm = (MultipleSubFormFieldDefinition) field;
    assertNotNull(multipleSubForm.getCreationForm());
    assertEquals(multipleSubForm.getCreationForm(), multipleSubForm.getEditionForm());
    FormDefinition nestedForm = allForms.get(multipleSubForm.getCreationForm());
    assertNotNull(nestedForm);
    assertNotNull(multipleSubForm.getColumnMetas());
    assertEquals(nestedForm.getFields().size(), multipleSubForm.getColumnMetas().size());
    multipleSubForm.getColumnMetas().forEach(columnMeta -> {
        FieldDefinition nestedField = nestedForm.getFieldByBinding(columnMeta.getProperty());
        assertNotNull(nestedField);
        assertEquals(nestedField.getLabel(), columnMeta.getLabel());
    });
}
Also used : PersonalData(org.kie.workbench.common.forms.jbpm.server.service.impl.model.PersonalData) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) PersonType(org.kie.workbench.common.forms.jbpm.server.service.impl.model.PersonType) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) LogEntry(org.kie.workbench.common.forms.jbpm.server.service.impl.model.LogEntry) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)

Example 58 with FormDefinition

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

the class BPMNFormGenerationTest method testSimpleVariables.

@Test
public void testSimpleVariables() {
    List<ModelProperty> variables = new ArrayList<>();
    variables.add(new ModelPropertyImpl("employee", new TypeInfoImpl(String.class.getName())));
    variables.add(new ModelPropertyImpl("manager", new TypeInfoImpl(String.class.getName())));
    variables.add(new ModelPropertyImpl("performance", new TypeInfoImpl(Integer.class.getName())));
    variables.add(new ModelPropertyImpl("approved", new TypeInfoImpl(Boolean.class.getName())));
    model = getModel(getModelId(), variables);
    Collection<FormDefinition> forms = getModelForms(model, classLoader);
    try {
        verify(classLoader, never()).loadClass(anyString());
    } catch (ClassNotFoundException e) {
        fail("We shouldn't be here: " + e.getMessage());
    }
    assertNotNull("There should one form", forms);
    assertEquals("There should one form", 1, forms.size());
    FormDefinition form = forms.iterator().next();
    assertEquals(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX, form.getId());
    assertEquals(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX, form.getName());
    assertEquals(form.getModel(), model);
    assertEquals("There should be 4 fields", 4, form.getFields().size());
    variables.forEach(variable -> {
        FieldDefinition field = form.getFieldByBinding(variable.getName());
        assertFieldStatus(field, variable);
    });
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 59 with FormDefinition

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

the class VFSSelectorFormProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    Map<String, String> values = new TreeMap<>();
    if (context.getModel() instanceof EntityRelationField) {
        FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
        FieldDefinition field = (FieldDefinition) context.getModel();
        List<FormDefinition> forms;
        if (field != null) {
            forms = vfsFormFinderService.findFormsForType(field.getStandaloneClassName(), editorContext.getFormPath());
        } else {
            forms = vfsFormFinderService.findAllForms(editorContext.getFormPath());
        }
        for (FormDefinition form : forms) {
            values.put(form.getId(), form.getName());
        }
    }
    return new SelectorData(values, null);
}
Also used : EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TreeMap(java.util.TreeMap) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 60 with FormDefinition

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

the class FormDefinitionIndexer method fillIndexBuilder.

@Override
protected DefaultIndexBuilder fillIndexBuilder(Path path) throws Exception {
    final DefaultIndexBuilder builder = getIndexBuilder(path);
    if (builder == null) {
        return null;
    }
    String formContent = ioService.readAllString(path);
    FormDefinition formDefinition = formDefinitionSerializer.deserialize(formContent);
    if (formDefinition != null) {
        Resource resParts = new Resource(formDefinition.getName(), ResourceType.FORM);
        FormDefinitionVisitor visitor = new FormDefinitionVisitor(resParts);
        visitor.visit(formDefinition);
        addReferencedResourcesToIndexBuilder(builder, visitor);
        FormModel model = formDefinition.getModel();
        if (model != null) {
            FormModelVisitorProvider provider = getProviderForModel(model.getClass());
            if (provider != null) {
                FormModelVisitor modelVisitor = provider.getVisitor();
                modelVisitor.index(formDefinition, model);
                addReferencedResourcesToIndexBuilder(builder, modelVisitor);
            }
        }
    } else {
        logger.error("Unable to read FormDefinition on " + path.toUri().toString() + ".");
        return null;
    }
    return builder;
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) Resource(org.kie.workbench.common.services.refactoring.Resource) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

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