Search in sources :

Example 1 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method setViewPoint.

/**
 * Allows the setting of a given data point. Overrides BaseDwr to resolve the point view id.
 *
 * @param pointId
 * @param valueStr
 * @return
 */
@DwrPermission(user = true)
public String setViewPoint(String viewComponentId, String valueStr) {
    User user = Common.getUser();
    GraphicalView view = GraphicalViewsCommon.getUserView(user);
    DataPointVO point = view.findDataPoint(viewComponentId);
    if (point != null) {
        // Check that setting is allowed.
        if (!view.isSetter(user))
            throw new PermissionException(new TranslatableMessage("permission.exception.setDataPoint", user.getUsername()), user);
        // Try setting the point.
        setPointImpl(point, valueStr, user);
    }
    return viewComponentId;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.

the class GraphicalViewDwr method saveView.

@DwrPermission(user = true)
public ProcessResult saveView(String name, String xid, int anonymousAccess, String readPermission, String setPermission, String editPermission) {
    ProcessResult result = new ProcessResult();
    User user = Common.getUser();
    GraphicalView view = GraphicalViewsCommon.getUserEditView(user);
    view.setName(name);
    view.setXid(xid);
    view.setAnonymousAccess(anonymousAccess);
    view.setReadPermission(readPermission);
    view.setSetPermission(setPermission);
    view.setEditPermission(editPermission);
    view.validate(result);
    if (!result.getHasMessages()) {
        view.setUserId(user.getId());
        new GraphicalViewDao().saveView(view);
        result.addData("view", view);
    }
    return result;
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) AnonymousUser(com.serotonin.m2m2.vo.AnonymousUser) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.

the class GraphicalViewHandler method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) {
    GraphicalViewDao viewDao = new GraphicalViewDao();
    User user = Common.getUser(request);
    List<IntStringPair> views = viewDao.getViewNames(user);
    model.put("views", views);
    try {
        GraphicalViewsCommon.ensureCanCreate(user);
        model.put("canCreateViews", true);
    } catch (Exception e) {
        model.put("canCreateViews", false);
    }
    // Set the current view.
    GraphicalView currentView = null;
    String vid = request.getParameter("viewId");
    if (StringUtils.isBlank(vid)) {
        String xid = request.getParameter("xid");
        if (xid != null)
            currentView = viewDao.getViewByXid(xid);
    } else {
        try {
            currentView = viewDao.getView(Integer.parseInt(vid));
        } catch (NumberFormatException e) {
        // no op
        }
    }
    if (currentView == null && views.size() > 0)
        currentView = viewDao.getView(views.get(0).getKey());
    if (currentView != null) {
        GraphicalViewsCommon.ensureViewPermission(user, currentView);
        // Make sure the owner still has permission to all of the points in the view, and that components are
        // otherwise valid.
        currentView.validateViewComponents(false);
        // Add the view to the session for the dwr access stuff.
        model.put("currentView", currentView);
        if (currentView.isOwner(user))
            model.put("owner", true);
        else
            model.put("owner", false);
        if (currentView.isEditor(user))
            model.put("canEditCurrentView", true);
        else
            model.put("canEditCurrentView", false);
        GraphicalViewsCommon.setUserView(user, currentView);
    }
    return null;
}
Also used : User(com.serotonin.m2m2.vo.User) IntStringPair(com.serotonin.db.pair.IntStringPair)

Example 4 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.

the class GraphicalViewLongPollDefinition method handleLongPoll.

@Override
public void handleLongPoll(LongPollData data, Map<String, Object> response, User user) {
    boolean view = false;
    boolean viewEdit = false;
    boolean anon = false;
    if (data.getRequest().hasHandler("graphicalView") && user != null)
        view = true;
    else if (data.getRequest().hasHandler("graphicalViewEdit") && user != null)
        viewEdit = true;
    else if (data.getRequest().hasHandler("graphicalViewAnon"))
        anon = true;
    if (view || viewEdit || anon) {
        LongPollState state = data.getState();
        List<ViewComponentState> graphicalViewStates = GraphicalViewsCommon.getGraphicalViewListStates(data);
        List<ViewComponentState> newStates;
        synchronized (state) {
            if (anon)
                newStates = graphicalViewDwr.getViewPointDataAnon(data.getRequest().getRefId());
            else
                newStates = graphicalViewDwr.getViewPointData(viewEdit);
            List<ViewComponentState> differentStates = new ArrayList<ViewComponentState>();
            for (ViewComponentState newState : newStates) {
                ViewComponentState oldState = getGraphicalViewState(newState.getId(), graphicalViewStates);
                if (oldState == null)
                    differentStates.add(newState);
                else {
                    ViewComponentState copy = newState.clone();
                    copy.removeEqualValue(oldState);
                    if (!copy.isEmpty())
                        differentStates.add(copy);
                }
            }
            if (!differentStates.isEmpty()) {
                response.put("viewStates", differentStates);
                GraphicalViewsCommon.setGraphicalViewListStates(data, newStates);
            }
        }
    }
}
Also used : LongPollState(com.serotonin.m2m2.web.dwr.longPoll.LongPollState) ArrayList(java.util.ArrayList)

Example 5 with GraphicalView

use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.

the class GraphicalView method validate.

public void validate(ProcessResult response) {
    if (StringUtils.isBlank(name))
        response.addMessage("name", new TranslatableMessage("validate.required"));
    else if (StringValidation.isLengthGreaterThan(name, 100))
        response.addMessage("name", new TranslatableMessage("validate.notLongerThan", 100));
    if (StringUtils.isBlank(xid))
        response.addMessage("xid", new TranslatableMessage("validate.required"));
    else if (StringValidation.isLengthGreaterThan(xid, 50))
        response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
    else if (!new GraphicalViewDao().isXidUnique(xid, id))
        response.addMessage("xid", new TranslatableMessage("validate.xidUsed"));
    for (ViewComponent vc : viewComponents) vc.validate(response);
    // Validate the permissions
    User user = Common.getUser();
    GraphicalView existingView = null;
    if (this.id != Common.NEW_ID) {
        existingView = new GraphicalViewDao().getView(id);
    }
    if (existingView == null) {
        Permissions.validateAddedPermissions(this.readPermission, user, response, "readPermission");
        Permissions.validateAddedPermissions(this.setPermission, user, response, "setPermission");
        Permissions.validateAddedPermissions(this.editPermission, user, response, "editPermission");
    } else {
        // We are updating a view so only validate the new permissions, allow existing ones to remain and don't let
        // the user remove permissions they do not have
        this.readPermission = trimPermission(this.readPermission);
        validateUpdatedPermissions(existingView.readPermission, this.readPermission, user, response, "readPermission");
        this.setPermission = trimPermission(this.setPermission);
        validateUpdatedPermissions(existingView.setPermission, this.setPermission, user, response, "setPermission");
        this.editPermission = trimPermission(this.editPermission);
        validateUpdatedPermissions(existingView.editPermission, this.editPermission, user, response, "editPermission");
    }
}
Also used : ShareUser(com.serotonin.m2m2.view.ShareUser) User(com.serotonin.m2m2.vo.User) ViewComponent(com.serotonin.m2m2.gviews.component.ViewComponent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

User (com.serotonin.m2m2.vo.User)9 ShareUser (com.serotonin.m2m2.view.ShareUser)6 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)6 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ViewComponent (com.serotonin.m2m2.gviews.component.ViewComponent)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 GraphicalView (com.serotonin.m2m2.gviews.GraphicalView)2 PointComponent (com.serotonin.m2m2.gviews.component.PointComponent)2 SimplePointComponent (com.serotonin.m2m2.gviews.component.SimplePointComponent)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)2 ArrayList (java.util.ArrayList)2 IntStringPair (com.serotonin.db.pair.IntStringPair)1 JsonException (com.serotonin.json.JsonException)1 JsonObject (com.serotonin.json.type.JsonObject)1 GraphicalViewDao (com.serotonin.m2m2.gviews.GraphicalViewDao)1 CompoundChild (com.serotonin.m2m2.gviews.component.CompoundChild)1 CompoundComponent (com.serotonin.m2m2.gviews.component.CompoundComponent)1 ImageChartComponent (com.serotonin.m2m2.gviews.component.ImageChartComponent)1