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);
}
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");
}
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();
}
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);
}
}
}
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();
}
Aggregations