Search in sources :

Example 1 with MapModelRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext 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 2 with MapModelRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext in project kie-wb-common by kiegroup.

the class MapModelBindingHelperTest method init.

@Before
public void init() {
    helper = new MapModelBindingHelper() {

        @Override
        protected void lookupPropertyGenerators() {
        // avoiding errai CDI lookup
        }
    };
    helper.initialize();
    context = new MapModelRenderingContext("");
    context.setRootForm(employeeForm);
    context.getAvailableForms().put(addressForm.getId(), addressForm);
}
Also used : MapModelRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext) Before(org.junit.Before)

Example 3 with MapModelRenderingContext

use of org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext in project kie-wb-common by kiegroup.

the class PreviewFormPresenter method preview.

public void preview(FormRenderingContext context) {
    MapModelRenderingContext mapContext = new MapModelRenderingContext("edit");
    mapContext.getAvailableForms().putAll(context.getAvailableForms());
    mapContext.setRootForm(context.getRootForm());
    mapContext.setModel(new HashMap<>());
    view.preview(mapContext);
}
Also used : MapModelRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext)

Aggregations

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