use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.
protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
// Check in the cache first
final Element element = this.entityIdParseCache.get(consistentEntityIdString);
if (element != null) {
final Object value = element.getObjectValue();
if (value != null) {
return (IPortletEntityId) value;
}
}
if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
}
// Verify the portlet definition id
final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
if (portletDefinition == null) {
throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
}
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Verify non-delegate layout node id exists and is for a portlet
final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
if (node == null || node.getType() != LayoutNodeType.PORTLET) {
throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
}
// TODO is this doable for delegation?
// Verify the portlet definition matches
final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
final String channelPublishId = portletNode.getChannelPublishId();
if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
}
}
// TODO when there is a JPA backed user dao actually verify this mapping
// User just conver to an int
final int userId;
final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
try {
userId = Integer.parseInt(userIdAsString);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
}
final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
// Cache the resolution
this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
return portletEntityId;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletEntityRegistryImpl method getOrCreatePortletEntity.
@Override
public IPortletEntity getOrCreatePortletEntity(HttpServletRequest request, IUserInstance userInstance, String layoutNodeId) {
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Find the channel and portlet definitions
final IUserLayoutChannelDescription channelNode = (IUserLayoutChannelDescription) userLayoutManager.getNode(layoutNodeId);
if (channelNode == null) {
this.logger.warn("No layout node exists for id " + layoutNodeId + ", no portlet entity will be returned.");
return null;
}
final String channelPublishId = channelNode.getChannelPublishId();
final IPortletDefinition portletDefinition = this.getPortletDefinition(request, userInstance, channelPublishId);
if (portletDefinition != null) {
final IPerson person = userInstance.getPerson();
return this.getOrCreatePortletEntity(request, portletDefinition.getPortletDefinitionId(), layoutNodeId, person.getID());
}
// No permission to see the portlet
return null;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getOrCreateStatelessPortletWindow.
@Override
public IPortletWindow getOrCreateStatelessPortletWindow(HttpServletRequest request, IPortletWindowId basePortletWindowId) {
// extract the entity ID
if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
final String basePortletWindowIdStr = basePortletWindowId.getStringId();
basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
}
// Get the entity ID for the portlet window
final IPortletEntityId portletEntityId = ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();
// Create the stateless ID
final PortletWindowIdImpl statelessPortletWindowId = this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);
// See if there is already a request cached stateless window
IPortletWindow statelessPortletWindow = this.getPortletWindow(request, statelessPortletWindowId);
if (statelessPortletWindow != null) {
return statelessPortletWindow;
}
// Lookup the base portlet window to clone the stateless from
final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);
final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap = this.getStatelessPortletWindowDataMap(request, true);
// If no base to clone from lookup the entity and pluto definition data
if (basePortletWindow == null) {
final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
if (portletEntity == null) {
throw new IllegalArgumentException("No IPortletEntity could be found for " + portletEntity + " while creating stateless portlet window for " + basePortletWindowId);
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
statelessPortletWindowDataMap.storeWindow(portletWindowData);
statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
} else // Clone the existing base window
{
final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
portletWindowData.setWindowState(basePortletWindow.getWindowState());
portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());
statelessPortletWindowDataMap.storeWindow(portletWindowData);
final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
final PortletDefinition portletDescriptor = basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
}
// Cache the stateless window in the request
final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
portletWindowMap.storeWindow(statelessPortletWindow);
return statelessPortletWindow;
}
use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.
the class AuthorizationImpl method canPrincipalConfigure.
@Override
@RequestCache
public boolean canPrincipalConfigure(IAuthorizationPrincipal principal, String portletDefinitionId) throws AuthorizationException {
String owner = IPermission.PORTAL_PUBLISH;
String target = IPermission.PORTLET_PREFIX + portletDefinitionId;
// retrieve the indicated channel from the channel registry store and
// determine its current lifecycle state
IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
if (portlet == null) {
throw new AuthorizationException("Unable to locate portlet " + portletDefinitionId);
}
final String activity = IPermission.PORTLET_MODE_CONFIG;
boolean isAllowed = doesPrincipalHavePermission(principal, owner, activity, target);
logger.trace("In canPrincipalConfigure() - principal.key=[{}], is allowed?=[{}]", principal.getKey(), isAllowed);
return isAllowed;
}
use of org.apereo.portal.portlet.om.IPortletDefinition 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;
}
Aggregations