Search in sources :

Example 1 with FieldValueProcessor

use of org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor in project kie-wb-common by kiegroup.

the class FormValuesProcessorImpl method readFormValues.

@Override
public Map<String, Object> readFormValues(FormDefinition form, Map<String, Object> rawValues, BackendFormRenderingContext context) {
    final Map<String, Object> result = new HashMap<>();
    rawValues.forEach((String key, final Object value) -> {
        FieldDefinition field = form.getFieldByBinding(key);
        Object fieldValue = value;
        if (field != null) {
            if (value != null) {
                FieldValueProcessor processor = fieldValueProcessors.get(field.getClass());
                if (processor != null) {
                    fieldValue = processor.toFlatValue(field, value, context);
                }
            }
            result.put(key, fieldValue);
        }
    });
    return result;
}
Also used : NestedFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.NestedFormFieldValueProcessor) FieldValueProcessor(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor) HashMap(java.util.HashMap) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 2 with FieldValueProcessor

use of org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor in project kie-wb-common by kiegroup.

the class FormValuesProcessorImpl method writeFormValues.

@Override
public Map<String, Object> writeFormValues(FormDefinition form, Map<String, Object> formValues, Map<String, Object> rawValues, BackendFormRenderingContext context) {
    final Map<String, Object> result = new HashMap<>();
    formValues.forEach((key, value) -> {
        FieldDefinition field = form.getFieldByBinding(key);
        if (field != null) {
            if (value != null) {
                FieldValueProcessor processor = fieldValueProcessors.get(field.getClass());
                if (processor != null) {
                    value = processor.toRawValue(field, value, rawValues.get(key), context);
                }
            }
        }
        result.put(key, value);
    });
    return result;
}
Also used : NestedFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.NestedFormFieldValueProcessor) FieldValueProcessor(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor) HashMap(java.util.HashMap) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 3 with FieldValueProcessor

use of org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor in project kie-wb-common by kiegroup.

the class AbstractBackendFormRenderingContextManagerTest method initTest.

@Before
public void initTest() {
    List<FieldValueProcessor> processors = Arrays.asList(new SubFormFieldValueProcessor(), new MultipleSubFormFieldValueProcessor());
    fieldValueProcessors = mock(Instance.class);
    when(fieldValueProcessors.iterator()).then(proc -> processors.iterator());
    formValuesProcessor = new FormValuesProcessorImpl(fieldValueProcessors);
    contextManager = new BackendFormRenderingContextManagerImpl(formValuesProcessor, new ContextModelConstraintsExtractorImpl());
    formData = generateFormData();
    classLoader = mock(ClassLoader.class);
    long timestamp = contextManager.registerContext(getRootForm(), formData, classLoader, getNestedForms()).getTimestamp();
    context = contextManager.getContext(timestamp);
    assertNotNull("Context cannot be null", context);
}
Also used : FieldValueProcessor(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor) MultipleSubFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.MultipleSubFormFieldValueProcessor) SubFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.SubFormFieldValueProcessor) Instance(javax.enterprise.inject.Instance) MultipleSubFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.MultipleSubFormFieldValueProcessor) SubFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.SubFormFieldValueProcessor) ContextModelConstraintsExtractorImpl(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.impl.ContextModelConstraintsExtractorImpl) MultipleSubFormFieldValueProcessor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.MultipleSubFormFieldValueProcessor) Before(org.junit.Before)

Aggregations

FieldValueProcessor (org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.FieldValueProcessor)3 HashMap (java.util.HashMap)2 NestedFormFieldValueProcessor (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.NestedFormFieldValueProcessor)2 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 Instance (javax.enterprise.inject.Instance)1 Before (org.junit.Before)1 MultipleSubFormFieldValueProcessor (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.MultipleSubFormFieldValueProcessor)1 SubFormFieldValueProcessor (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.fieldProcessors.SubFormFieldValueProcessor)1 ContextModelConstraintsExtractorImpl (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.impl.ContextModelConstraintsExtractorImpl)1