Search in sources :

Example 61 with Element

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

the class LocalGroupsCacheAuthenticationListener method userAuthenticated.

@Override
public void userAuthenticated(IPerson user) {
    /*
         * Used to log the time it takes to complete this operation;  the author
         * has some anxiety about running time with large numbers of elements in
         * the cache.
         */
    final long timestamp = System.currentTimeMillis();
    /*
         * Group/member relationships are cached 2 ways:  child-to-parents and
         * parent-to-children.  We need to flush both.
         */
    final EntityIdentifier ei = user.getEntityIdentifier();
    final Element parentGroupsElement = parentGroupsCache.get(ei);
    if (parentGroupsElement != null) {
        // We have some flushing work to do...
        final Set<IEntityGroup> parentGroups = (Set<IEntityGroup>) parentGroupsElement.getObjectValue();
        for (IEntityGroup group : parentGroups) {
            final EntityIdentifier uei = group.getUnderlyingEntityIdentifier();
            childrenCache.remove(uei);
        }
        parentGroupsCache.remove(ei);
        logger.debug("Purged the following local group cache entries for authenticated user '{}' in {}ms:  {}", user.getUserName(), Long.toBinaryString(System.currentTimeMillis() - timestamp), parentGroups);
    }
}
Also used : Set(java.util.Set) Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 62 with Element

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

the class EhcacheMemberIdAttributeExtractorTest method testAttributeFor.

@Test
public void testAttributeFor() {
    final EntityIdentifier parentEntityIdentifier = new EntityIdentifier("mock.group", IPerson.class);
    final String memberId = "mock.user";
    final EntityIdentifier childEntityIdentifier = new EntityIdentifier(memberId, IPerson.class);
    final MembershipCacheKey membershipCacheKey = new MembershipCacheKey(parentEntityIdentifier, childEntityIdentifier);
    final Element element = new Element(membershipCacheKey, new Object());
    final EhcacheMemberIdAttributeExtractor attributeExtractor = new EhcacheMemberIdAttributeExtractor();
    Assert.assertEquals(attributeExtractor.attributeFor(element, null), memberId);
}
Also used : Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier) Test(org.junit.Test)

Example 63 with Element

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

the class EntityPersonAttributesGroupStore method convertPagsGroupToEntity.

private IEntityGroup convertPagsGroupToEntity(IPersonAttributesGroupDefinition group) {
    final String cacheKey = group.getName();
    Element element = entityGroupCache.get(cacheKey);
    if (element == null) {
        final IEntityGroup entityGroup = new EntityTestingGroupImpl(group.getName(), IPERSON_CLASS);
        entityGroup.setName(group.getName());
        entityGroup.setDescription(group.getDescription());
        element = new Element(cacheKey, entityGroup);
        entityGroupCache.put(element);
    }
    return (IEntityGroup) element.getObjectValue();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) Element(net.sf.ehcache.Element) EntityTestingGroupImpl(org.apereo.portal.groups.EntityTestingGroupImpl)

Example 64 with Element

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

the class LayoutCachingService method getCachedLayout.

@Override
public DistributedUserLayout getCachedLayout(IPerson owner, IUserProfile profile) {
    final CacheKey cacheKey = this.getCacheKey(owner, profile);
    final Element element = this.layoutCache.get(cacheKey);
    if (element != null) {
        return (DistributedUserLayout) element.getObjectValue();
    }
    return null;
}
Also used : Element(net.sf.ehcache.Element) CacheKey(org.apereo.portal.utils.cache.CacheKey)

Example 65 with Element

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

the class AbstractDynamicSkinService method getSkinNames.

@Override
public /**
     * Returns the set of skins to use.  This implementation parses the skinList.xml file and returns the set of
     * skin-key element values.  If there is an error parsing the XML file, return an empty set.
     */
SortedSet<String> getSkinNames(PortletRequest request) {
    // Context to access the filesystem
    PortletContext ctx = request.getPortletSession().getPortletContext();
    // Determine the full path to the skins directory
    String skinsFilepath = ctx.getRealPath(this.localRelativeRootPath + "/skinList.xml");
    // Create File object to access the filesystem
    File skinList = new File(skinsFilepath);
    TreeSet<String> skins = new TreeSet<>();
    try {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(skinList);
        doc.getDocumentElement().normalize();
        NodeList nList = doc.getElementsByTagName("skin-key");
        for (int temp = 0; temp < nList.getLength(); temp++) {
            org.w3c.dom.Element element = (org.w3c.dom.Element) nList.item(temp);
            String skinName = element.getTextContent();
            log.debug("Found skin-key value {}", skinName);
            skins.add(skinName);
        }
    } catch (SAXException | ParserConfigurationException | IOException e) {
        log.error("Error processing skinsFilepath {}", skinsFilepath, e);
    }
    return skins;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(net.sf.ehcache.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) TreeSet(java.util.TreeSet) PortletContext(javax.portlet.PortletContext) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

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