use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class UpdatePreferencesServlet method moveElementInternal.
/**
* Moves the source element.
*
* <p>- If the destination is a tab, the new element automatically goes to the end of the first
* column or in a new column. - If the destination is a folder, the element is added to the end
* of the folder. - Otherwise, the element is inserted before the destination (the destination
* can't be a tab or folder so it must be a portlet).
*
* @return true if the element was moved and saved.
*/
private boolean moveElementInternal(HttpServletRequest request, String sourceId, String destinationId, String method) {
logger.debug("moveElementInternal invoked for sourceId={}, destinationId={}, method={}", sourceId, destinationId, method);
if (StringUtils.isEmpty(destinationId)) {
//shortcut for beginning and end
return true;
}
IUserInstance ui = userInstanceManager.getUserInstance(request);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
boolean success = false;
if (isTab(ulm, destinationId)) {
// If the target is a tab type node, move the element to the end of the first column.
// TODO Try to insert it into the first available column if multiple columns
Enumeration<String> columns = ulm.getChildIds(destinationId);
if (columns.hasMoreElements()) {
success = attemptNodeMove(ulm, sourceId, columns.nextElement(), null);
} else {
// Attempt to create a new column
IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
newColumn.setName("Column");
newColumn.setId("tbd");
newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newColumn.setHidden(false);
newColumn.setUnremovable(false);
newColumn.setImmutable(false);
// add the column to our layout
IUserLayoutNodeDescription col = ulm.addNode(newColumn, destinationId, null);
// If column was created (might not if the tab had addChild=false), move the channel.
if (col != null) {
success = attemptNodeMove(ulm, sourceId, col.getId(), null);
} else {
logger.info("Unable to move item into existing columns on tab {} and unable to create new column", destinationId);
}
}
} else {
// If destination is a column, attempt to move into end of column
if (isFolder(ulm, destinationId)) {
success = attemptNodeMove(ulm, sourceId, destinationId, null);
} else {
// If insertBefore move to prior to node else to end of folder containing node
success = attemptNodeMove(ulm, sourceId, ulm.getParentId(destinationId), "insertBefore".equals(method) ? destinationId : null);
}
}
try {
if (success) {
ulm.saveUserLayout();
}
} catch (PortalException e) {
logger.warn("Error saving layout", e);
return false;
}
return success;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method getNode.
public IUserLayoutNodeDescription getNode(String nodeId) throws PortalException {
if (nodeId == null)
return null;
Document uld = this.getUserLayoutDOM();
if (uld == null)
throw new PortalException("UserLayout has not been initialized for " + owner.getAttribute(IPerson.USERNAME) + ".");
// find an element with a given id
Element element = uld.getElementById(nodeId);
if (element == null) {
throw new PortalException("Element with ID=\"" + nodeId + "\" doesn't exist for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
// instantiate the node description
final IUserLayoutNodeDescription desc = createNodeDescription(element);
return desc;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method moveNode.
public boolean moveNode(String nodeId, String parentId, String nextSiblingId) throws PortalException {
IUserLayoutNodeDescription parent = this.getNode(parentId);
IUserLayoutNodeDescription node = this.getNode(nodeId);
String oldParentNodeId = getParentId(nodeId);
if (canMoveNode(node, parent, nextSiblingId)) {
// must be a folder
Document uld = this.getUserLayoutDOM();
Element childElement = uld.getElementById(nodeId);
Element parentElement = uld.getElementById(parentId);
if (nextSiblingId == null) {
parentElement.appendChild(childElement);
} else {
Node nextSibling = uld.getElementById(nextSiblingId);
parentElement.insertBefore(childElement, nextSibling);
}
this.updateCacheKey();
// propagate the change into the PLF
Element oldParent = uld.getElementById(oldParentNodeId);
TabColumnPrefsHandler.moveElement(childElement, oldParent, owner);
// fire event
final int layoutId = this.getLayoutId();
if (node instanceof IUserLayoutChannelDescription) {
this.channelsAdded = true;
final String fname = ((IUserLayoutChannelDescription) node).getFunctionalName();
this.portalEventFactory.publishPortletMovedInLayoutPortalEvent(this, this.owner, layoutId, oldParentNodeId, parent.getId(), fname);
} else {
this.portalEventFactory.publishFolderMovedInLayoutPortalEvent(this, this.owner, layoutId, oldParentNodeId, parent.getId());
}
return true;
}
return false;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method deleteNode.
public boolean deleteNode(String nodeId) throws PortalException {
if (canDeleteNode(nodeId)) {
IUserLayoutNodeDescription nodeDescription = this.getNode(nodeId);
String parentNodeId = this.getParentId(nodeId);
Document uld = this.getUserLayoutDOM();
Element ilfNode = uld.getElementById(nodeId);
Node parent = ilfNode.getParentNode();
if (parent != null) {
parent.removeChild(ilfNode);
} else {
throw new PortalException("Node \"" + nodeId + "\" has a NULL parent for layout of " + owner.getAttribute(IPerson.USERNAME) + ".");
}
this.updateCacheKey();
// now push into the PLF
TabColumnPrefsHandler.deleteNode(ilfNode, owner);
// inform the listeners
final int layoutId = this.getLayoutId();
if (nodeDescription instanceof IUserLayoutChannelDescription) {
final IUserLayoutChannelDescription userLayoutChannelDescription = (IUserLayoutChannelDescription) nodeDescription;
this.portalEventFactory.publishPortletDeletedFromLayoutPortalEvent(this, this.owner, layoutId, parentNodeId, userLayoutChannelDescription.getFunctionalName());
} else {
this.portalEventFactory.publishFolderDeletedFromLayoutPortalEvent(this, this.owner, layoutId, parentNodeId, nodeDescription.getId(), nodeDescription.getName());
}
return true;
}
return false;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class DistributedLayoutManager method addNode.
public IUserLayoutNodeDescription addNode(IUserLayoutNodeDescription node, String parentId, String nextSiblingId) throws PortalException {
boolean isChannel = false;
IUserLayoutNodeDescription parent = this.getNode(parentId);
if (canAddNode(node, parent, nextSiblingId)) {
// assign new Id
try {
if (node instanceof IUserLayoutChannelDescription) {
isChannel = true;
node.setId(this.distributedLayoutStore.generateNewChannelSubscribeId(owner));
} else {
node.setId(this.distributedLayoutStore.generateNewFolderId(owner));
}
} catch (Exception e) {
throw new PortalException("Exception encountered while " + "generating new user layout node Id for for " + owner.getAttribute(IPerson.USERNAME), e);
}
Document uld = getUserLayoutDOM();
Element childElement = node.getXML(uld);
Element parentElement = uld.getElementById(parentId);
if (nextSiblingId == null) {
parentElement.appendChild(childElement);
} else {
Node nextSibling = uld.getElementById(nextSiblingId);
parentElement.insertBefore(childElement, nextSibling);
}
// register element id
childElement.setIdAttribute(Constants.ATT_ID, true);
childElement.setAttribute(Constants.ATT_ID, node.getId());
this.updateCacheKey();
// push into the user's real layout that gets persisted.
HandlerUtils.createPlfNodeAndPath(childElement, isChannel, owner);
// fire event
final int layoutId = this.getLayoutId();
if (isChannel) {
this.channelsAdded = true;
final String fname = ((IUserLayoutChannelDescription) node).getFunctionalName();
this.portalEventFactory.publishPortletAddedToLayoutPortalEvent(this, this.owner, layoutId, parent.getId(), fname);
} else {
this.portalEventFactory.publishFolderAddedToLayoutPortalEvent(this, this.owner, layoutId, node.getId());
}
return node;
}
return null;
}
Aggregations