Package com.serotonin.m2m2.watchlist

Source Code of com.serotonin.m2m2.watchlist.WatchListCommon

/*
    Copyright (C) 2014 Infinite Automation Systems Inc. All rights reserved.
    @author Matthew Lohbihler
*/
package com.serotonin.m2m2.watchlist;

import java.util.ArrayList;
import java.util.List;

import com.serotonin.m2m2.view.ShareUser;
import com.serotonin.m2m2.vo.User;
import com.serotonin.m2m2.vo.permission.PermissionException;
import com.serotonin.m2m2.web.dwr.longPoll.LongPollData;

public class WatchListCommon {
    @SuppressWarnings("unchecked")
    public static List<WatchListState> getWatchListStates(LongPollData data) {
        List<WatchListState> watchListStates = (List<WatchListState>) data.getState().getAttribute("watchListStates");
        if (watchListStates == null) {
            synchronized (data) {
                watchListStates = (List<WatchListState>) data.getState().getAttribute("watchListStates");
                if (watchListStates == null) {
                    watchListStates = new ArrayList<WatchListState>();
                    data.getState().setAttribute("watchListStates", watchListStates);
                }
            }
        }
        return watchListStates;
    }

    public static void ensureWatchListPermission(User user, WatchList watchList) throws PermissionException {
        if (watchList.getUserAccess(user) == ShareUser.ACCESS_NONE)
            throw new PermissionException("User does not have permission to the watch list", user);
    }

    public static void ensureWatchListEditPermission(User user, WatchList watchList) throws PermissionException {
        if (watchList.getUserAccess(user) != ShareUser.ACCESS_OWNER)
            throw new PermissionException("User does not have permission to edit the watch list", user);
    }
}
TOP

Related Classes of com.serotonin.m2m2.watchlist.WatchListCommon

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.