use of net.jazdw.rql.parser.RQLParser in project mica2 by obiba.
the class RQLCriteriaOpalConverter method parse.
public void parse(String rqlQuery) {
RQLParser parser = new RQLParser();
ASTNode queryNode = parser.parse(rqlQuery);
parseNode(queryNode);
}
use of net.jazdw.rql.parser.RQLParser 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.RQLParser in project ma-modules-public by infiniteautomation.
the class WatchlistSqlVisitorTest method testRQL.
@Test
public void testRQL() throws IOException {
// Create a User
User user = new User();
user.setUsername("test");
user.setName("test");
user.setEmail("test@test.com");
user.setPassword("usernametest");
user.setPermissions("user,test,permission1");
validate(user);
UserDao.instance.saveUser(user);
// Insert some watchlists
for (int i = 0; i < 120; i++) {
WatchListVO wl = new WatchListVO();
wl.setXid(WatchListDao.instance.generateUniqueXid());
wl.setName("Watchilst " + i);
wl.setUserId(user.getId());
wl.setReadPermission("permission1");
WatchListDao.instance.saveWatchList(wl);
}
String rql = "limit(100,0)";
RQLParser parser = new RQLParser();
ASTNode root = null;
ASTNode queryNode = parser.parse(rql);
// Combine the existing query with an AND node
if (queryNode == null) {
root = new ASTNode("eq", "userId", user.getId());
} else {
// Filter by Permissions
Set<String> permissions = Permissions.explodePermissionGroups(user.getPermissions());
ASTNode permRQL = new ASTNode("in", "readPermission", permissions);
root = new ASTNode("or", new ASTNode("eq", "userId", user.getId()), permRQL, queryNode);
}
final AtomicLong selectCounter = new AtomicLong();
final AtomicLong countValue = new AtomicLong();
StreamableRowCallback<WatchListVO> selectCallback = new StreamableRowCallback<WatchListVO>() {
@Override
public void row(WatchListVO row, int index) throws Exception {
selectCounter.incrementAndGet();
}
};
StreamableRowCallback<Long> countCallback = new StreamableRowCallback<Long>() {
@Override
public void row(Long row, int index) throws Exception {
countValue.set(row);
}
};
StreamableSqlQuery<WatchListVO> query = WatchListDao.instance.createQuery(root, selectCallback, countCallback, modelMap, appenders, true);
query.query();
query.count();
assertEquals(100L, selectCounter.get());
assertEquals(120L, countValue.get());
}
use of net.jazdw.rql.parser.RQLParser 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