use of org.apereo.portal.layout.node.IUserLayoutNodeDescription 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();
//Have to test against the fname safe version of the externalId since the folderName 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;
}
}
}
//If an explicit nodeId match isn't found but at least one matching externalId was found 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.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class UpdatePreferencesServlet method getTabIdFromName.
protected String getTabIdFromName(IUserLayout userLayout, String tabName) {
@SuppressWarnings("unchecked") Enumeration<String> childrenOfRoot = userLayout.getChildIds(userLayout.getRootId());
while (childrenOfRoot.hasMoreElements()) {
//loop over folders that might be the favorites folder
String nodeId = childrenOfRoot.nextElement();
try {
IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
if (IUserLayoutNodeDescription.LayoutNodeType.FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
if (tabName.equalsIgnoreCase(folderDescription.getName())) {
return folderDescription.getId();
}
}
} catch (Exception e) {
logger.error("Error getting the nodeID of the tab name " + tabName, e);
}
}
logger.warn("Tab " + tabName + " was searched for but not found");
//didn't find tab
return null;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class FavoritesUtils method getFavoriteTabNodeId.
public static String getFavoriteTabNodeId(IUserLayout userLayout) {
@SuppressWarnings("unchecked") Enumeration<String> childrenOfRoot = userLayout.getChildIds(userLayout.getRootId());
while (childrenOfRoot.hasMoreElements()) {
//loop over folders that might be the favorites folder
String nodeId = childrenOfRoot.nextElement();
try {
IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
if (FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
if (FAVORITES_TYPE.equalsIgnoreCase(folderDescription.getFolderType())) {
return folderDescription.getId();
}
}
} catch (Exception e) {
logger.error("Ignoring on error a node while examining for favorites: node ID is [{}]", nodeId, e);
}
}
logger.warn("Favorite tab was searched for but not found");
//didn't find favorite tab
return null;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class FavoritesUtils method getFavoriteCollections.
/**
* Get the favorite collections of portlets (i.e. suitable folders ("tabs") in the user layout.)
* Suitable layout nodes are of type folder with @type attribute favorite_collection.
*
* @param userLayout
* @return non-null List of IUserLayoutDescriptions describing the tabs
*/
public static List<IUserLayoutNodeDescription> getFavoriteCollections(IUserLayout userLayout) {
if (null == userLayout) {
throw new IllegalArgumentException("Cannot get favorites collections from a null userLayout");
}
logger.trace("Extracting favorites collections from layout [{}].", userLayout);
Enumeration<String> nodeIds = userLayout.getChildIds(userLayout.getRootId());
List<IUserLayoutNodeDescription> results = new LinkedList<IUserLayoutNodeDescription>();
while (nodeIds.hasMoreElements()) {
String nodeId = nodeIds.nextElement();
try {
IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
String parentId = userLayout.getParentId(nodeId);
String nodeName = nodeDescription.getName();
IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
if (FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
String folderType = folderDescription.getFolderType();
if (FAVORITE_COLLECTION_TYPE.equals(folderType)) {
results.add(nodeDescription);
logger.trace("Selected node with id [{}] named [{}] with " + "folderType [{}] and type [{}] as a collection of favorites.", nodeId, nodeName, folderType, nodeType);
} else {
logger.trace("Rejected node with id [{}] named [{}] with " + "folderType [{}] and type [{}] as not a collection of favorites.", nodeId, nodeName, folderType, nodeType);
}
} else {
logger.trace("Rejected non-folder node with id [{}] named [{}] " + "with parentId [{}] and type [{}] as not a collection of favorites.", nodeId, nodeName, parentId, nodeType);
}
// if something goes wrong in processing a node, exclude it
} catch (Exception e) {
logger.error("Error determining whether to include layout node [{}]" + " as a collection of favorites. Excluding.", nodeId, e);
}
}
logger.debug("Extracted favorites collections [{}] from [{}]", results, userLayout);
return results;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method canMoveLeft.
private boolean canMoveLeft(String nodeId, String targetNextSibId) throws PortalException {
IUserLayoutNodeDescription node = getNode(nodeId);
Enumeration sibIds = getVisibleChildIds(getParentId(nodeId));
List sibs = Collections.list(sibIds);
for (int idx = sibs.indexOf(nodeId) - 1; idx >= 0; idx--) {
String prevSibId = (String) sibs.get(idx);
IUserLayoutNodeDescription prev = getNode(prevSibId);
if (!isFragmentOwner && !MovementRules.canHopLeft(node, prev))
return false;
if (targetNextSibId != null && prev.getId().equals(targetNextSibId))
return true;
}
// oops never found the sib
return false;
}
Aggregations