use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class GuestPortletEntityPreferencesImpl method storeSessionPreferences.
@SuppressWarnings("unchecked")
protected void storeSessionPreferences(IPortletEntityId portletEntityId, HttpServletRequest httpServletRequest, Map<String, IPortletPreference> preferences) {
final HttpSession session = httpServletRequest.getSession();
Map<IPortletEntityId, Map<String, IPortletPreference>> portletPreferences;
// Sync on the session to ensure other threads aren't creating the Map at the same time
synchronized (session) {
portletPreferences = (Map<IPortletEntityId, Map<String, IPortletPreference>>) session.getAttribute(PORTLET_PREFERENCES_MAP_ATTRIBUTE);
if (portletPreferences == null) {
portletPreferences = new ConcurrentHashMap<IPortletEntityId, Map<String, IPortletPreference>>();
session.setAttribute(PORTLET_PREFERENCES_MAP_ATTRIBUTE, portletPreferences);
}
}
portletPreferences.put(portletEntityId, preferences);
}
use of org.apereo.portal.portlet.om.IPortletEntityId 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.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityCache method storeIfAbsentEntity.
public T storeIfAbsentEntity(T entity) {
final IPortletEntityId portletEntityId = entity.getPortletEntityId();
// Check if the entity already exists (uses a read lock)
T existingEntity = this.getEntity(portletEntityId);
if (existingEntity != null) {
return existingEntity;
}
writeLock.lock();
try {
// Check again inside the write lock
existingEntity = this.entitiesById.get(portletEntityId);
if (existingEntity != null) {
return existingEntity;
}
this.storeEntity(entity);
} finally {
writeLock.unlock();
}
return entity;
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method getPortletEntityLock.
@Override
public Lock getPortletEntityLock(HttpServletRequest request, IPortletEntityId portletEntityId) {
final ConcurrentMap<IPortletEntityId, Lock> lockMap = getPortletEntityLockMap(request);
// See if the lock already exist, return if it does
Lock lock = lockMap.get(portletEntityId);
if (lock != null) {
return lock;
}
// Create a new lock and do a putIfAbsent to avoid synchronizing but still get a single lock
// instance for the session.
lock = createPortletEntityLock();
return ConcurrentMapUtils.putIfAbsent(lockMap, portletEntityId, lock);
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method storePortletEntity.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.registry.IPortletEntityRegistry#storePortletEntity(org.apereo.portal.portlet.om.IPortletEntity)
*/
@Override
public void storePortletEntity(HttpServletRequest request, final IPortletEntity portletEntity) {
Validate.notNull(portletEntity, "portletEntity can not be null");
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPerson person = userInstance.getPerson();
if (person.isGuest()) {
// Never persist things for the guest user, just rely on in-memory storage
return;
}
final IPortletEntityId wrapperPortletEntityId = portletEntity.getPortletEntityId();
final Lock portletEntityLock = this.getPortletEntityLock(request, wrapperPortletEntityId);
portletEntityLock.lock();
try {
final boolean shouldBePersisted = this.shouldBePersisted(portletEntity);
if (portletEntity instanceof PersistentPortletEntityWrapper) {
// Unwrap the persistent entity
final IPortletEntity persistentEntity = ((PersistentPortletEntityWrapper) portletEntity).getPersistentEntity();
// Already persistent entity that still has prefs
if (shouldBePersisted) {
try {
this.portletEntityDao.updatePortletEntity(persistentEntity);
} catch (HibernateOptimisticLockingFailureException e) {
// Check if this exception is from the entity being deleted from under us.
final boolean exists = this.portletEntityDao.portletEntityExists(persistentEntity.getPortletEntityId());
if (!exists) {
this.logger.warn("The persistent portlet has already been deleted: " + persistentEntity + ". The passed entity should be persistent so a new persistent entity will be created");
this.deletePortletEntity(request, portletEntity, true);
this.createPersistentEntity(persistentEntity, wrapperPortletEntityId);
} else {
throw e;
}
}
} else // Already persistent entity that should not be, DELETE!
{
// Capture identifiers needed to recreate the entity as session persistent
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
final String layoutNodeId = portletEntity.getLayoutNodeId();
final int userId = portletEntity.getUserId();
// Delete the persistent entity
this.deletePortletEntity(request, portletEntity, false);
// Create a new entity and stick it in the cache
this.getOrCreatePortletEntity(request, portletDefinitionId, layoutNodeId, userId);
}
} else if (portletEntity instanceof SessionPortletEntityImpl) {
// There are preferences on the interim entity, create an store it
if (shouldBePersisted) {
// Remove the session scoped entity from the request and session caches
this.deletePortletEntity(request, portletEntity, false);
final IPortletEntity persistentEntity = createPersistentEntity(portletEntity, wrapperPortletEntityId);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Session scoped entity " + wrapperPortletEntityId + " should now be persistent. Deleted it from session cache and created persistent portlet entity " + persistentEntity.getPortletEntityId());
}
} else // Session scoped entity that is still session scoped,
{
// Look for a persistent entity and delete it
final String channelSubscribeId = portletEntity.getLayoutNodeId();
final int userId = portletEntity.getUserId();
IPortletEntity existingPersistentEntity = this.portletEntityDao.getPortletEntity(channelSubscribeId, userId);
if (existingPersistentEntity != null) {
final IPortletEntityId consistentPortletEntityId = this.createConsistentPortletEntityId(existingPersistentEntity);
existingPersistentEntity = new PersistentPortletEntityWrapper(existingPersistentEntity, consistentPortletEntityId);
this.logger.warn("A persistent portlet entity already exists: " + existingPersistentEntity + ". The passed entity has no preferences so the persistent version will be deleted");
this.deletePortletEntity(request, existingPersistentEntity, false);
// Add to request cache
final PortletEntityCache<IPortletEntity> portletEntityMap = this.getPortletEntityMap(request);
portletEntityMap.storeIfAbsentEntity(portletEntity);
// Add to session cache
final PortletEntityCache<PortletEntityData> portletEntityDataMap = this.getPortletEntityDataMap(request);
portletEntityDataMap.storeIfAbsentEntity(((SessionPortletEntityImpl) portletEntity).getPortletEntityData());
}
}
} else {
throw new IllegalArgumentException("Invalid portlet entity implementation passed: " + portletEntity.getClass());
}
} finally {
portletEntityLock.unlock();
}
}
Aggregations