use of com.walmartlabs.concord.server.console.CustomFormServiceV1.FormDataDefinition in project concord by walmartlabs.
the class CustomFormServiceV2 method prepareData.
private FormData prepareData(boolean success, boolean processFailed, Form form, Map<String, Object> overrides, boolean skipMissingOverrides, List<ValidationError> errors, UUID processInstanceId) {
// TODO merge with FormResource
Map<String, FormDataDefinition> _definitions = new HashMap<>();
// the order of precedence should be:
// submitted value > form call value > field's default value > environment value
Map<String, Object> _values = new HashMap<>(form.options().extraValues());
Map<String, String> _errors = new HashMap<>();
form.fields().stream().filter(f -> f.defaultValue() != null).forEach(f -> _values.put(f.name(), f.defaultValue()));
List<String> fields = form.fields().stream().map(FormField::name).collect(Collectors.toList());
for (FormField f : form.fields()) {
Object allowedValue = f.allowedValue();
_definitions.put(f.name(), new FormDataDefinition(f.label(), f.type(), convert(f.cardinality()), allowedValue));
Object v = overrides != null ? overrides.get(f.name()) : null;
if (v == null && skipMissingOverrides) {
continue;
}
if (v == null) {
continue;
}
_values.put(f.name(), v);
}
if (errors != null) {
for (ValidationError e : errors) {
_errors.put(e.fieldName(), e.error());
}
}
String submitUrl = String.format(FORM_WIZARD_CONTINUE_URL_TEMPLATE, processInstanceId, form.name());
return new FormData(success, processFailed, submitUrl, fields, _definitions, _values, _errors);
}
Aggregations