Search in sources :

Example 6 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPrivate.

@Test
public void testDetermineCacheScopePortletDefinitionPrivate() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    PortletDefinition portletDefinition = mock(PortletDefinition.class);
    when(portletDefinition.getCacheScope()).thenReturn("private");
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
    when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
    when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDefinition);
    when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
    cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) Test(org.junit.Test)

Example 7 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class GuestPortletEntityPreferencesImpl method loadBasePortletPreferences.

@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
    final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
    //Add descriptor prefs to base Map
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
    for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
        final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
        basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
    }
    //Add definition prefs to base Map
    final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
    for (final IPortletPreference preference : definitionPreferences) {
        basePortletPreferences.put(preference.getName(), preference);
    }
    //Add entity prefs to base Map
    final List<IPortletPreference> entityPreferences = portletEntity.getPortletPreferences();
    for (final IPortletPreference preference : entityPreferences) {
        basePortletPreferences.put(preference.getName(), preference);
    }
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preference(org.apache.pluto.container.om.portlet.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preferences(org.apache.pluto.container.om.portlet.Preferences) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 8 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletDefinitionPreferencesImpl method loadBasePortletPreferences.

@Override
protected void loadBasePortletPreferences(IPortletDefinition portletDefinition, Map<String, IPortletPreference> basePortletPreferences) {
    //Add descriptor prefs to base Map
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
    for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
        final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
        basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
    }
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preference(org.apache.pluto.container.om.portlet.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preferences(org.apache.pluto.container.om.portlet.Preferences) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 9 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition in project uPortal by Jasig.

the class PortletEntityPreferencesImpl method loadBasePortletPreferences.

@Override
protected void loadBasePortletPreferences(IPortletEntity portletEntity, Map<String, IPortletPreference> basePortletPreferences) {
    final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
    //Add descriptor prefs to base Map
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
    final Preferences descriptorPreferences = portletDescriptor.getPortletPreferences();
    for (final Preference preference : descriptorPreferences.getPortletPreferences()) {
        final IPortletPreference preferenceWrapper = new PortletPreferenceImpl(preference);
        basePortletPreferences.put(preferenceWrapper.getName(), preferenceWrapper);
    }
    //Add definition prefs to base Map
    final List<IPortletPreference> definitionPreferences = portletDefinition.getPortletPreferences();
    for (final IPortletPreference preference : definitionPreferences) {
        basePortletPreferences.put(preference.getName(), preference);
    }
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preference(org.apache.pluto.container.om.portlet.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Preferences(org.apache.pluto.container.om.portlet.Preferences) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 10 with PortletDefinition

use of org.apache.pluto.container.om.portlet.PortletDefinition 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;
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) CacheControl(javax.portlet.CacheControl) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Aggregations

PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)13 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)7 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)7 PortletContainerException (org.apache.pluto.container.PortletContainerException)6 QName (javax.xml.namespace.QName)4 PortletRegistryService (org.apache.pluto.container.driver.PortletRegistryService)4 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)4 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)4 EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)3 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)3 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)3 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)3 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)3 CacheControl (javax.portlet.CacheControl)2 Event (javax.portlet.Event)2 Supports (org.apache.pluto.container.om.portlet.Supports)2 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)2