Search in sources :

Example 1 with PortletSubscribeIdResolver

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);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) PortletSubscribeIdResolver(org.apereo.portal.layout.PortletSubscribeIdResolver) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) UserLayoutFolderDescription(org.apereo.portal.layout.node.UserLayoutFolderDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PortalException (org.apereo.portal.PortalException)1 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)1 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)1 PortletSubscribeIdResolver (org.apereo.portal.layout.PortletSubscribeIdResolver)1 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)1 IPerson (org.apereo.portal.security.IPerson)1 IUserInstance (org.apereo.portal.user.IUserInstance)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1