Search in sources :

Example 6 with IUserLayoutChannelDescription

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

the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.

protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
    Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
    // Check in the cache first
    final Element element = this.entityIdParseCache.get(consistentEntityIdString);
    if (element != null) {
        final Object value = element.getObjectValue();
        if (value != null) {
            return (IPortletEntityId) value;
        }
    }
    if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
        throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
    }
    // Verify the portlet definition id
    final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
    if (portletDefinition == null) {
        throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
    }
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Verify non-delegate layout node id exists and is for a portlet
    final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
    if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
        final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
        if (node == null || node.getType() != LayoutNodeType.PORTLET) {
            throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
        }
        // TODO is this doable for delegation?
        // Verify the portlet definition matches
        final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
        final String channelPublishId = portletNode.getChannelPublishId();
        if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
            throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
        }
    }
    // TODO when there is a JPA backed user dao actually verify this mapping
    // User just conver to an int
    final int userId;
    final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
    try {
        userId = Integer.parseInt(userIdAsString);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
    }
    final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
    // Cache the resolution
    this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
    return portletEntityId;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(net.sf.ehcache.Element) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 7 with IUserLayoutChannelDescription

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

the class PortletEntityRegistryImpl method getOrCreatePortletEntity.

@Override
public IPortletEntity getOrCreatePortletEntity(HttpServletRequest request, IUserInstance userInstance, String layoutNodeId) {
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Find the channel and portlet definitions
    final IUserLayoutChannelDescription channelNode = (IUserLayoutChannelDescription) userLayoutManager.getNode(layoutNodeId);
    if (channelNode == null) {
        this.logger.warn("No layout node exists for id " + layoutNodeId + ", no portlet entity will be returned.");
        return null;
    }
    final String channelPublishId = channelNode.getChannelPublishId();
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, userInstance, channelPublishId);
    if (portletDefinition != null) {
        final IPerson person = userInstance.getPerson();
        return this.getOrCreatePortletEntity(request, portletDefinition.getPortletDefinitionId(), layoutNodeId, person.getID());
    }
    // No permission to see the portlet
    return null;
}
Also used : IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 8 with IUserLayoutChannelDescription

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

the class TransientUserLayoutManagerWrapper method createUserLayoutChannelDescription.

protected IUserLayoutChannelDescription createUserLayoutChannelDescription(String nodeId, IPortletDefinition chanDef) {
    IUserLayoutChannelDescription ulnd = new UserLayoutChannelDescription();
    ulnd.setId(nodeId);
    ulnd.setName(chanDef.getName());
    ulnd.setUnremovable(true);
    ulnd.setImmutable(true);
    ulnd.setHidden(false);
    ulnd.setTitle(chanDef.getTitle());
    ulnd.setDescription(chanDef.getDescription());
    ulnd.setChannelPublishId("" + chanDef.getPortletDefinitionId().getStringId());
    ulnd.setChannelTypeId("" + chanDef.getType().getId());
    ulnd.setFunctionalName(chanDef.getFName());
    ulnd.setTimeout(chanDef.getTimeout());
    Set<IPortletDefinitionParameter> parms = chanDef.getParameters();
    for (IPortletDefinitionParameter parm : parms) {
        ulnd.setParameterValue(parm.getName(), parm.getValue());
    }
    return ulnd;
}
Also used : IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) UserLayoutChannelDescription(org.apereo.portal.layout.node.UserLayoutChannelDescription) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription)

Example 9 with IUserLayoutChannelDescription

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

the class UpdatePreferencesServlet method addFavorite.

@RequestMapping(method = RequestMethod.POST, params = "action=addFavorite")
public ModelAndView addFavorite(@RequestParam String channelId, HttpServletRequest request, HttpServletResponse response) throws IOException {
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = getPerson(ui, response);
    final IPortletDefinition pdef = portletDefinitionRegistry.getPortletDefinition(channelId);
    final Locale locale = RequestContextUtils.getLocale(request);
    final IAuthorizationPrincipal authPrincipal = this.getUserPrincipal(person.getUserName());
    final String targetString = PermissionHelper.permissionTargetIdForPortletDefinition(pdef);
    if (!authPrincipal.hasPermission(IPermission.PORTAL_SYSTEM, IPermission.PORTLET_FAVORITE_ACTIVITY, targetString)) {
        logger.warn("Unauthorized attempt to favorite portlet '{}' through the REST API by user '{}'", pdef.getFName(), person.getUserName());
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.favorite.not.permitted", "Favorite not permitted", locale)));
    }
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(person, pdef, request.getSession());
    // get favorite tab
    final String favoriteTabNodeId = favoritesUtils.getFavoriteTabNodeId(ulm.getUserLayout());
    if (favoriteTabNodeId != null) {
        // add portlet to favorite tab
        final IUserLayoutNodeDescription node = addNodeToTab(ulm, channel, favoriteTabNodeId);
        if (node == null) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.add.portlet.in.tab", "Can''t add a new favorite", locale)));
        }
        try {
            // save the user's layout
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }
        // document success for notifications
        final Map<String, String> model = new HashMap<>();
        final String channelTitle = channel.getTitle();
        model.put("response", getMessage("favorites.added.favorite", channelTitle, "Added " + channelTitle + " as a favorite.", locale));
        model.put("newNodeId", node.getId());
        return new ModelAndView("jsonView", model);
    } else {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.finding.favorite.tab", "Can''t find favorite tab", locale)));
    }
}
Also used : Locale(java.util.Locale) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) 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) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with IUserLayoutChannelDescription

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

the class UpdatePreferencesServlet method addPortlet.

/**
 * Add a new channel.
 *
 * @param request
 * @param response
 * @throws IOException
 * @throws PortalException
 */
@RequestMapping(method = RequestMethod.POST, params = "action=addPortlet")
public ModelAndView addPortlet(HttpServletRequest request, HttpServletResponse response) throws IOException, PortalException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    final Locale locale = RequestContextUtils.getLocale(request);
    // gather the parameters we need to move a channel
    String destinationId = request.getParameter("elementID");
    String sourceId = request.getParameter("channelID");
    String method = request.getParameter("position");
    String fname = request.getParameter("fname");
    if (destinationId == null) {
        String tabName = request.getParameter("tabName");
        if (tabName != null) {
            destinationId = getTabIdFromName(ulm.getUserLayout(), tabName);
        }
    }
    IPortletDefinition definition;
    if (sourceId != null)
        definition = portletDefinitionRegistry.getPortletDefinition(sourceId);
    else if (fname != null)
        definition = portletDefinitionRegistry.getPortletDefinitionByFname(fname);
    else {
        logger.error("SourceId or fname invalid when adding a portlet");
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "SourceId or fname invalid"));
    }
    IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(getPerson(ui, response), definition, request.getSession());
    IUserLayoutNodeDescription node;
    if (isTab(ulm, destinationId)) {
        node = addNodeToTab(ulm, channel, destinationId);
    } else {
        boolean isInsert = method != null && method.equals("insertBefore");
        // If neither an insert or type folder - Can't "insert into" non-folder
        if (!(isInsert || isFolder(ulm, destinationId))) {
            logger.error("Cannot insert into portlet element");
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return new ModelAndView("jsonView", Collections.singletonMap("error", "Cannot insert into portlet element"));
        }
        String siblingId = isInsert ? destinationId : null;
        String target = isInsert ? ulm.getParentId(destinationId) : destinationId;
        // move the channel into the column
        node = ulm.addNode(channel, target, siblingId);
    }
    if (node == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.add.element", "Unable to add element", locale)));
    }
    String nodeId = node.getId();
    try {
        // save the user's layout
        ulm.saveUserLayout();
        if (addedWindowState != null) {
            IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, channel.getFunctionalName());
            portletWindow.setWindowState(addedWindowState);
            this.portletWindowRegistry.storePortletWindow(request, portletWindow);
        }
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    Map<String, String> model = new HashMap<>();
    model.put("response", getMessage("success.add.portlet", "Added a new channel", locale));
    model.put("newNodeId", nodeId);
    return new ModelAndView("jsonView", model);
}
Also used : Locale(java.util.Locale) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IUserInstance(org.apereo.portal.user.IUserInstance) 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) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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