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