Search in sources :

Example 16 with ModelProperty

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

Example 17 with ModelProperty

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

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

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

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

the class FormModelSynchronizationUtilImplTest method testNewModelProperties.

@Test
public void testNewModelProperties() {
    ModelProperty hobbies = ModelPropertiesGenerator.createModelProperty("hobbies", String.class.getName(), false);
    ModelProperty department = ModelPropertiesGenerator.createModelProperty("department", Long.class.getName(), false);
    ModelProperty manager = ModelPropertiesGenerator.createModelProperty("manager", Employee.class.getName(), false);
    formModelSynchronizationResult.getNewProperties().add(hobbies);
    formModelSynchronizationResult.getNewProperties().add(department);
    formModelSynchronizationResult.getNewProperties().add(manager);
    synchronizationUtil.init(form, formModelSynchronizationResult);
    int originalFormFields = form.getFields().size();
    synchronizationUtil.addNewFields();
    assertNotEquals(form.getFields().size(), originalFormFields);
    checkField(hobbies, TextBoxFieldDefinition.class);
    checkField(department, IntegerBoxFieldDefinition.class);
    checkField(manager, SubFormFieldDefinition.class);
}
Also used : Employee(org.kie.workbench.common.forms.dynamic.test.model.Employee) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Test(org.junit.Test)

Aggregations

ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)24 ArrayList (java.util.ArrayList)11 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)11 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)11 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)8 Test (org.junit.Test)7 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)7 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)5 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)4 HashMap (java.util.HashMap)3 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)3 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)3 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)3 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)3 FormModel (org.kie.workbench.common.forms.model.FormModel)3 FieldReadOnlyEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry)3 List (java.util.List)2 Optional (java.util.Optional)2 Dependent (javax.enterprise.context.Dependent)2 Inject (javax.inject.Inject)2