DatabaseStatsEventHandler - Statistics Recording for uP2.6

The ideas presented here have been incorporated into uPortal and are planned to be included in uPortal 3.1. See Database Event Logger for details

DatabaseStatsEventHandler

This is an implementation of AbstractLimitedSupportEventHandler that logs stats messages to a table,
STATSRECORDER in the uPortal database. The username, date/time, and an action message are recorded.
This event handler utilizes the new Spring configuration introduced in uPortal 2.6.

There are two different implementations for this handler. The first, DatabaseStatsEventHandler, uses JPA and Hibernate
to provide the persistence. The idea was to abstract away the sql for a particular database and provide the ability
to deploy on multiple environments without having to modify the source code. The second, JDBCDatabaseStatsEventHandler,
uses the uPortal RDBMServices to obtain connections to the database and uses sql to push data into the db.
This class may need to be changed based on what RDBMS.

DatabaseStatsEventHandler

The implementation also utilizes JPA and Hibernate as a provider. This was decided to eliminate issues
with sql specific queries for different database products. To configure the handler for your
environment you need to modify /resources/META-INF/persistence.xml file. This is the file that is
packaged with the handler. You need the change the

<jta-data-source>java:comp/env/jdbc/PortalDb</jta-data-source>

property to match your jdbc data source used for uPortal. This is usually defined in the uPortal.xml
file in [catalina.base]/conf/Catalina/localhost directory.

Next modify dialect, change the property to use the appropriate dialect for your database

<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

Building the handler

Before you can build the databasestatsrecoder.jar, you need to modify the build.xml file.
Change the following properties to match your environment.

<!-- UPortal Classes - change to point to your uportal classes -->
<property name="uportal.classes" value="F:/uPortal/uPortal_rel-2-6-0/build/WEB-INF/classes"/>
<!-- UPortal Deployment Directory  - change to your app -->
<property name="uportal.deploy" value="F:/uPortal/Tomcat_5-5-9/webapps/uPortal"/>

Once the build.xml file is modified you can compile, jar, and deploy the jar.

To utilize the DatabaseStatsEventHandler with uPortal 2.6+, you need to modify the statsContext.xml file
in the uPortal properties directory. Here is a sample statsContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!--
        | The parent bean is the Conditional wrapper because first we want to filter down to
        | the events we're actually going to log.
        +-->
    <bean id="eventListener" class="org.jasig.portal.events.SimpleEventListener">
        <property name="eventHandlers">
            <list>
                <bean class="edu.fullcoll.portal.services.stats.DatabaseStatsEventHandler">
                    <property name="supportedEvents">
                        <list>
                            <value>org.jasig.portal.events.support.UserSessionCreatedPortalEvent</value>
                            <value>org.jasig.portal.events.support.UserSessionDestroyedPortalEvent</value>
                            <value>org.jasig.portal.events.support.UserLoggedInPortalEvent</value>
                            <value>org.jasig.portal.events.support.UserLoggedOutPortalEvent</value>
                            <value>org.jasig.portal.events.support.LayoutPortalEvent</value>
                            <value>org.jasig.portal.events.support.ChannelPortalEvent</value>
                            <value>org.jasig.portal.events.support.ChannelLayoutPortalEvent</value>

                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>
</beans>

You may change the supportedEvents to only record specific events that you are interested in.

JDBCDatabaseStatsEventHandler  

The JDBCDatabaseStatsEventHandler can be used and deployed by making any necessary changes to the java source, modifying
the build.xml file and using the ant target jdbcdeploy to deploy the jar. You must also change the statsContext.xml
to use the edu.fullcoll.portal.services.stats.JDBCDatabaseStatsEventHandler. I opted for this version after seeing
additional classes being loaded for the JPA/Hibernate version. You're welcome to investigate further to see which version is more
appropriate for your environment.

This implementation is modification a of the University of Kansas implementation of the DatabaseStatsRecorder.
The DatabaseStatsEventHandler was the first implementation as mentioned to abstract away the sql for particular database.
The JDBCDatabaseStatsEventHandler is the second, while sql statements exist in the code, it reduces the amount of classes loaded
for recording statistics.