Search in sources :

Example 11 with IUserPreferencesManager

use of org.apereo.portal.IUserPreferencesManager 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 12 with IUserPreferencesManager

use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.

the class UserLocaleHelper method updateUserLocale.

/**
     * Update the current user's locale to match the selected locale. This implementation will
     * update the session locale, and if the user is not a guest, will also update the locale in the
     * user's persisted preferences.
     *
     * @param request
     * @param localeString
     */
public void updateUserLocale(HttpServletRequest request, String localeString) {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    final IUserProfile userProfile = upm.getUserProfile();
    LocaleManager localeManager = userProfile.getLocaleManager();
    if (localeString != null) {
        // build a new Locale[] array from the specified locale
        Locale userLocale = parseLocale(localeString);
        Locale[] locales = new Locale[] { userLocale };
        // set this locale in the session
        localeManager.setSessionLocales(locales);
        // if the current user is logged in, also update the persisted
        // user locale
        final IPerson person = ui.getPerson();
        if (!person.isGuest()) {
            try {
                localeManager.persistUserLocales(new Locale[] { userLocale });
                localeStore.updateUserLocales(person, new Locale[] { userLocale });
                // remove person layout framgent from session since it contains some of the data in previous
                // translation and won't be cleared until next logout-login (applies when using
                // RDBMDistributedLayoutStore as user layout store).
                person.setAttribute(Constants.PLF, null);
                upm.getUserLayoutManager().loadUserLayout(true);
            } catch (Exception e) {
                throw new PortalException(e);
            }
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) LocaleManager(org.apereo.portal.i18n.LocaleManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 13 with IUserPreferencesManager

use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.

the class LayoutRESTController method getRESTController.

/**
     * A REST call to get a json feed of the current users layout. Intent was to provide a layout
     * document without per-tab information for mobile device rendering.
     *
     * @param request The servlet request. Utilized to get the users instance and eventually there
     *     layout
     * @param tab The tab name of which you would like to filter; optional; if not provided, will
     *     return entire layout.
     * @return json feed of the layout
     * @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
     *     includes regions and breakout per tab
     */
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
    final IPerson person = personManager.getPerson(request);
    List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
    try {
        final IUserInstance ui = userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager upm = ui.getPreferencesManager();
        final IUserProfile profile = upm.getUserProfile();
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
        Document document = userLayout.getLayout();
        NodeList portletNodes = null;
        if (tab != null) {
            NodeList folders = document.getElementsByTagName("folder");
            for (int i = 0; i < folders.getLength(); i++) {
                Node node = folders.item(i);
                if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
                    TabListOfNodes tabNodes = new TabListOfNodes();
                    tabNodes.addAllChannels(node.getChildNodes());
                    portletNodes = tabNodes;
                    break;
                }
            }
        } else {
            portletNodes = document.getElementsByTagName("channel");
        }
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                //get alt max URL
                String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
                if (alternativeMaximizedLink != null) {
                    portlet.setUrl(alternativeMaximizedLink);
                    portlet.setAltMaxUrl(true);
                } else {
                    // get the maximized URL for this portlet
                    final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
                    final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
                    if (targetPortletWindowId != null) {
                        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
                        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
                    }
                    portlet.setUrl(portalUrlBuilder.getUrlString());
                    portlet.setAltMaxUrl(false);
                }
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("layout", portlets);
        mv.setViewName("json");
        return mv;
    } catch (Exception e) {
        log.error("Error retrieving user layout document", e);
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) TabListOfNodes(org.apereo.portal.rest.layout.TabListOfNodes) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with IUserPreferencesManager

use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.

the class StylesheetUserPreferencesServiceImpl method getStylesheetPreferencesKey.

protected final StylesheetPreferencesKey getStylesheetPreferencesKey(HttpServletRequest request, PreferencesScope prefScope) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserProfile userProfile = preferencesManager.getUserProfile();
    final IStylesheetDescriptor stylesheetDescriptor = getStylesheetDescriptor(request, prefScope);
    return new StylesheetPreferencesKey(person, userProfile, stylesheetDescriptor);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 15 with IUserPreferencesManager

use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.

the class StylesheetUserPreferencesServiceImpl method getDistributedStylesheetUserPreferences.

protected final IStylesheetUserPreferences getDistributedStylesheetUserPreferences(HttpServletRequest request, PreferencesScope prefScope) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayout userLayout = userLayoutManager.getUserLayout();
    return prefScope.getDistributedIStylesheetUserPreferences(userLayout);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Aggregations

IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)29 IUserInstance (org.apereo.portal.user.IUserInstance)27 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)15 IUserProfile (org.apereo.portal.IUserProfile)9 IPerson (org.apereo.portal.security.IPerson)8 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)5 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IUserLayout (org.apereo.portal.layout.IUserLayout)4 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)4 PortalException (org.apereo.portal.PortalException)3 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Locale (java.util.Locale)2 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)2 LocaleManager (org.apereo.portal.i18n.LocaleManager)2