use of com.walmartlabs.concord.forms.FormField in project concord by walmartlabs.
the class FormResourceV2 method get.
/**
* Return the current state of a form instance.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public FormInstanceEntry get(UUID processInstanceId, String formName) {
PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
Form form = formService.get(processKey, formName);
if (form == null) {
throw new ConcordApplicationException("Form " + formName + " not found. Process ID: " + processKey, Status.NOT_FOUND);
}
List<FormInstanceEntry.Field> fields = new ArrayList<>();
for (FormField f : form.fields()) {
String fieldName = f.name();
FormInstanceEntry.Cardinality c = map(f.cardinality());
String type = f.type();
Serializable value = f.defaultValue();
Serializable allowedValue = f.allowedValue();
Map options = f.options();
fields.add(new FormInstanceEntry.Field(fieldName, f.label(), type, c, value, allowedValue, options));
}
String name = form.name();
boolean yield = form.options().yield();
String resourcePath = FORMS_RESOURCES_PATH + "/" + name;
boolean isCustomForm = formService.exists(processKey, resourcePath);
return new FormInstanceEntry(processInstanceId.toString(), name, fields, isCustomForm, yield);
}
use of com.walmartlabs.concord.forms.FormField 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