Search in sources :

Example 1 with RQLParserException

use of net.jazdw.rql.parser.RQLParserException in project ma-core-public by infiniteautomation.

the class DataPointEventsByDataPointRQLQueryDefinition method validateImpl.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.module.ModuleQueryDefinition#validateImpl(com.fasterxml.jackson.databind.JsonNode)
     */
@Override
protected void validateImpl(final User user, final JsonNode parameters, final RestValidationResult result) {
    if (parameters.get("rql") == null)
        result.addRequiredError("rql");
    else {
        try {
            JsonNode rqlNode = parameters.get("rql");
            ObjectReader reader = Common.objectMapper.getObjectReader(String.class);
            String rql = reader.readValue(rqlNode);
            if (rql != null && !rql.isEmpty()) {
                RQLParser parser = new RQLParser();
                parser.parse(rql);
            }
        } catch (IOException | RQLParserException | IllegalArgumentException e) {
            result.addInvalidValueError("rql");
        }
    }
}
Also used : RQLParser(net.jazdw.rql.parser.RQLParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) RQLParserException(net.jazdw.rql.parser.RQLParserException) IOException(java.io.IOException)

Example 2 with RQLParserException

use of net.jazdw.rql.parser.RQLParserException in project ma-core-public by infiniteautomation.

the class DataPointEventsByDataPointRQLQueryDefinition method createQuery.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
     */
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
    JsonNode rqlNode = parameters.get("rql");
    ObjectReader reader = Common.objectMapper.getObjectReader(String.class);
    String rql = reader.readValue(rqlNode);
    ASTNode rqlAstNode;
    if (rql == null || rql.isEmpty()) {
        rqlAstNode = new ASTNode("limit", AbstractBasicDao.DEFAULT_LIMIT);
    }
    RQLParser parser = new RQLParser();
    try {
        rqlAstNode = parser.parse(rql);
    } catch (RQLParserException | IllegalArgumentException e) {
        throw new IOException(e.getMessage());
    }
    // Lookup data points by tag
    List<Object> args = new ArrayList<>();
    args.add("typeRef1");
    DataPointDao.instance.rqlQuery(rqlAstNode, new MappedRowCallback<DataPointVO>() {

        @Override
        public void row(DataPointVO dp, int index) {
            if (Permissions.hasDataPointReadPermission(user, dp)) {
                args.add(Integer.toString(dp.getId()));
            }
        }
    });
    // Create Event Query for these Points
    if (args.size() > 0) {
        ASTNode query = new ASTNode("in", args);
        query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
        query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
        return query;
    } else {
        return new ASTNode("limit", 0, 0);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ASTNode(net.jazdw.rql.parser.ASTNode) RQLParser(net.jazdw.rql.parser.RQLParser) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) RQLParserException(net.jazdw.rql.parser.RQLParserException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)2 IOException (java.io.IOException)2 RQLParser (net.jazdw.rql.parser.RQLParser)2 RQLParserException (net.jazdw.rql.parser.RQLParserException)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 ArrayList (java.util.ArrayList)1 ASTNode (net.jazdw.rql.parser.ASTNode)1