use of org.apereo.portal.layout.IUserLayoutManager in project uPortal by Jasig.
the class UserInstanceManagerImpl method getUserInstance.
/**
* Returns the UserInstance object that is associated with the given request.
*
* @param request Incoming HttpServletRequest
* @return UserInstance object associated with the given request
*/
@Override
public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
try {
request = this.portalRequestUtils.getOriginalPortalRequest(request);
} catch (IllegalArgumentException iae) {
// ignore, just means that this isn't a wrapped request
}
// Use request attributes first for the fastest possible retrieval
IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
if (userInstance != null) {
return userInstance;
}
final IPerson person;
try {
// Retrieve the person object that is associated with the request
person = this.personManager.getPerson(request);
} catch (Exception e) {
logger.error("Exception while retrieving IPerson!", e);
throw new PortalSecurityException("Could not retrieve IPerson", e);
}
if (person == null) {
throw new PortalSecurityException("PersonManager returned null person for this request. With no user, there's no UserInstance. Is PersonManager misconfigured? RDBMS access misconfigured?");
}
final HttpSession session = request.getSession();
if (session == null) {
throw new IllegalStateException("HttpServletRequest.getSession() returned a null session for request: " + request);
}
// Return the UserInstance object if it's in the session
UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
if (userInstanceHolder != null) {
userInstance = userInstanceHolder.getUserInstance();
if (userInstance != null) {
return userInstance;
}
}
// Create either a UserInstance or a GuestUserInstance
final LocaleManager localeManager = this.getLocaleManager(request, person);
final String userAgent = this.getUserAgent(request);
final IUserProfile userProfile = this.getUserProfile(request, person, localeManager, userAgent);
// Create the user layout manager and user instance object
IUserLayoutManager userLayoutManager = userLayoutManagerFactory.getUserLayoutManager(person, userProfile);
final UserPreferencesManager userPreferencesManager = new UserPreferencesManager(person, userProfile, userLayoutManager);
userInstance = new UserInstance(person, userPreferencesManager, localeManager);
// Ensure the newly created UserInstance is cached in the session
if (userInstanceHolder == null) {
userInstanceHolder = new UserInstanceHolder();
}
userInstanceHolder.setUserInstance(userInstance);
session.setAttribute(KEY, userInstanceHolder);
request.setAttribute(KEY, userInstance);
// Return the new UserInstance
return userInstance;
}
use of org.apereo.portal.layout.IUserLayoutManager in project uPortal by Jasig.
the class FavoritesEditController method initializeView.
/**
* Handles all Favorites portlet EDIT mode renders. Populates model with user's favorites and
* selects a view to display those favorites.
*
* <p>View selection:
*
* <p>Returns "jsp/Favorites/edit" in the normal case where the user has at least one favorited
* portlet or favorited collection.
*
* <p>Returns "jsp/Favorites/edit_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)
* successMessageCode --> String success message bundle key, or null if none errorMessageCode
* --> String error message bundle key, or null if none nameOfFavoriteActedUpon --> Name of
* favorite acted upon, intended as parameter to success or error message
*
* @param model . Spring model. This method adds five model attributes.
* @return jsp/Favorites/edit[_zero]
*/
@RenderMapping
public String initializeView(Model model, RenderRequest renderRequest) {
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);
model.addAttribute("successMessageCode", renderRequest.getParameter("successMessageCode"));
model.addAttribute("errorMessageCode", renderRequest.getParameter("errorMessageCode"));
model.addAttribute("nameOfFavoriteActedUpon", renderRequest.getParameter("nameOfFavoriteActedUpon"));
// default to the regular old edit view
String viewName = "jsp/Favorites/edit";
if (collections.isEmpty() && favorites.isEmpty()) {
// use the special case view
viewName = "jsp/Favorites/edit_zero";
}
logger.trace("Favorites Portlet EDIT mode built model [{}] and selected view {}.", model, viewName);
return viewName;
}
use of org.apereo.portal.layout.IUserLayoutManager in project uPortal by Jasig.
the class SingleTabUrlNodeSyntaxHelper method getLayoutNodeForFolderNames.
@Override
public String getLayoutNodeForFolderNames(HttpServletRequest request, List<String> folderNames) {
if (folderNames == null || folderNames.isEmpty()) {
logger.warn("Asked to get layout node for an empty or null folderNames ({}).", folderNames);
return null;
}
// Check if the folder name is compound and parse it if it is
String folderName = folderNames.get(0);
String layoutNodeId = null;
final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
if (seperatorIndex > 0 && seperatorIndex < folderName.length() - 1) {
layoutNodeId = folderName.substring(seperatorIndex + 1);
folderName = folderName.substring(0, seperatorIndex);
}
if (folderNames.size() > 1) {
logger.warn("Asked to consider multiple folder names {}, " + "but ignoring all but the first which has been parsed as {}.", folderNames, folderName);
}
// Search the users layout attributes for a layout node with a matching externalId value
String firstMatchingNodeId = null;
final Map<String, String> allNodesAndValuesForAttribute = stylesheetUserPreferencesService.getAllNodesAndValuesForAttribute(request, PreferencesScope.STRUCTURE, EXTERNAL_ID_ATTR);
for (final Entry<String, String> entry : allNodesAndValuesForAttribute.entrySet()) {
final String value = entry.getValue();
// could have already been translated
if (value.equals(folderName) || FunctionalNameType.makeValid(value).equals(folderName)) {
final String nodeId = entry.getKey();
if (nodeId.equals(layoutNodeId)) {
// ExternalId matched as well as the layoutNodeId, clear the firstMatchingNodeId
// since we found the nodeId here
logger.trace("Parsed folder names {} to nodeId {}.", folderNames, nodeId);
return nodeId;
} else if (firstMatchingNodeId == null) {
firstMatchingNodeId = nodeId;
}
}
}
// use that match
if (firstMatchingNodeId != null) {
layoutNodeId = firstMatchingNodeId;
} else // In this case the folderName must not have been an externalId, assume it is a layout node
if (layoutNodeId == null) {
layoutNodeId = folderName;
}
// Verify the parsed layoutNodeId matches a node in the user's layout
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final IUserLayoutNodeDescription node;
try {
node = userLayoutManager.getNode(layoutNodeId);
} catch (PortalException e) {
logger.warn("Parsed requested folder names {} to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId, e);
return null;
}
if (node == null) {
logger.warn("Parsed requested folder names to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId);
return null;
}
String nodeId = node.getId();
logger.trace("Resolved node id {} for folder names {}.", nodeId, folderNames);
return nodeId;
}
use of org.apereo.portal.layout.IUserLayoutManager 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();
}
use of org.apereo.portal.layout.IUserLayoutManager in project uPortal by Jasig.
the class TransientPortletEntityDao method wrapEntity.
/**
* Adds a TransientPortletEntity wrapper to the portletEntity if it is needed. If the specified
* entity is transient but no transient subscribe id has been registered for it yet in the
* transientIdMap null is returned. If no wrapping is needed the original entity is returned.
*/
protected IPortletEntity wrapEntity(IPortletEntity portletEntity) {
if (portletEntity == null) {
return null;
}
final String persistentLayoutNodeId = portletEntity.getLayoutNodeId();
if (persistentLayoutNodeId.startsWith(TransientUserLayoutManagerWrapper.SUBSCRIBE_PREFIX)) {
final IUserLayoutManager userLayoutManager = this.getUserLayoutManager();
if (userLayoutManager == null) {
this.logger.warn("Could not find IUserLayoutManager when trying to wrap transient portlet entity: " + portletEntity);
return portletEntity;
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final String fname = portletDefinition.getFName();
final String layoutNodeId = userLayoutManager.getSubscribeId(fname);
return new TransientPortletEntity(portletEntity, layoutNodeId);
}
return portletEntity;
}
Aggregations