use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UpdatePreferencesServlet method removeByFName.
/**
* Remove the first element with the provided fname from the layout.
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @param fname fname of the portlet to remove from the layout
* @return json response
* @throws IOException if the person cannot be retrieved
*/
@RequestMapping(method = RequestMethod.POST, params = "action=removeByFName")
public ModelAndView removeByFName(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "fname") String fname) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
try {
String elementId = ulm.getUserLayout().findNodeId(new PortletSubscribeIdResolver(fname));
if (elementId != null) {
// all node types, so we can just have a generic action.
if (!ulm.deleteNode(elementId)) {
logger.info("Failed to remove element ID {} from layout root folder ID {}, delete node returned false", elementId, ulm.getRootFolderId());
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
}
} else {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
ulm.saveUserLayout();
return new ModelAndView("jsonView", Collections.emptyMap());
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UpdatePreferencesServlet method addTab.
/**
* Add a new tab to the layout. The new tab will be appended to the end of the list and named
* with the BLANK_TAB_NAME variable.
*
* @param request
* @throws IOException
*/
@RequestMapping(method = RequestMethod.POST, params = "action=addTab")
public ModelAndView addTab(HttpServletRequest request, HttpServletResponse response, @RequestParam("widths[]") String[] widths) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson person = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
// Verify that the user has permission to add this tab
final IAuthorizationPrincipal authPrincipal = this.getUserPrincipal(person.getUserName());
if (!authPrincipal.hasPermission(IPermission.PORTAL_SYSTEM, IPermission.ADD_TAB_ACTIVITY, IPermission.ALL_TARGET)) {
logger.warn("Attempt to add a tab through the REST API by unauthorized user '" + person.getUserName() + "'");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Add tab disabled"));
}
// construct a brand new tab
String id = "tbd";
String tabName = request.getParameter("tabName");
if (StringUtils.isBlank(tabName))
tabName = DEFAULT_TAB_NAME;
IUserLayoutFolderDescription newTab = new UserLayoutFolderDescription();
newTab.setName(tabName);
newTab.setId(id);
newTab.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newTab.setHidden(false);
newTab.setUnremovable(false);
newTab.setImmutable(false);
// add the tab to the layout
ulm.addNode(newTab, ulm.getRootFolderId(), null);
try {
// save the user's layout
ulm.saveUserLayout();
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
// get the id of the newly added tab
String tabId = newTab.getId();
for (String width : widths) {
// create new column element
IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
newColumn.setName("Column");
newColumn.setId("tbd");
newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newColumn.setHidden(false);
newColumn.setUnremovable(false);
newColumn.setImmutable(false);
// add the column to our layout
ulm.addNode(newColumn, tabId, null);
this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, newColumn.getId(), CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME, width + "%");
try {
// This sets the column attribute in memory but doesn't persist it. Comment says
// saves changes "prior to persisting"
Element folder = ulm.getUserLayoutDOM().getElementById(newColumn.getId());
UserPrefsHandler.setUserPreference(folder, CLASSIC_COLUMNS_WIDTH_USER_PREFERENCE_NAME, person);
} catch (Exception e) {
logger.error("Error saving new column widths", e);
}
}
// this new tab; use the currently active tabGroup.
if (request.getParameter(TAB_GROUP_PARAMETER) != null) {
String tabGroup = request.getParameter(TAB_GROUP_PARAMETER).trim();
if (logger.isDebugEnabled()) {
logger.debug(TAB_GROUP_PARAMETER + "=" + tabGroup);
}
if (!TAB_GROUP_DEFAULT.equals(tabGroup) && tabGroup.length() != 0) {
// Persists SSUP values to the database
this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, tabId, TAB_GROUP_PARAMETER, tabGroup);
}
}
try {
// save the user's layout
ulm.saveUserLayout();
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
return new ModelAndView("jsonView", Collections.singletonMap("tabId", tabId));
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class UpdatePreferencesServlet method updateAttributes.
/**
* Update the attributes for the node. Unrecognized attributes will log a warning, but are
* otherwise ignored.
*
* @param request
* @param response
* @param targetId - the id of the node whose attributes will be updated.
* @param attributes - parse the JSON name-value pairs in the body as the attributes of the
* folder. e.g. : { "structureAttributes" : {"display" : "row", "other" : "another" },
* "attributes" : {"hidden": "true", "type" : "header-top" } }
*/
@RequestMapping(method = RequestMethod.POST, params = "action=updateAttributes")
public ModelAndView updateAttributes(HttpServletRequest request, HttpServletResponse response, @RequestParam("targetId") String targetId, @RequestBody Map<String, Map<String, String>> attributes) {
IUserLayoutManager ulm = userInstanceManager.getUserInstance(request).getPreferencesManager().getUserLayoutManager();
if (!ulm.getNode(targetId).isEditAllowed()) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
}
// Update the attributes based on the supplied JSON (request body name-value pairs)
IUserLayoutNodeDescription node = ulm.getNode(targetId);
if (node == null) {
logger.warn("[updateAttributes()] Unable to locate node with id: " + targetId);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView("jsonView", Collections.singletonMap("error", "Unable to locate node with id: " + targetId));
} else {
setObjectAttributes(node, request, attributes);
final Locale locale = RequestContextUtils.getLocale(request);
try {
ulm.saveUserLayout();
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
Map<String, String> model = Collections.singletonMap("success", getMessage("success.element.update", "Updated element attributes", locale));
return new ModelAndView("jsonView", model);
}
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class DeleteManager method getDeleteSet.
/**
* Get the delete set if any stored in the root of the document or create it is passed in create
* flag is true.
*/
private static Element getDeleteSet(Document plf, IPerson person, boolean create) throws PortalException {
Node root = plf.getDocumentElement();
Node child = root.getFirstChild();
while (child != null) {
if (child.getNodeName().equals(Constants.ELM_DELETE_SET))
return (Element) child;
child = child.getNextSibling();
}
if (create == false)
return null;
String ID = null;
try {
ID = getDLS().getNextStructDirectiveId(person);
} catch (Exception e) {
throw new PortalException("Exception encountered while " + "generating new delete set node " + "Id for userId=" + person.getID(), e);
}
Element delSet = plf.createElement(Constants.ELM_DELETE_SET);
delSet.setAttribute(Constants.ATT_TYPE, Constants.ELM_DELETE_SET);
delSet.setAttribute(Constants.ATT_ID, ID);
root.appendChild(delSet);
return delSet;
}
use of org.apereo.portal.PortalException in project uPortal by Jasig.
the class DistributedLayoutManager method updateNode.
/**
* Handles pushing changes made to the passed-in node into the user's layout. If the node is an
* ILF node then the change is recorded via directives in the PLF if such changes are allowed by
* the owning fragment. If the node is a user owned node then the changes are applied directly
* to the corresponding node in the PLF.
*/
public synchronized boolean updateNode(IUserLayoutNodeDescription node) throws PortalException {
if (canUpdateNode(node)) {
String nodeId = node.getId();
IUserLayoutNodeDescription oldNode = getNode(nodeId);
if (oldNode instanceof IUserLayoutChannelDescription) {
IUserLayoutChannelDescription oldChanDesc = (IUserLayoutChannelDescription) oldNode;
if (!(node instanceof IUserLayoutChannelDescription)) {
throw new PortalException("Change channel to folder is " + "not allowed by updateNode() method! Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
IUserLayoutChannelDescription newChanDesc = (IUserLayoutChannelDescription) node;
updateChannelNode(nodeId, newChanDesc, oldChanDesc);
} else {
// must be a folder
IUserLayoutFolderDescription oldFolderDesc = (IUserLayoutFolderDescription) oldNode;
if (oldFolderDesc.getId().equals(getRootFolderId()))
throw new PortalException("Update of root node is not currently allowed!");
if (node instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription newFolderDesc = (IUserLayoutFolderDescription) node;
updateFolderNode(nodeId, newFolderDesc, oldFolderDesc);
}
}
this.updateCacheKey();
return true;
}
return false;
}
Aggregations