Search in sources :

Example 11 with IPortletDefinitionId

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;
}
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)

Example 12 with IPortletDefinitionId

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);
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 13 with IPortletDefinitionId

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;
}
Also used : WindowState(javax.portlet.WindowState) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)

Example 14 with IPortletDefinitionId

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;
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) Element(net.sf.ehcache.Element) JAXBElement(javax.xml.bind.JAXBElement) Tuple(org.apereo.portal.utils.Tuple) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition)

Example 15 with IPortletDefinitionId

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);
}
Also used : IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PortalException(org.apereo.portal.PortalException) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) SQLException(java.sql.SQLException) AuthorizationException(org.apereo.portal.AuthorizationException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)28 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)15 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)14 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)12 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)11 Test (org.junit.Test)11 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)10 List (java.util.List)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 Callable (java.util.concurrent.Callable)4 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 IUserInstance (org.apereo.portal.user.IUserInstance)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 Element (net.sf.ehcache.Element)2