use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletEventCoordinatationService method resolvePortletEvents.
@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
// Skip all processing if there are no new events.
if (events.isEmpty()) {
return;
}
// Get all the portlets the user is subscribed to
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
// Make a local copy so we can remove data from it
final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
while (!events.isEmpty()) {
final QueuedEvent queuedEvent = events.poll();
if (queuedEvent == null) {
// no more queued events, done resolving
return;
}
final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
final Event event = queuedEvent.getEvent();
final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
if (globalEvent) {
portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
}
// Check each subscription to see what events it is registered to see
for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
final String layoutNodeId = layoutNodeIdItr.next();
IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
if (portletEntity == null) {
portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
// remove it (see UP-3378)
if (portletEntity == null) {
layoutNodeIdItr.remove();
continue;
}
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
if (portletDescriptor == null) {
// Missconfigured portlet, remove it from the list so we don't check again
// and ignore it
layoutNodeIdItr.remove();
continue;
}
final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
// they are not checked again
if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
layoutNodeIdItr.remove();
continue;
}
portletEntityCache.put(layoutNodeId, portletEntity);
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
// If this is the default portlet entity remove the definition from the all defs
// set to avoid duplicate processing
final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
if (defaultPortletEntity.equals(portletEntity)) {
portletDefinitions.remove(portletDefinition);
}
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
continue;
}
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
} else {
portletDefinitions.remove(portletDefinition);
}
}
if (!portletDefinitions.isEmpty()) {
final IPerson user = userInstance.getPerson();
final EntityIdentifier ei = user.getEntityIdentifier();
final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
// targeting
for (final IPortletDefinition portletDefinition : portletDefinitions) {
// Is this portlet permitted to receive events? (Or is it
// disablePortletEvents=true?)
IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
continue;
}
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
// Check if the user can render the portlet definition before doing event tests
if (ap.canRender(portletDefinitionId.getStringId())) {
if (this.supportsEvent(event, portletDefinitionId)) {
this.logger.debug("{} supports event {}", portletDefinition, event);
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
for (final IPortletWindow portletWindow : portletWindows) {
this.logger.debug("{} resolved target {}", event, portletWindow);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
}
}
}
}
}
}
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class DefinitionHeaderProvider method createHeader.
@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
// Include?
if (!isIncluded(renderRequest, INCLUDE_PREFERENCE)) {
return null;
}
// Username
final String username = getUsername(renderRequest);
// Obtain the MarketplacePortletDefinition for this soffit
final HttpServletRequest httpr = portalRequestUtils.getCurrentPortalRequest();
final IPortletWindowId portletWindowId = portletWindowRegistry.getPortletWindowId(httpr, renderRequest.getWindowID());
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpr, portletWindowId);
final IPortletDefinition pdef = portletWindow.getPortletEntity().getPortletDefinition();
final MarketplacePortletDefinition mpdef = this.marketplaceService.getOrCreateMarketplacePortletDefinition(pdef);
final IPerson user = personManager.getPerson(httpr);
final Locale locale = getUserLocale(user);
// Title
final String title = mpdef.getTitle(locale.toString());
// FName
final String fname = mpdef.getFName();
// Description
final String description = mpdef.getDescription(locale.toString());
// Categories
List<String> categories = new ArrayList<>();
for (PortletCategory pc : mpdef.getCategories()) {
categories.add(pc.getName());
}
// Parameters
Map<String, List<String>> parameters = new HashMap<>();
for (IPortletDefinitionParameter param : mpdef.getParameters()) {
parameters.put(param.getName(), Collections.singletonList(param.getValue()));
}
final Definition definition = definitionService.createDefinition(title, fname, description, categories, parameters, username, getExpiration(renderRequest));
final Header rslt = new BasicHeader(Headers.DEFINITION.getName(), definition.getEncryptedToken());
logger.debug("Produced the following {} header for username='{}': {}", Headers.DEFINITION.getName(), username, rslt);
return rslt;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class PortletExecutionManager method getPortletTitle.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.rendering.IPortletExecutionManager#getPortletTitle(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public String getPortletTitle(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
final IPortletDefinition portletDefinition = getPortletDefinition(portletWindowId, request);
final IPortletDefinitionParameter disableDynamicTitle = portletDefinition.getParameter("disableDynamicTitle");
String titleToReturn = null;
if (disableDynamicTitle == null || !Boolean.parseBoolean(disableDynamicTitle.getValue())) {
try {
final PortletRenderResult portletRenderResult = getPortletRenderResult(portletWindowId, request, response);
if (portletRenderResult != null) {
titleToReturn = portletRenderResult.getTitle();
}
} catch (Exception e) {
logger.warn("unable to get portlet title, falling back to title defined in channel definition for portletWindowId " + portletWindowId);
}
}
if (titleToReturn == null) {
// we assume that response locale has been set to correct value
String locale = response.getLocale().toString();
titleToReturn = portletDefinition.getTitle(locale);
}
// Personalize the title
titleToReturn = this.personalizer.personalize(this.personManager.getPerson(request), titleToReturn, request.getSession());
// return portlet title from channel definition
return titleToReturn;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class TransientUserLayoutXMLEventReader method getAdditionalEvents.
/**
* Examines the current token and when appropriate creates and returns dynamically created
* content. If dynamic content is not created, return null.
*
* @param event The current event
* @return Dynamic content to inject into document, else null if no additional dynamic content
* was created.
*/
@Override
protected Deque<XMLEvent> getAdditionalEvents(XMLEvent event) {
if (event.isStartElement()) {
final StartElement startElement = event.asStartElement();
// All following logic requires an ID attribute, ignore any element without one
final Attribute idAttribute = startElement.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
if (idAttribute == null) {
return null;
}
// Create and return a transient (dynamically created) folder that includes a transient
// channel
// if we are processing the tart element of the root node
// iff the subscribeId is present and describes a transient channel and not a regular
// layout channel.
final String subscribeId = this.userLayoutManager.getFocusedId();
if (this.rootFolderId.equals(idAttribute.getValue()) && subscribeId != null && !subscribeId.equals("") && this.userLayoutManager.isTransientChannel(subscribeId)) {
IPortletDefinition chanDef = null;
try {
chanDef = this.userLayoutManager.getChannelDefinition(subscribeId);
} catch (Exception e) {
logger.error("Could not obtain IChannelDefinition for subscribe id: {}", subscribeId, e);
}
if (chanDef != null) {
final QName name = startElement.getName();
final String namespaceURI = name.getNamespaceURI();
final String prefix = name.getPrefix();
final Deque<XMLEvent> transientEventBuffer = new LinkedList<XMLEvent>();
final Collection<Attribute> transientFolderAttributes = new LinkedList<Attribute>();
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("ID", TransientUserLayoutManagerWrapper.TRANSIENT_FOLDER_ID));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("name", chanDef != null ? chanDef.getTitle() : "Temporary"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("type", "regular"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("hidden", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("immutable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:addChildAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:editAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:precedence", "100.0"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("transient", "true"));
final StartElement transientFolder = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, transientFolderAttributes.iterator(), null);
transientEventBuffer.add(transientFolder);
// TODO Move IChannelDefinition/IPortletDefinition -> StAX events code somewhere
// reusable
final Collection<Attribute> channelAttrs = new LinkedList<Attribute>();
channelAttrs.add(EVENT_FACTORY.createAttribute("ID", subscribeId));
channelAttrs.add(EVENT_FACTORY.createAttribute("typeID", Integer.toString(chanDef.getType().getId())));
channelAttrs.add(EVENT_FACTORY.createAttribute("hidden", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("name", chanDef.getName()));
channelAttrs.add(EVENT_FACTORY.createAttribute("description", chanDef.getDescription()));
channelAttrs.add(EVENT_FACTORY.createAttribute("title", chanDef.getTitle()));
channelAttrs.add(EVENT_FACTORY.createAttribute("chanID", chanDef.getPortletDefinitionId().getStringId()));
channelAttrs.add(EVENT_FACTORY.createAttribute("fname", chanDef.getFName()));
channelAttrs.add(EVENT_FACTORY.createAttribute("timeout", Integer.toString(chanDef.getTimeout())));
channelAttrs.add(EVENT_FACTORY.createAttribute("transient", "true"));
final StartElement startChannel = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, channelAttrs.iterator(), null);
transientEventBuffer.offer(startChannel);
// add channel parameter elements
for (final IPortletDefinitionParameter parm : chanDef.getParameters()) {
final Collection<Attribute> parameterAttrs = new LinkedList<Attribute>();
parameterAttrs.add(EVENT_FACTORY.createAttribute("name", parm.getName()));
parameterAttrs.add(EVENT_FACTORY.createAttribute("value", parm.getValue()));
final StartElement startParameter = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, parameterAttrs.iterator(), null);
transientEventBuffer.offer(startParameter);
final EndElement endParameter = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, null);
transientEventBuffer.offer(endParameter);
}
final EndElement endChannel = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, null);
transientEventBuffer.offer(endChannel);
final EndElement endFolder = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, null);
transientEventBuffer.offer(endFolder);
return transientEventBuffer;
} else {
// I don't think subscribeId could be null, but log warning if so.
logger.warn("Unable to resolve portlet definition for subscribe ID {}", subscribeId);
}
}
}
return null;
}
Aggregations