Search in sources :

Example 11 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.

the class PointLinksDwr method init.

@DwrPermission(user = true)
public Map<String, Object> init() {
    User user = Common.getUser();
    Map<String, Object> data = new HashMap<String, Object>();
    // Get the points that this user can access.
    List<DataPointVO> allPoints = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    List<IntStringPair> sourcePoints = new ArrayList<IntStringPair>();
    List<IntStringPair> targetPoints = new ArrayList<IntStringPair>();
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO point : allPoints) {
        if (admin || Permissions.hasDataPointReadPermission(user, point))
            sourcePoints.add(new IntStringPair(point.getId(), point.getExtendedName()));
        if (point.getPointLocator().isSettable() && (admin || Permissions.hasDataPointSetPermission(user, point)))
            targetPoints.add(new IntStringPair(point.getId(), point.getExtendedName()));
    }
    data.put("sourcePoints", sourcePoints);
    data.put("targetPoints", targetPoints);
    // Get the existing point links.
    List<PointLinkVO> pointLinks = new ArrayList<PointLinkVO>();
    for (PointLinkVO pointLink : PointLinkDao.instance.getPointLinks()) {
        if (containsPoint(sourcePoints, pointLink.getSourcePointId()) && containsPoint(targetPoints, pointLink.getTargetPointId()))
            pointLinks.add(pointLink);
    }
    data.put("pointLinks", pointLinks);
    return data;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 12 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 13 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 14 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 15 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.

the class MangoApiSystemSettingsDwr method loadHeaders.

@DwrPermission(admin = true)
public ProcessResult loadHeaders() {
    ProcessResult result = new ProcessResult();
    List<StringStringPair> headersList = new ArrayList<StringStringPair>();
    String header = Common.envProps.getString("rest.cors.allowedOrigins", "");
    if (!StringUtils.isEmpty(header))
        headersList.add(new StringStringPair("Access-Control-Allow-Origin", header));
    header = Common.envProps.getString("rest.cors.allowedMethods", "");
    if (!StringUtils.isEmpty(header))
        headersList.add(new StringStringPair("Access-Control-Allow-Methods", header));
    header = Common.envProps.getString("rest.cors.allowedHeaders", "");
    if (!StringUtils.isEmpty(header))
        headersList.add(new StringStringPair("Access-Control-Allow-Headers", header));
    header = Common.envProps.getString("rest.cors.exposedHeaders", "");
    if (!StringUtils.isEmpty(header))
        headersList.add(new StringStringPair("Access-Control-Expose-Headers", header));
    headersList.add(new StringStringPair("Access-Control-Allow-Credentials", Boolean.toString(Common.envProps.getBoolean("rest.cors.allowCredentials", false))));
    header = Common.envProps.getString("rest.cors.maxAge", "");
    if (!StringUtils.isEmpty(header))
        headersList.add(new StringStringPair("Access-Control-Max-Age", header));
    result.addData("enabled", Common.envProps.getBoolean("rest.cors.enabled", false));
    result.addData("headers", headersList);
    return result;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6