Search in sources :

Example 1 with WatchListDao

use of com.serotonin.m2m2.watchlist.WatchListDao in project ma-modules-public by infiniteautomation.

the class MobileWatchListHandler method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) {
    User user = Common.getHttpUser();
    WatchListDao watchListDao = WatchListDao.instance;
    // Check for a watchlist id parameter. If given, update the user.
    try {
        int watchListId = Integer.parseInt(request.getParameter("watchListId"));
        WatchListVO watchList = watchListDao.get(watchListId);
        WatchListCommon.ensureWatchListPermission(user, watchList);
        watchListDao.saveSelectedWatchList(user.getId(), watchList.getId());
    } catch (NumberFormatException e) {
    // no op
    }
    prepareModel(request, model, user);
    // Get the selected watchlist.
    int watchListId = (Integer) model.get(KEY_SELECTED_WATCHLIST);
    // Get the point data.
    List<MobileWatchListState> states = new ArrayList<MobileWatchListState>();
    for (DataPointVO pointVO : watchListDao.get(watchListId).getPointList()) {
        MobileWatchListState state = createState(request, pointVO);
        states.add(state);
    }
    model.put(KEY_WATCHLIST_DATA, states);
    return null;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) WatchListDao(com.serotonin.m2m2.watchlist.WatchListDao) ArrayList(java.util.ArrayList) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 2 with WatchListDao

use of com.serotonin.m2m2.watchlist.WatchListDao 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

User (com.serotonin.m2m2.vo.User)2 WatchListDao (com.serotonin.m2m2.watchlist.WatchListDao)2 WatchListVO (com.serotonin.m2m2.watchlist.WatchListVO)2 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)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 ArrayList (java.util.ArrayList)1 ASTNode (net.jazdw.rql.parser.ASTNode)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1