use of org.apereo.portal.layout.node.IUserLayoutFolderDescription 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.IUserLayoutFolderDescription 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.IUserLayoutFolderDescription in project uPortal by Jasig.
the class DistributedLayoutManager method canAddNode.
protected boolean canAddNode(IUserLayoutNodeDescription node, IUserLayoutNodeDescription parent, String nextSiblingId) throws PortalException {
// make sure sibling exists and is a child of nodeId
if (nextSiblingId != null && !nextSiblingId.equals("")) {
IUserLayoutNodeDescription sibling = getNode(nextSiblingId);
if (sibling == null) {
throw new PortalException("Unable to find a sibling node " + "with id=\"" + nextSiblingId + "\". Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
if (!parent.getId().equals(getParentId(nextSiblingId))) {
throw new PortalException("Given sibling (\"" + nextSiblingId + "\") is not a child of a given parentId (\"" + parent.getId() + "\"). Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
}
if (parent == null || !(node.isMoveAllowed() || isFragmentOwner))
return false;
if (parent instanceof IUserLayoutFolderDescription && !(((IUserLayoutFolderDescription) parent).isAddChildAllowed()) && !isFragmentOwner)
return false;
if (// end of list targeted
nextSiblingId == null || nextSiblingId.equals(""))
return true;
// so lets see if we can place it at the end of the sibling list and
// hop left until we get into the correct position.
Enumeration sibIds = getVisibleChildIds(parent.getId());
List sibs = Collections.list(sibIds);
if (// last node in list so should be ok
sibs.size() == 0)
return true;
// unprocessed nodes is not altered.
for (int idx = sibs.size() - 1; idx >= 0; idx--) {
IUserLayoutNodeDescription prev = getNode((String) sibs.get(idx));
if (!isFragmentOwner && !MovementRules.canHopLeft(node, prev))
return false;
if (prev.getId().equals(nextSiblingId))
return true;
}
// oops never found the sib
return false;
}
Aggregations