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;
}
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();
}
Aggregations