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");
}
}
}
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);
}
}
Aggregations