com.shapestone.session.SessionOverseer Maven / Gradle / Ivy
The newest version!
package com.shapestone.session;
import java.util.*;
import static com.shapestone.session.SessionEvent.builder;
import static java.lang.String.valueOf;
import static java.lang.System.currentTimeMillis;
import static java.util.UUID.randomUUID;
import static org.apache.commons.lang3.StringUtils.isEmpty;
/**
* Name: Michael Williams
* Date: 9/21/16.
*/
public class SessionOverseer {
private final Session session;
public SessionOverseer(Session session) {
if (isEmpty(session.getSessionId())) {
session.setSessionId(randomUUID().toString());
}
if (session.getModifiedDate() == null || session.getModifiedDate() <= 0) {
session.setModifiedDate(currentTimeMillis());
}
if (session.getCreatedDate() == null || session.getCreatedDate() <= 0) {
session.setCreatedDate(currentTimeMillis());
}
this.session = session;
}
public Session createStoreNewSession() {
return new Session(session);
}
public Session createStoreUpdatedSession() {
final Session session = new Session(this.session);
session.setCreatedDate(null);
return session;
}
public List createSessionEvents() {
final List sessionEvents = new ArrayList<>();
final long timeMillis = currentTimeMillis();
// private String partyId;
if (!isEmpty(session.getPartyId())) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("partyId")
.valueType(String.class.getName())
.value(session.getPartyId())
.createdDate(timeMillis)
.build());
}
// private String userAgent;
if (!isEmpty(session.getUserAgent())) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("userAgent")
.eventType(String.class.getName())
.value(session.getUserAgent())
.createdDate(timeMillis)
.build());
}
// private String ipAddress;
if (!isEmpty(session.getIpAddress())) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("ipAddress")
.valueType(String.class.getName())
.value(session.getIpAddress())
.createdDate(timeMillis)
.build());
}
// private String language;
if (!isEmpty(session.getLanguage())) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("language")
.valueType(String.class.getName())
.value(session.getLanguage())
.createdDate(timeMillis)
.build());
}
// private String fingerPrint;
if (!isEmpty(session.getFingerPrint())) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("fingerPrint")
.valueType(String.class.getName())
.value(session.getFingerPrint())
.createdDate(timeMillis)
.build());
}
// private Long modifiedDate;
if (session.getModifiedDate() != null && session.getModifiedDate() > 0) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("modifiedDate")
.valueType(String.class.getName())
.value(valueOf(session.getModifiedDate()))
.createdDate(timeMillis)
.build());
}
// private Long createdDate;
if (session.getCreatedDate() != null && session.getCreatedDate() > 0) {
sessionEvents.add(builder()
.eventId(randomUUID().toString())
.eventSourceId(session.getSessionId())
.eventSource("SESSION")
.eventType("CREATE")
.name("createdDate")
.valueType(String.class.getName())
.createdDate(timeMillis)
.build());
}
return sessionEvents;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy