use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletEntityPreferencesImpl method storeInternal.
@Override
protected boolean storeInternal() {
final HttpServletRequest containerRequest = portletRequestContext.getContainerRequest();
final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(containerRequest, portletEntityId);
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final Lock portletEntityLock = this.portletEntityRegistry.getPortletEntityLock(containerRequest, portletEntityId);
// Do a tryLock first so that we can warn about concurrent preference modification if it
// fails
boolean locked = portletEntityLock.tryLock();
try {
if (!locked) {
logger.warn("Concurrent portlet preferences modification by: " + portletEntity + " " + "This has the potential for changes to preferences to be lost. " + "This portlet should be modified to synchronize its preference modifications appropriately", new Throwable());
portletEntityLock.lock();
locked = true;
}
return this.transactionOperations.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
// Refresh the entity to avoid optimistic locking errors
final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(containerRequest, portletEntityId);
final Map<String, IPortletPreference> targetPortletPreferences = getTargetPortletPreferences();
final Collection<IPortletPreference> values = targetPortletPreferences.values();
final boolean modified = portletEntity.setPortletPreferences(new ArrayList<>(values));
if (!modified) {
// Nothing actually changed, skip the store
return Boolean.FALSE;
}
portletEntityRegistry.storePortletEntity(containerRequest, portletEntity);
return Boolean.TRUE;
}
});
} finally {
// logging
if (locked) {
portletEntityLock.unlock();
}
}
}
use of org.apereo.portal.portlet.om.IPortletEntityId 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);
// 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.IPortletEntityId in project uPortal by Jasig.
the class PortletEnvironmentServiceImpl method createPortletSession.
@Override
public PortletSession createPortletSession(PortletContext portletContext, PortletWindow portletWindow, HttpSession session) {
// TODO pluto 1.1 PortletEnvironmentService#createPortletSession passed in the request; now
// use IPortalRequestUtils#getCurrentPortalRequest()?
final HttpServletRequest request = portalRequestUtils.getCurrentPortalRequest();
final IPortletWindow internalPortletWindow = this.portletWindowRegistry.convertPortletWindow(request, portletWindow);
final IPortletEntity portletEntity = internalPortletWindow.getPortletEntity();
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
return new ScopingPortletSessionImpl(portletEntityId, portletContext, portletWindow, session);
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletPreferencesFactoryImpl method createPortletPreferences.
@Override
public PortletPreferences createPortletPreferences(final PortletRequestContext requestContext, boolean render) {
final HttpServletRequest containerRequest = requestContext.getContainerRequest();
final PortletWindow plutoPortletWindow = requestContext.getPortletWindow();
final IPortletWindow portletWindow = portletWindowRegistry.convertPortletWindow(containerRequest, plutoPortletWindow);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
final boolean configMode = IPortletRenderer.CONFIG.equals(portletWindow.getPortletMode());
if (configMode) {
final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
return new PortletDefinitionPreferencesImpl(portletDefinitionRegistry, transactionOperations, portletDefinitionId, render);
} else if (this.isStoreInMemory(containerRequest)) {
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
return new GuestPortletEntityPreferencesImpl(requestContext, portletEntityRegistry, portletDefinitionRegistry, portletEntityId, render);
} else {
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
return new PortletEntityPreferencesImpl(requestContext, portletEntityRegistry, portletDefinitionRegistry, transactionOperations, portletEntityId, render);
}
}
use of org.apereo.portal.portlet.om.IPortletEntityId in project uPortal by Jasig.
the class PortletCacheControlServiceImpl method getPortletCacheState.
/**
* Get the cached portlet data looking in both the public and then private caches returning the
* first found
*
* @param request The current request
* @param portletWindow The window to get data for
* @param publicCacheKey The public cache key
* @param publicOutputCache The public cache
* @param privateOutputCache The private cache
*/
@SuppressWarnings("unchecked")
protected <D extends CachedPortletResultHolder<T>, T extends Serializable> CacheState<D, T> getPortletCacheState(HttpServletRequest request, IPortletWindow portletWindow, PublicPortletCacheKey publicCacheKey, Ehcache publicOutputCache, Ehcache privateOutputCache) {
final CacheState<D, T> cacheState = new CacheState<D, T>();
cacheState.setPublicPortletCacheKey(publicCacheKey);
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
// Check for publicly cached data
D cachedPortletData = (D) this.getCachedPortletData(publicCacheKey, publicOutputCache, portletWindow);
if (cachedPortletData != null) {
cacheState.setCachedPortletData(cachedPortletData);
return cacheState;
}
// Generate private cache key
final HttpSession session = request.getSession();
final String sessionId = session.getId();
final IPortletEntityId entityId = portletWindow.getPortletEntityId();
final PrivatePortletCacheKey privateCacheKey = new PrivatePortletCacheKey(sessionId, portletWindowId, entityId, publicCacheKey);
cacheState.setPrivatePortletCacheKey(privateCacheKey);
// Check for privately cached data
cachedPortletData = (D) this.getCachedPortletData(privateCacheKey, privateOutputCache, portletWindow);
if (cachedPortletData != null) {
cacheState.setCachedPortletData(cachedPortletData);
return cacheState;
}
return cacheState;
}
Aggregations