Search in sources :

Example 1 with FilteredPageQueryStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream 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)

Example 2 with FilteredPageQueryStream

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

Example 3 with FilteredPageQueryStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream in project ma-modules-public by infiniteautomation.

the class DataPointRestController method query.

@ApiOperation(value = "Query Data Points", notes = "", response = DataPointModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/query")
public ResponseEntity<QueryDataPageStream<DataPointVO>> query(@ApiParam(value = "Query", required = true) @RequestBody(required = true) ASTNode root, HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<DataPointVO>> result = new RestProcessResult<QueryDataPageStream<DataPointVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        // We are going to filter the results, so we need to strip out the limit(limit,offset) or limit(limit) clause.
        DataPointStreamCallback callback = new DataPointStreamCallback(this, user);
        if (!user.isAdmin()) {
            // Limit our results based on the fact that our permissions should be in the permissions strings
            root = addPermissionsFilter(root, user);
            FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao> stream = new FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao>(DataPointDao.instance, this, root, callback);
            stream.setupQuery();
            return result.createResponseEntity(stream);
        } else {
            // Admin Users Don't need to filter the results
            return result.createResponseEntity(getPageStream(root));
        }
    }
    return result.createResponseEntity();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) DataPointStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointStreamCallback) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) DataPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) FilteredPageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with FilteredPageQueryStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream in project ma-modules-public by infiniteautomation.

the class EventDetectorRestV2Controller method queryRQL.

@ApiOperation(value = "Query Event Detectors", notes = "Use RQL formatted query, filtered by data point permissions", response = AbstractEventDetectorModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<QueryDataPageStream<AbstractEventDetectorVO<?>>> queryRQL(@AuthenticationPrincipal User user, HttpServletRequest request) {
    ASTNode node = parseRQLtoAST(request.getQueryString());
    if (user.isAdmin()) {
        // admin users don't need to filter the results
        return new ResponseEntity<>(getPageStream(node), HttpStatus.OK);
    } else {
        EventDetectorStreamCallback callback = new EventDetectorStreamCallback(this, user);
        FilteredPageQueryStream<AbstractEventDetectorVO<?>, AbstractEventDetectorModel<?>, EventDetectorDao> stream = new FilteredPageQueryStream<AbstractEventDetectorVO<?>, AbstractEventDetectorModel<?>, EventDetectorDao>(EventDetectorDao.instance, this, node, callback);
        stream.setupQuery();
        return new ResponseEntity<>(stream, HttpStatus.OK);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) EventDetectorStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.eventDetector.EventDetectorStreamCallback) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) ASTNode(net.jazdw.rql.parser.ASTNode) AbstractEventDetectorModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel) EventDetectorDao(com.serotonin.m2m2.db.dao.EventDetectorDao) FilteredPageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with FilteredPageQueryStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream in project ma-modules-public by infiniteautomation.

the class EventHandlerRestController method queryRQL.

@ApiOperation(value = "Query Event Handlers", notes = "Use RQL formatted query", response = AbstractEventHandlerModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<AbstractEventHandlerVO<?>>> queryRQL(HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<AbstractEventHandlerVO<?>>> result = new RestProcessResult<QueryDataPageStream<AbstractEventHandlerVO<?>>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        try {
            ASTNode node = parseRQLtoAST(request.getQueryString());
            EventHandlerStreamCallback callback = new EventHandlerStreamCallback(this, user);
            FilteredPageQueryStream<AbstractEventHandlerVO<?>, AbstractEventHandlerModel<?>, EventHandlerDao> stream = new FilteredPageQueryStream<AbstractEventHandlerVO<?>, AbstractEventHandlerModel<?>, EventHandlerDao>(EventHandlerDao.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();
}
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) AbstractEventHandlerModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.handlers.AbstractEventHandlerModel) ASTNode(net.jazdw.rql.parser.ASTNode) EventHandlerStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.eventHandler.EventHandlerStreamCallback) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) EventHandlerDao(com.serotonin.m2m2.db.dao.EventHandlerDao) FilteredPageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FilteredPageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 User (com.serotonin.m2m2.vo.User)4 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)4 ASTNode (net.jazdw.rql.parser.ASTNode)4 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)3 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)2 DataPointStreamCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointStreamCallback)2 EventDetectorDao (com.serotonin.m2m2.db.dao.EventDetectorDao)1 EventHandlerDao (com.serotonin.m2m2.db.dao.EventHandlerDao)1 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)1 AbstractEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO)1 WatchListDao (com.serotonin.m2m2.watchlist.WatchListDao)1 WatchListVO (com.serotonin.m2m2.watchlist.WatchListVO)1 WatchListSummaryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListSummaryModel)1 EventDetectorStreamCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.eventDetector.EventDetectorStreamCallback)1