private Collection<NodeMatch> unionMatches(QueryPath path, FormTree.Node parentField) { List<NodeMatch> results = Lists.newArrayList(); for (ResourceId childFormId : parentField.getRange()) { Optional<FormClass> childForm = tree.getFormClassIfPresent(childFormId); if(childForm.isPresent()) { Iterable<FormTree.Node> childFields = parentField.getChildren(childFormId); if (path.matches(childForm.get()) && path.peek().equals(ColumnModel.RECORD_ID_SYMBOL)) { results.add(NodeMatch.forId(parentField, childForm.get())); } else if (path.matches(childForm.get()) || path.matches(parentField)) { results.addAll(matchNodes(path.next(), childFields)); } else { // Descend the next level results.addAll(matchNodes(path, childFields)); } } } return results; }
private Optional<NodeMatch> matchEnum(QueryPath queryPath, FormTree.Node field) { if(queryPath.matches(field)) { QueryPath next = queryPath.next(); if(next.isLeaf()) { EnumType type = (EnumType) field.getType(); List<EnumItem> matchingItems = Lists.newArrayList(); for (EnumItem enumItem : type.getValues()) { if(next.head().equals(enumItem.getId().asString()) || next.head().equalsIgnoreCase(enumItem.getLabel()) || next.head().equalsIgnoreCase(enumItem.getCode())) { matchingItems.add(enumItem); } } if(matchingItems.size() == 1) { return Optional.of(NodeMatch.forFieldComponent(field, matchingItems.get(0).getId().asString())); } } } return Optional.absent(); }
/** * Resolves a compound expression like "province.name" to one or more {@code FormTree.Nodes} * * @return a binding to the corresponding {@code FormTree.Node} * * @throws AmbiguousSymbolException if the expression could match multiple nodes in the tree */ public Collection<NodeMatch> resolveCompoundExpr(CompoundExpr expr) { QueryPath queryPath = new QueryPath(expr); // Given an expression like Province.Name, see if we can match the // the first symbol against the root form's id or label if(queryPath.matches(tree.getRootFormClass())) { return matchNodes(queryPath.next(), tree.getRootFields()); } return matchNodes(queryPath, tree.getRootFields()); }