use of org.z3950.zing.cql.CQLParser in project okapi by folio-org.
the class CQLUtilTest method reduce.
private String reduce(String input) {
CQLParser parser = new CQLParser(CQLParser.V1POINT2);
try {
CQLRelation rel = new CQLRelation("=");
CQLTermNode source = new CQLTermNode("source", rel, "kb");
CQLNode top = parser.parse(input);
Comparator<CQLTermNode> f = (CQLTermNode n1, CQLTermNode n2) -> n1.getIndex().equals(n2.getIndex()) ? 0 : -1;
CQLNode res = CQLUtil.reducer(top, source, f);
if (res == null) {
return "null";
} else {
return res.toCQL();
}
} catch (Exception ex) {
return "Error: " + ex.getMessage();
}
}
use of org.z3950.zing.cql.CQLParser in project okapi by folio-org.
the class CQLUtilTest method eval.
private boolean eval(String input) {
CQLParser parser = new CQLParser(CQLParser.V1POINT2);
try {
CQLRelation rel = new CQLRelation("=");
CQLTermNode source = new CQLTermNode("source", rel, "kb");
CQLNode top = parser.parse(input);
Comparator<CQLTermNode> f = (CQLTermNode n1, CQLTermNode n2) -> {
if (n1.getIndex().equals(n2.getIndex()) && !n1.getTerm().equals(n2.getTerm())) {
return -1;
}
return 0;
};
return CQLUtil.eval(top, source, f);
} catch (Exception ex) {
return false;
}
}
use of org.z3950.zing.cql.CQLParser in project raml-module-builder by folio-org.
the class CQL2PgJSON method toSql.
/**
* Convert the CQL query into a SQL query and return the WHERE and the ORDER BY clause.
* @param cql the query to convert
* @return SQL query
* @throws QueryValidationException
*/
public SqlSelect toSql(String cql) throws QueryValidationException {
try {
CQLParser parser = new CQLParser();
CQLNode node = parser.parse(cql);
return toSql(node);
} catch (IOException | CQLParseException e) {
throw new QueryValidationException(e);
}
}
use of org.z3950.zing.cql.CQLParser in project raml-module-builder by folio-org.
the class CQL2PgJSON method cql2pgJson.
/**
* Return an SQL WHERE clause for the CQL expression.
* @param cql CQL expression to convert
* @return SQL WHERE clause, without leading "WHERE ", may contain "ORDER BY" clause
* @throws QueryValidationException when parsing or validating cql fails
*
* @deprecated use toSql instead
*/
@Deprecated
public String cql2pgJson(String cql) throws QueryValidationException {
try {
CQLParser parser = new CQLParser();
CQLNode node = parser.parse(cql);
return pg(node);
} catch (IOException | CQLParseException e) {
throw new QueryValidationException(e);
}
}
use of org.z3950.zing.cql.CQLParser 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;
}
}
Aggregations