use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method getViewPointData.
/**
* Retrieves point state for all points on a given view. This is the monitoring version of the method. See below for
* the view editing version.
*
* @param viewId
* @return
*/
public List<ViewComponentState> getViewPointData(boolean edit) {
User user = Common.getUser();
GraphicalView view;
if (edit)
view = GraphicalViewsCommon.getUserEditView(user);
else
view = GraphicalViewsCommon.getUserView(user);
return getViewPointData(user, view, edit);
}
use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.
the class GraphicalViewDwr method addPointComponentState.
private void addPointComponentState(ViewComponent viewComponent, boolean update, RuntimeManager rtm, Map<String, Object> model, HttpServletRequest request, GraphicalView view, User user, List<ViewComponentState> states, boolean edit, boolean add) {
if (viewComponent.isPointComponent() && (edit || viewComponent.isVisible())) {
PointComponent pointComponent = (PointComponent) viewComponent;
DataPointRT dataPointRT = null;
if (pointComponent.tgetDataPoint() != null)
dataPointRT = rtm.getDataPoint(pointComponent.tgetDataPoint().getId());
ViewComponentState state = preparePointComponentState(pointComponent, update, user, dataPointRT, model, request);
if (!edit) {
if (pointComponent.isSettable()) {
if (view.isEditor(user) || view.isSetter(user))
setChange(pointComponent.tgetDataPoint(), state, dataPointRT, request, model);
}
if (pointComponent.tgetDataPoint() != null)
setChart(pointComponent.tgetDataPoint(), state, request, model);
}
if (add)
states.add(state);
model.clear();
}
}
use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.
the class GraphicalViewEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject viewJson = jsonValue.toJsonObject();
String xid = viewJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = graphicalViewDao.generateUniqueXid();
ensureDao();
GraphicalView view = graphicalViewDao.getViewByXid(xid);
if (view == null) {
view = new GraphicalView();
view.setXid(xid);
}
try {
importContext.getReader().readInto(view, viewJson);
// Now validate it. Use a new response object so we can distinguish errors in this view from other
// errors.
ProcessResult viewResponse = new ProcessResult();
view.validate(viewResponse);
if (viewResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = view.isNew();
graphicalViewDao.saveView(view);
importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.gviews.GraphicalView 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;
}
use of com.serotonin.m2m2.gviews.GraphicalView in project ma-modules-public by infiniteautomation.
the class ImageUploadServlet method doPost.
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
if (ServletFileUpload.isMultipartContent(request)) {
User user = Common.getUser(request);
GraphicalView view = GraphicalViewsCommon.getUserEditView(user);
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// Fail if we don't have permissions for this
if (!Permissions.hasPermission(user, SystemSettingsDao.getValue(GraphicalViewUploadPermissionDefinition.PERMISSION))) {
// The GraphicalViewDwr.clearBackground() method will notify the user of a failure so we can ignore them here
return;
}
List<FileItem> items;
try {
items = upload.parseRequest(request);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (FileItem item : items) {
if ("backgroundImage".equals(item.getFieldName())) {
final DiskFileItem diskItem = (DiskFileItem) item;
try {
// will throw IOException if not supported or null if not an image
if (ImageIO.read(diskItem.getInputStream()) != null) {
// Create the path to the upload directory.
File dir = GraphicalViewsCommon.getUploadDir();
// Create the image file name.
String filename = GraphicalViewsCommon.getNextImageFilename(dir, diskItem.getName());
// Save the file.
FileOutputStream fos = new FileOutputStream(new File(dir, filename));
StreamUtils.transfer(diskItem.getInputStream(), fos);
fos.close();
view.setBackgroundFilename(ImageUploadServletDefinition.IMAGE_DIR + "/" + filename);
} else {
// Unsupported File Type
}
} catch (Exception e) {
// Unsupported Image Type
}
}
}
}
}
Aggregations