Search in sources :

Example 16 with IUserLayoutManager

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

the class PortalUrlProviderImpl method verifyPortletWindowId.

/**
 * Verify the requested portlet window corresponds to a node in the user's layout and return the
 * corresponding layout node id
 */
protected String verifyPortletWindowId(HttpServletRequest request, IPortletWindowId portletWindowId) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
    final IPortletWindowId delegationParentWindowId = portletWindow.getDelegationParentId();
    if (delegationParentWindowId != null) {
        return verifyPortletWindowId(request, delegationParentWindowId);
    }
    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final String channelSubscribeId = portletEntity.getLayoutNodeId();
    final IUserLayoutNodeDescription node = userLayoutManager.getNode(channelSubscribeId);
    if (node == null) {
        throw new IllegalArgumentException("No layout node exists for id " + channelSubscribeId + " of window " + portletWindowId);
    }
    return node.getId();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 17 with IUserLayoutManager

use of org.apereo.portal.layout.IUserLayoutManager 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 18 with IUserLayoutManager

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

the class UserLayoutStoreComponent method getCacheKey.

@Override
public CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
    final IUserLayoutManager userLayoutManager = this.getUserLayoutManager(request);
    final String cacheKey = userLayoutManager.getCacheKey();
    return CacheKey.build(this.getClass().getName(), cacheKey);
}
Also used : IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 19 with IUserLayoutManager

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

the class UserLayoutStoreComponent method getEventReader.

@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final long timestamp = System.currentTimeMillis();
    logger.debug("STARTING user layout fetch for user '{}' #milestone", request.getRemoteUser());
    final IUserLayoutManager userLayoutManager = getUserLayoutManager(request);
    final XMLEventReader userLayoutReader = userLayoutManager.getUserLayoutReader();
    logger.debug("FINISHED user layout fetch for user '{}' in {}ms #milestone", request.getRemoteUser(), Long.toString(System.currentTimeMillis() - timestamp));
    return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(userLayoutReader);
}
Also used : XMLEventReader(javax.xml.stream.XMLEventReader) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 20 with IUserLayoutManager

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

the class UpdatePreferencesServlet method subscribeToTab.

/**
     * Subscribe a user to a pre-formatted tab (pulled DLM fragment).
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    // Get the fragment owner's name from the request and construct
    // an IPerson object representing that user
    String fragmentOwnerName = request.getParameter("sourceID");
    if (StringUtils.isBlank(fragmentOwnerName)) {
        logger.warn("Attempted to subscribe to tab with null owner ID");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
    }
    RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
    fragmentOwner.setUserName(fragmentOwnerName);
    // Mark the currently-authenticated user as subscribed to this fragment.
    // If an inactivated fragment registration already exists, update it
    // as an active subscription.  Otherwise, create a new fragment
    // subscription.
    IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
    if (userFragmentInfo == null) {
        userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
    } else {
        userFragmentInfo.setActive(true);
        userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
    }
    try {
        // reload user layout and stylesheet to incorporate new DLM fragment
        ulm.loadUserLayout(true);
        // get the target node this new tab should be moved after
        String destinationId = request.getParameter("elementID");
        // get the user layout for the currently-authenticated user
        int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
        Document layoutDocument = userLayout.getLayout();
        // attempt to find the new subscribed tab in the layout so we can
        // move it
        StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
        XPathFactory fac = XPathFactory.newInstance();
        XPath xpath = fac.newXPath();
        NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
        String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
        ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
        ulm.saveUserLayout();
        return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
    } catch (XPathExpressionException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) Document(org.w3c.dom.Document) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) XPathFactory(javax.xml.xpath.XPathFactory) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)38 IUserInstance (org.apereo.portal.user.IUserInstance)28 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)17 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)16 PortalException (org.apereo.portal.PortalException)16 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPerson (org.apereo.portal.security.IPerson)10 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)9 IUserLayout (org.apereo.portal.layout.IUserLayout)7 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)7 HashMap (java.util.HashMap)6 Locale (java.util.Locale)6 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)5 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)5 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)4 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)4 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)4