Search in sources :

Example 6 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-modules-public by infiniteautomation.

the class EventsRestController method getAll.

@ApiOperation(value = "Get all events", notes = "", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/list")
public ResponseEntity<QueryArrayStream<EventInstanceVO>> getAll(HttpServletRequest request, @RequestParam(value = "limit", required = false, defaultValue = "100") Integer limit) {
    RestProcessResult<QueryArrayStream<EventInstanceVO>> result = new RestProcessResult<QueryArrayStream<EventInstanceVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ASTNode root = new ASTNode("and", new ASTNode("eq", "userId", user.getId()), new ASTNode("limit", limit));
        return result.createResponseEntity(getPageStream(root));
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) User(com.serotonin.m2m2.vo.User) ASTNode(net.jazdw.rql.parser.ASTNode) QueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO 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)

Example 8 with EventInstanceVO

use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.

the class EventExportServlet method exportExcel.

/**
 * @param response
 * @param def
 * @param user
 * @throws IOException
 */
private void exportExcel(HttpServletResponse response, User user) throws IOException {
    // Stream the content.
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    final EventInstanceEmporter sheetEmporter = new EventInstanceEmporter();
    final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    emporter.prepareExport(bos);
    emporter.prepareSheetExport(sheetEmporter);
    QueryDefinition queryData = (QueryDefinition) user.getAttribute("eventInstanceExportDefinition");
    DojoQueryCallback<EventInstanceVO> callback = new DojoQueryCallback<EventInstanceVO>(false) {

        @Override
        public void row(EventInstanceVO vo, int rowIndex) {
            sheetEmporter.exportRow(vo);
        }
    };
    EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
    emporter.finishExport();
}
Also used : QueryDefinition(com.serotonin.m2m2.web.dwr.QueryDefinition) EventInstanceEmporter(com.serotonin.m2m2.vo.event.EventInstanceEmporter) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) DojoQueryCallback(com.serotonin.m2m2.db.dao.DojoQueryCallback) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

EventInstanceVO (com.serotonin.m2m2.vo.event.EventInstanceVO)7 User (com.serotonin.m2m2.vo.User)6 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DojoQueryCallback (com.serotonin.m2m2.db.dao.DojoQueryCallback)3 ASTNode (net.jazdw.rql.parser.ASTNode)3 ResultSetCounter (com.serotonin.m2m2.db.dao.ResultSetCounter)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 QueryDataPageStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryDataPageStream)2 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 EventDao (com.serotonin.m2m2.db.dao.EventDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 SpreadsheetEmporter (com.serotonin.m2m2.vo.emport.SpreadsheetEmporter)1 EventInstanceEmporter (com.serotonin.m2m2.vo.event.EventInstanceEmporter)1 QueryDefinition (com.serotonin.m2m2.web.dwr.QueryDefinition)1 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)1 EventInstanceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel)1