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) {
// 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");
if (disableDynamicTitle == null || !Boolean.parseBoolean(disableDynamicTitle.getValue())) {
try {
final PortletRenderResult portletRenderResult = getPortletRenderResult(portletWindowId, request, response);
if (portletRenderResult != null) {
final String title = portletRenderResult.getTitle();
if (title != null) {
return title;
}
}
} catch (Exception e) {
logger.warn("unable to get portlet title, falling back to title defined in channel definition for portletWindowId " + portletWindowId);
}
}
// we assume that response locale has been set to correct value
String locale = response.getLocale().toString();
// return portlet title from channel definition
return portletDefinition.getTitle(locale);
}
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;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionParameter in project uPortal by Jasig.
the class DistributedLayoutManager method updateChannelNode.
/**
* Compares the new channel description object with the old channel description object to
* determine what items were changed and if those changes are allowed. Once all changes are
* verified as being allowed changes then they are pushed into both the ILF and the PLF as
* appropriate. No changes are made until we determine that all changes are allowed.
*
* @param nodeId
* @param newChanDesc
* @param oldChanDesc
* @throws PortalException
*/
private void updateChannelNode(String nodeId, IUserLayoutChannelDescription newChanDesc, IUserLayoutChannelDescription oldChanDesc) throws PortalException {
Element ilfNode = (Element) getUserLayoutDOM().getElementById(nodeId);
List<ILayoutProcessingAction> pendingActions = new ArrayList<ILayoutProcessingAction>();
boolean isIncorporated = nodeId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX);
// ATT: DLM Restrictions
if (isFragmentOwner && (newChanDesc.isDeleteAllowed() != oldChanDesc.isDeleteAllowed() || newChanDesc.isEditAllowed() != oldChanDesc.isEditAllowed() || newChanDesc.isMoveAllowed() != oldChanDesc.isMoveAllowed())) {
pendingActions.add(new LPAEditRestriction(owner, ilfNode, newChanDesc.isMoveAllowed(), newChanDesc.isDeleteAllowed(), newChanDesc.isEditAllowed(), newChanDesc.isAddChildAllowed()));
}
// ATT: other? if other attributes should be editable in DLM on channels
// we can add calls like this to enable such support.
// updateNodeAttribute(ilfNode, nodeId, "hidden",
// newChanDesc.getName(), oldChanDesc.getName(), pendingActions);
/*
* now we loop through all parameters in the new channel description and
* see if there is a corresponding parameter in the old channel
* description and see if the change is allowed. For each allowed change
* we add an object that will make such a change once all changes have
* been approved. As we find matches in the old channel description we
* remove those parameters. Then any left there after processing those
* of the new channel description indicate parameters that were removed.
*/
FragmentChannelInfo fragChanInf = null;
Map pubParms = getPublishedChannelParametersMap(newChanDesc.getChannelPublishId());
if (isIncorporated)
fragChanInf = this.distributedLayoutStore.getFragmentChannelInfo(nodeId);
Map oldParms = new HashMap(oldChanDesc.getParameterMap());
for (Iterator itr = newChanDesc.getParameterMap().entrySet().iterator(); itr.hasNext(); ) {
Map.Entry e = (Entry) itr.next();
String name = (String) e.getKey();
String newVal = (String) e.getValue();
String oldVal = (String) oldParms.remove(name);
if (oldVal == null) {
/*
* not in old description so this is a new ad-hoc parameter
*/
pendingActions.add(new LPAAddParameter(nodeId, name, newVal, owner, ilfNode));
} else if (!oldVal.equals(newVal)) {
if (isIncorporated) {
/*
* if the fragment does not have a value for this parm then
* this is an ad-hoc value and we need a directive to
* persist the user's desired value. if the frament does
* have a value and it is the same as the new value then we
* can remove the override since it won't accomplish
* anything. if the fragment does have a value and it is
* different then we need the directive to persist the
* user's desired value.
*/
String fragValue = fragChanInf.getParameterValue(name);
if (fragValue == null) {
/*
* so fragment doesn't override. See if the value
* specified matches that of the channel definition
*/
IPortletDefinitionParameter cp = (IPortletDefinitionParameter) pubParms.get(name);
if (cp != null && cp.getValue().equals(newVal))
/*
* new value matches that of published channel to
* remove any user parameter spec since not needed
*/
pendingActions.add(new LPARemoveParameter(nodeId, name, owner, ilfNode));
else
/*
* value doesn't match that of published chanel so
* we need change any existing parameter spec or add
* a new one if it doesn't exist.
*/
pendingActions.add(new LPAChangeParameter(nodeId, name, newVal, owner, ilfNode));
} else if (!fragValue.equals(newVal)) {
/*
* so fragment does specify and user value is different
* so change any existing parameter spec or add a new
* one if it doesn't exist.
*/
pendingActions.add(new LPAChangeParameter(nodeId, name, newVal, owner, ilfNode));
} else {
/*
* new val same as fragment value so don't persist.
* remove any parameter spec if it exists.
*/
pendingActions.add(new LPAResetParameter(nodeId, name, fragValue, owner, ilfNode));
}
} else // not incorporated from a fragment
{
/*
* see if the value specified matches that of the channel
* definition.
*/
IPortletDefinitionParameter cp = (IPortletDefinitionParameter) pubParms.get(name);
if (cp != null && cp.getValue().equals(newVal))
pendingActions.add(new LPARemoveParameter(nodeId, name, owner, ilfNode));
else
pendingActions.add(new LPAChangeParameter(nodeId, name, newVal, owner, ilfNode));
}
}
}
/*
* So any parameters remaining in the oldParms map at this point didn't
* match those in the new channel description which means that they were
* removed. So remove any parameter spec if it exists.
*/
for (Iterator itr = oldParms.entrySet().iterator(); itr.hasNext(); ) {
Map.Entry e = (Entry) itr.next();
String name = (String) e.getKey();
pendingActions.add(new LPARemoveParameter(nodeId, name, owner, ilfNode));
}
/*
* if we make it to this point then all edits made are allowed so
* process the actions to push the edits into the layout
*/
for (Iterator itr = pendingActions.iterator(); itr.hasNext(); ) {
ILayoutProcessingAction action = (ILayoutProcessingAction) itr.next();
action.perform();
}
}
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));
}
}
}
}
}
}
}
Aggregations