use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class DataPointEventsByWatchlistQueryDefinition method createQuery.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
*/
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
// Lookup data points by watchlist
WatchListVO vo = WatchListDao.instance.getByXid(parameters.get("watchListXid").asText());
if (vo == null)
throw new NotFoundException();
if (!WatchListRestController.hasReadPermission(user, vo))
throw new PermissionException(new TranslatableMessage("common.default", "Unauthorized access"), user);
List<Object> args = new ArrayList<>();
args.add("typeRef1");
WatchListDao.instance.getPoints(vo.getId(), new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO dp, int index) {
if (Permissions.hasDataPointReadPermission(user, dp)) {
args.add(Integer.toString(dp.getId()));
}
}
});
// Create Event Query for these Points
ASTNode query = new ASTNode("in", args);
query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
// TODO Should we force a limit if none is supplied?
if (parameters.has("limit")) {
int offset = 0;
int limit = parameters.get("limit").asInt();
if (parameters.has("offset"))
offset = parameters.get("offset").asInt();
query = addAndRestriction(query, new ASTNode("limit", limit, offset));
}
return query;
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method exportCurrentWatchlist.
@DwrPermission(user = true)
public ProcessResult exportCurrentWatchlist() {
ProcessResult result = new ProcessResult();
WatchListVO wl = getWatchList();
Map<String, Object> data = new LinkedHashMap<>();
// Get the Full VO for the export
List<WatchListVO> vos = new ArrayList<>();
vos.add(wl);
data.put(WatchListEmportDefinition.elementId, vos);
result.addData("json", EmportDwr.export(data, 3));
return result;
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method moveUp.
@DwrPermission(user = true)
public void moveUp(int pointId) {
User user = Common.getUser();
WatchListVO watchList = getWatchList(user);
WatchListCommon.ensureWatchListEditPermission(user, watchList);
List<DataPointVO> points = watchList.getPointList();
DataPointVO point;
for (int i = 0; i < points.size(); i++) {
point = points.get(i);
if (point.getId() == pointId) {
points.set(i, points.get(i - 1));
points.set(i - 1, point);
break;
}
}
WatchListDao.instance.saveWatchList(watchList);
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method resetWatchListState.
@DwrPermission(anonymous = true)
public void resetWatchListState(int pollSessionId) {
LongPollData data = getLongPollData(pollSessionId, false);
synchronized (data.getState()) {
WatchListCommon.getWatchListStates(data).clear();
WatchListVO wl = getWatchList();
for (DataPointVO dp : wl.getPointList()) dp.resetLastValue();
}
notifyLongPollImpl(data.getRequest());
}
use of com.serotonin.m2m2.watchlist.WatchListVO in project ma-modules-public by infiniteautomation.
the class WatchListDwr method getPointDataImpl.
private List<WatchListState> getPointDataImpl(WatchListVO watchList) {
if (watchList == null)
return new ArrayList<>();
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
User user = Common.getUser(request);
WatchListState state;
List<WatchListState> states = new ArrayList<>(watchList.getPointList().size());
Map<String, Object> model = new HashMap<>();
for (DataPointVO point : watchList.getPointList()) {
// Create the watch list state.
state = createWatchListState(request, point, Common.runtimeManager, model, user);
states.add(state);
}
return states;
}
Aggregations