Search in sources :

Example 11 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class JspInvokerPortletController method getViewLocation.

private String getViewLocation(PortletRequest req) {
    String rslt;
    PortletPreferences prefs = req.getPreferences();
    String preferenceViewLocation = prefs.getValue(VIEW_LOCATION_PREFERENCE, null);
    if (StringUtils.isNotBlank(preferenceViewLocation)) {
        rslt = preferenceViewLocation;
    } else {
        throw new RuntimeException("Portlet preference '" + VIEW_LOCATION_PREFERENCE + "' not set");
    }
    logger.debug("Invoking with viewLocation={}", rslt);
    return rslt;
}
Also used : PortletPreferences(javax.portlet.PortletPreferences)

Example 12 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class PortletMarketplaceController method getPermittedCategories.

private Set<PortletCategory> getPermittedCategories(PortletRequest req) {
    // default
    Set<PortletCategory> rslt = Collections.emptySet();
    final PortletPreferences prefs = req.getPreferences();
    final String[] permittedCategories = prefs.getValues(PERMITTED_CATEGORIES_PREFERENCE, new String[0]);
    if (permittedCategories.length != 0) {
        // Expensive to create, use cache for this collection...
        Set<String> cacheKey = new HashSet<>(Arrays.asList(permittedCategories));
        net.sf.ehcache.Element cacheElement = marketplaceCategoryCache.get(cacheKey);
        if (cacheElement == null) {
            // Nothing in cache currently;  need to populate cache
            HashSet<PortletCategory> portletCategories = new HashSet<>();
            for (final String categoryName : permittedCategories) {
                EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
                if (cats != null && cats.length > 0) {
                    PortletCategory pc = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
                    if (pc != null) {
                        portletCategories.add(pc);
                    } else {
                        logger.warn("No PortletCategory found in portletCategoryRegistry for id '{}'", cats[0].getKey());
                    }
                } else {
                    logger.warn("No category found in GroupService for name '{}'", categoryName);
                }
            }
            /*
                 * Sanity Check:  Since at least 1 category name was specified, we
                 * need to make certain there's at least 1 PortletCategory in the
                 * set;  otherwise, a restricted Marketplace portlet would become
                 * an unrestricted one.
                 */
            if (portletCategories.isEmpty()) {
                throw new IllegalStateException("None of the specified category " + "names could be resolved to a PortletCategory:  " + Arrays.asList(permittedCategories));
            }
            cacheElement = new net.sf.ehcache.Element(cacheKey, portletCategories);
            this.marketplaceCategoryCache.put(cacheElement);
        }
        rslt = (Set<PortletCategory>) cacheElement.getObjectValue();
    }
    return rslt;
}
Also used : EntityIdentifier(org.apereo.portal.EntityIdentifier) PortletPreferences(javax.portlet.PortletPreferences) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet)

Example 13 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class PortletMarketplaceController method saveRating.

/**
     * Use to save the rating of portlet
     *
     * @param request
     * @param response
     * @param portletFName fname of the portlet to rate
     * @param rating will be parsed to int
     * @param review optional review to be saved along with rating
     * @throws NumberFormatException if rating cannot be parsed to an int
     */
@ResourceMapping("saveRating")
public void saveRating(ResourceRequest request, ResourceResponse response, PortletRequest portletRequest, @RequestParam String portletFName, @RequestParam String rating, @RequestParam(required = false) String review) {
    Validate.notNull(rating, "Please supply a rating - should not be null");
    Validate.notNull(portletFName, "Please supply a portlet to rate - should not be null");
    // Make certain reviews are permitted before trying to save one
    final PortletPreferences prefs = request.getPreferences();
    final String enableReviewsPreferenceValue = prefs.getValue(ENABLE_REVIEWS_PREFERENCE, ENABLE_REVIEWS_DEFAULT);
    if (!Boolean.valueOf(enableReviewsPreferenceValue)) {
        // Clear the parameter if sent...
        review = null;
    }
    marketplaceRatingDAO.createOrUpdateRating(Integer.parseInt(rating), portletRequest.getRemoteUser(), review, portletDefinitionDao.getPortletDefinitionByFname(portletFName));
}
Also used : PortletPreferences(javax.portlet.PortletPreferences) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 14 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class SearchPortletController method showSearchForm.

/** Display a search form */
@RequestMapping
public ModelAndView showSearchForm(RenderRequest request, RenderResponse response) {
    final Map<String, Object> model = new HashMap<>();
    // Determine if this portlet displays the search launch view or regular search view.
    PortletPreferences prefs = request.getPreferences();
    final boolean isMobile = isMobile(request);
    String viewName = isMobile ? "/jsp/Search/mobileSearch" : "/jsp/Search/search";
    // If this search portlet is configured to be the searchLauncher, calculate the URLs to the indicated
    // search portlet.
    final String searchLaunchFname = prefs.getValue(SEARCH_LAUNCH_FNAME, null);
    if (searchLaunchFname != null) {
        model.put("searchLaunchUrl", calculateSearchLaunchUrl(request, response));
        model.put("autocompleteUrl", calculateAutocompleteResourceUrl(request, response));
        viewName = "/jsp/Search/searchLauncher";
    }
    return new ModelAndView(viewName, model);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with PortletPreferences

use of javax.portlet.PortletPreferences in project uPortal by Jasig.

the class PreferencesHeaderProvider method createHeader.

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
    // Username
    final String username = getUsername(renderRequest);
    // PreferencesMap
    final Map<String, List<String>> preferencesMap = new HashMap<>();
    final PortletPreferences prefs = renderRequest.getPreferences();
    for (Map.Entry<String, String[]> y : prefs.getMap().entrySet()) {
        final String name = y.getKey();
        /*
             * We ignore (skip) preferences that exist for the benefit of the
             * SoffitConnectorController.
             */
        if (name.startsWith(SoffitConnectorController.CONNECTOR_PREFERENCE_PREFIX)) {
            continue;
        }
        List<String> values = Arrays.asList(prefs.getValues(name, new String[0]));
        if (!values.isEmpty()) {
            preferencesMap.put(name, values);
        }
    }
    // Preferences header
    final Preferences preferences = preferencesService.createPreferences(preferencesMap, username, getExpiration(renderRequest));
    final Header rslt = new BasicHeader(Headers.PREFERECES.getName(), preferences.getEncryptedToken());
    logger.debug("Produced the following Preferences header for username='{}':  {}", username, rslt);
    return rslt;
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HashMap(java.util.HashMap) List(java.util.List) PortletPreferences(javax.portlet.PortletPreferences) PortletPreferences(javax.portlet.PortletPreferences) Preferences(org.apereo.portal.soffit.model.v1_0.Preferences) HashMap(java.util.HashMap) Map(java.util.Map) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

PortletPreferences (javax.portlet.PortletPreferences)38 HashMap (java.util.HashMap)10 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)9 ModelAndView (org.springframework.web.portlet.ModelAndView)6 List (java.util.List)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPerson (org.apereo.portal.security.IPerson)5 PortletRequest (javax.portlet.PortletRequest)4 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Header (org.apache.http.Header)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2