Search in sources :

Example 11 with QueryDataPageStream

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

the class DataPointSummaryRestController method query.

@ApiOperation(value = "Query Data Points", notes = "", response = DataPointSummary.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 query, HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<DataPointVO>> result = new RestProcessResult<QueryDataPageStream<DataPointVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        DataPointSummaryStreamCallback callback = new DataPointSummaryStreamCallback(this, user);
        return result.createResponseEntity(getPageStream(query, callback));
    }
    return result.createResponseEntity();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) 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) DataPointSummaryStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointSummaryStreamCallback) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with QueryDataPageStream

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

the class DataPointSummaryRestController method queryRQL.

@ApiOperation(value = "Query Data Points", notes = "", response = DataPointSummary.class, responseContainer = "Array")
@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 query = parseRQLtoAST(request.getQueryString());
            DataPointSummaryStreamCallback callback = new DataPointSummaryStreamCallback(this, user);
            return result.createResponseEntity(getPageStream(query, callback));
        } 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) QueryDataPageStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) DataPointSummaryStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointSummaryStreamCallback) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with QueryDataPageStream

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

the class EventsRestController method queryRQL.

@ApiOperation(value = "Query Events", notes = "Query via rql in url", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<EventInstanceVO>> queryRQL(HttpServletRequest request) {
    RestProcessResult<QueryDataPageStream<EventInstanceVO>> result = new RestProcessResult<QueryDataPageStream<EventInstanceVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        try {
            // Parse the RQL Query
            ASTNode query = parseRQLtoAST(request.getQueryString());
            query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
            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) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiOperation (com.wordnik.swagger.annotations.ApiOperation)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)11 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)11 User (com.serotonin.m2m2.vo.User)10 ASTNode (net.jazdw.rql.parser.ASTNode)10 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)8 FilteredPageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream)5 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)2 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)2 DataPointStreamCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointStreamCallback)2 DataPointSummaryStreamCallback (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointSummaryStreamCallback)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 EventDetectorDao (com.serotonin.m2m2.db.dao.EventDetectorDao)1 EventHandlerDao (com.serotonin.m2m2.db.dao.EventHandlerDao)1 UserCommentVO (com.serotonin.m2m2.vo.comment.UserCommentVO)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1