Search in sources :

Example 6 with ModelProperty

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

the class BPMNFormModelGeneratorImpl method createModelProperty.

protected ModelProperty createModelProperty(Variable variable, ClassLoader classLoader) {
    ModelProperty property = ModelPropertiesGenerator.createModelProperty(variable.getName(), variable.getType(), FormModelPropertiesUtil.isListType(variable.getType()), classLoader);
    property.getMetaData().addEntry(new FieldReadOnlyEntry(variable.isInput() && !variable.isOutput()));
    if (!property.getTypeInfo().isMultiple() && property.getTypeInfo().getClassName().equals(Object.class.getName())) {
        property.getMetaData().addEntry(new FieldTypeEntry(TextAreaFieldDefinition.FIELD_TYPE.getTypeName()));
    }
    return property;
}
Also used : FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Example 7 with ModelProperty

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

the class BPMNFormModelGeneratorImpl method generateProcessFormModel.

@Override
public BusinessProcessFormModel generateProcessFormModel(Definitions source, Path path) {
    Process process = getProcess(source);
    if (process != null) {
        final ClassLoader projectClassLoader = projectClassLoaderHelper.getModuleClassLoader(moduleService.resolveModule(path));
        List<ModelProperty> properties = process.getProperties().stream().map(property -> {
            String varName = property.getId();
            String varType = BPMNVariableUtils.getRealTypeForInput(property.getItemSubjectRef().getStructureRef());
            Variable variable = new Variable(varName, varType);
            variable.setInput(true);
            variable.setOutput(true);
            return createModelProperty(variable, projectClassLoader);
        }).sorted((property1, property2) -> property1.getName().compareToIgnoreCase(property2.getName())).collect(Collectors.toList());
        return new BusinessProcessFormModel(process.getId(), process.getName(), properties);
    }
    return null;
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) ModuleClassLoaderHelper(org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper) LoggerFactory(org.slf4j.LoggerFactory) FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) StringUtils(org.apache.commons.lang3.StringUtils) Parser(org.jsoup.parser.Parser) Inject(javax.inject.Inject) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) DataInput(org.eclipse.bpmn2.DataInput) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) DataOutput(org.eclipse.bpmn2.DataOutput) Path(org.uberfire.backend.vfs.Path) Definitions(org.eclipse.bpmn2.Definitions) Process(org.eclipse.bpmn2.Process) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) BPMNVariableUtils(org.kie.workbench.common.forms.jbpm.service.bpmn.util.BPMNVariableUtils) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) Collectors(java.util.stream.Collectors) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) List(java.util.List) Dependent(javax.enterprise.context.Dependent) Assignment(org.eclipse.bpmn2.Assignment) ModelPropertiesGenerator(org.kie.workbench.common.forms.service.backend.util.ModelPropertiesGenerator) Optional(java.util.Optional) FormModelPropertiesUtil(org.kie.workbench.common.forms.model.util.formModel.FormModelPropertiesUtil) Collections(java.util.Collections) BPMNFormModelGenerator(org.kie.workbench.common.forms.jbpm.server.service.BPMNFormModelGenerator) UserTask(org.eclipse.bpmn2.UserTask) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Process(org.eclipse.bpmn2.Process) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)

Example 8 with ModelProperty

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

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

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

the class BPMNFormModelGeneratorImplTest method checkExpectedMergedFormVariables.

protected void checkExpectedMergedFormVariables(TaskFormModel formModel) {
    final Map<String, String> EXPECTED_TYPES = new HashMap<>();
    EXPECTED_TYPES.put("name", String.class.getName());
    EXPECTED_TYPES.put("lastName", String.class.getName());
    EXPECTED_TYPES.put("age", Integer.class.getName());
    EXPECTED_TYPES.put("married", Boolean.class.getName());
    assertEquals(EXPECTED_TYPES.size(), formModel.getProperties().size());
    for (ModelProperty property : formModel.getProperties()) {
        assertNotNull(EXPECTED_TYPES.get(property.getName()));
        assertEquals(EXPECTED_TYPES.get(property.getName()), property.getTypeInfo().getClassName());
    }
}
Also used : HashMap(java.util.HashMap) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Matchers.anyString(org.mockito.Matchers.anyString)

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