-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuditLogEntry.java
More file actions
156 lines (141 loc) · 4.86 KB
/
AuditLogEntry.java
File metadata and controls
156 lines (141 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package net.staticstudios.audit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;
/**
* Represents an entry in the audit log.
*/
public class AuditLogEntry<T extends ActionData> {
private final @NotNull String actorType;
private final @NotNull UUID actorId;
private final @Nullable UUID sessionId;
private final @NotNull String applicationGroup;
private final @NotNull String applicationId;
private final @NotNull Instant timestamp;
private final @NotNull Action<T> action;
private final @NotNull T data;
/**
* Creates a new AuditLogEntry.
*
* @param actorType the type of actor who performed the action (e.g., "user", "server")
* @param actorId the ID of the actor who performed the action
* @param sessionId the ID of the session in which the action was performed (nullable)
* @param applicationGroup the application group that logged the action
* @param applicationId the application ID that logged the action
* @param timestamp the timestamp when the action was performed
* @param action the action that was performed
* @param data the data associated with the action
*/
public AuditLogEntry(@NotNull String actorType, @NotNull UUID actorId, @Nullable UUID sessionId, @NotNull String applicationGroup, @NotNull String applicationId, @NotNull Instant timestamp, @NotNull Action<T> action, @NotNull T data) {
this.actorType = actorType;
this.actorId = actorId;
this.sessionId = sessionId;
this.applicationGroup = applicationGroup;
this.applicationId = applicationId;
this.timestamp = timestamp;
this.action = action;
this.data = data;
}
/**
* Gets the type of actor who performed the action.
*
* @return the actor type (e.g., "user", "server")
*/
public @NotNull String getActorType() {
return actorType;
}
/**
* Gets the ID of the actor who performed the action.
*
* @return the actor ID
*/
public @NotNull UUID getActorId() {
return actorId;
}
/**
* Gets the session ID in which the action was performed.
*
* @return the session ID, or null if not available
*/
public @Nullable UUID getSessionId() {
return sessionId;
}
/**
* Gets the application group that logged the action.
*
* @return the application group
*/
public @NotNull String getApplicationGroup() {
return applicationGroup;
}
/**
* Gets the application ID that logged the action.
*
* @return the application ID
*/
public @NotNull String getApplicationId() {
return applicationId;
}
/**
* Gets the timestamp when the action was performed.
*
* @return the timestamp
*/
public @NotNull Instant getTimestamp() {
return timestamp;
}
/**
* Gets the action that was performed.
*
* @return the action
*/
public @NotNull Action<T> getAction() {
return action;
}
/**
* Gets the data associated with the action.
*
* @return the action data
*/
public @NotNull T getData() {
return data;
}
/**
* Returns a string representation of this AuditLogEntry.
*
* @return a string representation of the object
*/
@Override
public String toString() {
return String.format("AuditLogEntry{actorType=%s, actorId=%s, sessionId=%s, applicationGroup='%s', applicationId='%s', timestamp=%s, action=%s, data=%s}",
actorType, actorId, sessionId, applicationGroup, applicationId, timestamp, action, data);
}
/**
* Checks if this AuditLogEntry is equal to another object.
*
* @param obj the object to compare
* @return true if equal, false otherwise
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
AuditLogEntry<?> that = (AuditLogEntry<?>) obj;
return Objects.equals(action, that.action) && Objects.equals(data, that.data) &&
Objects.equals(actorType, that.actorType) &&
Objects.equals(actorId, that.actorId) && Objects.equals(sessionId, that.sessionId) &&
Objects.equals(applicationGroup, that.applicationGroup) && Objects.equals(applicationId, that.applicationId)
&& Objects.equals(timestamp, that.timestamp);
}
/**
* Returns the hash code for this AuditLogEntry.
*
* @return the hash code
*/
@Override
public int hashCode() {
return Objects.hash(action, data, actorType, actorId, sessionId, applicationGroup, applicationId, timestamp);
}
}