@Test(expected = NullPointerException.class) public void testRemoveByFNameNull() throws IOException { ModelAndView modelAndView = updatePreferencesServlet.removeByFName(req, res, "fname"); }
@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) { 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); } }
UpdatePreferencesServlet { @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) { 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); } } }
UpdatePreferencesServlet { @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) { 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); } }  }
UpdatePreferencesServlet { @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) { 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); } }  @Autowired void setUserLayoutStore(IUserLayoutStore userLayoutStore); @Autowired void setStylesheetUserPreferencesService(
            IStylesheetUserPreferencesService stylesheetUserPreferencesService); @Autowired void setPortletDefinitionRegistry(IPortletDefinitionRegistry portletDefinitionRegistry); @Autowired void setUserIdentityStore(IUserIdentityStore userStore); @Autowired void setUserInstanceManager(IUserInstanceManager userInstanceManager); @Autowired void setMessageSource(MessageSource messageSource); @Autowired void setPortletWindowRegistry(IPortletWindowRegistry portletWindowRegistry); @Autowired void setFavoritesUtils(FavoritesUtils favoritesUtils); @RequestMapping(method = RequestMethod.POST, params = "action=removeElement") ModelAndView removeElement(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=removeByFName") ModelAndView removeByFName(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "fname") String fname); @RequestMapping(method = RequestMethod.POST, params = "action=movePortletAjax") ModelAndView movePortletAjax(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam String sourceId,
            @RequestParam String previousNodeId,
            @RequestParam String nextNodeId); @RequestMapping(method = RequestMethod.POST, params = "action=movePortlet") @Deprecated ModelAndView movePortlet(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=moveElement") ModelAndView moveElement(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=changeColumns") ModelAndView changeColumns(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("tabId") String tabId,
            @RequestParam("widths[]") String[] widths,
            @RequestParam(value = "deleted[]", required = false) String[] deleted,
            @RequestParam(value = "acceptor", required = false) String acceptor); @RequestMapping(method = RequestMethod.POST, params = "action=moveTab") ModelAndView moveTab(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=addFavorite") ModelAndView addFavorite(
            @RequestParam String channelId,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=removeFavorite") ModelAndView removeFavorite(
            @RequestParam String channelId,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=addPortlet") ModelAndView addPortlet(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=chooseSkin") ModelAndView chooseSkin(HttpServletRequest request, @RequestParam String skinName); @RequestMapping(method = RequestMethod.POST, params = "action=addTab") ModelAndView addTab(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("widths[]") String[] widths); @RequestMapping(method = RequestMethod.POST, params = "action=addFolder") ModelAndView addFolder(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("targetId") String targetId,
            @RequestParam(value = "siblingId", required = false) String siblingId,
            @RequestBody(required = false) Map<String, Map<String, String>> attributes); @RequestMapping(method = RequestMethod.POST, params = "action=updateAttributes") ModelAndView updateAttributes(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("targetId") String targetId,
            @RequestBody Map<String, Map<String, String>> attributes); @RequestMapping(method = RequestMethod.POST, params = "action=renameTab") ModelAndView renameTab(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=updatePermissions") ModelAndView updatePermissions(HttpServletRequest request, HttpServletResponse response); }
UpdatePreferencesServlet { @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) { 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); } }  @Autowired void setUserLayoutStore(IUserLayoutStore userLayoutStore); @Autowired void setStylesheetUserPreferencesService(
            IStylesheetUserPreferencesService stylesheetUserPreferencesService); @Autowired void setPortletDefinitionRegistry(IPortletDefinitionRegistry portletDefinitionRegistry); @Autowired void setUserIdentityStore(IUserIdentityStore userStore); @Autowired void setUserInstanceManager(IUserInstanceManager userInstanceManager); @Autowired void setMessageSource(MessageSource messageSource); @Autowired void setPortletWindowRegistry(IPortletWindowRegistry portletWindowRegistry); @Autowired void setFavoritesUtils(FavoritesUtils favoritesUtils); @RequestMapping(method = RequestMethod.POST, params = "action=removeElement") ModelAndView removeElement(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=removeByFName") ModelAndView removeByFName(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "fname") String fname); @RequestMapping(method = RequestMethod.POST, params = "action=movePortletAjax") ModelAndView movePortletAjax(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam String sourceId,
            @RequestParam String previousNodeId,
            @RequestParam String nextNodeId); @RequestMapping(method = RequestMethod.POST, params = "action=movePortlet") @Deprecated ModelAndView movePortlet(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=moveElement") ModelAndView moveElement(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=changeColumns") ModelAndView changeColumns(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("tabId") String tabId,
            @RequestParam("widths[]") String[] widths,
            @RequestParam(value = "deleted[]", required = false) String[] deleted,
            @RequestParam(value = "acceptor", required = false) String acceptor); @RequestMapping(method = RequestMethod.POST, params = "action=moveTab") ModelAndView moveTab(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "sourceID") String sourceId,
            @RequestParam String method,
            @RequestParam(value = "elementID") String destinationId); @RequestMapping(method = RequestMethod.POST, params = "action=addFavorite") ModelAndView addFavorite(
            @RequestParam String channelId,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=removeFavorite") ModelAndView removeFavorite(
            @RequestParam String channelId,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=addPortlet") ModelAndView addPortlet(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=chooseSkin") ModelAndView chooseSkin(HttpServletRequest request, @RequestParam String skinName); @RequestMapping(method = RequestMethod.POST, params = "action=addTab") ModelAndView addTab(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("widths[]") String[] widths); @RequestMapping(method = RequestMethod.POST, params = "action=addFolder") ModelAndView addFolder(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("targetId") String targetId,
            @RequestParam(value = "siblingId", required = false) String siblingId,
            @RequestBody(required = false) Map<String, Map<String, String>> attributes); @RequestMapping(method = RequestMethod.POST, params = "action=updateAttributes") ModelAndView updateAttributes(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("targetId") String targetId,
            @RequestBody Map<String, Map<String, String>> attributes); @RequestMapping(method = RequestMethod.POST, params = "action=renameTab") ModelAndView renameTab(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, params = "action=updatePermissions") ModelAndView updatePermissions(HttpServletRequest request, HttpServletResponse response);  }