Search in sources :

Example 16 with WatchListVO

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

the class WatchListDwr method setSelectedWatchList.

@DwrPermission(user = true)
public Map<String, Object> setSelectedWatchList(int watchListId) {
    User user = Common.getUser();
    WatchListVO watchList = WatchListDao.instance.get(watchListId);
    WatchListCommon.ensureWatchListPermission(user, watchList);
    prepareWatchList(watchList, user);
    WatchListDao.instance.saveSelectedWatchList(user.getId(), watchList.getId());
    Map<String, Object> data = getWatchListData(user, watchList);
    // Set the watchlist in the user object after getting the data since it may take a while, and the long poll
    // updates will all be missed in the meantime.
    setWatchList(user, watchList);
    return data;
}
Also used : User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 17 with WatchListVO

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

the class WatchListDwr method init.

@DwrPermission(user = true)
public Map<String, Object> init() {
    Map<String, Object> data = new HashMap<>();
    PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true).copyFoldersOnly();
    User user = Common.getHttpUser();
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO point : points) {
        if (admin || Permissions.hasDataPointReadPermission(user, point))
            ph.addDataPoint(point.getPointFolderId(), new DataPointSummary(point));
    }
    ph.parseEmptyFolders();
    WatchListVO watchList = WatchListDao.instance.getSelectedWatchList(user.getId());
    prepareWatchList(watchList, user);
    setWatchList(user, watchList);
    data.put("pointFolder", ph.getRoot());
    data.put("selectedWatchList", getWatchListData(user, watchList));
    return data;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 18 with WatchListVO

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

the class WatchListDwr method getPermissions.

@DwrPermission(user = true)
public ProcessResult getPermissions() {
    WatchListVO wl = getWatchList();
    ProcessResult result = new ProcessResult();
    result.addData("readPermission", wl.getReadPermission());
    result.addData("editPermission", wl.getEditPermission());
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 19 with WatchListVO

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

the class WatchListDwr method getWatchListData.

private Map<String, Object> getWatchListData(User user, WatchListVO watchList) {
    Map<String, Object> data = new HashMap<>();
    if (watchList == null)
        return data;
    List<DataPointVO> points = watchList.getPointList();
    List<Integer> pointIds = new ArrayList<>(points.size());
    for (DataPointVO point : points) {
        if (Permissions.hasDataPointReadPermission(user, point))
            pointIds.add(point.getId());
    }
    data.put("points", pointIds);
    data.put("access", watchList.getUserAccess(user));
    data.put("readPermission", watchList.getReadPermission());
    data.put("editPermission", watchList.getEditPermission());
    return data;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList)

Example 20 with WatchListVO

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

the class WatchListDwr method addNewWatchList.

@DwrPermission(user = true)
public IntStringPair addNewWatchList(int copyId) {
    User user = Common.getUser();
    WatchListVO watchList;
    if (copyId == Common.NEW_ID) {
        watchList = new WatchListVO();
        watchList.setName(translate("common.newName"));
    } else {
        watchList = WatchListDao.instance.get(getWatchList().getId());
        watchList.setId(Common.NEW_ID);
        watchList.setName(translate(new TranslatableMessage("common.copyPrefix", watchList.getName())));
    }
    watchList.setUserId(user.getId());
    watchList.setXid(WatchListDao.instance.generateUniqueXid());
    WatchListDao.instance.saveWatchList(watchList);
    setWatchList(user, watchList);
    WatchListDao.instance.saveSelectedWatchList(user.getId(), watchList.getId());
    return new IntStringPair(watchList.getId(), watchList.getName());
}
Also used : User(com.serotonin.m2m2.vo.User) IntStringPair(com.serotonin.db.pair.IntStringPair) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

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