Search in sources :

Example 11 with ModelProperty

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

the class BPMNFormModelGeneratorImplTest method assertJBPMVariablesAreCorrect.

private void assertJBPMVariablesAreCorrect(AbstractJBPMFormModel formModel, Map<String, String> expectedVariables) {
    Map<String, String> actualVariables = new HashMap<>();
    for (ModelProperty modelProperty : formModel.getProperties()) {
        actualVariables.put(modelProperty.getName(), modelProperty.getTypeInfo().getClassName());
    }
    assertEquals(expectedVariables, actualVariables);
}
Also used : HashMap(java.util.HashMap) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Matchers.anyString(org.mockito.Matchers.anyString)

Example 12 with ModelProperty

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

the class DataObjectFormModelHandler method getDataObjectProperties.

protected List<ModelProperty> getDataObjectProperties(DataObject dataObject) {
    List<ModelProperty> properties = new ArrayList<>();
    dataObject.getProperties().forEach(property -> {
        if (isValidDataObjectProperty(property)) {
            Optional<ModelProperty> optional = createModelProperty(property.getName(), property.getClassName(), property.isMultiple());
            if (optional.isPresent()) {
                ModelProperty modelProperty = optional.get();
                extractMetaData(property, modelProperty);
                properties.add(modelProperty);
            }
        }
    });
    return properties;
}
Also used : ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ArrayList(java.util.ArrayList)

Example 13 with ModelProperty

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

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

the class AbstractBPMNFormGeneratorServiceTest method checkSimpleVariableForms.

protected void checkSimpleVariableForms() {
    List<ModelProperty> properties = new ArrayList<>();
    properties.add(new ModelPropertyImpl(TEXT_VARIABLE, new TypeInfoImpl(String.class.getName())));
    properties.add(new ModelPropertyImpl(INTEGER_VARIABLE, new TypeInfoImpl(Integer.class.getName())));
    properties.add(new ModelPropertyImpl(DOUBLE_VARIABLE, new TypeInfoImpl(Double.class.getName())));
    properties.add(new ModelPropertyImpl(BOOLEAN_VARIABLE, new TypeInfoImpl(Boolean.class.getName())));
    properties.add(new ModelPropertyImpl(DATE_VARIABLE, new TypeInfoImpl(Date.class.getName())));
    BusinessProcessFormModel model = new BusinessProcessFormModel(PROCESS_ID, PROCESS_ID, properties);
    FormGenerationResult result = service.generateForms(model, source);
    assertNotNull(result);
    assertNotNull(result.getRootForm());
    assertTrue(result.getNestedForms().isEmpty());
    checkRootForm(model, result, properties);
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ArrayList(java.util.ArrayList) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Date(java.util.Date)

Example 15 with ModelProperty

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

the class AbstractBPMNFormGeneratorServiceTest method launchNestedFormsTest.

protected FormGenerationResult launchNestedFormsTest() {
    List<ModelProperty> variableList = new ArrayList<>();
    variableList.add(new ModelPropertyImpl(EXPENSE_VARIABLE, new TypeInfoImpl(TypeKind.OBJECT, Expense.class.getName(), false)));
    variableList.add(new ModelPropertyImpl(TEXT_VARIABLE, new TypeInfoImpl(String.class.getName())));
    BusinessProcessFormModel model = new BusinessProcessFormModel(PROCESS_ID, PROCESS_ID, variableList);
    FormGenerationResult result = service.generateForms(model, source);
    assertNotNull(result);
    assertNotNull(result.getRootForm());
    checkRootForm(model, result, variableList);
    return result;
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) Expense(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Expense) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ArrayList(java.util.ArrayList) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl)

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