Search in sources :

Example 1 with DistributedUserLayout

use of org.apereo.portal.layout.dlm.DistributedUserLayout in project uPortal by Jasig.

the class PortletMarketplaceController method getLayoutInfo.

@ResourceMapping("layoutInfo")
public String getLayoutInfo(ResourceRequest request, @RequestParam String portletFName, Model model) throws TransformerException {
    Validate.notNull(portletFName, "Please supply a portlet fname");
    final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IUserInstance ui = userInstanceManager.getUserInstance(servletRequest);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    IPerson person = ui.getPerson();
    DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, upm.getUserProfile());
    List<PortletTab> tabs = getPortletTabInfo(userLayout, portletFName);
    boolean isFavorite = isPortletFavorited(ulm.getUserLayout(), portletFName);
    model.addAttribute("favorite", isFavorite);
    model.addAttribute("tabs", tabs);
    return "json";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 2 with DistributedUserLayout

use of org.apereo.portal.layout.dlm.DistributedUserLayout in project uPortal by Jasig.

the class LayoutRESTController method getRESTController.

/**
     * A REST call to get a json feed of the current users layout. Intent was to provide a layout
     * document without per-tab information for mobile device rendering.
     *
     * @param request The servlet request. Utilized to get the users instance and eventually there
     *     layout
     * @param tab The tab name of which you would like to filter; optional; if not provided, will
     *     return entire layout.
     * @return json feed of the layout
     * @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
     *     includes regions and breakout per tab
     */
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
    final IPerson person = personManager.getPerson(request);
    List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
    try {
        final IUserInstance ui = userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager upm = ui.getPreferencesManager();
        final IUserProfile profile = upm.getUserProfile();
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
        Document document = userLayout.getLayout();
        NodeList portletNodes = null;
        if (tab != null) {
            NodeList folders = document.getElementsByTagName("folder");
            for (int i = 0; i < folders.getLength(); i++) {
                Node node = folders.item(i);
                if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
                    TabListOfNodes tabNodes = new TabListOfNodes();
                    tabNodes.addAllChannels(node.getChildNodes());
                    portletNodes = tabNodes;
                    break;
                }
            }
        } else {
            portletNodes = document.getElementsByTagName("channel");
        }
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                //get alt max URL
                String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
                if (alternativeMaximizedLink != null) {
                    portlet.setUrl(alternativeMaximizedLink);
                    portlet.setAltMaxUrl(true);
                } else {
                    // get the maximized URL for this portlet
                    final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
                    final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
                    if (targetPortletWindowId != null) {
                        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
                        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
                    }
                    portlet.setUrl(portalUrlBuilder.getUrlString());
                    portlet.setAltMaxUrl(false);
                }
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("layout", portlets);
        mv.setViewName("json");
        return mv;
    } catch (Exception e) {
        log.error("Error retrieving user layout document", e);
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) TabListOfNodes(org.apereo.portal.rest.layout.TabListOfNodes) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DistributedUserLayout

use of org.apereo.portal.layout.dlm.DistributedUserLayout in project uPortal by Jasig.

the class UpdatePreferencesServlet method subscribeToTab.

/**
     * Subscribe a user to a pre-formatted tab (pulled DLM fragment).
     *
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=subscribeToTab")
public ModelAndView subscribeToTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    // Get the fragment owner's name from the request and construct
    // an IPerson object representing that user
    String fragmentOwnerName = request.getParameter("sourceID");
    if (StringUtils.isBlank(fragmentOwnerName)) {
        logger.warn("Attempted to subscribe to tab with null owner ID");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Attempted to subscribe to tab with null owner ID"));
    }
    RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
    fragmentOwner.setUserName(fragmentOwnerName);
    // Mark the currently-authenticated user as subscribed to this fragment.
    // If an inactivated fragment registration already exists, update it
    // as an active subscription.  Otherwise, create a new fragment
    // subscription.
    IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao.getUserFragmentInfo(per, fragmentOwner);
    if (userFragmentInfo == null) {
        userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per, fragmentOwner);
    } else {
        userFragmentInfo.setActive(true);
        userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
    }
    try {
        // reload user layout and stylesheet to incorporate new DLM fragment
        ulm.loadUserLayout(true);
        // get the target node this new tab should be moved after
        String destinationId = request.getParameter("elementID");
        // get the user layout for the currently-authenticated user
        int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
        Document layoutDocument = userLayout.getLayout();
        // attempt to find the new subscribed tab in the layout so we can
        // move it
        StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'").append(Constants.FRAGMENT_ID_USER_PREFIX).append(uid).append("')]");
        XPathFactory fac = XPathFactory.newInstance();
        XPath xpath = fac.newXPath();
        NodeList nodes = (NodeList) xpath.evaluate(expression.toString(), layoutDocument, XPathConstants.NODESET);
        String sourceId = nodes.item(0).getAttributes().getNamedItem("ID").getTextContent();
        ulm.moveNode(sourceId, ulm.getParentId(destinationId), destinationId);
        ulm.saveUserLayout();
        return new ModelAndView("jsonView", Collections.singletonMap("tabId", sourceId));
    } catch (XPathExpressionException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Xpath error"));
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) Document(org.w3c.dom.Document) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) XPathFactory(javax.xml.xpath.XPathFactory) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DistributedUserLayout (org.apereo.portal.layout.dlm.DistributedUserLayout)3 IPerson (org.apereo.portal.security.IPerson)3 IUserInstance (org.apereo.portal.user.IUserInstance)3 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)2 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 IUserProfile (org.apereo.portal.IUserProfile)1 PortalException (org.apereo.portal.PortalException)1 IUserFragmentSubscription (org.apereo.portal.fragment.subscribe.IUserFragmentSubscription)1 LayoutPortlet (org.apereo.portal.layout.LayoutPortlet)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1