Search in sources :

Example 6 with CQLNode

use of org.z3950.zing.cql.CQLNode in project okapi by folio-org.

the class CQLUtil method reduceBoolean.

private static CQLNode reduceBoolean(CQLBooleanNode n1, CQLTermNode tn, Comparator<CQLTermNode> cmp) {
    CQLNode n2 = null;
    CQLNode left = reducer(n1.getLeftOperand(), tn, cmp);
    CQLNode right = reducer(n1.getRightOperand(), tn, cmp);
    ModifierSet mSet = new ModifierSet(n1.getOperator().toString().toLowerCase());
    List<Modifier> mods = n1.getModifiers();
    for (Modifier m : mods) {
        mSet.addModifier(m.getType(), m.getComparison(), m.getValue());
    }
    if (left == null) {
        n2 = right;
    } else if (right == null) {
        n2 = left;
    }
    switch(n1.getOperator()) {
        case AND:
            if (left != null && right != null) {
                n2 = new CQLAndNode(left, right, mSet);
            }
            break;
        case OR:
            if (left != null && right != null) {
                n2 = new CQLOrNode(left, right, mSet);
            }
            break;
        case NOT:
            if (left != null && right != null) {
                n2 = new CQLNotNode(left, right, mSet);
            }
            break;
        case PROX:
            if (left != null && right != null) {
                n2 = new CQLProxNode(left, right, mSet);
            }
            break;
    }
    return n2;
}
Also used : CQLAndNode(org.z3950.zing.cql.CQLAndNode) CQLNotNode(org.z3950.zing.cql.CQLNotNode) CQLProxNode(org.z3950.zing.cql.CQLProxNode) Modifier(org.z3950.zing.cql.Modifier) CQLNode(org.z3950.zing.cql.CQLNode) ModifierSet(org.z3950.zing.cql.ModifierSet) CQLOrNode(org.z3950.zing.cql.CQLOrNode)

Example 7 with CQLNode

use of org.z3950.zing.cql.CQLNode in project raml-module-builder by folio-org.

the class PgUtil method getSortNode.

/**
 * Return the sort node from the sortBy clause of the cql query, or null if no
 * sortBy clause exists or cql is invalid.
 * @param cql  the CQL query to parse
 * @return sort node, or null
 */
static CQLSortNode getSortNode(String cql) {
    try {
        CQLParser parser = new CQLParser();
        CQLNode node = parser.parse(cql);
        return getSortNode(node);
    } catch (IOException | CQLParseException | NullPointerException e) {
        return null;
    }
}
Also used : IOException(java.io.IOException) CQLParser(org.z3950.zing.cql.CQLParser) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLNode(org.z3950.zing.cql.CQLNode)

Aggregations

CQLNode (org.z3950.zing.cql.CQLNode)7 CQLParser (org.z3950.zing.cql.CQLParser)5 IOException (java.io.IOException)3 CQLParseException (org.z3950.zing.cql.CQLParseException)3 CQLTermNode (org.z3950.zing.cql.CQLTermNode)3 QueryValidationException (org.folio.cql2pgjson.exception.QueryValidationException)2 CQLRelation (org.z3950.zing.cql.CQLRelation)2 ModifierSet (org.z3950.zing.cql.ModifierSet)2 CQLAndNode (org.z3950.zing.cql.CQLAndNode)1 CQLBooleanNode (org.z3950.zing.cql.CQLBooleanNode)1 CQLNotNode (org.z3950.zing.cql.CQLNotNode)1 CQLOrNode (org.z3950.zing.cql.CQLOrNode)1 CQLPrefix (org.z3950.zing.cql.CQLPrefix)1 CQLPrefixNode (org.z3950.zing.cql.CQLPrefixNode)1 CQLProxNode (org.z3950.zing.cql.CQLProxNode)1 CQLSortNode (org.z3950.zing.cql.CQLSortNode)1 Modifier (org.z3950.zing.cql.Modifier)1