Search in sources :

Example 1 with TypeInfo

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

the class DataObjectFormModelHandlerTest method checkCommonProperties.

private FieldDefinition checkCommonProperties(String dataFieldName) {
    ObjectProperty dataField = dataObject.getProperty(dataFieldName);
    FieldDefinition formField = fieldManager.getDefinitionByModelProperty(formModel.getProperty(dataFieldName));
    String dataFieldClassName = dataField.getClassName();
    TypeInfo fieldTypeInfo = formField.getFieldTypeInfo();
    // test common properties
    assertEquals(dataFieldClassName, fieldTypeInfo.getClassName());
    assertNotEquals(TypeKind.ENUM, fieldTypeInfo.getType());
    assertEquals(dataField.isMultiple(), fieldTypeInfo.isMultiple());
    assertEquals(dataField.getName().toLowerCase(), formField.getLabel().toLowerCase());
    assertEquals(dataField.getName(), formField.getBinding());
    assertEquals(dataFieldClassName, formField.getStandaloneClassName());
    assertFalse(formField.getReadOnly());
    assertFalse(formField.getRequired());
    assertTrue(formField.getValidateOnChange());
    // test interface specific properties
    if (formField instanceof HasPlaceHolder) {
        assertEquals(dataField.getName().toLowerCase(), ((HasPlaceHolder) formField).getPlaceHolder().toLowerCase());
    }
    if (formField instanceof HasMaxLength) {
        long maxLength = ((HasMaxLength) formField).getMaxLength();
        assertTrue(formField instanceof CharacterBoxFieldDefinition ? maxLength == 1 : maxLength == 100);
    }
    return formField;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) HasMaxLength(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasMaxLength) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) 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) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) 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) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo)

Example 2 with TypeInfo

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

the class FormDefinitionSerializerImpl method deserialize.

@Override
public FormDefinition deserialize(String serializedForm) {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(FormModel.class, formModelSerializer);
    builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer);
    builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class));
    builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class));
    builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class));
    builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> {
        JsonObject jsonField = json.getAsJsonObject();
        JsonElement jsonName = jsonField.get("name");
        return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString()));
    });
    Gson gson = builder.create();
    return gson.fromJson(serializedForm, FormDefinition.class);
}
Also used : JsonObject(com.google.gson.JsonObject) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) GsonBuilder(com.google.gson.GsonBuilder) MetaDataEntryManager(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryManager) Inject(javax.inject.Inject) JsonElement(com.google.gson.JsonElement) FormModel(org.kie.workbench.common.forms.model.FormModel) Dependent(javax.enterprise.context.Dependent) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) Gson(com.google.gson.Gson) JsonDeserializer(com.google.gson.JsonDeserializer) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry) ModelMetaDataImpl(org.kie.workbench.common.forms.model.impl.meta.ModelMetaDataImpl) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) ModelMetaData(org.kie.workbench.common.forms.model.ModelMetaData) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 3 with TypeInfo

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

the class FieldManagerTest method testGettingAllMultipleProvidersDefinitions.

@Test
public void testGettingAllMultipleProvidersDefinitions() {
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicMultipleTypeProviders()) {
        for (String className : provider.getSupportedTypes()) {
            TypeInfo typeInfo = new TypeInfoImpl(TypeKind.BASE, className, true);
            FieldDefinition fieldDefinition = fieldManager.getFieldFromProvider(provider.getFieldTypeName(), typeInfo);
            Assertions.assertThat(fieldDefinition).isNotNull();
        }
    }
}
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) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Test(org.junit.Test)

Example 4 with TypeInfo

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

the class FieldManagerTest method testGettingAllProvidersDefinitions.

@Test
public void testGettingAllProvidersDefinitions() {
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
        for (String className : provider.getSupportedTypes()) {
            try {
                Class clazz = Class.forName(className);
                TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
                FieldDefinition fieldDefinition = fieldManager.getFieldFromProvider(provider.getFieldTypeName(), typeInfo);
                Assertions.assertThat(fieldDefinition).isNotNull();
            } catch (ClassNotFoundException e) {
            // swallow error caused by looking up simple types
            }
        }
    }
}
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) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Test(org.junit.Test)

Example 5 with TypeInfo

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

TypeInfo (org.kie.workbench.common.forms.model.TypeInfo)7 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)6 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)6 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)4 Test (org.junit.Test)3 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)3 BasicTypeFieldProvider (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider)2 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)2 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonDeserializer (com.google.gson.JsonDeserializer)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 HasMaxLength (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasMaxLength)1