use of org.apereo.portal.layout.PortletSubscribeIdResolver 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", required = true) String fname) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
try {
String elementId = ulm.getUserLayout().findNodeId(new PortletSubscribeIdResolver(fname));
if (elementId != null && elementId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX) && ulm.getNode(elementId) instanceof org.apereo.portal.layout.node.UserLayoutFolderDescription) {
removeSubscription(per, elementId, ulm);
} else 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.EMPTY_MAP);
} catch (PortalException e) {
return handlePersistError(request, response, e);
}
}
Aggregations