Permalink
Browse files

UP-3452 Update event session if it already exists

  • Loading branch information...
edalquist committed Apr 23, 2012
1 parent 5252d81 commit 33804a03c4712354afb80480350a13444b0e54ac
@@ -158,6 +158,11 @@ public String getEventSessionId() {
return ugm;
}
+ public void addGroupMappings(Set<AggregatedGroupMapping> groupMappings) {
+ this.groupMappings.addAll(groupMappings);
+ this.unmodifiableGroupMappings = null;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -132,7 +132,15 @@ public EventSession createEventSession(LoginEvent loginEvent) {
groupMappings.add(groupMapping);
}
- final EventSessionImpl eventSession = new EventSessionImpl(loginEvent.getEventSessionId(), groupMappings);
+ final String eventSessionId = loginEvent.getEventSessionId();
+ EventSessionImpl eventSession = this.getEventSession(eventSessionId);
+ if (eventSession == null) {
+ eventSession = new EventSessionImpl(eventSessionId, groupMappings);
+ }
+ else {
+ logger.warn("Updating existing EventSession, either sessionIds got reused or this login event has been processed multiple times: {}", loginEvent);
+ eventSession.addGroupMappings(groupMappings);
+ }
this.entityManager.persist(eventSession);
@@ -141,7 +149,7 @@ public EventSession createEventSession(LoginEvent loginEvent) {
@Transactional("aggrEvents")
@Override
- public EventSession getEventSession(String eventSessionId) {
+ public EventSessionImpl getEventSession(String eventSessionId) {
final TypedQuery<EventSessionImpl> query = this.createCachedQuery(this.findByEventSessionIdQuery);
query.setParameter(this.eventSessionIdParameter, eventSessionId);

0 comments on commit 33804a0

Please sign in to comment.