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;
}
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;
}
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;
}
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);
}
}
}
}
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");
}
}
Aggregations