use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.
the class SingleTabUrlNodeSyntaxHelper method getFolderNamesForLayoutNode.
@RequestCache(keyMask = { false, true })
@Override
public List<String> getFolderNamesForLayoutNode(HttpServletRequest request, String layoutNodeId) {
/*
* Implementation note:
* While the API allows one or more folder names, this implementation will only ever return
* a List with zero or one element. It's not entirely clear that a List with zero members
* was allowed by the interface definition, but this implementation will return an empty
* list if the layoutNodeId cannot be found in the layout.
*/
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final IUserLayout userLayout = userLayoutManager.getUserLayout();
final String tabId = userLayout.findNodeId(new PortletTabIdResolver(layoutNodeId));
if (StringUtils.isEmpty(tabId)) {
return Collections.emptyList();
}
String externalId = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.STRUCTURE, tabId, EXTERNAL_ID_ATTR);
if (externalId != null) {
final Map<String, String> allNodesAndValuesForAttribute = stylesheetUserPreferencesService.getAllNodesAndValuesForAttribute(request, PreferencesScope.STRUCTURE, EXTERNAL_ID_ATTR);
boolean appendNodeId = false;
for (final Entry<String, String> nodeAttributeEntry : allNodesAndValuesForAttribute.entrySet()) {
final String entryNodeId = nodeAttributeEntry.getKey();
final String entryValue = nodeAttributeEntry.getValue();
if (!tabId.equals(entryNodeId) && externalId.equals(entryValue)) {
appendNodeId = true;
break;
}
}
if (!FunctionalNameType.isValid(externalId)) {
logger.warn("ExternalId {} for tab {} is not a valid fname. It will be converted for use in the URL but this results in additional overhead", externalId, tabId);
externalId = FunctionalNameType.makeValid(externalId);
}
if (appendNodeId) {
externalId = externalId + PORTLET_PATH_ELEMENT_SEPERATOR + layoutNodeId;
}
logger.trace("Tab identified by {} resolved to externalId {} " + "so returning that externalId as the sole folder name for node.", layoutNodeId, externalId);
return Arrays.asList(externalId);
} else {
logger.trace("Tab identified by {} had no externalId " + "so returning just {} as the sole folder name for node {}.", layoutNodeId, tabId, layoutNodeId);
return Arrays.asList(tabId);
}
}
use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.
the class TransientPortletEntityDao method getUserLayoutManager.
protected IUserLayoutManager getUserLayoutManager() {
final HttpServletRequest portalRequest = this.portalRequestUtils.getCurrentPortalRequest();
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(portalRequest);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
return preferencesManager.getUserLayoutManager();
}
use of org.apereo.portal.IUserPreferencesManager in project uPortal by Jasig.
the class UserLocaleHelper method getCurrentUserLocale.
/**
* Return the current user's locale.
*
* @param request The current {@link PortletRequest}
* @return
*/
public Locale getCurrentUserLocale(PortletRequest request) {
final HttpServletRequest originalPortalRequest = this.portalRequestUtils.getPortletHttpRequest(request);
IUserInstance ui = userInstanceManager.getUserInstance(originalPortalRequest);
IUserPreferencesManager upm = ui.getPreferencesManager();
final IUserProfile userProfile = upm.getUserProfile();
LocaleManager localeManager = userProfile.getLocaleManager();
// first check the session locales
List<Locale> sessionLocales = localeManager.getSessionLocales();
if (sessionLocales != null && sessionLocales.size() > 0) {
return sessionLocales.get(0);
}
// if no session locales were found, check the user locales
List<Locale> userLocales = localeManager.getUserLocales();
if (userLocales != null && userLocales.size() > 0) {
return userLocales.get(0);
}
// just return null
return null;
}
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(Collections.singletonList(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.setUserLocales(Collections.singletonList(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 UserLayoutParameterProcessor method processParameters.
@Override
@SuppressWarnings("FallThrough")
public boolean processParameters(HttpServletRequest request, HttpServletResponse response) {
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final String tabId = portalRequestInfo.getTargetedLayoutNodeId();
if (tabId != null) {
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "focusedTabID", tabId);
}
// on a portlet, it will get overwritten with the new value below.
if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
transientUserLayoutManagerWrapper.setFocusedId(null);
}
final UrlState urlState = portalRequestInfo.getUrlState();
switch(urlState) {
case DETACHED:
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "detached", Boolean.TRUE.toString());
case MAX:
{
final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
if (portletRequestInfo != null) {
final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final String channelSubscribeId = portletEntity.getLayoutNodeId();
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", channelSubscribeId);
if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
// get wrapper implementation for focusing
final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
// .. and now set it as the focused id
transientUserLayoutManagerWrapper.setFocusedId(channelSubscribeId);
}
// If portletRequestInfo was null just fall through to NORMAL state
break;
}
}
case NORMAL:
default:
{
this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", IUserLayout.ROOT_NODE_NAME);
break;
}
}
return true;
}
Aggregations