use of org.kie.workbench.common.forms.dynamic.service.context.generation.dynamic.BackendFormRenderingContext 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.service.context.generation.dynamic.BackendFormRenderingContext 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;
}
Aggregations