Skip to content

Commit

Permalink
Adds the interface "UserEvent" to allow re-usable generic code where …
Browse files Browse the repository at this point in the history
…only the user data is important.

This will e.g. allow re-using constraints on the user data fields for different event types as well as to allow a default duplicate preventer for streaming events (in a future commit).

An interface is used instead of an abstract class to keep the inheritance limitations low.

Fixes: SE-14230
  • Loading branch information
fhaScireum committed Dec 10, 2024
1 parent eb19a72 commit 198ac89
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @see EventRecorder
* @see #withAggregationUrl(String)
*/
public class PageImpressionEvent extends Event<PageImpressionEvent> {
public class PageImpressionEvent extends Event<PageImpressionEvent> implements UserEvent {

/**
* Contains a generic or shortened URI which can be used to aggregate on.
Expand Down Expand Up @@ -82,7 +82,6 @@ public class PageImpressionEvent extends Event<PageImpressionEvent> {
/**
* Contains the current user, tenant and scope if available.
*/
public static final Mapping USER_DATA = Mapping.named("userData");
private final UserData userData = new UserData();

/**
Expand Down Expand Up @@ -168,6 +167,7 @@ public String getAggregationUri() {
return aggregationUri;
}

@Override
public UserData getUserData() {
return userData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
*
* @see sirius.biz.tenants.TenantUserManager#recordUserActivityEvent(UserInfo)
*/
public class UserActivityEvent extends Event<UserActivityEvent> {
public class UserActivityEvent extends Event<UserActivityEvent> implements UserEvent {

/**
* Contains the current user, tenant and scope if available.
*/
public static final Mapping USER_DATA = Mapping.named("userData");
private final UserData userData = new UserData();

/**
Expand All @@ -38,6 +37,7 @@ public class UserActivityEvent extends Event<UserActivityEvent> {
public static final Mapping WEB_DATA = Mapping.named("webData");
private final WebData webData = new WebData();

@Override
public UserData getUserData() {
return userData;
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/sirius/biz/analytics/events/UserEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.analytics.events;

import sirius.db.mixing.Mapping;

/**
* May be implemented by an {@link Event} to provide access to the {@link UserData} of the current user.
*/
public interface UserEvent {

/**
* Contains the user data of the event.
*/
Mapping USER_DATA = Mapping.named("userData");

/**
* Returns the user data of the event.
*
* @return the user data of the event
*/
UserData getUserData();
}
5 changes: 3 additions & 2 deletions src/main/java/sirius/biz/tycho/updates/UpdateClickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@

import sirius.biz.analytics.events.Event;
import sirius.biz.analytics.events.UserData;
import sirius.biz.analytics.events.UserEvent;
import sirius.db.mixing.Mapping;

/**
* Records a click on an {@link UpdateInfo}.
*
* @see UpdateManager
*/
public class UpdateClickEvent extends Event<UpdateClickEvent> {
public class UpdateClickEvent extends Event<UpdateClickEvent> implements UserEvent {

public static final Mapping UPDATE_GUID = Mapping.named("updateGuid");
private String updateGuid;

/**
* Contains the current user, tenant and scope if available.
*/
public static final Mapping USER_DATA = Mapping.named("userData");
private final UserData userData = new UserData();

/**
Expand All @@ -43,6 +43,7 @@ public String getUpdateGuid() {
return updateGuid;
}

@Override
public UserData getUserData() {
return userData;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/sirius/biz/util/SOAPCallEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@

import sirius.biz.analytics.events.Event;
import sirius.biz.analytics.events.UserData;
import sirius.biz.analytics.events.UserEvent;
import sirius.db.mixing.Mapping;
import sirius.db.mixing.annotations.NullAllowed;
import sirius.db.mixing.annotations.Trim;

/**
* Record a SOAP call performed by {@link sirius.biz.util.MonitoredSOAPClient}.
*/
public class SOAPCallEvent extends Event<SOAPCallEvent> {
public class SOAPCallEvent extends Event<SOAPCallEvent> implements UserEvent {

/**
* Contains the shop, customer and user which triggered the event.
*/
public static final Mapping USER_DATA = Mapping.named("userData");
private final UserData userData = new UserData();

/**
Expand Down Expand Up @@ -155,6 +156,7 @@ public boolean isErroneous() {
return erroneous;
}

@Override
public UserData getUserData() {
return userData;
}
Expand Down

0 comments on commit 198ac89

Please sign in to comment.