Search in sources :

Example 1 with MetaDataEntry

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

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

the class AbstractFieldManager method getDefinitionByModelProperty.

@Override
public FieldDefinition getDefinitionByModelProperty(ModelProperty modelProperty) {
    FieldTypeEntry fieldTypeEntry = (FieldTypeEntry) modelProperty.getMetaData().getEntry(FieldTypeEntry.NAME);
    FieldDefinition fieldDefinition = null;
    if (fieldTypeEntry != null) {
        fieldDefinition = getFieldFromProvider(fieldTypeEntry.getValue(), modelProperty.getTypeInfo());
    }
    if (fieldDefinition == null) {
        Optional<FieldDefinition> optional = Optional.ofNullable(getDefinitionByDataType(modelProperty.getTypeInfo()));
        if (optional.isPresent()) {
            fieldDefinition = optional.get();
        }
    }
    if (fieldDefinition != null) {
        fieldDefinition.setName(modelProperty.getName());
        fieldDefinition.setBinding(modelProperty.getName());
        String label = modelProperty.getName();
        label = label.substring(0, 1).toUpperCase() + label.substring(1);
        fieldDefinition.setLabel(label);
        fieldDefinition.setStandaloneClassName(modelProperty.getTypeInfo().getClassName());
        if (fieldDefinition instanceof HasPlaceHolder) {
            ((HasPlaceHolder) fieldDefinition).setPlaceHolder(label);
        }
        for (MetaDataEntry entry : modelProperty.getMetaData().getEntries()) {
            MetaDataEntryProcessor processor = metaDataEntryManager.getProcessorForEntry(entry);
            if (processor != null && processor.supports(fieldDefinition)) {
                processor.process(entry, fieldDefinition);
            }
        }
        return fieldDefinition;
    }
    return null;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) 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) MetaDataEntryProcessor(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryProcessor) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 3 with MetaDataEntry

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

the class FormDefinitionGeneratorImplTest method checkTaskFormModel.

private void checkTaskFormModel(TaskFormModel formModel, String taskName, boolean readOnly) {
    Assertions.assertThat(formModel).hasFieldOrPropertyWithValue("processId", PROCESS_ID).hasFieldOrPropertyWithValue("taskName", taskName);
    Assertions.assertThat(formModel.getProperties()).isNotEmpty().hasSize(VARIABLES.size());
    VARIABLES.forEach((key, value) -> {
        ModelProperty property = formModel.getProperty(key);
        assertNotNull(property);
        assertEquals(value, property.getTypeInfo().getClassName());
        MetaDataEntry readOnlyEntry = property.getMetaData().getEntry(FieldReadOnlyEntry.NAME);
        Assertions.assertThat(readOnlyEntry).isNotNull().isInstanceOf(FieldReadOnlyEntry.class).hasFieldOrPropertyWithValue("value", readOnly);
    });
}
Also used : FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Aggregations

MetaDataEntry (org.kie.workbench.common.forms.model.MetaDataEntry)3 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)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 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 HasPlaceHolder (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder)1 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)1 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 FormModel (org.kie.workbench.common.forms.model.FormModel)1 ModelMetaData (org.kie.workbench.common.forms.model.ModelMetaData)1 TypeInfo (org.kie.workbench.common.forms.model.TypeInfo)1 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)1 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)1 ModelMetaDataImpl (org.kie.workbench.common.forms.model.impl.meta.ModelMetaDataImpl)1