use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method getOrCreatePortletEntity.
/* (non-Javadoc)
* @see org.apereo.portal.portlet.registry.IPortletEntityRegistry#getOrCreatePortletEntity(org.apereo.portal.portlet.om.IPortletDefinitionId, java.lang.String, int)
*/
@Override
public IPortletEntity getOrCreatePortletEntity(HttpServletRequest request, IPortletDefinitionId portletDefinitionId, String layoutNodeId, int userId) {
final PortletEntityCache<IPortletEntity> portletEntityCache = getPortletEntityMap(request);
// Try just getting an existing entity first
IPortletEntity portletEntity = this.getPortletEntity(request, portletEntityCache, null, layoutNodeId, userId);
// Found an existing entity!
if (portletEntity != null) {
// Verify the definition IDs match, this is a MUST in the case where the subscribed
// portlet changes
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
if (portletDefinitionId.equals(portletDefinition.getPortletDefinitionId())) {
return portletEntity;
}
// Remove the entity if the definition IDs don't match
this.logger.warn("Found portlet entity '{}' is not the correct entity for portlet definition id: {}. The entity will be deleted and a new one created.", portletEntity, portletDefinitionId);
this.deletePortletEntity(request, portletEntity, false);
}
// Create the entity data object and store it in the session map (if not already there)
final PortletEntityCache<PortletEntityData> portletEntityDataMap = this.getPortletEntityDataMap(request);
final IPortletEntityId portletEntityId = this.createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
PortletEntityData portletEntityData = new PortletEntityData(portletEntityId, portletDefinitionId, layoutNodeId, userId);
portletEntityData = portletEntityDataMap.storeIfAbsentEntity(portletEntityData);
portletEntity = wrapPortletEntityData(portletEntityData);
// Stick the wrapper in the request map
portletEntity = portletEntityCache.storeIfAbsentEntity(portletEntity);
return portletEntity;
}
use of org.apereo.portal.portlet.om.IPortletEntityId 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.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method deletePortletEntity.
/**
* Delete a portlet entity, removes it from the request, session and persistent stores
*/
protected void deletePortletEntity(HttpServletRequest request, IPortletEntity portletEntity, boolean cacheOnly) {
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
// Remove from request cache
final PortletEntityCache<IPortletEntity> portletEntityMap = this.getPortletEntityMap(request);
portletEntityMap.removeEntity(portletEntityId);
// Remove from session cache
final PortletEntityCache<PortletEntityData> portletEntityDataMap = this.getPortletEntityDataMap(request);
portletEntityDataMap.removeEntity(portletEntityId);
if (!cacheOnly && portletEntity instanceof PersistentPortletEntityWrapper) {
final IPortletEntity persistentEntity = ((PersistentPortletEntityWrapper) portletEntity).getPersistentEntity();
try {
this.portletEntityDao.deletePortletEntity(persistentEntity);
} catch (HibernateOptimisticLockingFailureException e) {
this.logger.warn("This persistent portlet has already been deleted: " + persistentEntity + ", trying to find and delete by layout node and user.");
final IPortletEntity existingPersistentEntity = this.portletEntityDao.getPortletEntity(persistentEntity.getLayoutNodeId(), persistentEntity.getUserId());
if (existingPersistentEntity != null) {
this.portletEntityDao.deletePortletEntity(existingPersistentEntity);
}
}
}
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method getPortletEntity.
/**
* Lookup the portlet entity by layoutNodeId and userId
*/
protected IPortletEntity getPortletEntity(HttpServletRequest request, PortletEntityCache<IPortletEntity> portletEntityCache, IPortletEntityId portletEntityId, String layoutNodeId, int userId) {
IPortletEntity portletEntity;
// First look in the request map
if (portletEntityId != null) {
portletEntity = portletEntityCache.getEntity(portletEntityId);
} else {
portletEntity = portletEntityCache.getEntity(layoutNodeId, userId);
}
if (portletEntity != null) {
logger.trace("Found IPortletEntity {} in request cache", portletEntity.getPortletEntityId());
return portletEntity;
}
// Didn't find it, next look in the session map
final PortletEntityCache<PortletEntityData> portletEntityDataMap = this.getPortletEntityDataMap(request);
final PortletEntityData portletEntityData;
if (portletEntityId != null) {
portletEntityData = portletEntityDataMap.getEntity(portletEntityId);
} else {
portletEntityData = portletEntityDataMap.getEntity(layoutNodeId, userId);
}
if (portletEntityData != null) {
// Stick the entity wrapper in the request map (if it wasn't already added by another
// thread)
portletEntity = portletEntityCache.storeIfAbsentEntity(portletEntityData.getPortletEntityId(), new Function<IPortletEntityId, IPortletEntity>() {
@Override
public IPortletEntity apply(IPortletEntityId input) {
// Found a session stored entity, wrap it to make it a real
// IPortletEntity
logger.trace("Found PortletEntityData {} in session cache, caching wrapper in the request", portletEntityData.getPortletEntityId());
return wrapPortletEntityData(portletEntityData);
}
});
return portletEntity;
}
// Still didn't find it, look in the persistent store
if (portletEntityId != null) {
if (portletEntityId instanceof PortletEntityIdImpl) {
final PortletEntityIdImpl consistentPortletEntityId = (PortletEntityIdImpl) portletEntityId;
final String localLayoutNodeId = consistentPortletEntityId.getLayoutNodeId();
final int localUserId = consistentPortletEntityId.getUserId();
portletEntity = this.portletEntityDao.getPortletEntity(localLayoutNodeId, localUserId);
} else {
portletEntity = this.portletEntityDao.getPortletEntity(portletEntityId);
}
} else {
portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
}
// session stored entities
if (portletEntity != null) {
final IPortletEntityId consistentPortletEntityId = this.createConsistentPortletEntityId(portletEntity);
final IPortletEntity anonPortletEntity = portletEntity;
// Stick the entity wrapper in the request map (if it wasn't already added by another
// thread)
portletEntity = portletEntityCache.storeIfAbsentEntity(consistentPortletEntityId, new Function<IPortletEntityId, IPortletEntity>() {
@Override
public IPortletEntity apply(IPortletEntityId input) {
logger.trace("Found persistent IPortletEntity {}, mapped id to {}, caching the wrapper in the request", anonPortletEntity.getPortletEntityId(), consistentPortletEntityId);
return new PersistentPortletEntityWrapper(anonPortletEntity, consistentPortletEntityId);
}
});
return portletEntity;
}
// Didn't find an entity, just return null
return null;
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getAllLayoutPortletWindows.
@Override
@RequestCache(keyMask = { false })
public Set<IPortletWindow> getAllLayoutPortletWindows(HttpServletRequest request) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final Set<String> allSubscribedChannels = userLayoutManager.getAllSubscribedChannels();
final Set<IPortletWindow> allLayoutWindows = new LinkedHashSet<>(allSubscribedChannels.size());
for (final String channelSubscribeId : allSubscribedChannels) {
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, channelSubscribeId);
if (portletEntity == null) {
this.logger.debug("No portlet entity found for layout node {} for user {}", channelSubscribeId, userInstance.getPerson().getUserName());
continue;
}
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final IPortletWindow portletWindow = this.getOrCreateDefaultPortletWindow(request, portletEntityId);
if (portletWindow == null) {
this.logger.debug("No portlet window found for {}", portletEntity);
continue;
}
allLayoutWindows.add(portletWindow);
}
return allLayoutWindows;
}
Aggregations