Search in sources :

Example 1 with WatchListSummaryModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListSummaryModel 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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) WatchListDao(com.serotonin.m2m2.watchlist.WatchListDao) WatchListSummaryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListSummaryModel) ASTNode(net.jazdw.rql.parser.ASTNode) FilteredPageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 User (com.serotonin.m2m2.vo.User)1 WatchListDao (com.serotonin.m2m2.watchlist.WatchListDao)1 WatchListVO (com.serotonin.m2m2.watchlist.WatchListVO)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 FilteredPageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream)1 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)1 WatchListSummaryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListSummaryModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)1 ASTNode (net.jazdw.rql.parser.ASTNode)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1