Search in sources :

Example 16 with InvalidRQLRestException

use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.

the class EventsRestController method acknowledgeManyEvents.

@ApiOperation(value = "Acknowledge many existing events", notes = "")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/acknowledge")
public ResponseEntity<EventAcknowledgeQueryStream> acknowledgeManyEvents(@RequestBody(required = false) TranslatableMessageModel message, UriComponentsBuilder builder, HttpServletRequest request) {
    RestProcessResult<EventAcknowledgeQueryStream> result = new RestProcessResult<EventAcknowledgeQueryStream>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        // Parse the RQL Query
        ASTNode query;
        try {
            query = parseRQLtoAST(request.getQueryString());
            query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
            TranslatableMessage tlm = null;
            if (message != null)
                tlm = new TranslatableMessage(message.getKey(), message.getArgs().toArray());
            // Perform the query and stream through acknowledger
            EventAcknowledgeQueryStreamCallback callback = new EventAcknowledgeQueryStreamCallback(user, tlm);
            EventAcknowledgeQueryStream stream = new EventAcknowledgeQueryStream(dao, this, query, callback);
            // Ensure its ready
            stream.setupQuery();
            return result.createResponseEntity(stream);
        } catch (InvalidRQLRestException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
            return result.createResponseEntity();
        }
    }
    // Not logged in
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)16 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)16 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)16 ASTNode (net.jazdw.rql.parser.ASTNode)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 User (com.serotonin.m2m2.vo.User)13 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)8 FilteredPageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredPageQueryStream)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 AuditEventDao (com.serotonin.m2m2.db.dao.AuditEventDao)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 EventHandlerDao (com.serotonin.m2m2.db.dao.EventHandlerDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 UserCommentVO (com.serotonin.m2m2.vo.comment.UserCommentVO)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)1 EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)1 AuditEventInstanceVO (com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)1 WatchListDao (com.serotonin.m2m2.watchlist.WatchListDao)1