private Optional<ResourceId> findUniqueFieldReference(List<FieldReference> references, FormClass rootFormClass) { Set<ResourceId> rootFields = new HashSet<>(); for (FieldReference reference : references) { switch (reference.getMatch().getType()) { case RECORD_ID: findFormReferenceField(reference, rootFormClass).transform(rootFields::add); break; case FORM_ID: return Optional.absent(); case FIELD: rootFields.add(reference.getMatch().getFieldNode().getPath().getRoot()); break; } } if(rootFields.size() == 1) { return Optional.of(rootFields.iterator().next()); } else { return Optional.absent(); } }
private Slot<ColumnView> addColumn(Collection<NodeMatch> nodes) { // Recursively expand any calculated fields List<Slot<ColumnView>> expandedNodes = Lists.newArrayList(); for (NodeMatch node : nodes) { switch (node.getType()) { case FORM_NAME: case RECORD_ID: case FORM_ID: expandedNodes.add(batch.addColumn(filterLevel, node)); break; case FIELD: if (node.isCalculated()) { expandedNodes.add(expandCalculatedField(node)); } else { expandedNodes.add(batch.addColumn(filterLevel, node)); } break; } } if(expandedNodes.isEmpty()) { return batch.addEmptyColumn(filterLevel, rootFormClass); } else if(expandedNodes.size() == 1) { return expandedNodes.get(0); } else { return new FunctionCallSlot(CoalesceFunction.INSTANCE, expandedNodes); } }
private ColumnPlanNode plan(NodeMatch match) { if(match.isJoined()) { throw new UnsupportedOperationException("TODO: Joins"); } switch (match.getType()) { case RECORD_ID: return new IdFetchOp(match.getFormClass().getId()); case FORM_ID: throw new UnsupportedOperationException("TODO: class"); default: throw new UnsupportedOperationException("type: " + match.getType()); case FIELD: return new ColumnFetchOp(match.getFieldNode().getDefiningFormClass().getId(), match.getFieldNode().getField()); } } }
public String getLabel() { // If this formula is just a field reference if(simpleReference && references.size() == 1) { NodeMatch ref = references.get(0).getMatch(); if(ref.isEnumBoolean()) { return ref.getEnumItem().getLabel(); } else if(ref.getType() == NodeMatch.Type.FIELD) { FormTree.Node field = ref.getFieldNode(); if (field.isRoot()) { return field.getField().getLabel(); } else { return field.getDefiningFormClass().getLabel() + " " + field.getField().getLabel(); } } } return formula; } }
/** * Adds a query to the batch for a column derived from a single node within the FormTree, along * with any necessary join structures required to join this column to the base table, if the column * is nested. * * @return a ColumnView Slot that can be used to retrieve the result after the batch * has finished executing. */ public Slot<ColumnView> addColumn(FilterLevel filterLevel, NodeMatch match) { if (match.isJoined()) { // requires join return addJoinedColumn(filterLevel, match); } else { // form label column, id column, simple root column or embedded form switch (match.getType()) { case FORM_NAME: return addConstantColumn(filterLevel, match.getFormClass(), match.getFormClass().getLabel()); case RECORD_ID: return addRecordIdColumn(filterLevel, match.getFormClass().getId()); case FORM_ID: return addConstantColumn(filterLevel, match.getFormClass(), match.getFormClass().getId().asString()); case FIELD: return getDataColumn(filterLevel, match.getFormClass().getId(), match.getFieldComponent()); default: throw new UnsupportedOperationException("Type: " + match.getType()); } } }