Search in sources :

Example 1 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class SubscribableTabsRESTController method getSubscriptionList.

@RequestMapping(value = "/subscribableTabs.json", method = RequestMethod.GET)
public ModelAndView getSubscriptionList(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>();
    /** Retrieve the IPerson and IAuthorizationPrincipal for the currently authenticated user */
    IUserInstance userInstance = userInstanceManager.getUserInstance(request);
    IPerson person = userInstance.getPerson();
    AuthorizationService authService = AuthorizationService.instance();
    IAuthorizationPrincipal principal = authService.newPrincipal(person.getUserName(), IPerson.class);
    /**
         * Build a collection of owner IDs for the fragments to which the authenticated user is
         * subscribed
         */
    // get the list of current subscriptions for this user
    List<IUserFragmentSubscription> subscriptions = userFragmentSubscriptionDao.getUserFragmentInfo(person);
    // transform it into the set of owners
    Set<String> subscribedOwners = new HashSet<String>();
    for (IUserFragmentSubscription subscription : subscriptions) {
        if (subscription.isActive()) {
            subscribedOwners.add(subscription.getFragmentOwner());
        }
    }
    /**
         * Iterate through the list of all currently defined DLM fragments and determine if the
         * current user has permissions to subscribe to each. Any subscribable fragments will be
         * transformed into a JSON-friendly bean and added to the model.
         */
    final List<SubscribableFragment> jsonFragments = new ArrayList<SubscribableFragment>();
    // get the list of fragment definitions from DLM
    final List<FragmentDefinition> fragmentDefinitions = configurationLoader.getFragments();
    final Locale locale = RequestContextUtils.getLocale(request);
    // iterate through the list
    for (FragmentDefinition fragmentDefinition : fragmentDefinitions) {
        if (isSubscribable(fragmentDefinition, principal)) {
            String owner = fragmentDefinition.getOwnerId();
            // this fragment
            if (principal.hasPermission("UP_FRAGMENT", "FRAGMENT_SUBSCRIBE", owner)) {
                // create a JSON fragment bean and add it to our list
                boolean subscribed = subscribedOwners.contains(owner);
                final String name = getMessage("fragment." + owner + ".name", fragmentDefinition.getName(), locale);
                final String description = getMessage("fragment." + owner + ".description", fragmentDefinition.getDescription(), locale);
                SubscribableFragment jsonFragment = new SubscribableFragment(name, description, owner, subscribed);
                jsonFragments.add(jsonFragment);
            }
        }
    }
    model.put("fragments", jsonFragments);
    return new ModelAndView("json", model);
}
Also used : Locale(java.util.Locale) FragmentDefinition(org.apereo.portal.layout.dlm.FragmentDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserFragmentSubscription(org.apereo.portal.fragment.subscribe.IUserFragmentSubscription) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IUserInstance

use of org.apereo.portal.user.IUserInstance 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);
    final 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);
        final Document document = userLayout.getLayout();
        final NodeList portletNodes = getNodeList(tab, document);
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                final NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                final IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                final LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                // get alt max URL
                setAltMaxURL(request, attributes, def, portlet);
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        final 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) NodeList(org.w3c.dom.NodeList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServletTest method testRemoveFavorite.

@Test(expected = NullPointerException.class)
public void testRemoveFavorite() throws IOException {
    req.setLocalName("en-US");
    IPerson person = new PersonImpl();
    person.setUserName("jdoe");
    person.setFullName("john doe");
    IUserInstance userInstance = new UserInstance(person, null, null);
    Mockito.when(userInstanceManager.getUserInstance(req)).thenReturn(userInstance);
    ModelAndView modelAndView = updatePreferencesServlet.removeFavorite("channelId", req, res);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) PersonImpl(org.apereo.portal.security.provider.PersonImpl) ModelAndView(org.springframework.web.servlet.ModelAndView) UserInstance(org.apereo.portal.UserInstance) IUserInstance(org.apereo.portal.user.IUserInstance) Test(org.junit.Test)

Example 4 with IUserInstance

use of org.apereo.portal.user.IUserInstance 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 5 with IUserInstance

use of org.apereo.portal.user.IUserInstance 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)

Aggregations

IUserInstance (org.apereo.portal.user.IUserInstance)67 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)29 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)28 IPerson (org.apereo.portal.security.IPerson)26 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)16 PortalException (org.apereo.portal.PortalException)14 ModelAndView (org.springframework.web.servlet.ModelAndView)14 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)12 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 IUserProfile (org.apereo.portal.IUserProfile)10 Locale (java.util.Locale)9 IUserLayout (org.apereo.portal.layout.IUserLayout)8 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)8 HashMap (java.util.HashMap)6 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)6 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)5 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)5