Search in sources :

Example 16 with IUserPreferencesManager

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

the class StylesheetUserPreferencesServiceImplTest method testThemeStylesheetUserPreferences.

/** @throws Exception */
@Test
public void testThemeStylesheetUserPreferences() throws Exception {
    //Setup mocks
    final HttpServletRequest request = new MockHttpServletRequest();
    //initialize the session
    request.getSession();
    final IStylesheetDescriptorDao stylesheetDescriptorDao = mock(IStylesheetDescriptorDao.class);
    final IUserInstanceManager userInstanceManager = mock(IUserInstanceManager.class);
    final IStylesheetUserPreferencesDao stylesheetUserPreferencesDao = mock(IStylesheetUserPreferencesDao.class);
    final IFragmentDefinitionUtils fragmentUtils = mock(IFragmentDefinitionUtils.class);
    final IUserInstance userInstance = mock(IUserInstance.class);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    final IPerson person = mock(IPerson.class);
    when(userInstance.getPerson()).thenReturn(person);
    final IUserPreferencesManager preferencesManager = mock(IUserPreferencesManager.class);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    final IUserProfile userProfile = mock(IUserProfile.class);
    when(preferencesManager.getUserProfile()).thenReturn(userProfile);
    final IUserLayoutManager userLayoutManager = mock(IUserLayoutManager.class);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    final IUserLayout userLayout = mock(IUserLayout.class);
    when(userLayoutManager.getUserLayout()).thenReturn(userLayout);
    when(userProfile.getThemeStylesheetId()).thenReturn(1);
    final IStylesheetDescriptor stylesheetDescriptor = mock(IStylesheetDescriptor.class);
    when(stylesheetDescriptorDao.getStylesheetDescriptor(1)).thenReturn(stylesheetDescriptor);
    final ILayoutAttributeDescriptor skinLayoutAttributeDescriptor = mock(ILayoutAttributeDescriptor.class);
    when(stylesheetDescriptor.getLayoutAttributeDescriptor("minimized")).thenReturn(skinLayoutAttributeDescriptor);
    when(skinLayoutAttributeDescriptor.getName()).thenReturn("minimized");
    when(skinLayoutAttributeDescriptor.getScope()).thenReturn(Scope.REQUEST);
    when(skinLayoutAttributeDescriptor.getTargetElementNames()).thenReturn(Collections.singleton("folder"));
    final IOutputPropertyDescriptor mediaOutputPropertyDescriptor = mock(IOutputPropertyDescriptor.class);
    when(stylesheetDescriptor.getOutputPropertyDescriptor("media")).thenReturn(mediaOutputPropertyDescriptor);
    when(mediaOutputPropertyDescriptor.getName()).thenReturn("media");
    when(mediaOutputPropertyDescriptor.getScope()).thenReturn(Scope.SESSION);
    final IStylesheetParameterDescriptor skinStylesheetParameterDescriptor = mock(IStylesheetParameterDescriptor.class);
    when(stylesheetDescriptor.getStylesheetParameterDescriptor("skin")).thenReturn(skinStylesheetParameterDescriptor);
    when(skinStylesheetParameterDescriptor.getName()).thenReturn("media");
    when(skinStylesheetParameterDescriptor.getScope()).thenReturn(Scope.PERSISTENT);
    final IStylesheetUserPreferences persistentStylesheetUserPreferences = mock(IStylesheetUserPreferences.class);
    when(stylesheetUserPreferencesDao.createStylesheetUserPreferences(stylesheetDescriptor, person, userProfile)).thenReturn(persistentStylesheetUserPreferences);
    when(stylesheetUserPreferencesDao.getStylesheetUserPreferences(stylesheetDescriptor, person, userProfile)).thenReturn(persistentStylesheetUserPreferences);
    when(persistentStylesheetUserPreferences.getStylesheetParameter("skin")).thenReturn(null).thenReturn("red");
    //Create and initialize service bean
    final StylesheetUserPreferencesServiceImpl stylesheetUserPreferencesService = new StylesheetUserPreferencesServiceImpl();
    stylesheetUserPreferencesService.setStylesheetDescriptorDao(stylesheetDescriptorDao);
    stylesheetUserPreferencesService.setUserInstanceManager(userInstanceManager);
    stylesheetUserPreferencesService.setStylesheetUserPreferencesDao(stylesheetUserPreferencesDao);
    stylesheetUserPreferencesService.setFragmentDefinitionUtils(fragmentUtils);
    //Run test
    String actual;
    actual = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized", "true");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.THEME, "u1l1n1", "minimized");
    assertEquals("true", actual);
    actual = stylesheetUserPreferencesService.getStylesheetParameter(request, PreferencesScope.THEME, "skin");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.THEME, "skin", "red");
    verify(persistentStylesheetUserPreferences).setStylesheetParameter("skin", "red");
    assertNull(actual);
    actual = stylesheetUserPreferencesService.getStylesheetParameter(request, PreferencesScope.THEME, "skin");
    assertEquals("red", actual);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IStylesheetDescriptorDao(org.apereo.portal.layout.dao.IStylesheetDescriptorDao) ILayoutAttributeDescriptor(org.apereo.portal.layout.om.ILayoutAttributeDescriptor) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IOutputPropertyDescriptor(org.apereo.portal.layout.om.IOutputPropertyDescriptor) IStylesheetParameterDescriptor(org.apereo.portal.layout.om.IStylesheetParameterDescriptor) IStylesheetUserPreferencesDao(org.apereo.portal.layout.dao.IStylesheetUserPreferencesDao) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IStylesheetUserPreferences(org.apereo.portal.layout.om.IStylesheetUserPreferences) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserInstanceManager(org.apereo.portal.user.IUserInstanceManager) IFragmentDefinitionUtils(org.apereo.portal.utils.IFragmentDefinitionUtils) Test(org.junit.Test)

Example 17 with IUserPreferencesManager

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

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

the class PortalUrlProviderImpl method getLayoutNodeType.

/**
     * Verify the requested node exists in the user's layout. Also if the node exists see if it is a
     * portlet node and if it is return the {@link IPortletWindowId} of the corresponding portlet.
     */
protected LayoutNodeType getLayoutNodeType(HttpServletRequest request, String folderNodeId) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayoutNodeDescription node = userLayoutManager.getNode(folderNodeId);
    if (node == null) {
        return null;
    }
    return node.getType();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 19 with IUserPreferencesManager

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

the class LocaleManagerLocaleResolver method setLocale.

@Override
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final LocaleManager localeManager = userInstance.getLocaleManager();
    localeManager.setSessionLocales(new Locale[] { locale });
    // if the current user is logged in, also update the persisted user locale
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = ui.getPerson();
    if (!person.isGuest()) {
        try {
            localeManager.persistUserLocales(new Locale[] { locale });
            localeStore.updateUserLocales(person, new Locale[] { locale });
            final IUserPreferencesManager upm = ui.getPreferencesManager();
            upm.getUserLayoutManager().loadUserLayout();
        } catch (Exception e) {
            throw new PortalException(e);
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 20 with IUserPreferencesManager

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

the class SingleTabUrlNodeSyntaxHelper method getDefaultLayoutNodeId.

@Override
public String getDefaultLayoutNodeId(HttpServletRequest httpServletRequest) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpServletRequest);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayout userLayout = userLayoutManager.getUserLayout();
    //This logic is specific to tab/column layouts
    final String defaultTabIndex = this.getDefaultTabIndex(httpServletRequest);
    if (defaultTabIndex != null) {
        final String defaultTabId = this.getTabId(userLayout, defaultTabIndex);
        if (StringUtils.isNotEmpty(defaultTabId)) {
            return defaultTabId;
        }
    }
    this.logger.warn("Failed to find default tab id for '" + userInstance.getPerson().getUserName() + "' with default tab index " + defaultTabIndex + ". Index 1 will be tried as a fall-back.");
    final String firstTabId = getTabId(userLayout, "1");
    if (StringUtils.isNotEmpty(firstTabId)) {
        return firstTabId;
    }
    this.logger.warn("Failed to find default tab id for '" + userInstance.getPerson().getUserName() + "' with default tab index 1. The user has no tabs.");
    return userLayout.getRootId();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

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