Search in sources :

Example 1 with IUserLayout

use of org.apereo.portal.layout.IUserLayout in project uPortal by Jasig.

the class FavoritesEditController method unFavoriteNode.

/**
 * Un-favorite a favorite node (portlet or collection) identified by node ID. Routed by the
 * action=delete parameter. If no favorites remain after un-favoriting, switches portlet mode to
 * VIEW.
 *
 * <p>Sets render parameters: successMessageCode: message code of success message if applicable
 * errorMessageCode: message code of error message if applicable nameOfFavoriteActedUpon:
 * user-facing name of favorite acted upon. action: will be set to "list" to facilitate not
 * repeatedly attempting delete.
 *
 * <p>Exactly one of [successMessageCode|errorMessageCode] render parameters will be set.
 * nameOfFavoriteActedUpon and action will always be set.
 *
 * @param nodeId identifier of target node
 * @param response ActionResponse onto which render parameters will, mode may, be set
 */
@ActionMapping(params = { "action=delete" })
public void unFavoriteNode(@RequestParam("nodeId") String nodeId, ActionResponse response) {
    try {
        // ferret out the layout manager
        HttpServletRequest servletRequest = this.portalRequestUtils.getCurrentPortalRequest();
        IUserInstance userInstance = this.userInstanceManager.getUserInstance(servletRequest);
        IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
        IUserLayoutManager layoutManager = preferencesManager.getUserLayoutManager();
        IUserLayoutNodeDescription nodeDescription = layoutManager.getNode(nodeId);
        String userFacingNodeName = nodeDescription.getName();
        response.setRenderParameter("nameOfFavoriteActedUpon", userFacingNodeName);
        if (nodeDescription.isDeleteAllowed()) {
            boolean nodeSuccessfullyDeleted = layoutManager.deleteNode(nodeId);
            if (nodeSuccessfullyDeleted) {
                layoutManager.saveUserLayout();
                response.setRenderParameter("successMessageCode", "favorites.unfavorite.success.parameterized");
                IUserLayout updatedLayout = layoutManager.getUserLayout();
                // if removed last favorite, return to VIEW mode
                if (!favoritesUtils.hasAnyFavorites(updatedLayout)) {
                    response.setPortletMode(PortletMode.VIEW);
                }
                logger.debug("Successfully unfavorited [{}]", nodeDescription);
            } else {
                logger.error("Failed to delete node [{}] on unfavorite request, but this should have succeeded?", nodeDescription);
                response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
            }
        } else {
            logger.warn("Attempt to unfavorite [{}] failed because user lacks permission to delete that layout node.", nodeDescription);
            response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.lack.permission.parameterized");
        }
    } catch (Exception e) {
        // TODO: this log message is kind of useless without the username to put the node in
        // context
        logger.error("Something went wrong unfavoriting nodeId [{}].", nodeId);
        // may have failed to load node description, so fall back on describing by id
        final String fallbackUserFacingNodeName = "node with id " + nodeId;
        response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
        response.setRenderParameter("nameOfFavoriteActedUpon", fallbackUserFacingNodeName);
    }
    response.setRenderParameter("action", "list");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 2 with IUserLayout

use of org.apereo.portal.layout.IUserLayout in project uPortal by Jasig.

the class FavoritesController method initializeView.

/**
 * Handles all Favorites portlet VIEW mode renders. Populates model with user's favorites and
 * selects a view to display those favorites.
 *
 * <p>View selection:
 *
 * <p>Returns "jsp/Favorites/view" in the normal case where the user has at least one favorited
 * portlet or favorited collection.
 *
 * <p>Returns "jsp/Favorites/view_zero" in the edge case where the user has zero favorited
 * portlets AND zero favorited collections.
 *
 * <p>Model: marketPlaceFname --> String functional name of Marketplace portlet, or null if not
 * available. collections --> List of favorited collections (IUserLayoutNodeDescription s)
 * favorites --> List of favorited individual portlets (IUserLayoutNodeDescription s)
 *
 * @param model . Spring model. This method adds three model attributes.
 * @return jsp/Favorites/view[_zero]
 */
@RenderMapping
public String initializeView(PortletRequest req, Model model) {
    final IUserInstance ui = userInstanceManager.getUserInstance(portalRequestUtils.getCurrentPortalRequest());
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final IUserLayout userLayout = ulm.getUserLayout();
    // TODO: the portlet could predicate including a non-null marketplace portlet fname
    // on the accessing user having permission to render the portlet referenced by that fname
    // so that portlet would gracefully degrade when configured with bad marketplace portlet
    // fname
    // and also gracefully degrade when the accessing user doesn't have permission to access an
    // otherwise
    // viable configured marketplace.  This complexity may not be worth it.  Anyway it is not
    // yet implemented.
    model.addAttribute("marketplaceFname", this.marketplaceFName);
    final List<IUserLayoutNodeDescription> collections = favoritesUtils.getFavoriteCollections(userLayout);
    model.addAttribute("collections", collections);
    final List<IUserLayoutNodeDescription> rawFavorites = favoritesUtils.getFavoritePortletLayoutNodes(userLayout);
    /*
         * Filter the collection by SUBSCRIBE permission.
         *
         * NOTE:  In the "regular" (non-Favorites) layout, this permissions check is handled by
         * the rendering engine.  It will refuse to spawn a worker for a portlet to which you
         * cannot SUBSCRIBE.
         */
    final String username = req.getRemoteUser() != null ? req.getRemoteUser() : // First item is the default
    PersonFactory.getGuestUsernames().get(0);
    final IAuthorizationPrincipal principal = authorizationService.newPrincipal(username, IPerson.class);
    // final List<IUserLayoutNodeDescription> favorites = new ArrayList<>();
    final List<IUserLayoutChannelDescription> favoriteChannelDescriptions = new ArrayList<>();
    for (IUserLayoutNodeDescription nodeDescription : rawFavorites) {
        if (nodeDescription instanceof IUserLayoutChannelDescription) {
            final IUserLayoutChannelDescription channelDescription = (IUserLayoutChannelDescription) nodeDescription;
            if (principal.canRender(channelDescription.getChannelPublishId())) {
                // favorites.add(nodeDescription);
                favoriteChannelDescriptions.add(channelDescription);
            }
        }
    }
    // Filter list of IUserLayoutChannelDescription by FunctionalName
    final List<IUserLayoutChannelDescription> uniqueFavoritesChannel = FavoritesUtils.filterChannelFavoritesToUnique(favoriteChannelDescriptions);
    // Cast List of IUserLayoutChannelDescription to List of IUserLayoutNodeDescription
    final List<IUserLayoutNodeDescription> uniqueFavorites = FavoritesUtils.castListChannelDescriptionToListNodeDescription(uniqueFavoritesChannel);
    model.addAttribute("favorites", uniqueFavorites);
    // default to the regular old view
    String viewName = "jsp/Favorites/view";
    if (collections.isEmpty() && uniqueFavorites.isEmpty()) {
        // special edge case of zero favorites, switch to special view
        viewName = "jsp/Favorites/view_zero";
    }
    logger.debug("Favorites Portlet VIEW mode render populated model [{}] for render by view {}.", model, viewName);
    return viewName;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 3 with IUserLayout

use of org.apereo.portal.layout.IUserLayout in project uPortal by Jasig.

the class UrlSyntaxProviderImpl method parseLegacyPortalUrl.

protected IPortalRequestInfo parseLegacyPortalUrl(HttpServletRequest request, Map<String, String[]> parameterMap) {
    final PortalRequestInfoImpl portalRequestInfo = new PortalRequestInfoImpl();
    final String[] fname = parameterMap.remove(LEGACY_PARAM_PORTLET_FNAME);
    if (fname != null && fname.length > 0) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname[0]);
        if (portletWindow != null) {
            logger.debug("Legacy fname parameter {} resolved to {}", fname[0], portletWindow);
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            portalRequestInfo.setTargetedPortletWindowId(portletWindowId);
            final PortletRequestInfoImpl portletRequestInfo = portalRequestInfo.getPortletRequestInfo(portletWindowId);
            // Check the portlet request type
            final String[] type = parameterMap.remove(LEGACY_PARAM_PORTLET_REQUEST_TYPE);
            if (type != null && type.length > 0 && "ACTION".equals(type[0])) {
                portalRequestInfo.setUrlType(UrlType.ACTION);
            }
            // Set the window state
            final String[] state = parameterMap.remove(LEGACY_PARAM_PORTLET_STATE);
            if (state != null && state.length > 0) {
                final WindowState windowState = PortletUtils.getWindowState(state[0]);
                // none of the other options make sense
                if (portalRequestInfo.getUrlType() == UrlType.ACTION || PATH_WINDOW_STATES.contains(windowState)) {
                    portletRequestInfo.setWindowState(windowState);
                }
            }
            // If no window state was set assume MAXIMIZED
            if (portletRequestInfo.getWindowState() == null) {
                portletRequestInfo.setWindowState(WindowState.MAXIMIZED);
            }
            // Set the portlet mode
            final String[] mode = parameterMap.remove(LEGACY_PARAM_PORTLET_MODE);
            if (mode != null && mode.length > 0) {
                final PortletMode portletMode = PortletUtils.getPortletMode(mode[0]);
                portletRequestInfo.setPortletMode(portletMode);
            }
            // Set the parameters
            final Map<String, List<String>> portletParameters = portletRequestInfo.getPortletParameters();
            for (final Map.Entry<String, String[]> parameterEntry : parameterMap.entrySet()) {
                final String prefixedName = parameterEntry.getKey();
                // If the parameter starts with the portlet param prefix
                if (prefixedName.startsWith(LEGACY_PARAM_PORTLET_PARAM_PREFX)) {
                    final String name = prefixedName.substring(LEGACY_PARAM_PORTLET_PARAM_PREFX.length());
                    portletParameters.put(name, Arrays.asList(parameterEntry.getValue()));
                }
            }
            // Set the url state based on the window state
            final UrlState urlState = this.determineUrlState(portletWindow, portletRequestInfo.getWindowState());
            portalRequestInfo.setUrlState(urlState);
        } else {
            logger.debug("Could not find portlet for legacy fname fname parameter {}", fname[0]);
        }
    }
    // Check root=uP_root
    final String[] root = parameterMap.remove(LEGACY_PARAM_LAYOUT_ROOT);
    if (root != null && root.length > 0) {
        if (LEGACY_PARAM_LAYOUT_ROOT_VALUE.equals(root[0])) {
            // Check uP_sparam=activeTab
            final String[] structParam = parameterMap.remove(LEGACY_PARAM_LAYOUT_STRUCT_PARAM);
            if (structParam != null && structParam.length > 0) {
                if (LEGACY_PARAM_LAYOUT_TAB_ID.equals(structParam[0])) {
                    // Get the active tab id
                    final String[] activeTabId = parameterMap.remove(LEGACY_PARAM_LAYOUT_TAB_ID);
                    if (activeTabId != null && activeTabId.length > 0) {
                        // Get the user's layout and do xpath for tab at index=activeTabId[0]
                        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
                        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
                        final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
                        final IUserLayout userLayout = userLayoutManager.getUserLayout();
                        final String nodeId = this.xpathOperations.doWithExpression("/layout/folder/folder[@type='regular' and @hidden='false'][position() = $activeTabId]/@ID", Collections.singletonMap("activeTabId", activeTabId[0]), new Function<XPathExpression, String>() {

                            @Override
                            public String apply(XPathExpression xPathExpression) {
                                return userLayout.findNodeId(xPathExpression);
                            }
                        });
                        // Found nodeId for activeTabId
                        if (nodeId != null) {
                            logger.debug("Found layout node {} for legacy activeTabId parameter {}", nodeId, activeTabId[0]);
                            portalRequestInfo.setTargetedLayoutNodeId(nodeId);
                        } else {
                            logger.debug("No layoout node found for legacy activeTabId parameter {}", activeTabId[0]);
                        }
                    }
                }
            }
        }
    }
    return portalRequestInfo;
}
Also used : WindowState(javax.portlet.WindowState) XPathExpression(javax.xml.xpath.XPathExpression) IUserLayout(org.apereo.portal.layout.IUserLayout) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode) IUserInstance(org.apereo.portal.user.IUserInstance) LinkedList(java.util.LinkedList) List(java.util.List) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 4 with IUserLayout

use of org.apereo.portal.layout.IUserLayout in project uPortal by Jasig.

the class FavoritesController method initializeView.

/**
     * Handles all Favorites portlet VIEW mode renders. Populates model with user's favorites and
     * selects a view to display those favorites.
     *
     * <p>View selection:
     *
     * <p>Returns "jsp/Favorites/view" in the normal case where the user has at least one favorited
     * portlet or favorited collection.
     *
     * <p>Returns "jsp/Favorites/view_zero" in the edge case where the user has zero favorited
     * portlets AND zero favorited collections.
     *
     * <p>Model: marketPlaceFname --> String functional name of Marketplace portlet, or null if not
     * available. collections --> List of favorited collections (IUserLayoutNodeDescription s)
     * favorites --> List of favorited individual portlets (IUserLayoutNodeDescription s)
     *
     * @param model . Spring model. This method adds three model attributes.
     * @return jsp/Favorites/view[_zero]
     */
@RenderMapping
public String initializeView(Model model) {
    IUserInstance ui = userInstanceManager.getUserInstance(portalRequestUtils.getCurrentPortalRequest());
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    IUserLayout userLayout = ulm.getUserLayout();
    // TODO: the portlet could predicate including a non-null marketplace portlet fname
    // on the accessing user having permission to render the portlet referenced by that fname
    // so that portlet would gracefully degrade when configured with bad marketplace portlet fname
    // and also gracefully degrade when the accessing user doesn't have permission to access an otherwise
    // viable configured marketplace.  This complexity may not be worth it.  Anyway it is not yet implemented.
    model.addAttribute("marketplaceFname", this.marketplaceFName);
    List<IUserLayoutNodeDescription> collections = FavoritesUtils.getFavoriteCollections(userLayout);
    model.addAttribute("collections", collections);
    List<IUserLayoutNodeDescription> favorites = FavoritesUtils.getFavoritePortlets(userLayout);
    model.addAttribute("favorites", favorites);
    // default to the regular old view
    String viewName = "jsp/Favorites/view";
    if (collections.isEmpty() && favorites.isEmpty()) {
        // special edge case of zero favorites, switch to special view
        viewName = "jsp/Favorites/view_zero";
    }
    logger.trace("Favorites Portlet VIEW mode render populated model [{}] for render by view {}.", model, viewName);
    return viewName;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 5 with IUserLayout

use of org.apereo.portal.layout.IUserLayout in project uPortal by Jasig.

the class ChannelListController method calculateFavoritePortlets.

private Set<IPortletDefinition> calculateFavoritePortlets(HttpServletRequest request) {
    /*
         * It's not fantastic, but the storage strategy for favorites in the layout XML doc.  We
         * have to use it to know which portlets are favorites.
         */
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final IUserLayout layout = ulm.getUserLayout();
    final Set<IPortletDefinition> rslt = favoritesUtils.getFavoritePortletDefinitions(layout);
    log.debug("Found the following favoritePortlets for user='{}':  {}", request.getRemoteUser(), rslt);
    return rslt;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

IUserLayout (org.apereo.portal.layout.IUserLayout)8 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)8 IUserInstance (org.apereo.portal.user.IUserInstance)8 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)5 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)4 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)4 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 PortletMode (javax.portlet.PortletMode)1 WindowState (javax.portlet.WindowState)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 XPathExpression (javax.xml.xpath.XPathExpression)1 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)1 PortletTabIdResolver (org.apereo.portal.layout.PortletTabIdResolver)1 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)1