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;
}
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;
}
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));
}
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);
}
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;
}
Aggregations