Search in sources :

Example 16 with TypeInfoImpl

use of org.kie.workbench.common.forms.model.impl.TypeInfoImpl 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 17 with TypeInfoImpl

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

the class JBPMFormModelCreationPresenterTest method initFormModels.

protected void initFormModels() {
    List<ModelProperty> processVariables = new ArrayList<>();
    processVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("offering", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    processVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
    processVariables.add(new ModelPropertyImpl("signed", new TypeInfoImpl(Boolean.class.getName())));
    BusinessProcessFormModel processFormModel = new BusinessProcessFormModel("hiring", "hiring", processVariables);
    TaskFormModel taskFormModel;
    List<TaskFormModel> processTasks = new ArrayList<>();
    List<ModelProperty> taskVariables = new ArrayList<>();
    taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(String.class.getName())));
    taskFormModel = new TaskFormModel("hiring", "HRInterview", taskVariables);
    processTasks.add(taskFormModel);
    taskVariables = new ArrayList<>();
    taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
    taskVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
    taskVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
    taskFormModel = new TaskFormModel("hiring", "TechInterview", taskVariables);
    processTasks.add(taskFormModel);
    JBPMProcessModel model = new JBPMProcessModel(processFormModel, processTasks);
    formModels.add(model);
}
Also used : JBPMProcessModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMProcessModel) ArrayList(java.util.ArrayList) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

Example 18 with TypeInfoImpl

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

the class ModelPropertiesGenerator method createModelProperty.

public static ModelProperty createModelProperty(String name, String className, boolean isMultiple, ClassLoader classLoader) {
    if (FormModelPropertiesUtil.isBaseType(className)) {
        // Dealing with basic type properties (String, Integer...)
        return new ModelPropertyImpl(name, new TypeInfoImpl(className, isMultiple));
    } else {
        // Dealing with complex types.
        if (FormModelPropertiesUtil.isListType(className)) {
            // If className is a List let's create a model for Object...
            return createModelProperty(name, Object.class.getName(), true);
        }
        try {
            Class clazz = classLoader.loadClass(className);
            TypeKind typeKind = clazz.isEnum() ? TypeKind.ENUM : TypeKind.OBJECT;
            return new ModelPropertyImpl(name, new TypeInfoImpl(typeKind, className, isMultiple));
        } catch (ClassNotFoundException e) {
            logger.warn("Unable to create property '" + name + "' for class '" + className + "':", e);
        }
    }
    return null;
}
Also used : TypeKind(org.kie.workbench.common.forms.model.TypeKind) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

Example 19 with TypeInfoImpl

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

the class FieldManagerTest method testCompatiblefields.

protected void testCompatiblefields(boolean addFieldType) {
    for (Class clazz : basicTypesSupported) {
        TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
        FieldDefinition fieldDefinition = fieldManager.getDefinitionByDataType(typeInfo);
        Assertions.assertThat(fieldDefinition).isNotNull();
        if (addFieldType) {
            fieldDefinition.setStandaloneClassName(typeInfo.getClassName());
        }
        Collection<String> compatibles = fieldManager.getCompatibleFields(fieldDefinition);
        Assertions.assertThat(compatibles).isNotNull().isNotEmpty();
    }
}
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) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo)

Example 20 with TypeInfoImpl

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

the class FieldManagerTest method testGetFieldByTypeInfo.

@Test
public void testGetFieldByTypeInfo() {
    for (Class clazz : basicTypesSupported) {
        TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
        checkFieldExists(typeInfo);
    }
    for (Class clazz : basicMultipleTypesSupported) {
        TypeInfo typeInfo = new TypeInfoImpl(TypeKind.BASE, clazz.getName(), true);
        checkFieldExists(typeInfo);
    }
    // check nested form
    checkFieldExists(new TypeInfoImpl(TypeKind.OBJECT, Object.class.getName(), false));
    // check multiple subform
    checkFieldExists(new TypeInfoImpl(TypeKind.OBJECT, Object.class.getName(), true));
}
Also used : TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) Test(org.junit.Test)

Aggregations

TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)23 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)14 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)13 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)11 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)7 Date (java.util.Date)5 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)5 TypeInfo (org.kie.workbench.common.forms.model.TypeInfo)5 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)5 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)4 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)4 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)4 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)4 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)4 Person (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.model.Person)3 BasicTypeFieldProvider (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider)3 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)3