Search in sources :

Example 1 with FieldValueMarshaller

use of org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller in project kie-wb-common by kiegroup.

the class AbstractBackendFormRenderingContextManagerTest method initTest.

@Before
public void initTest() {
    SubFormFieldValueMarshaller subFormFieldValueMarshaller = new SubFormFieldValueMarshaller();
    MultipleSubFormFieldValueMarshaller multipleSubFormFieldValueMarshaller = new MultipleSubFormFieldValueMarshaller();
    List<FieldValueMarshaller> marshallers = Arrays.asList(subFormFieldValueMarshaller, multipleSubFormFieldValueMarshaller, new DateMultipleInputFieldValueMarshaller(), new DateMultipleSelectorFieldValueMarshaller(), new LocalDateFieldValueMarshaller(), new TextAreaFormFieldValueMarshaller(), new StringMultipleInputValueMarshaller(), new StringMultipleSelectorValueMarshaller());
    marshallersInstance = mock(Instance.class);
    when(marshallersInstance.iterator()).then(proc -> marshallers.iterator());
    registry = new FieldValueMarshallerRegistryImpl(marshallersInstance);
    subFormFieldValueMarshaller.setRegistry(registry);
    multipleSubFormFieldValueMarshaller.setRegistry(registry);
    contextManager = new BackendFormRenderingContextManagerImpl(registry, 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 : FieldValueMarshallerRegistryImpl(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshallerRegistryImpl) SubFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.models.SubFormFieldValueMarshaller) MultipleSubFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.models.MultipleSubFormFieldValueMarshaller) StringMultipleInputValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.lists.StringMultipleInputValueMarshaller) Instance(javax.enterprise.inject.Instance) TextAreaFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.TextAreaFormFieldValueMarshaller) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller) DateMultipleSelectorFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.DateMultipleSelectorFieldValueMarshaller) LocalDateFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.LocalDateFieldValueMarshaller) SubFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.models.SubFormFieldValueMarshaller) DateMultipleInputFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.DateMultipleInputFieldValueMarshaller) MultipleSubFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.models.MultipleSubFormFieldValueMarshaller) StringMultipleSelectorValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.lists.StringMultipleSelectorValueMarshaller) TextAreaFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.TextAreaFormFieldValueMarshaller) DateMultipleSelectorFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.DateMultipleSelectorFieldValueMarshaller) LocalDateFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.LocalDateFieldValueMarshaller) MultipleSubFormFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.models.MultipleSubFormFieldValueMarshaller) ContextModelConstraintsExtractorImpl(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.impl.ContextModelConstraintsExtractorImpl) DateMultipleInputFieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.time.DateMultipleInputFieldValueMarshaller) Before(org.junit.Before)

Example 2 with FieldValueMarshaller

use of org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller in project kie-wb-common by kiegroup.

the class BackendFormRenderingContextManagerImpl method registerContext.

@Override
public BackendFormRenderingContext registerContext(FormDefinition rootForm, Map<String, Object> formData, ClassLoader classLoader, Map<String, String> params, FormDefinition... nestedForms) {
    MapModelRenderingContext clientRenderingContext = new MapModelRenderingContext(String.valueOf(System.currentTimeMillis()));
    clientRenderingContext.setRootForm(rootForm);
    Arrays.stream(nestedForms).forEach(form -> clientRenderingContext.getAvailableForms().put(form.getId(), form));
    BackendFormRenderingContextImpl context = new BackendFormRenderingContextImpl(System.currentTimeMillis(), clientRenderingContext, formData, classLoader, params);
    Map<String, Object> clientFormData = new HashMap<>();
    rootForm.getFields().stream().filter(fieldDefinition -> !StringUtils.isEmpty(fieldDefinition.getBinding())).forEach(fieldDefinition -> {
        Object value = formData.get(fieldDefinition.getBinding());
        FieldValueMarshaller marshaller = registry.getMarshaller(fieldDefinition);
        if (marshaller != null) {
            marshaller.init(value, fieldDefinition, rootForm, context);
            context.getRootFormMarshallers().put(fieldDefinition.getBinding(), marshaller);
            value = marshaller.toFlatValue();
        }
        clientFormData.put(fieldDefinition.getBinding(), value);
    });
    constraintsExtractor.readModelConstraints(clientRenderingContext, classLoader);
    clientRenderingContext.setModel(clientFormData);
    contexts.put(context.getTimestamp(), context);
    return context;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FieldValueMarshallerRegistry(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshallerRegistry) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SessionScoped(javax.enterprise.context.SessionScoped) StringUtils(org.apache.commons.lang3.StringUtils) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller) Inject(javax.inject.Inject) MapModelRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext) ContextModelConstraintsExtractor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.ContextModelConstraintsExtractor) Map(java.util.Map) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) BackendFormRenderingContextManager(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContextManager) BackendFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContext) HashMap(java.util.HashMap) MapModelRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller)

Example 3 with FieldValueMarshaller

use of org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller in project kie-wb-common by kiegroup.

the class BackendFormRenderingContextManagerImpl method updateContextData.

@Override
public BackendFormRenderingContext updateContextData(long timestamp, Map<String, Object> formValues) {
    BackendFormRenderingContextImpl context = contexts.get(timestamp);
    if (context == null) {
        throw new IllegalArgumentException("Unable to find context with id '" + timestamp + "'");
    }
    FormDefinition rootForm = context.getRenderingContext().getRootForm();
    Map<String, Object> contextData = new HashMap<>();
    rootForm.getFields().stream().filter(fieldDefinition -> !StringUtils.isEmpty(fieldDefinition.getBinding())).forEach(fieldDefinition -> {
        Object value = formValues.get(fieldDefinition.getBinding());
        FieldValueMarshaller marshaller = context.getRootFormMarshallers().get(fieldDefinition.getBinding());
        if (marshaller != null) {
            value = marshaller.toRawValue(value);
        }
        contextData.put(fieldDefinition.getBinding(), value);
    });
    context.setFormData(contextData);
    return context;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FieldValueMarshallerRegistry(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshallerRegistry) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SessionScoped(javax.enterprise.context.SessionScoped) StringUtils(org.apache.commons.lang3.StringUtils) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller) Inject(javax.inject.Inject) MapModelRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext) ContextModelConstraintsExtractor(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.ContextModelConstraintsExtractor) Map(java.util.Map) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) BackendFormRenderingContextManager(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContextManager) BackendFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContext) HashMap(java.util.HashMap) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller)

Example 4 with FieldValueMarshaller

use of org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller in project kie-wb-common by kiegroup.

the class ModelMarshaller method toFlatValue.

public Map<String, Object> toFlatValue() {
    Map<String, Object> result = new HashMap<>();
    if (model != null) {
        iterateFormFields(fieldDefinition -> {
            String binding = fieldDefinition.getBinding();
            FieldValueMarshaller marshaller = marshallers.get(binding);
            if (marshaller != null) {
                result.put(binding, marshaller.toFlatValue());
            } else {
                result.put(binding, readValue(binding));
            }
        });
    }
    return result;
}
Also used : HashMap(java.util.HashMap) FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller)

Example 5 with FieldValueMarshaller

use of org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller in project kie-wb-common by kiegroup.

the class ModelMarshaller method registerMarshaller.

private void registerMarshaller(FieldDefinition field) {
    FieldValueMarshaller marshaller = registry.getMarshaller(field);
    if (marshaller != null) {
        marshaller.init(readValue(field.getBinding()), field, formDefinition, context);
        marshallers.put(field.getBinding(), marshaller);
    }
}
Also used : FieldValueMarshaller(org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller)

Aggregations

FieldValueMarshaller (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshaller)6 HashMap (java.util.HashMap)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 SessionScoped (javax.enterprise.context.SessionScoped)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang3.StringUtils)2 FieldValueMarshallerRegistry (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshallerRegistry)2 ContextModelConstraintsExtractor (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.validation.ContextModelConstraintsExtractor)2 BackendFormRenderingContext (org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContext)2 BackendFormRenderingContextManager (org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContextManager)2 MapModelRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext)2 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Instance (javax.enterprise.inject.Instance)1 Before (org.junit.Before)1 FieldValueMarshallerRegistryImpl (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.FieldValueMarshallerRegistryImpl)1 TextAreaFormFieldValueMarshaller (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.TextAreaFormFieldValueMarshaller)1 StringMultipleInputValueMarshaller (org.kie.workbench.common.forms.dynamic.backend.server.context.generation.dynamic.impl.marshalling.lists.StringMultipleInputValueMarshaller)1