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

box / box-java-sdk / #6242

10 Feb 2026 05:27PM UTC coverage: 35.714% (+11.4%) from 24.324%
#6242

push

github

web-flow
fix(boxsdkgen): Move assigning default values from builder constructor to `build()` method (box/box-codegen#922) (#1712)

0 of 1677 new or added lines in 569 files covered. (0.0%)

2146 existing lines in 544 files now uncovered.

7382 of 20670 relevant lines covered (35.71%)

0.4 hits per line

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

0.0
/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) {
×
31
    this.auth = builder.auth;
×
32
    this.networkSession = builder.networkSession;
×
33
  }
×
34

35
  /**
36
   * Returns a list of real-time servers that can be used for long-polling updates to the [event
37
   * stream](https://developer.box.com/reference/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
50
   * endpoint](https://developer.box.com/reference/get-events) with the last known
51
   * `stream_position`.
52
   *
53
   * <p>After the server sends this response it closes the connection. You must now repeat the long
54
   * poll process to begin listening for events again.
55
   *
56
   * <p>If no events occur for a while and the connection times out you will receive a response with
57
   * the value `reconnect`. When you receive this response you’ll make another call to this endpoint
58
   * to restart the process.
59
   *
60
   * <p>If you receive no events in `retry_timeout` seconds then you will need to make another
61
   * request to the real-time server (one of the URLs in the response for this endpoint). This might
62
   * be necessary due to network errors.
63
   *
64
   * <p>Finally, if you receive a `max_retries` error when making a request to the real-time server,
65
   * you should start over by making a call to this endpoint first.
66
   */
67
  public RealtimeServers getEventsWithLongPolling() {
68
    return getEventsWithLongPolling(new GetEventsWithLongPollingHeaders());
×
69
  }
70

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

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

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

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

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

206
  /** Get an event stream for the Box API */
207
  public EventStream getEventStream() {
208
    return getEventStream(new GetEventStreamQueryParams(), new GetEventStreamHeaders());
×
209
  }
210

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

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

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

240
  public Authentication getAuth() {
241
    return auth;
×
242
  }
243

244
  public NetworkSession getNetworkSession() {
245
    return networkSession;
×
246
  }
247

248
  public static class Builder {
249

250
    protected Authentication auth;
251

252
    protected NetworkSession networkSession;
253

NEW
254
    public Builder() {}
×
255

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

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

266
    public EventsManager build() {
NEW
267
      if (this.networkSession == null) {
×
NEW
268
        this.networkSession = new NetworkSession();
×
269
      }
270
      return new EventsManager(this);
×
271
    }
272
  }
273
}
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