Search in sources :

Example 16 with IPortletEntityId

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();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) Lock(java.util.concurrent.locks.Lock) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) Collection(java.util.Collection) Map(java.util.Map) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Example 17 with IPortletEntityId

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;
}
Also used : IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 18 with IPortletEntityId

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) ScopingPortletSessionImpl(org.apereo.portal.portlet.session.ScopingPortletSessionImpl) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Example 19 with IPortletEntityId

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) PortletWindow(org.apache.pluto.container.PortletWindow) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Example 20 with IPortletEntityId

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;
}
Also used : HttpSession(javax.servlet.http.HttpSession) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Aggregations

IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)33 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)25 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)10 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)9 Test (org.junit.Test)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 List (java.util.List)7 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)7 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)6 IUserInstance (org.apereo.portal.user.IUserInstance)6 Callable (java.util.concurrent.Callable)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpSession (javax.servlet.http.HttpSession)4 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)4 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)4 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)4 Map (java.util.Map)3 Lock (java.util.concurrent.locks.Lock)3