Search in sources :

Example 6 with IUserLayoutNodeDescription

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;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) UserLayoutFolderDescription(org.apereo.portal.layout.node.UserLayoutFolderDescription) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 7 with IUserLayoutNodeDescription

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;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document)

Example 8 with IUserLayoutNodeDescription

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;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription)

Example 9 with IUserLayoutNodeDescription

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;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription)

Example 10 with IUserLayoutNodeDescription

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;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) XMLStreamException(javax.xml.stream.XMLStreamException) PortalException(org.apereo.portal.PortalException)

Aggregations

IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)30 PortalException (org.apereo.portal.PortalException)14 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)14 IUserInstance (org.apereo.portal.user.IUserInstance)12 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)11 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)8 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)8 Element (org.w3c.dom.Element)7 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 Document (org.w3c.dom.Document)5 Node (org.w3c.dom.Node)5 ArrayList (java.util.ArrayList)4 Enumeration (java.util.Enumeration)4 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 UserLayoutChannelDescription (org.apereo.portal.layout.node.UserLayoutChannelDescription)4 List (java.util.List)3