• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.44
/src/main/java/com/box/sdkgen/managers/events/EventsManager.java
1
package com.box.sdkgen.managers.events;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.box.eventstream.EventStream;
10
import com.box.sdkgen.networking.auth.Authentication;
11
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
12
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
13
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
14
import com.box.sdkgen.networking.network.NetworkSession;
15
import com.box.sdkgen.schemas.events.Events;
16
import com.box.sdkgen.schemas.realtimeservers.RealtimeServers;
17
import com.box.sdkgen.serialization.json.JsonManager;
18
import java.util.Map;
19

20
public class EventsManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

26
  public EventsManager() {
×
27
    this.networkSession = new NetworkSession();
×
28
  }
×
29

30
  protected EventsManager(Builder builder) {
1✔
31
    this.auth = builder.auth;
1✔
32
    this.networkSession = builder.networkSession;
1✔
33
  }
1✔
34

35
  /**
36
   * Returns a list of real-time servers that can be used for long-polling updates to the [event
37
   * stream](#get-events).
38
   *
39
   * <p>Long polling is the concept where a HTTP request is kept open until the server sends a
40
   * response, then repeating the process over and over to receive updated responses.
41
   *
42
   * <p>Long polling the event stream can only be used for user events, not for enterprise events.
43
   *
44
   * <p>To use long polling, first use this endpoint to retrieve a list of long poll URLs. Next,
45
   * make a long poll request to any of the provided URLs.
46
   *
47
   * <p>When an event occurs in monitored account a response with the value `new_change` will be
48
   * sent. The response contains no other details as it only serves as a prompt to take further
49
   * action such as sending a request to the [events endpoint](#get-events) with the last known
50
   * `stream_position`.
51
   *
52
   * <p>After the server sends this response it closes the connection. You must now repeat the long
53
   * poll process to begin listening for events again.
54
   *
55
   * <p>If no events occur for a while and the connection times out you will receive a response with
56
   * the value `reconnect`. When you receive this response you’ll make another call to this endpoint
57
   * to restart the process.
58
   *
59
   * <p>If you receive no events in `retry_timeout` seconds then you will need to make another
60
   * request to the real-time server (one of the URLs in the response for this endpoint). This might
61
   * be necessary due to network errors.
62
   *
63
   * <p>Finally, if you receive a `max_retries` error when making a request to the real-time server,
64
   * you should start over by making a call to this endpoint first.
65
   */
66
  public RealtimeServers getEventsWithLongPolling() {
67
    return getEventsWithLongPolling(new GetEventsWithLongPollingHeaders());
1✔
68
  }
69

70
  /**
71
   * Returns a list of real-time servers that can be used for long-polling updates to the [event
72
   * stream](#get-events).
73
   *
74
   * <p>Long polling is the concept where a HTTP request is kept open until the server sends a
75
   * response, then repeating the process over and over to receive updated responses.
76
   *
77
   * <p>Long polling the event stream can only be used for user events, not for enterprise events.
78
   *
79
   * <p>To use long polling, first use this endpoint to retrieve a list of long poll URLs. Next,
80
   * make a long poll request to any of the provided URLs.
81
   *
82
   * <p>When an event occurs in monitored account a response with the value `new_change` will be
83
   * sent. The response contains no other details as it only serves as a prompt to take further
84
   * action such as sending a request to the [events endpoint](#get-events) with the last known
85
   * `stream_position`.
86
   *
87
   * <p>After the server sends this response it closes the connection. You must now repeat the long
88
   * poll process to begin listening for events again.
89
   *
90
   * <p>If no events occur for a while and the connection times out you will receive a response with
91
   * the value `reconnect`. When you receive this response you’ll make another call to this endpoint
92
   * to restart the process.
93
   *
94
   * <p>If you receive no events in `retry_timeout` seconds then you will need to make another
95
   * request to the real-time server (one of the URLs in the response for this endpoint). This might
96
   * be necessary due to network errors.
97
   *
98
   * <p>Finally, if you receive a `max_retries` error when making a request to the real-time server,
99
   * you should start over by making a call to this endpoint first.
100
   *
101
   * @param headers Headers of getEventsWithLongPolling method
102
   */
103
  public RealtimeServers getEventsWithLongPolling(GetEventsWithLongPollingHeaders headers) {
104
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
105
    FetchResponse response =
1✔
106
        this.networkSession
107
            .getNetworkClient()
1✔
108
            .fetch(
1✔
109
                new FetchOptions.Builder(
110
                        String.join(
1✔
111
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/events"),
1✔
112
                        "OPTIONS")
113
                    .headers(headersMap)
1✔
114
                    .responseFormat(ResponseFormat.JSON)
1✔
115
                    .auth(this.auth)
1✔
116
                    .networkSession(this.networkSession)
1✔
117
                    .build());
1✔
118
    return JsonManager.deserialize(response.getData(), RealtimeServers.class);
1✔
119
  }
120

121
  /**
122
   * Returns up to a year of past events for a given user or for the entire enterprise.
123
   *
124
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
125
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
126
   * or `admin_logs` for querying across historical events. The user making the API call will need
127
   * to have admin privileges, and the application will need to have the scope `manage enterprise
128
   * properties` checked.
129
   */
130
  public Events getEvents() {
131
    return getEvents(new GetEventsQueryParams(), new GetEventsHeaders());
1✔
132
  }
133

134
  /**
135
   * Returns up to a year of past events for a given user or for the entire enterprise.
136
   *
137
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
138
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
139
   * or `admin_logs` for querying across historical events. The user making the API call will need
140
   * to have admin privileges, and the application will need to have the scope `manage enterprise
141
   * properties` checked.
142
   *
143
   * @param queryParams Query parameters of getEvents method
144
   */
145
  public Events getEvents(GetEventsQueryParams queryParams) {
146
    return getEvents(queryParams, new GetEventsHeaders());
1✔
147
  }
148

149
  /**
150
   * Returns up to a year of past events for a given user or for the entire enterprise.
151
   *
152
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
153
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
154
   * or `admin_logs` for querying across historical events. The user making the API call will need
155
   * to have admin privileges, and the application will need to have the scope `manage enterprise
156
   * properties` checked.
157
   *
158
   * @param headers Headers of getEvents method
159
   */
160
  public Events getEvents(GetEventsHeaders headers) {
161
    return getEvents(new GetEventsQueryParams(), headers);
×
162
  }
163

164
  /**
165
   * Returns up to a year of past events for a given user or for the entire enterprise.
166
   *
167
   * <p>By default this returns events for the authenticated user. To retrieve events for the entire
168
   * enterprise, set the `stream_type` to `admin_logs_streaming` for live monitoring of new events,
169
   * or `admin_logs` for querying across historical events. The user making the API call will need
170
   * to have admin privileges, and the application will need to have the scope `manage enterprise
171
   * properties` checked.
172
   *
173
   * @param queryParams Query parameters of getEvents method
174
   * @param headers Headers of getEvents method
175
   */
176
  public Events getEvents(GetEventsQueryParams queryParams, GetEventsHeaders headers) {
177
    Map<String, String> queryParamsMap =
1✔
178
        prepareParams(
1✔
179
            mapOf(
1✔
180
                entryOf("stream_type", convertToString(queryParams.getStreamType())),
1✔
181
                entryOf("stream_position", convertToString(queryParams.getStreamPosition())),
1✔
182
                entryOf("limit", convertToString(queryParams.getLimit())),
1✔
183
                entryOf("event_type", convertToString(queryParams.getEventType())),
1✔
184
                entryOf("created_after", convertToString(queryParams.getCreatedAfter())),
1✔
185
                entryOf("created_before", convertToString(queryParams.getCreatedBefore()))));
1✔
186
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
187
    FetchResponse response =
1✔
188
        this.networkSession
189
            .getNetworkClient()
1✔
190
            .fetch(
1✔
191
                new FetchOptions.Builder(
192
                        String.join(
1✔
193
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/events"),
1✔
194
                        "GET")
195
                    .params(queryParamsMap)
1✔
196
                    .headers(headersMap)
1✔
197
                    .responseFormat(ResponseFormat.JSON)
1✔
198
                    .auth(this.auth)
1✔
199
                    .networkSession(this.networkSession)
1✔
200
                    .build());
1✔
201
    return JsonManager.deserialize(response.getData(), Events.class);
1✔
202
  }
203

204
  /** Get an event stream for the Box API */
205
  public EventStream getEventStream() {
206
    return getEventStream(new GetEventStreamQueryParams(), new GetEventStreamHeaders());
1✔
207
  }
208

209
  /**
210
   * Get an event stream for the Box API
211
   *
212
   * @param queryParams Query parameters of getEvents method
213
   */
214
  public EventStream getEventStream(GetEventStreamQueryParams queryParams) {
215
    return getEventStream(queryParams, new GetEventStreamHeaders());
×
216
  }
217

218
  /**
219
   * Get an event stream for the Box API
220
   *
221
   * @param headers Headers of getEvents method
222
   */
223
  public EventStream getEventStream(GetEventStreamHeaders headers) {
224
    return getEventStream(new GetEventStreamQueryParams(), headers);
×
225
  }
226

227
  /**
228
   * Get an event stream for the Box API
229
   *
230
   * @param queryParams Query parameters of getEvents method
231
   * @param headers Headers of getEvents method
232
   */
233
  public EventStream getEventStream(
234
      GetEventStreamQueryParams queryParams, GetEventStreamHeaders headers) {
235
    return new EventStream.Builder(this, queryParams).headersInput(headers).build();
1✔
236
  }
237

238
  public Authentication getAuth() {
239
    return auth;
×
240
  }
241

242
  public NetworkSession getNetworkSession() {
243
    return networkSession;
×
244
  }
245

246
  public static class Builder {
247

248
    protected Authentication auth;
249

250
    protected NetworkSession networkSession;
251

252
    public Builder() {
1✔
253
      this.networkSession = new NetworkSession();
1✔
254
    }
1✔
255

256
    public Builder auth(Authentication auth) {
257
      this.auth = auth;
1✔
258
      return this;
1✔
259
    }
260

261
    public Builder networkSession(NetworkSession networkSession) {
262
      this.networkSession = networkSession;
1✔
263
      return this;
1✔
264
    }
265

266
    public EventsManager build() {
267
      return new EventsManager(this);
1✔
268
    }
269
  }
270
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc