use of org.apereo.portal.layout.IUserLayout 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.getFavoritePortletLayoutNodes(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.IUserLayout 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.IUserLayout 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);
}
}
Aggregations