Search in sources :

Example 6 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class PartnerDimBinding method getColumnQuery.

private List<ColumnModel> getColumnQuery(ResourceId formId) {
    SymbolNode partnerField = new SymbolNode(CuidAdapter.field(formId, CuidAdapter.PARTNER_FIELD));
    ColumnModel partnerId = new ColumnModel();
    partnerId.setFormula(partnerField);
    partnerId.setId(PARTNER_ID_COLUMN);
    ColumnModel partnerLabel = new ColumnModel();
    partnerLabel.setFormula(new CompoundExpr(partnerField, new SymbolNode("label")));
    partnerLabel.setId(PARTNER_LABEL_COLUMN);
    return Arrays.asList(partnerId, partnerLabel);
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 7 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class ProjectDimBinding method getTargetColumnQuery.

@Override
public List<ColumnModel> getTargetColumnQuery(ResourceId targetFormId) {
    SymbolNode projectField = new SymbolNode(CuidAdapter.field(targetFormId, CuidAdapter.PROJECT_FIELD));
    ColumnModel projectId = new ColumnModel();
    projectId.setFormula(projectField);
    projectId.setId(PROJECT_ID_COLUMN);
    ColumnModel projectLabel = new ColumnModel();
    projectLabel.setFormula(new CompoundExpr(projectField, new SymbolNode("label")));
    projectLabel.setId(PROJECT_LABEL_COLUMN);
    return Arrays.asList(projectId, projectLabel);
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 8 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class NodeMatcherTest method resolve.

private Collection<String> resolve(String exprString) {
    FormTree tree = tree();
    symbolTable = new NodeMatcher(tree);
    FormulaNode expr = FormulaParser.parse(exprString);
    Collection<NodeMatch> matches;
    if (expr instanceof SymbolNode) {
        matches = symbolTable.resolveSymbol((SymbolNode) expr);
    } else if (expr instanceof CompoundExpr) {
        matches = symbolTable.resolveCompoundExpr((CompoundExpr) expr);
    } else {
        throw new IllegalArgumentException(exprString);
    }
    // Create a string that we can match against easily
    List<String> strings = Lists.newArrayList();
    for (NodeMatch match : matches) {
        strings.add(match.toDebugString());
    }
    System.out.println("Resolved " + exprString + " => " + strings);
    return strings;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree)

Example 9 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class NodeMatch method forEnumItem.

public static NodeMatch forEnumItem(FormTree.Node fieldNode, EnumItem item) {
    NodeMatch match = forField(fieldNode, Optional.<StatFunction>absent());
    match.fieldExpr = new CompoundExpr(match.fieldExpr, new SymbolNode(item.getId()));
    match.enumItem = item;
    return match;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode)

Example 10 with SymbolNode

use of org.activityinfo.model.formula.SymbolNode in project activityinfo by bedatadriven.

the class SiteFormStorage method getPermissions.

@Override
public FormPermissions getPermissions(int userId) {
    if (activity.getOwnerUserId() == userId) {
        return FormPermissions.owner();
    } else {
        UserPermission databasePermission = permissionsCache.getPermission(userId, activity.getDatabaseId());
        FormPermissions.Builder permissions = FormPermissions.builder();
        FormulaNode partnerFilter = Formulas.equals(new SymbolNode(CuidAdapter.partnerField(activity.getId())), new ConstantNode(CuidAdapter.partnerRecordId(databasePermission.getPartnerId()).asString()));
        if (databasePermission.isViewAll()) {
            permissions.allowView();
        } else if (databasePermission.isView()) {
            permissions.allowFilteredView(partnerFilter.asExpression());
        }
        if (databasePermission.isEditAll()) {
            permissions.allowEdit();
        } else if (databasePermission.isEdit()) {
            permissions.allowFilteredEdit(partnerFilter.asExpression());
        }
        if (databasePermission.isDesign()) {
            permissions.allowSchemaUpdate();
        }
        // published property of activity overrides user permissions
        if (activity.isPublished()) {
            permissions.allowUnfilteredView();
        }
        return permissions.build();
    }
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ConstantNode(org.activityinfo.model.formula.ConstantNode) UserPermission(org.activityinfo.store.mysql.metadata.UserPermission)

Aggregations

SymbolNode (org.activityinfo.model.formula.SymbolNode)22 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)12 FormulaNode (org.activityinfo.model.formula.FormulaNode)8 ColumnModel (org.activityinfo.model.query.ColumnModel)6 Test (org.junit.Test)5 FormTree (org.activityinfo.model.formTree.FormTree)4 ResourceId (org.activityinfo.model.resource.ResourceId)3 JoinNode (org.activityinfo.store.query.shared.join.JoinNode)3 ConstantNode (org.activityinfo.model.formula.ConstantNode)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 ColumnView (org.activityinfo.model.query.ColumnView)2 QueryModel (org.activityinfo.model.query.QueryModel)2 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Supplier (com.google.common.base.Supplier)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1