Search in sources :

Example 11 with IUserLayoutChannelDescription

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

the class UpdatePreferencesServlet method removeFavorite.

/**
 * This method removes the channelId specified from favorites. Note that even if you pass in the
 * layout channel id, it will always remove from the favorites.
 *
 * @param channelId The long channel ID that is used to determine which fname to remove from
 *     favorites
 * @param request
 * @param response
 * @return returns a mav object with a response attribute for noty
 * @throws IOException if it has problem reading the layout file.
 */
@RequestMapping(method = RequestMethod.POST, params = "action=removeFavorite")
public ModelAndView removeFavorite(@RequestParam String channelId, HttpServletRequest request, HttpServletResponse response) throws IOException {
    UserPreferencesManager upm = (UserPreferencesManager) userInstanceManager.getUserInstance(request).getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    final Locale locale = RequestContextUtils.getLocale(request);
    IPortletDefinition portletDefinition = portletDefinitionRegistry.getPortletDefinition(channelId);
    if (portletDefinition != null && StringUtils.isNotBlank(portletDefinition.getFName())) {
        String functionalName = portletDefinition.getFName();
        List<IUserLayoutNodeDescription> favoritePortlets = favoritesUtils.getFavoritePortletLayoutNodes(ulm.getUserLayout());
        // Retrieve favorites matching functional name from list of favorites
        List<IUserLayoutChannelDescription> favoritesToDelete = FavoritesUtils.getDuplicateFavoritesByFNameToDelete(favoritePortlets, functionalName);
        String resp = new String();
        for (IUserLayoutChannelDescription deleteNode : favoritesToDelete) {
            if (deleteNode != null && deleteNode instanceof UserLayoutChannelDescription) {
                UserLayoutChannelDescription channelDescription = (UserLayoutChannelDescription) deleteNode;
                try {
                    if (!ulm.deleteNode(channelDescription.getChannelSubscribeId())) {
                        logger.warn("Error deleting the node {} from favorites for user {}", channelId, (upm.getPerson() == null ? "unknown" : upm.getPerson().getID()));
                        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
                        // load fail message
                        resp = getMessage("error.remove.favorite", "Can''t remove favorite", locale);
                    } else {
                        // load success message
                        resp = getMessage("success.remove.portlet", "Removed from Favorites successfully", locale);
                    }
                    // save the user's layout
                    ulm.saveUserLayout();
                } catch (PortalException e) {
                    return handlePersistError(request, response, e);
                }
            }
        }
        return new ModelAndView("jsonView", Collections.singletonMap("response", resp));
    }
    // save the user's layout
    ulm.saveUserLayout();
    return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.finding.favorite", "Can''t find favorite", locale)));
}
Also used : Locale(java.util.Locale) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserLayoutChannelDescription(org.apereo.portal.layout.node.UserLayoutChannelDescription) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with IUserLayoutChannelDescription

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

the class TransientPortletEntityDao method determineDatabaseChannelSubscribeId.

protected String determineDatabaseChannelSubscribeId(String layoutNodeId) {
    // Find the referenced Node in the user's layout
    final IUserLayoutManager userLayoutManager = this.getUserLayoutManager();
    final IUserLayoutChannelDescription channelNode = (IUserLayoutChannelDescription) userLayoutManager.getNode(layoutNodeId);
    // Lookup the IportletDefinition for the node
    final String portletPublishId = channelNode.getChannelPublishId();
    final IPortletDefinition portletDefinition = this.portletDefinitionRegistry.getPortletDefinition(portletPublishId);
    // Generate the subscribe ID used for the database
    return this.getPersistentLayoutNodeId(portletDefinition.getPortletDefinitionId());
}
Also used : IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 13 with IUserLayoutChannelDescription

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

the class FavoritesUtils method getFavoritePortletDefinitions.

public Set<IPortletDefinition> getFavoritePortletDefinitions(IUserLayout layout) {
    final Set<IPortletDefinition> rslt = new HashSet<>();
    final List<IUserLayoutNodeDescription> favoriteLayoutNodes = getFavoritePortletLayoutNodes(layout);
    favoriteLayoutNodes.stream().forEach(node -> {
        if (IUserLayoutChannelDescription.class.isInstance(node)) {
            final IUserLayoutChannelDescription chanDef = (IUserLayoutChannelDescription) node;
            // Not the most usable API...
            final IPortletDefinitionId pId = new IPortletDefinitionId() {

                @Override
                public long getLongId() {
                    return Long.valueOf(chanDef.getChannelPublishId());
                }

                @Override
                public String getStringId() {
                    return chanDef.getChannelPublishId();
                }
            };
            final IPortletDefinition pDef = portletRegistry.getPortletDefinition(pId);
            if (pDef != null) {
                rslt.add(pDef);
            }
        }
    });
    return rslt;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet)

Example 14 with IUserLayoutChannelDescription

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

the class FavoritesUtils method castListChannelDescriptionToListNodeDescription.

public static List<IUserLayoutNodeDescription> castListChannelDescriptionToListNodeDescription(List<IUserLayoutChannelDescription> nodeList) {
    List<IUserLayoutNodeDescription> nodeDescriptionList = new ArrayList<>();
    for (IUserLayoutNodeDescription nodeDescription : nodeList) {
        if (nodeDescription instanceof IUserLayoutChannelDescription) {
            final IUserLayoutChannelDescription channelDescription = (IUserLayoutChannelDescription) nodeDescription;
            nodeDescriptionList.add(channelDescription);
        }
    }
    return nodeDescriptionList;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) ArrayList(java.util.ArrayList) 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