Search in sources :

Example 1 with IUserLayoutChannelDescription

use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.

the class FavoritesController method initializeView.

/**
 * Handles all Favorites portlet VIEW mode renders. Populates model with user's favorites and
 * selects a view to display those favorites.
 *
 * <p>View selection:
 *
 * <p>Returns "jsp/Favorites/view" in the normal case where the user has at least one favorited
 * portlet or favorited collection.
 *
 * <p>Returns "jsp/Favorites/view_zero" in the edge case where the user has zero favorited
 * portlets AND zero favorited collections.
 *
 * <p>Model: marketPlaceFname --> String functional name of Marketplace portlet, or null if not
 * available. collections --> List of favorited collections (IUserLayoutNodeDescription s)
 * favorites --> List of favorited individual portlets (IUserLayoutNodeDescription s)
 *
 * @param model . Spring model. This method adds three model attributes.
 * @return jsp/Favorites/view[_zero]
 */
@RenderMapping
public String initializeView(PortletRequest req, Model model) {
    final IUserInstance ui = userInstanceManager.getUserInstance(portalRequestUtils.getCurrentPortalRequest());
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final IUserLayout userLayout = ulm.getUserLayout();
    // TODO: the portlet could predicate including a non-null marketplace portlet fname
    // on the accessing user having permission to render the portlet referenced by that fname
    // so that portlet would gracefully degrade when configured with bad marketplace portlet
    // fname
    // and also gracefully degrade when the accessing user doesn't have permission to access an
    // otherwise
    // viable configured marketplace.  This complexity may not be worth it.  Anyway it is not
    // yet implemented.
    model.addAttribute("marketplaceFname", this.marketplaceFName);
    final List<IUserLayoutNodeDescription> collections = favoritesUtils.getFavoriteCollections(userLayout);
    model.addAttribute("collections", collections);
    final List<IUserLayoutNodeDescription> rawFavorites = favoritesUtils.getFavoritePortletLayoutNodes(userLayout);
    /*
         * Filter the collection by SUBSCRIBE permission.
         *
         * NOTE:  In the "regular" (non-Favorites) layout, this permissions check is handled by
         * the rendering engine.  It will refuse to spawn a worker for a portlet to which you
         * cannot SUBSCRIBE.
         */
    final String username = req.getRemoteUser() != null ? req.getRemoteUser() : // First item is the default
    PersonFactory.getGuestUsernames().get(0);
    final IAuthorizationPrincipal principal = authorizationService.newPrincipal(username, IPerson.class);
    // final List<IUserLayoutNodeDescription> favorites = new ArrayList<>();
    final List<IUserLayoutChannelDescription> favoriteChannelDescriptions = new ArrayList<>();
    for (IUserLayoutNodeDescription nodeDescription : rawFavorites) {
        if (nodeDescription instanceof IUserLayoutChannelDescription) {
            final IUserLayoutChannelDescription channelDescription = (IUserLayoutChannelDescription) nodeDescription;
            if (principal.canRender(channelDescription.getChannelPublishId())) {
                // favorites.add(nodeDescription);
                favoriteChannelDescriptions.add(channelDescription);
            }
        }
    }
    // Filter list of IUserLayoutChannelDescription by FunctionalName
    final List<IUserLayoutChannelDescription> uniqueFavoritesChannel = FavoritesUtils.filterChannelFavoritesToUnique(favoriteChannelDescriptions);
    // Cast List of IUserLayoutChannelDescription to List of IUserLayoutNodeDescription
    final List<IUserLayoutNodeDescription> uniqueFavorites = FavoritesUtils.castListChannelDescriptionToListNodeDescription(uniqueFavoritesChannel);
    model.addAttribute("favorites", uniqueFavorites);
    // default to the regular old view
    String viewName = "jsp/Favorites/view";
    if (collections.isEmpty() && uniqueFavorites.isEmpty()) {
        // special edge case of zero favorites, switch to special view
        viewName = "jsp/Favorites/view_zero";
    }
    logger.debug("Favorites Portlet VIEW mode render populated model [{}] for render by view {}.", model, viewName);
    return viewName;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 2 with IUserLayoutChannelDescription

use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.

the class DistributedLayoutManager method moveNode.

@Override
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 3 with IUserLayoutChannelDescription

use of org.apereo.portal.layout.node.IUserLayoutChannelDescription 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.
 */
@Override
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.getUserName() + ".");
            }
            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 4 with IUserLayoutChannelDescription

use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.

the class DistributedLayoutManager method addNode.

@Override
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.getUserName(), 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)

Example 5 with IUserLayoutChannelDescription

use of org.apereo.portal.layout.node.IUserLayoutChannelDescription in project uPortal by Jasig.

the class DistributedLayoutManager method deleteNode.

@Override
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.getUserName() + ".");
        }
        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)

Aggregations

IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)14 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 PortalException (org.apereo.portal.PortalException)6 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)4 UserLayoutChannelDescription (org.apereo.portal.layout.node.UserLayoutChannelDescription)4 IUserInstance (org.apereo.portal.user.IUserInstance)4 Locale (java.util.Locale)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)2 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 IPerson (org.apereo.portal.security.IPerson)2