Search in sources :

Example 51 with FieldDefinition

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

the class FormEditorPresenterTest method testAddFields.

protected void testAddFields(boolean checkAvailable) {
    int formFields = editorHelper.getFormDefinition().getFields().size();
    int availableFields = editorHelper.getAvailableFields().size();
    presenter.onSyncPalette(presenter.getFormDefinition().getId());
    for (FieldDefinition field : employeeFields) {
        addField(field);
        availableFields--;
        formFields++;
        checkExpectedFields(availableFields, formFields, checkAvailable);
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)

Example 52 with FieldDefinition

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

the class FormEditorPresenterTest method testOnSyncPalette.

private void testOnSyncPalette(boolean noContext) {
    loadContent();
    VerificationMode count = times(1);
    if (noContext) {
        when(editorHelper.getContent()).thenReturn(null);
        count = never();
    }
    FormEditorPresenter presenterSpy = spy(presenter);
    String formId = presenterSpy.getFormDefinition().getId();
    presenterSpy.onSyncPalette(formId);
    Collection<FieldDefinition> availableFieldsValues = editorHelper.getAvailableFields().values();
    verify(presenterSpy, count).removeAllDraggableGroupComponent(presenter.getFormDefinition().getFields());
    verify(presenterSpy, count).removeAllDraggableGroupComponent(availableFieldsValues);
    verify(presenterSpy, count).addAllDraggableGroupComponent(availableFieldsValues);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Mockito.anyString(org.mockito.Mockito.anyString) VerificationMode(org.mockito.verification.VerificationMode)

Example 53 with FieldDefinition

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

the class DataObjectFormModelHandlerTest method dataTypesGenerateCorrectFieldDefinitions.

@Test
public void dataTypesGenerateCorrectFieldDefinitions() {
    // all possible types of data object fields - expected field types couples
    Map<String, List<String>> expectedFieldTypes = new HashMap<>();
    expectedFieldTypes.put(DecimalBoxFieldDefinition.class.getSimpleName(), Arrays.asList(BigDecimal.class.getName(), Double.class.getName(), Float.class.getName(), double.class.getName(), float.class.getName()));
    expectedFieldTypes.put(IntegerBoxFieldDefinition.class.getSimpleName(), Arrays.asList(BigInteger.class.getName(), Byte.class.getName(), Integer.class.getName(), Long.class.getName(), Short.class.getName(), byte.class.getName(), int.class.getName(), long.class.getName(), short.class.getName()));
    expectedFieldTypes.put(CheckBoxFieldDefinition.class.getSimpleName(), Arrays.asList(Boolean.class.getName(), boolean.class.getName()));
    expectedFieldTypes.put(TextBoxFieldDefinition.class.getSimpleName(), Arrays.asList(String.class.getName()));
    expectedFieldTypes.put(CharacterBoxFieldDefinition.class.getSimpleName(), Arrays.asList(Character.class.getName(), char.class.getName()));
    expectedFieldTypes.put(DatePickerFieldDefinition.class.getSimpleName(), Arrays.asList(Date.class.getName(), LocalDate.class.getName(), LocalDateTime.class.getName(), OffsetDateTime.class.getName(), LocalTime.class.getName()));
    // TODO: Update after JBPM-5911 is fixed (move date-types from SubFormFieldType to DatePickerFieldType)
    expectedFieldTypes.put(SubFormFieldDefinition.class.getSimpleName(), Collections.singletonList(NESTED_CLASSNAME));
    expectedFieldTypes.put(MultipleSubFormFieldDefinition.class.getSimpleName(), Collections.singletonList(NESTED_CLASSNAME));
    formModel = handler.createFormModel(dataObject, path);
    List<FieldDefinition> formModelFields = formModel.getProperties().stream().map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toList());
    formFieldsShouldNotBeGeneratedForPersistenceId(formModelFields);
    listsOfBasicDataTypesShouldBeExcludedFromTheFormFields(formModelFields);
    for (FieldDefinition field : formModelFields) {
        String dataType = field.getStandaloneClassName();
        String fieldDefinition = field.getClass().getSimpleName();
        assertTrue(expectedFieldTypes.get(fieldDefinition).contains(dataType));
    }
}
Also used : HashMap(java.util.HashMap) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) 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) 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) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) 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) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) List(java.util.List) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) Test(org.junit.Test)

Example 54 with FieldDefinition

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

the class BPMNRuntimeFormGeneratorService method extractModelFields.

@Override
protected List<FieldDefinition> extractModelFields(JavaFormModel formModel, GenerationContext<ClassLoader> context) {
    Class clazz;
    String modelType = formModel.getType();
    try {
        clazz = context.getSource().loadClass(modelType);
        if (clazz == null) {
            clazz = getClass().forName(modelType);
        }
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Unable to extract Form Fields for class '" + modelType + "'");
    }
    if (clazz == null) {
        throw new IllegalArgumentException("Unable to extract Form Fields for class '" + modelType + "'");
    }
    ModuleDataModelOracle oracle = getModuleOracle(clazz);
    if (oracle != null) {
        List<FieldDefinition> formFields = new ArrayList<>();
        ModelField[] fields = oracle.getModuleModelFields().get(modelType);
        Arrays.stream(fields).forEach(modelField -> {
            if (modelField.getName().equals("this")) {
                return;
            }
            String fieldType = modelField.getClassName();
            boolean isEnunm = oracle.getModuleJavaEnumDefinitions().get(modelType + "#" + modelField.getName()) != null;
            boolean isList = DataType.TYPE_COLLECTION.equals(modelField.getType());
            if (isList) {
                fieldType = oracle.getModuleFieldParametersType().get(modelType + "#" + modelField.getName());
            }
            TypeKind typeKind = isEnunm ? TypeKind.ENUM : FormModelPropertiesUtil.isBaseType(fieldType) ? TypeKind.BASE : TypeKind.OBJECT;
            TypeInfo info = new TypeInfoImpl(typeKind, fieldType, isList);
            ModelProperty modelProperty = new ModelPropertyImpl(modelField.getName(), info);
            formModel.getProperties().add(modelProperty);
            FieldDefinition field = generateFieldDefinition(modelProperty, context);
            if (field != null) {
                formFields.add(field);
            }
        });
        return formFields;
    }
    return null;
}
Also used : ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ArrayList(java.util.ArrayList) TypeKind(org.kie.workbench.common.forms.model.TypeKind) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

Example 55 with FieldDefinition

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

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7