= Session Log

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The Session Log extension provides an implementation of the xref:refguide:applib:index/services/session/SessionSubscriber.adoc[SessionSubscriber] SPI, logging each session as a `SessionLogEntry` entity.

When a user logs on, a `SessionLogEntry` instance is persisted; when they log off, the same instance is updated.


== Setup

=== Dependency Management

In your application's top level `pom.xml`, add a dependency for this module's own bill of materials (BOM):

[source,xml,subs="attributes+"]
.pom.xml
----
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.extensions</groupId>
            <artifactId>causeway-extensions-sessionlog</artifactId>
             <scope>import</scope>
            <type>pom</type>
           <version>{page-causewayprevv2}</version>
        </dependency>
    </dependencies>
</dependencyManagement>
----

=== Dependencies / Imports

Your application may or may not need to interact with the audit trail directly.
If it does, then add a dependency/import to the applib module wherever required:

* add this dependency:
+
[source,xml,subs="attributes+"]
.pom.xml
----
<dependencies>
    <dependency>
        <groupId>org.apache.causeway.extensions</groupId>
        <artifactId>causeway-extensions-sessionlog-applib</artifactId>
    </dependency>
</dependencies>
----

* and `@Import` this module:
+
[source,java]
.MyModule.java
----
@Configuration
@Import({
    CausewayModuleExtSessionLogApplib.class,
    // ...
})
public class MyModule { ... }
----

In your application's xref:userguide::modules.adoc#appmanifest[App Manifest], import the implementation modules of this extension.
The exact modules to use will depend upon the persistence mechanism in use:

* add this dependency to your webapp's `pom.xml`:
+
[source,xml,subs="attributes+"]
.pom.xml
----
<dependencies>
    <dependency>
        <groupId>org.apache.causeway.extensions</groupId>
        <artifactId>causeway-extensions-sessionlog-persistence-xxx</artifactId> <!--.-->
    </dependency>
</dependencies>
----
<.> either:
** `causeway-extensions-sessionlog-persistence-jpa` (xref:pjpa::about.adoc[]) or
** `causeway-extensions-sessionlog-persistence-jdo` (xref:pjdo::about.adoc[])

* and `@Import` this module to your app manifest:
+
[source,java]
.MyAppManifest.java
----
@Configuration
@Import({
    CausewayModuleExtSessionLogPersistenceXxx.class,    // <.>
    // ...
})
public class MyAppManifest { ... }
----
<.> either
+
** `CausewayModuleExtSessionLogPersistenceJpa` (xref:pjpa::about.adoc[]) or
** `CausewayModuleExtSessionLogPersistenceJdo` (xref:pjdo::about.adoc[])



== menubar.layout.xml

Once configured, the extension provides a number of menu actions.
You can use `menubars.layout.xml` to arrange these as you see fit.
To get you started, the following fragment adds all of the actions to an "Activity" secondary menu:

[source,xml]
.menubars.layout.xml
----
<mb:secondary>
    ...
    <mb:menu>
        <mb:named>Activity</mb:named>
        ...
        <mb:section>
            <mb:named>Sessions</mb:named>
            <mb:serviceAction id="activeSessions" objectType="causeway.ext.sessionLog.SessionLogMenu"/>
            <mb:serviceAction id="findSessions" objectType="causeway.ext.sessionLog.SessionLogMenu"/>
        </mb:section>
        ...
    </mb:menu>
</mb:secondary>
----
