use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method updateNode.
/**
* Handles pushing changes made to the passed-in node into the user's layout. If the node is an
* ILF node then the change is recorded via directives in the PLF if such changes are allowed by
* the owning fragment. If the node is a user owned node then the changes are applied directly
* to the corresponding node in the PLF.
*/
public synchronized boolean updateNode(IUserLayoutNodeDescription node) throws PortalException {
if (canUpdateNode(node)) {
String nodeId = node.getId();
IUserLayoutNodeDescription oldNode = getNode(nodeId);
if (oldNode instanceof IUserLayoutChannelDescription) {
IUserLayoutChannelDescription oldChanDesc = (IUserLayoutChannelDescription) oldNode;
if (!(node instanceof IUserLayoutChannelDescription)) {
throw new PortalException("Change channel to folder is " + "not allowed by updateNode() method! Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
IUserLayoutChannelDescription newChanDesc = (IUserLayoutChannelDescription) node;
updateChannelNode(nodeId, newChanDesc, oldChanDesc);
} else {
// must be a folder
IUserLayoutFolderDescription oldFolderDesc = (IUserLayoutFolderDescription) oldNode;
if (oldFolderDesc.getId().equals(getRootFolderId()))
throw new PortalException("Update of root node is not currently allowed!");
if (node instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription newFolderDesc = (IUserLayoutFolderDescription) node;
updateFolderNode(nodeId, newFolderDesc, oldFolderDesc);
}
}
this.updateCacheKey();
return true;
}
return false;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method getChildIds.
private Enumeration<String> getChildIds(String nodeId, boolean visibleOnly) throws PortalException {
Vector<String> v = new Vector<String>();
IUserLayoutNodeDescription node = getNode(nodeId);
if (node instanceof IUserLayoutFolderDescription) {
Document uld = this.getUserLayoutDOM();
Element felement = uld.getElementById(nodeId);
for (Node n = felement.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE && (visibleOnly == false || (visibleOnly == true && ((Element) n).getAttribute(Constants.ATT_HIDDEN).equals("false")))) {
Element e = (Element) n;
if (e.getAttribute("ID") != null) {
v.add(e.getAttribute("ID"));
}
}
}
}
return v.elements();
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class SimpleLayout method getChildIds.
@Override
public Enumeration getChildIds(String nodeId) throws PortalException {
Vector v = new Vector();
IUserLayoutNodeDescription node = getNodeDescription(nodeId);
if (node instanceof IUserLayoutFolderDescription) {
Element element = layout.getElementById(nodeId);
for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) n;
if (e.getAttribute("ID") != null) {
v.add(e.getAttribute("ID"));
}
}
}
}
return v.elements();
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class FavoritesEditController method unFavoriteNode.
/**
* Un-favorite a favorite node (portlet or collection) identified by node ID. Routed by the
* action=delete parameter. If no favorites remain after un-favoriting, switches portlet mode to
* VIEW.
*
* <p>Sets render parameters: successMessageCode: message code of success message if applicable
* errorMessageCode: message code of error message if applicable nameOfFavoriteActedUpon:
* user-facing name of favorite acted upon. action: will be set to "list" to facilitate not
* repeatedly attempting delete.
*
* <p>Exactly one of [successMessageCode|errorMessageCode] render parameters will be set.
* nameOfFavoriteActedUpon and action will always be set.
*
* @param nodeId identifier of target node
* @param response ActionResponse onto which render parameters will, mode may, be set
*/
@ActionMapping(params = { "action=delete" })
public void unFavoriteNode(@RequestParam("nodeId") String nodeId, ActionResponse response) {
try {
// ferret out the layout manager
HttpServletRequest servletRequest = this.portalRequestUtils.getCurrentPortalRequest();
IUserInstance userInstance = this.userInstanceManager.getUserInstance(servletRequest);
IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
IUserLayoutManager layoutManager = preferencesManager.getUserLayoutManager();
IUserLayoutNodeDescription nodeDescription = layoutManager.getNode(nodeId);
String userFacingNodeName = nodeDescription.getName();
response.setRenderParameter("nameOfFavoriteActedUpon", userFacingNodeName);
if (nodeDescription.isDeleteAllowed()) {
boolean nodeSuccessfullyDeleted = layoutManager.deleteNode(nodeId);
if (nodeSuccessfullyDeleted) {
layoutManager.saveUserLayout();
response.setRenderParameter("successMessageCode", "favorites.unfavorite.success.parameterized");
IUserLayout updatedLayout = layoutManager.getUserLayout();
// if removed last favorite, return to VIEW mode
if (!FavoritesUtils.hasAnyFavorites(updatedLayout)) {
response.setPortletMode(PortletMode.VIEW);
}
logger.debug("Successfully unfavorited [{}]", nodeDescription);
} else {
logger.error("Failed to delete node [{}] on unfavorite request, but this should have succeeded?", nodeDescription);
response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
}
} else {
logger.warn("Attempt to unfavorite [{}] failed because user lacks permission to delete that layout node.", nodeDescription);
response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.lack.permission.parameterized");
}
} catch (Exception e) {
// TODO: this log message is kind of useless without the username to put the node in context
logger.error("Something went wrong unfavoriting nodeId [{}].", nodeId);
// may have failed to load node description, so fall back on describing by id
final String fallbackUserFacingNodeName = "node with id " + nodeId;
response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
response.setRenderParameter("nameOfFavoriteActedUpon", fallbackUserFacingNodeName);
}
response.setRenderParameter("action", "list");
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class PortalUrlProviderImpl method getLayoutNodeType.
/**
* Verify the requested node exists in the user's layout. Also if the node exists see if it is a
* portlet node and if it is return the {@link IPortletWindowId} of the corresponding portlet.
*/
protected LayoutNodeType getLayoutNodeType(HttpServletRequest request, String folderNodeId) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final IUserLayoutNodeDescription node = userLayoutManager.getNode(folderNodeId);
if (node == null) {
return null;
}
return node.getType();
}
Aggregations