use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.
the class PortletEntityPreferencesImpl method loadBasePortletPreferences.
@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
// Add descriptor prefs to base Map
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
}
// Add definition prefs to base Map
final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
for (final IPortletPreference preference : definitionPreferences) {
basePortletPreferences.put(preference.getName(), preference);
}
}
use of org.apereo.portal.portlet.om.IPortletDefinitionId 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.IPortletDefinitionId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method createPersistentEntity.
protected IPortletEntity createPersistentEntity(final IPortletEntity portletEntity, final IPortletEntityId wrapperPortletEntityId) {
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final String layoutNodeId = portletEntity.getLayoutNodeId();
final int userId = portletEntity.getUserId();
IPortletEntity persistentEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
if (persistentEntity != null) {
this.logger.warn("A persistent portlet entity already exists: " + persistentEntity + ". The data from the passed in entity will be copied to the persistent entity: " + portletEntity);
} else {
persistentEntity = this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}
// Copy over preferences to avoid modifying any part of the interim entity by reference
final List<IPortletPreference> existingPreferences = portletEntity.getPortletPreferences();
final List<IPortletPreference> persistentPreferences = persistentEntity.getPortletPreferences();
// Only do the copy if the List objects are not the same instance
if (persistentPreferences != existingPreferences) {
persistentPreferences.clear();
for (final IPortletPreference preference : existingPreferences) {
persistentPreferences.add(new PortletPreferenceImpl(preference));
}
}
// Copy over WindowStates
final Map<Long, WindowState> windowStates = portletEntity.getWindowStates();
for (Map.Entry<Long, WindowState> windowStateEntry : windowStates.entrySet()) {
final Long stylesheetDescriptorId = windowStateEntry.getKey();
final IStylesheetDescriptor stylesheetDescriptor = stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetDescriptorId);
final WindowState windowState = windowStateEntry.getValue();
persistentEntity.setWindowState(stylesheetDescriptor, windowState);
}
this.portletEntityDao.updatePortletEntity(persistentEntity);
return persistentEntity;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionId 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.IPortletDefinitionId in project uPortal by Jasig.
the class PortletEventCoordinatationService method supportsEvent.
protected boolean supportsEvent(Event event, IPortletDefinitionId portletDefinitionId) {
final QName eventName = event.getQName();
// The cache key to use
final Tuple<IPortletDefinitionId, QName> key = new Tuple<IPortletDefinitionId, QName>(portletDefinitionId, eventName);
// Check in the cache if the portlet definition supports this event
final Element element = this.supportedEventCache.get(key);
if (element != null) {
final Boolean supported = (Boolean) element.getObjectValue();
if (supported != null) {
return supported;
}
}
final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId);
if (portletApplicationDescriptor == null) {
return false;
}
final Set<QName> aliases = this.getAllAliases(eventName, portletApplicationDescriptor);
final String defaultNamespace = portletApplicationDescriptor.getDefaultNamespace();
// No support found so far, do more complex namespace matching
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
if (portletDescriptor == null) {
return false;
}
final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
for (final EventDefinitionReference eventDefinitionReference : supportedProcessingEvents) {
final QName qualifiedName = eventDefinitionReference.getQualifiedName(defaultNamespace);
if (qualifiedName == null) {
continue;
}
// Look for alias names
if (qualifiedName.equals(eventName) || aliases.contains(qualifiedName)) {
this.supportedEventCache.put(new Element(key, Boolean.TRUE));
return true;
}
// Look for namespaced events
if (StringUtils.isEmpty(qualifiedName.getNamespaceURI())) {
final QName namespacedName = new QName(defaultNamespace, qualifiedName.getLocalPart());
if (eventName.equals(namespacedName)) {
this.supportedEventCache.put(new Element(key, Boolean.TRUE));
return true;
}
}
}
this.supportedEventCache.put(new Element(key, Boolean.FALSE));
return false;
}
Aggregations