protected Set<String> collectFieldIds(List<FormField> fields) { Set<String> fieldIds = new HashSet<>(); for (FormField field : fields) { if (field.getId() != null) { fieldIds.add(field.getId()); } } return fieldIds; }
public void parse(Form form, WorkflowParser parser) { this.form = form; if (form != null && form.getFields() != null && !form.getFields().isEmpty()) { int index = 0; Set<String> fieldIds = collectFieldIds(form.getFields()); for (FormField field : form.getFields()) { parser.pushContext("fields", field, null, index); Binding binding = field.getBinding(); if (binding != null) { BindingImpl bindingImpl = parser.parseBinding(binding, "binding"); if (!field.isReadOnly() && (bindingImpl.expression == null || bindingImpl.expression.fields != null)) { parser.addWarning( "Writable form fields should have an expression containing a variable id"); } else { String variableId = null; if (bindingImpl != null) { ExpressionImpl expression = bindingImpl.expression; if (!field.isReadOnly() && expression != null && expression.fields != null) { parser.addWarning( "Writable form fields can only specify variables, not fields inside variables"); } if (field.getType() == null && expression.type != null) { field.setType(expression.type.serialize()); } if (field.getName() == null && expression != null && expression.fields == null) { ScopeImpl scope = parser.getCurrentScope(); VariableImpl variableImpl = scope.findVariableByIdRecursive(bindingImpl.expression.variableId); if (variableImpl != null) { variableId = variableImpl.id; field.setName(variableImpl.variable.getName()); } } } String fieldId = field.getId(); if (fieldId == null) { fieldId = generateFieldId(fieldIds, variableId); field.setId(fieldId); fieldIds.add(fieldId); } addBinding(field, bindingImpl); } } parser.popContext(); index++; } } }
public void addBinding(FormField formField, BindingImpl binding) { if (formFieldBindings == null) { formFieldBindings = new HashMap<>(); } formFieldBindings.put(formField.getId(), new FormFieldBinding(formField, binding)); }