use of com.serotonin.m2m2.gviews.GraphicalViewDao 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.GraphicalViewDao 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.GraphicalViewDao 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");
}
}
use of com.serotonin.m2m2.gviews.GraphicalViewDao in project ma-modules-public by infiniteautomation.
the class GraphicalViewEditHandler method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
GraphicalView view;
User user = Common.getUser(request);
// Fresh hit. Get the id.
String viewIdStr = request.getParameter("viewId");
if (viewIdStr != null) {
// An existing view.
view = new GraphicalViewDao().getView(Integer.parseInt(viewIdStr));
if (view == null)
// Doesn't exist. Redirect back to the views page.
return new RedirectView("/views.shtm");
GraphicalViewsCommon.ensureViewEditPermission(user, view);
if ("true".equals(request.getParameter("copy"))) {
// Make a copy
GraphicalView copy = new GraphicalView();
copy.setId(Common.NEW_ID);
copy.setUserId(user.getId());
copy.setXid(new GraphicalViewDao().generateUniqueXid());
copy.setName(StringUtils.abbreviate(TranslatableMessage.translate(ControllerUtils.getTranslations(request), "common.copyPrefix", view.getName()), 100));
copy.setBackgroundFilename(GraphicalViewsCommon.copyImage(view.getBackgroundFilename()));
for (ViewComponent vc : view.getViewComponents()) copy.addViewComponent(vc);
view = copy;
}
} else {
// A new view.
GraphicalViewsCommon.ensureCanCreate(user);
view = new GraphicalView();
view.setId(Common.NEW_ID);
view.setUserId(user.getId());
view.setXid(new GraphicalViewDao().generateUniqueXid());
}
GraphicalViewsCommon.setUserEditView(user, view);
view.validateViewComponents(false);
model.put("imageSets", Common.imageSets);
model.put("dynamicImages", Common.dynamicImages);
model.put("view", view);
return null;
}
Aggregations