Search in sources :

Example 41 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class PortletSpELServiceImpl method parseExpression.

@Override
public Expression parseExpression(String expressionString) throws ParseException {
    if (this.expressionCache == null) {
        return parseExpression(expressionString, TemplateParserContext.INSTANCE);
    }
    Element element = this.expressionCache.get(expressionString);
    if (element != null) {
        return (Expression) element.getObjectValue();
    }
    final Expression expression = parseExpression(expressionString, TemplateParserContext.INSTANCE);
    element = new Element(expressionString, expression);
    this.expressionCache.put(element);
    return expression;
}
Also used : Expression(org.springframework.expression.Expression) Element(net.sf.ehcache.Element)

Example 42 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class SqlQueryPortletController method handleRenderRequest.

@Override
public ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception {
    // find the configured SQL statement
    PortletPreferences preferences = request.getPreferences();
    String sqlQuery = preferences.getValue(SQL_QUERY_PARAM_NAME, null);
    String dsName = preferences.getValue(DATASOURCE_BEAN_NAME_PARAM_NAME, BasePortalJpaDao.PERSISTENCE_UNIT_NAME);
    String viewName = preferences.getValue(VIEW_PARAM_NAME, "jsp/SqlQuery/results");
    // Allow substituting attributes from the request and userInfo objects using the SPEL ${} notation..
    String spelSqlQuery = evaluateSpelExpression(sqlQuery, request);
    List<Map<String, Object>> results = null;
    String cacheKey = createCacheKey(spelSqlQuery, dsName);
    Cache cache = getCache(request);
    if (cache != null) {
        Element cachedElement = cache.get(cacheKey);
        if (cachedElement != null) {
            log.debug("Cache hit. Returning item for query: {}, substituted query: {}, from cache {} for key {}", sqlQuery, spelSqlQuery, cache.getName(), cacheKey);
            results = (List<Map<String, Object>>) cachedElement.getObjectValue();
        }
    }
    if (results == null) {
        // generate a JDBC template for the requested data source
        DataSource ds = (DataSource) getApplicationContext().getBean(dsName);
        JdbcTemplate template = new JdbcTemplate(ds);
        // Execute the SQL query and build a results object.  This result will consist of one
        // rowname -> rowvalue map for each row in the result set
        results = template.query(spelSqlQuery, new ColumnMapRowMapper());
        log.debug("found {} results for query {}", results.size(), spelSqlQuery);
        if (cache != null) {
            log.debug("Adding SQL results to cache {}, query: {}, substituted query: {}", cache.getName(), sqlQuery, spelSqlQuery);
            Element cachedElement = new Element(cacheKey, results);
            cache.put(cachedElement);
        }
    }
    // build the model
    ModelAndView modelandview = new ModelAndView(viewName);
    modelandview.addObject("results", results);
    return modelandview;
}
Also used : Element(net.sf.ehcache.Element) ModelAndView(org.springframework.web.portlet.ModelAndView) PortletPreferences(javax.portlet.PortletPreferences) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Map(java.util.Map) Cache(net.sf.ehcache.Cache) DataSource(javax.sql.DataSource)

Example 43 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.

protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
    Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
    //Check in the cache first
    final Element element = this.entityIdParseCache.get(consistentEntityIdString);
    if (element != null) {
        final Object value = element.getObjectValue();
        if (value != null) {
            return (IPortletEntityId) value;
        }
    }
    if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
        throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
    }
    //Verify the portlet definition id
    final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
    if (portletDefinition == null) {
        throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
    }
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    //Verify non-delegate layout node id exists and is for a portlet
    final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
    if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
        final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
        if (node == null || node.getType() != LayoutNodeType.PORTLET) {
            throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
        }
        //TODO is this doable for delegation?
        //Verify the portlet definition matches
        final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
        final String channelPublishId = portletNode.getChannelPublishId();
        if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
            throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
        }
    }
    //TODO when there is a JPA backed user dao actually verify this mapping
    //User just conver to an int
    final int userId;
    final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
    try {
        userId = Integer.parseInt(userIdAsString);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
    }
    final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
    //Cache the resolution
    this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
    return portletEntityId;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(net.sf.ehcache.Element) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 44 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class AnyUnblockedGrantPermissionPolicy method hasUnblockedPathToGrantWithCache.

private boolean hasUnblockedPathToGrantWithCache(IAuthorizationService service, IAuthorizationPrincipal principal, IPermissionOwner owner, IPermissionActivity activity, IPermissionTarget target, Set<IGroupMember> seenGroups) throws GroupsException {
    final CacheTuple cacheTuple = new CacheTuple(principal.getPrincipalString(), owner.getFname(), activity.getFname(), target.getKey());
    Element element = hasUnblockedGrantCache.get(cacheTuple);
    if (element == null) {
        final boolean answer = hasUnblockedPathToGrant(service, principal, owner, activity, target, seenGroups);
        element = new Element(cacheTuple, answer);
        hasUnblockedGrantCache.put(element);
    }
    return (Boolean) element.getObjectValue();
}
Also used : Element(net.sf.ehcache.Element)

Example 45 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class MapCacheProvider method put.

/* (non-Javadoc)
     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
     */
public V put(K key, V value) {
    final V old = this.get(key);
    this.cache.put(new Element(key, value));
    return old;
}
Also used : Element(net.sf.ehcache.Element)

Aggregations

Element (net.sf.ehcache.Element)114 Test (org.junit.Test)21 CacheKey (org.apereo.portal.utils.cache.CacheKey)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cache (net.sf.ehcache.Cache)7 HashSet (java.util.HashSet)6 CacheException (net.sf.ehcache.CacheException)6 MalformedURLException (java.net.MalformedURLException)5 ConfigurationException (javax.naming.ConfigurationException)5 Ehcache (net.sf.ehcache.Ehcache)5 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 EntityIdentifier (org.apereo.portal.EntityIdentifier)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 SQLException (java.sql.SQLException)4 EntityExistsException (javax.persistence.EntityExistsException)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 BaseCacheTest (org.apache.camel.component.BaseCacheTest)4