use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class MarketplaceEntry method getPortletCategories.
private Set<String> getPortletCategories(MarketplacePortletDefinition pdef) {
Set<PortletCategory> categories = pdef.getCategories();
Set<String> rslt = new HashSet<String>();
for (PortletCategory category : categories) {
String lowerCase = category.getName().toLowerCase();
if (!"all categories".equals(lowerCase)) {
rslt.add(StringUtils.capitalize(category.getName().toLowerCase()));
}
}
return rslt;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class AuthorizationImpl method canPrincipalManage.
/**
* This checks if the framework has granted principal a right to publish. DO WE WANT SOMETHING
* THIS COARSE (de)?
*
* @param principal IAuthorizationPrincipal
* @return boolean
*/
@RequestCache
public boolean canPrincipalManage(IAuthorizationPrincipal principal, PortletLifecycleState state, String categoryId) throws AuthorizationException {
// return doesPrincipalHavePermission
// (principal, IPermission.PORTAL_FRAMEWORK, IPermission.CHANNEL_PUBLISHER_ACTIVITY, null);
String owner = IPermission.PORTAL_PUBLISH;
// retrieve the indicated channel from the channel registry store and
// determine its current lifecycle state
PortletCategory category = PortletCategoryRegistryLocator.getPortletCategoryRegistry().getPortletCategory(categoryId);
if (category == null) {
// IPermission.CHANNEL_MANAGER_APPROVED_ACTIVITY, target);
throw new AuthorizationException("Unable to locate category " + categoryId);
}
int order = state.getOrder();
String activity = IPermission.PORTLET_MANAGER_MAINTENANCE_ACTIVITY;
if (order <= PortletLifecycleState.MAINTENANCE.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
return true;
}
activity = IPermission.PORTLET_MANAGER_EXPIRED_ACTIVITY;
if (order <= PortletLifecycleState.EXPIRED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
return true;
}
activity = IPermission.PORTLET_MANAGER_ACTIVITY;
if (order <= PortletLifecycleState.PUBLISHED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
return true;
}
activity = IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY;
if (order <= PortletLifecycleState.APPROVED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
return true;
}
activity = IPermission.PORTLET_MANAGER_CREATED_ACTIVITY;
if (order <= PortletLifecycleState.CREATED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
return true;
}
return false;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class MarketplaceService method loadMarketplaceEntriesFor.
/**
* Load the list of marketplace entries for a user. Will load entries async. This method is
* primarily intended for seeding data. Most impls should call browseableMarketplaceEntriesFor()
* instead.
*
* <p>Note: Set is immutable since it is potentially shared between threads. If the set needs
* mutability, be sure to consider the thread safety implications. No protections have been
* provided against modifying the MarketplaceEntry itself, so be careful when modifying the
* entities contained in the list.
*
* @param user The non-null user
* @param categories Restricts the output to entries within the specified categories if
* non-empty
* @return a Future that will resolve to a set of MarketplaceEntry objects the requested user
* has browse access to.
* @throws java.lang.IllegalArgumentException if user is null
* @since 4.2
*/
@Async
public Future<ImmutableSet<MarketplaceEntry>> loadMarketplaceEntriesFor(final IPerson user, final Set<PortletCategory> categories) {
final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
List<IPortletDefinition> allDisplayablePortletDefinitions = this.portletDefinitionRegistry.getAllPortletDefinitions();
if (!categories.isEmpty()) {
// Indicates we plan to restrict portlets displayed in the Portlet
// Marketplace to those that belong to one or more specified groups.
Element portletDefinitionsElement = marketplaceCategoryCache.get(categories);
if (portletDefinitionsElement == null) {
/*
* Collection not in cache -- need to recreate it
*/
// Gather the complete collection of allowable categories (specified categories & their descendants)
final Set<PortletCategory> allSpecifiedAndDecendantCategories = new HashSet<>();
for (PortletCategory pc : categories) {
collectSpecifiedAndDescendantCategories(pc, allSpecifiedAndDecendantCategories);
}
// Filter portlets that match the criteria
Set<IPortletDefinition> filteredPortletDefinitions = new HashSet<>();
for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
final Set<PortletCategory> parents = portletCategoryRegistry.getParentCategories(portletDefinition);
for (final PortletCategory parent : parents) {
if (allSpecifiedAndDecendantCategories.contains(parent)) {
filteredPortletDefinitions.add(portletDefinition);
break;
}
}
}
portletDefinitionsElement = new Element(categories, new ArrayList<>(filteredPortletDefinitions));
marketplaceCategoryCache.put(portletDefinitionsElement);
}
allDisplayablePortletDefinitions = (List<IPortletDefinition>) portletDefinitionsElement.getObjectValue();
}
final Set<MarketplaceEntry> visiblePortletDefinitions = new HashSet<>();
for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
if (mayBrowsePortlet(principal, portletDefinition)) {
final MarketplacePortletDefinition marketplacePortletDefinition = getOrCreateMarketplacePortletDefinition(portletDefinition);
final MarketplaceEntry entry = new MarketplaceEntry(marketplacePortletDefinition, user);
// flag whether this use can add the portlet...
boolean canAdd = mayAddPortlet(user, portletDefinition);
entry.setCanAdd(canAdd);
visiblePortletDefinitions.add(entry);
}
}
logger.trace("These portlet definitions {} are browseable by {}.", visiblePortletDefinitions, user);
Future<ImmutableSet<MarketplaceEntry>> result = new AsyncResult<>(ImmutableSet.copyOf(visiblePortletDefinitions));
Element cacheElement = new Element(user.getUserName(), result);
marketplaceUserPortletDefinitionCache.put(cacheElement);
return result;
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class MarketplaceService method onApplicationEvent.
/**
* Handle the portal LoginEvent. If marketplace caching is enabled, will preload marketplace
* entries for the currently logged in user.
*
* @param loginEvent the login event.
*/
@Override
public void onApplicationEvent(LoginEvent loginEvent) {
if (enableMarketplacePreloading) {
final IPerson person = loginEvent.getPerson();
/*
* Passing an empty collection pre-loads an unfiltered collection;
* instances of PortletMarketplace that specify filtering will
* trigger a new collection to be loaded.
*/
final Set<PortletCategory> empty = Collections.emptySet();
loadMarketplaceEntriesFor(person, empty);
}
}
use of org.apereo.portal.portlet.om.PortletCategory in project uPortal by Jasig.
the class ChannelListController method getRegistryOriginal.
/*
* Private methods that support the original (pre-4.3) version of the API
*/
/**
* Gathers and organizes the response based on the specified rootCategory and the permissions of
* the specified user.
*/
private Map<String, SortedSet<?>> getRegistryOriginal(WebRequest request, IPerson user) {
/*
* This collection of all the portlets in the portal is for the sake of
* tracking which ones are uncategorized.
*/
Set<IPortletDefinition> portletsNotYetCategorized = new HashSet<IPortletDefinition>(portletDefinitionRegistry.getAllPortletDefinitions());
// construct a new channel registry
Map<String, SortedSet<?>> rslt = new TreeMap<String, SortedSet<?>>();
SortedSet<ChannelCategoryBean> categories = new TreeSet<ChannelCategoryBean>();
// add the root category and all its children to the registry
final PortletCategory rootCategory = portletCategoryRegistry.getTopLevelPortletCategory();
final Locale locale = getUserLocale(user);
categories.add(prepareCategoryBean(request, rootCategory, portletsNotYetCategorized, user, locale));
/*
* uPortal historically has provided for a convention that portlets not in any category
* may potentially be viewed by users but may not be subscribed to.
*
* As of uPortal 4.2, the logic below now takes any portlets the user has BROWSE access to
* that have not already been identified as belonging to a category and adds them to a category
* called Uncategorized.
*/
EntityIdentifier ei = user.getEntityIdentifier();
IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
// construct a new channel category bean for this category
String uncategorizedString = messageSource.getMessage(UNCATEGORIZED, new Object[] {}, locale);
ChannelCategoryBean uncategorizedPortletsBean = new ChannelCategoryBean(new PortletCategory(uncategorizedString));
uncategorizedPortletsBean.setName(UNCATEGORIZED);
uncategorizedPortletsBean.setDescription(messageSource.getMessage(UNCATEGORIZED_DESC, new Object[] {}, locale));
for (IPortletDefinition portlet : portletsNotYetCategorized) {
if (authorizationService.canPrincipalBrowse(ap, portlet)) {
// construct a new channel bean from this channel
ChannelBean channel = getChannel(portlet, request, locale);
uncategorizedPortletsBean.addChannel(channel);
}
}
// Add even if no portlets in category
categories.add(uncategorizedPortletsBean);
rslt.put("categories", categories);
return rslt;
}
Aggregations