Search in sources :

Example 11 with IUserLayoutNodeDescription

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

Example 12 with IUserLayoutNodeDescription

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

Example 13 with IUserLayoutNodeDescription

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

Example 14 with IUserLayoutNodeDescription

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 15 with IUserLayoutNodeDescription

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

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