use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.
the class PortletCacheControlServiceImpl method getPortletState.
private <D extends CachedPortletResultHolder<T>, T extends Serializable> CacheState<D, T> getPortletState(HttpServletRequest request, IPortletWindow portletWindow, PublicPortletCacheKey publicCacheKey, Ehcache publicOutputCache, Ehcache privateOutputCache, boolean useHttpHeaders) {
//See if there is any cached data for the portlet header request
final CacheState<D, T> cacheState = this.<D, T>getPortletCacheState(request, portletWindow, publicCacheKey, publicOutputCache, privateOutputCache);
String etagHeader = null;
final D cachedPortletData = cacheState.getCachedPortletData();
if (cachedPortletData != null) {
if (useHttpHeaders) {
//Browser headers being used, check ETag and Last Modified
etagHeader = request.getHeader(IF_NONE_MATCH);
if (etagHeader != null && etagHeader.equals(cachedPortletData.getEtag())) {
//ETag is valid, mark the browser data as matching
cacheState.setBrowserDataMatches(true);
} else {
long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE);
if (ifModifiedSince >= 0 && cachedPortletData.getTimeStored() <= ifModifiedSince) {
//Cached content hasn't been modified since header date, mark the browser data as matching
cacheState.setBrowserDataMatches(true);
}
}
}
final long expirationTime = cachedPortletData.getExpirationTime();
if (expirationTime == -1 || expirationTime > System.currentTimeMillis()) {
//Cached data exists, see if it can be used with no additional work
//Cached data is not expired, check if browser data should be used
cacheState.setUseCachedData(true);
//Copy browser-data-matching flag to the user-browser-data flag
cacheState.setUseBrowserData(cacheState.isBrowserDataMatches());
//No browser side data to be used, return the cached data for replay
return cacheState;
}
}
//Build CacheControl structure
final CacheControl cacheControl = cacheState.getCacheControl();
//Get the portlet descriptor
final IPortletEntity entity = portletWindow.getPortletEntity();
final IPortletDefinitionId definitionId = entity.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(definitionId);
//Set the default scope
final String cacheScopeValue = portletDescriptor.getCacheScope();
if (MimeResponse.PUBLIC_SCOPE.equalsIgnoreCase(cacheScopeValue)) {
cacheControl.setPublicScope(true);
}
//Set the default expiration time
cacheControl.setExpirationTime(portletDescriptor.getExpirationCache());
// Use the request etag if it exists (implies useHttpHeaders==true)
if (etagHeader != null) {
cacheControl.setETag(etagHeader);
cacheState.setBrowserSetEtag(true);
} else // No browser-set etag, use the cached etag value if there is cached data
if (cachedPortletData != null) {
logger.debug("setting cacheControl.eTag from cached data to {}", cachedPortletData.getEtag());
cacheControl.setETag(cachedPortletData.getEtag());
}
return cacheState;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.
the class PortletEntityRegistryImpl method wrapPortletEntityData.
protected IPortletEntity wrapPortletEntityData(final PortletEntityData portletEntityData) {
final IPortletDefinitionId portletDefinitionId = portletEntityData.getPortletDefinitionId();
final IPortletDefinition portletDefinition = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
return new SessionPortletEntityImpl(portletDefinition, portletEntityData);
}
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 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;
}
use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.
the class RDBMDistributedLayoutStore method getPortletEntity.
private IPortletEntity getPortletEntity(String fName, String layoutNodeId, int userId) {
//Try getting the entity
final IPortletEntity portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
if (portletEntity != null) {
return portletEntity;
}
//Load the portlet definition
final IPortletDefinition portletDefinition;
try {
portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
} catch (Exception e) {
throw new DataRetrievalFailureException("Failed to retrieve ChannelDefinition for fName='" + fName + "'", e);
}
//The channel definition for the fName MUST exist for this class to function
if (portletDefinition == null) {
throw new EmptyResultDataAccessException("No ChannelDefinition exists for fName='" + fName + "'", 1);
}
//create the portlet entity
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
return this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}
Aggregations