Search in sources :

Example 1 with ModelPropertyImpl

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

the class FieldManagerTest method initTest.

@Before
public void initTest() {
    fieldManager = new TestFieldManager();
    Assertions.assertThat(fieldManager.getBaseFieldTypes()).isNotNull().isNotEmpty();
    property = new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName()));
}
Also used : TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Before(org.junit.Before)

Example 2 with ModelPropertyImpl

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

the class FormGenerationWithSynchronizationTest method testRemoveModelProperties.

@Test
public void testRemoveModelProperties() {
    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())));
    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(), String.class.getName());
    field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
    assertNotNull(field);
    assertEquals(field.getStandaloneClassName(), String.class.getName());
    assertNull(formDefinition.getFieldByBinding(AGE_PROPERTY));
    assertNull(formDefinition.getFieldByBinding(MARRIED_PROPERTY));
    assertNull(formDefinition.getFieldByBinding(ADDRESS_PROPERTY));
    assertNotNull(formDefinition.getFieldByName(AGE_PROPERTY));
    assertNotNull(formDefinition.getFieldByName(MARRIED_PROPERTY));
    assertNotNull(formDefinition.getFieldByName(ADDRESS_PROPERTY));
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) 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) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ArrayList(java.util.ArrayList) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 3 with ModelPropertyImpl

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

the class BPMNFormGenerationTest method testComplexFields.

protected void testComplexFields(boolean fromClassLoader) {
    if (fromClassLoader) {
        try {
            when(classLoader.loadClass(Person.class.getName())).then(new Answer<Class<?>>() {

                @Override
                public Class<?> answer(InvocationOnMock invocationOnMock) throws Throwable {
                    return Person.class;
                }
            });
        } catch (ClassNotFoundException e) {
            fail("We shouldn't be here: " + e.getMessage());
        }
    }
    List<ModelProperty> properties = new ArrayList<>();
    properties.add(new ModelPropertyImpl("person", new TypeInfoImpl(TypeKind.OBJECT, Person.class.getName(), false)));
    model = getModel(getModelId(), properties);
    Collection<FormDefinition> forms = getModelForms(model, classLoader);
    Map<String, FormDefinition> allForms = new HashMap<>();
    forms.forEach(form -> allForms.put(form.getId(), form));
    try {
        verify(classLoader, times(3)).loadClass(anyString());
    } catch (ClassNotFoundException e) {
        fail(e.getMessage());
    }
    assertNotNull("There should some forms", forms);
    assertEquals("There should 4 forms", 4, forms.size());
    FormDefinition form = allForms.get(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX);
    checkBPMForm(form, allForms);
    form = findFormForModel(Person.class.getName(), allForms);
    checkPersonForm(form, allForms);
    form = findFormForModel(PersonalData.class.getName(), allForms);
    checkPersonalDataForm(form, allForms);
    form = findFormForModel(LogEntry.class.getName(), allForms);
    checkLogEntryForm(form);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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) Person(org.kie.workbench.common.forms.jbpm.server.service.impl.model.Person)

Example 4 with ModelPropertyImpl

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

the class FormEditorHelperTest method initFields.

private void initFields() {
    TextBoxFieldDefinition name = new TextBoxFieldDefinition();
    name.setId("name");
    name.setName("name");
    name.setLabel("Name");
    name.setPlaceHolder("Name");
    name.setBinding("name");
    name.setStandaloneClassName(String.class.getName());
    nameField = name;
    TextBoxFieldDefinition lastName = new TextBoxFieldDefinition();
    lastName.setId("lastName");
    lastName.setName("lastName");
    lastName.setLabel("Last Name");
    lastName.setPlaceHolder("Last Name");
    lastName.setBinding("lastName");
    lastName.setStandaloneClassName(String.class.getName());
    lastNameField = lastName;
    DatePickerFieldDefinition birthday = new DatePickerFieldDefinition();
    birthday.setId("birthday");
    birthday.setName("birthday");
    birthday.setLabel("Birthday");
    birthday.setBinding("birthday");
    birthday.setStandaloneClassName(Date.class.getName());
    CheckBoxFieldDefinition married = new CheckBoxFieldDefinition();
    married.setId("married");
    married.setName("married");
    married.setLabel("Married");
    married.setBinding("married");
    married.setStandaloneClassName(Boolean.class.getName());
    marriedField = married;
    IntegerBoxFieldDefinition age = new IntegerBoxFieldDefinition();
    age.setId("age");
    age.setName("age");
    age.setLabel("Age");
    age.setBinding("age");
    ageField = age;
    DecimalBoxFieldDefinition weight = new DecimalBoxFieldDefinition();
    weight.setId("weight");
    weight.setName("weight");
    weight.setLabel("Weight");
    weight.setBinding("weight");
    weightField = weight;
    employeeFields = new ArrayList<>();
    employeeFields.add(name);
    employeeFields.add(lastName);
    employeeFields.add(birthday);
    employeeFields.add(married);
    employeeFields.add(age);
    employeeFields.add(weight);
    modelProperties = new ArrayList<>();
    employeeFields.forEach(fieldDefinition -> modelProperties.add(new ModelPropertyImpl(fieldDefinition.getBinding(), new TypeInfoImpl(fieldDefinition.getStandaloneClassName()))));
}
Also used : 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) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) Mockito.anyString(org.mockito.Mockito.anyString) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Date(java.util.Date) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)

Example 5 with ModelPropertyImpl

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

Aggregations

ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)15 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)13 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)10 ArrayList (java.util.ArrayList)9 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)7 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)6 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)5 Test (org.junit.Test)4 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 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)4 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)4 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)3 Mockito.anyString (org.mockito.Mockito.anyString)3 Date (java.util.Date)2 Before (org.junit.Before)2 EnumListBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)2 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)2