use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class WatchListRestController method queryRQL.
@ApiOperation(value = "Query WatchLists", notes = "", response = WatchListSummaryModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = WatchListSummaryModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<WatchListVO>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<WatchListVO>> result = new RestProcessResult<QueryDataPageStream<WatchListVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
ASTNode query = parseRQLtoAST(request.getQueryString());
if (!user.isAdmin()) {
// We are going to filter the results, so we need to strip out the limit(limit,offset) or limit(limit) clause.
WatchListStreamCallback callback = new WatchListStreamCallback(this, user);
FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao> stream = new FilteredPageQueryStream<WatchListVO, WatchListSummaryModel, WatchListDao>(WatchListDao.instance, this, query, callback);
stream.setupQuery();
return result.createResponseEntity(stream);
} else
return result.createResponseEntity(getPageStream(query));
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class LoggingRestController method query.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Query ma.log logs", notes = "Returns a list of recent logs, ie. /by-filename/ma.log?limit(10)\n" + "<br>Query Examples: \n" + "by-filename/ma.log/?level=gt=DEBUG\n" + "by-filename/ma.log/?thread=qtp-1\n" + "by-filename/ma.log/?message=setPointValue\n" + "NOTE: Querying non ma.log files is not supported.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/by-filename/{filename}")
public ResponseEntity<QueryArrayStream<?>> query(@PathVariable String filename, HttpServletRequest request) {
RestProcessResult<QueryArrayStream<?>> result = new RestProcessResult<QueryArrayStream<?>>(HttpStatus.OK);
try {
ASTNode query = parseRQLtoAST(request.getQueryString());
File file = new File(Common.getLogsDir(), filename);
if (file.exists()) {
// Pattern pattern = new
if (filename.matches(LogQueryArrayStream.LOGFILE_REGEX)) {
LogQueryArrayStream stream = new LogQueryArrayStream(filename, query);
return result.createResponseEntity(stream);
} else {
throw new AccessDeniedException("Non ma.log files are not accessible on this endpoint.");
}
} else {
result.addRestMessage(getDoesNotExistMessage());
}
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkApplyReadPermissions.
@ApiOperation(value = "Bulk Update Read Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-apply-read-permissions")
public ResponseEntity<Long> bulkApplyReadPermissions(@ApiParam(value = "Permissions", required = true) @RequestBody(required = true) String permissions, HttpServletRequest request) {
RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (!user.isAdmin()) {
LOG.warn("User " + user.getUsername() + " attempted to set bulk permissions");
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
long changed = this.dao.bulkUpdatePermissions(node, permissions, false);
return result.createResponseEntity(changed);
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method queryRQL.
@ApiOperation(value = "Query Data Points", notes = "Use RQL formatted query", response = DataPointModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<DataPointVO>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<DataPointVO>> result = new RestProcessResult<QueryDataPageStream<DataPointVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
if (user.isAdmin()) {
// Admin Users Don't need to filter the results
return result.createResponseEntity(getPageStream(node));
} else {
// Limit our results based on the fact that our permissions should be in the permissions strings
node = addPermissionsFilter(node, user);
DataPointStreamCallback callback = new DataPointStreamCallback(this, user);
FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao> stream = new FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao>(DataPointDao.instance, this, node, callback);
stream.setupQuery();
return result.createResponseEntity(stream);
}
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class ServerRestController method queryTimezone.
@ApiOperation(value = "Query Timezones", notes = "", response = TimezoneModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/timezones")
public ResponseEntity<PageQueryResultModel<TimezoneModel>> queryTimezone(HttpServletRequest request) {
RestProcessResult<PageQueryResultModel<TimezoneModel>> result = new RestProcessResult<PageQueryResultModel<TimezoneModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
try {
// Parse the RQL Query
ASTNode root = parseRQLtoAST(request.getQueryString());
List<TimezoneModel> list = root.accept(new RQLToObjectListQuery<TimezoneModel>(), allTimezones);
PageQueryResultModel<TimezoneModel> model = new PageQueryResultModel<TimezoneModel>(list, allTimezones.size() + 1);
return result.createResponseEntity(model);
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations