Search in sources :

Example 1 with WatchListVO

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;
}
Also used : PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) ASTNode(net.jazdw.rql.parser.ASTNode) NotFoundException(com.serotonin.m2m2.vo.exception.NotFoundException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 2 with WatchListVO

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;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with WatchListVO

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);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 4 with WatchListVO

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());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) LongPollData(com.serotonin.m2m2.web.dwr.longPoll.LongPollData) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with WatchListVO

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList)

Aggregations

User (com.serotonin.m2m2.vo.User)18 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)13 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)11 WatchListVO (com.serotonin.m2m2.watchlist.WatchListVO)6 ArrayList (java.util.ArrayList)6 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)5 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 WatchListDataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListDataPointModel)3 WatchListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.WatchListModel)3 ASTNode (net.jazdw.rql.parser.ASTNode)3 IntStringPair (com.serotonin.db.pair.IntStringPair)2 JsonException (com.serotonin.json.JsonException)2