1+ package io .getstream .client ;
2+
3+ import io .getstream .core .exceptions .StreamException ;
4+
5+ /**
6+ * Filters for querying audit logs.
7+ * Either entityType+entityID pair OR userID is required by the API.
8+ *
9+ * Common entity types in Stream include:
10+ * - "activity" - for feed activities
11+ * - "reaction" - for activity reactions
12+ * - "user" - for Stream users
13+ * - "feed" - for feed configurations
14+ */
15+ public class QueryAuditLogsFilters {
16+ private String entityType ;
17+ private String entityID ;
18+ private String userID ;
19+
20+ /**
21+ * Private constructor, use builder instead.
22+ */
23+ private QueryAuditLogsFilters () {
24+ }
25+
26+ /**
27+ * Creates a new builder for QueryAuditLogsFilters.
28+ *
29+ * @return a new QueryAuditLogsFilters.Builder
30+ */
31+ public static Builder builder () {
32+ return new Builder ();
33+ }
34+
35+ /**
36+ * Creates a new filter for user ID queries.
37+ *
38+ * @param userID The ID of the user
39+ * @return a new QueryAuditLogsFilters with the user ID set
40+ */
41+ public static QueryAuditLogsFilters forUser (String userID ) {
42+ return builder ().withUserID (userID ).build ();
43+ }
44+
45+ /**
46+ * Creates a new filter for entity type and ID queries.
47+ *
48+ * @param entityType The type of entity (e.g., "activity", "reaction", "user", "feed")
49+ * @param entityID The ID of the entity
50+ * @return a new QueryAuditLogsFilters with the entity type and ID set
51+ */
52+ public static QueryAuditLogsFilters forEntity (String entityType , String entityID ) {
53+ return builder ().withEntityType (entityType ).withEntityID (entityID ).build ();
54+ }
55+
56+ /**
57+ * Convenience method to create a filter for activity entities.
58+ *
59+ * @param activityID The ID of the activity
60+ * @return a new QueryAuditLogsFilters for the activity
61+ */
62+ public static QueryAuditLogsFilters forActivity (String activityID ) {
63+ return forEntity ("activity" , activityID );
64+ }
65+
66+ /**
67+ * Convenience method to create a filter for reaction entities.
68+ *
69+ * @param reactionID The ID of the reaction
70+ * @return a new QueryAuditLogsFilters for the reaction
71+ */
72+ public static QueryAuditLogsFilters forReaction (String reactionID ) {
73+ return forEntity ("reaction" , reactionID );
74+ }
75+
76+ public String getEntityType () {
77+ return entityType ;
78+ }
79+
80+ public String getEntityID () {
81+ return entityID ;
82+ }
83+
84+ public String getUserID () {
85+ return userID ;
86+ }
87+
88+ /**
89+ * Set the entity type for existing filter instance.
90+ *
91+ * @param entityType The type of entity (e.g., "activity", "reaction")
92+ * @return this instance for method chaining
93+ */
94+ public QueryAuditLogsFilters setEntityType (String entityType ) {
95+ this .entityType = entityType ;
96+ return this ;
97+ }
98+
99+ /**
100+ * Set the entity ID for existing filter instance.
101+ *
102+ * @param entityID The ID of the entity
103+ * @return this instance for method chaining
104+ */
105+ public QueryAuditLogsFilters setEntityID (String entityID ) {
106+ this .entityID = entityID ;
107+ return this ;
108+ }
109+
110+ /**
111+ * Set the user ID for existing filter instance.
112+ *
113+ * @param userID The ID of the user
114+ * @return this instance for method chaining
115+ */
116+ public QueryAuditLogsFilters setUserID (String userID ) {
117+ this .userID = userID ;
118+ return this ;
119+ }
120+
121+ /**
122+ * Validates that the filters contain the required fields.
123+ * Either (entityType AND entityID) OR userID must be set.
124+ *
125+ * @throws StreamException if the required fields are not set
126+ */
127+ public void validate () throws StreamException {
128+ boolean hasEntityFields = entityType != null && !entityType .isEmpty () &&
129+ entityID != null && !entityID .isEmpty ();
130+ boolean hasUserID = userID != null && !userID .isEmpty ();
131+
132+ if (!hasEntityFields && !hasUserID ) {
133+ throw new StreamException ("Either entityType+entityID or userID is required for audit logs queries" );
134+ }
135+ }
136+
137+ /**
138+ * Checks if the filter is valid according to API requirements.
139+ *
140+ * @return true if either (entityType AND entityID) OR userID is set
141+ */
142+ public boolean isValid () {
143+ boolean hasEntityFields = entityType != null && !entityType .isEmpty () &&
144+ entityID != null && !entityID .isEmpty ();
145+ boolean hasUserID = userID != null && !userID .isEmpty ();
146+
147+ return hasEntityFields || hasUserID ;
148+ }
149+
150+ /**
151+ * Builder class for QueryAuditLogsFilters.
152+ */
153+ public static class Builder {
154+ private final QueryAuditLogsFilters filters ;
155+
156+ private Builder () {
157+ filters = new QueryAuditLogsFilters ();
158+ }
159+
160+ /**
161+ * Set the entity type.
162+ *
163+ * @param entityType The type of entity (e.g., "activity", "reaction")
164+ * @return this builder for method chaining
165+ */
166+ public Builder withEntityType (String entityType ) {
167+ filters .entityType = entityType ;
168+ return this ;
169+ }
170+
171+ /**
172+ * Set the entity ID.
173+ *
174+ * @param entityID The ID of the entity
175+ * @return this builder for method chaining
176+ */
177+ public Builder withEntityID (String entityID ) {
178+ filters .entityID = entityID ;
179+ return this ;
180+ }
181+
182+ /**
183+ * Set the user ID.
184+ *
185+ * @param userID The ID of the user
186+ * @return this builder for method chaining
187+ */
188+ public Builder withUserID (String userID ) {
189+ filters .userID = userID ;
190+ return this ;
191+ }
192+
193+ /**
194+ * Builds the QueryAuditLogsFilters instance.
195+ *
196+ * @return a new QueryAuditLogsFilters instance
197+ */
198+ public QueryAuditLogsFilters build () {
199+ return filters ;
200+ }
201+ }
202+ }
0 commit comments