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;
}
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);
}
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();
}
}
}
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
}
}
}
}
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;
}
Aggregations