private View saveView(final View view) { try { if (view.getId() != -1) { viewService.updatePublishedView(view); } else { long viewId = viewService.addView(view); view.setId(viewId); } } catch (ViewException e) { log.error("Error when trying add/update published view", e); } return view; }
private View getBaseView(final JSONObject publisherInput, final User user) throws ActionException { if (user.isGuest()) { throw new ActionDeniedException("Trying to publish map, but couldn't determine user"); } // not editing, use template view if (PUBLISHED_VIEW_TEMPLATE_ID == -1) { log.error("Publish template id not configured (property: view.template.publish)!"); throw new ActionParamsException("Trying to publish map, but template isn't configured"); } log.debug("Using template to create a new view"); // Get publisher defaults View templateView = viewService.getViewWithConf(PUBLISHED_VIEW_TEMPLATE_ID); if (templateView == null) { log.error("Could not get template View with id:", PUBLISHED_VIEW_TEMPLATE_ID); throw new ActionParamsException("Could not get template View"); } // clone a blank view based on template (so template doesn't get updated!!) final View view = templateView.cloneBasicInfo(); final long viewId = publisherInput.optLong("id", -1); if (viewId != -1) { // check loaded view against user if we are updating a view log.debug("Loading view for editing:", viewId); final View existingView = viewService.getViewWithConf(viewId); if (user.getId() != existingView.getCreator()) { throw new ActionDeniedException("No permissions to update view with id:" + viewId); } // setup ids for updating a view view.setId(existingView.getId()); view.setSupplementId(existingView.getSupplementId()); view.setUuid(existingView.getUuid()); view.setOldId(existingView.getOldId()); } return view; }