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

box / box-java-sdk / #5027

03 Oct 2025 09:45AM UTC coverage: 13.656% (-0.008%) from 13.664%
#5027

Pull #1478

github

web-flow
Merge 7e3e09ba8 into ac7d3d5fe
Pull Request #1478: fix: Make `role` parameter of update collaboration optional (box/box-openapi#557)

0 of 4 new or added lines in 2 files covered. (0.0%)

15 existing lines in 9 files now uncovered.

8368 of 61275 relevant lines covered (13.66%)

0.14 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/usercollaborations/UserCollaborationsManager.java
1
package com.box.sdkgen.managers.usercollaborations;
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.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.collaboration.Collaboration;
15
import com.box.sdkgen.serialization.json.JsonManager;
16
import java.util.Map;
17

18
public class UserCollaborationsManager {
19

20
  public Authentication auth;
21

22
  public NetworkSession networkSession;
23

24
  public UserCollaborationsManager() {
×
25
    this.networkSession = new NetworkSession();
×
26
  }
×
27

28
  protected UserCollaborationsManager(Builder builder) {
×
29
    this.auth = builder.auth;
×
30
    this.networkSession = builder.networkSession;
×
31
  }
×
32

33
  /**
34
   * Retrieves a single collaboration.
35
   *
36
   * @param collaborationId The ID of the collaboration. Example: "1234"
37
   */
38
  public Collaboration getCollaborationById(String collaborationId) {
39
    return getCollaborationById(
×
40
        collaborationId, new GetCollaborationByIdQueryParams(), new GetCollaborationByIdHeaders());
41
  }
42

43
  /**
44
   * Retrieves a single collaboration.
45
   *
46
   * @param collaborationId The ID of the collaboration. Example: "1234"
47
   * @param queryParams Query parameters of getCollaborationById method
48
   */
49
  public Collaboration getCollaborationById(
50
      String collaborationId, GetCollaborationByIdQueryParams queryParams) {
51
    return getCollaborationById(collaborationId, queryParams, new GetCollaborationByIdHeaders());
×
52
  }
53

54
  /**
55
   * Retrieves a single collaboration.
56
   *
57
   * @param collaborationId The ID of the collaboration. Example: "1234"
58
   * @param headers Headers of getCollaborationById method
59
   */
60
  public Collaboration getCollaborationById(
61
      String collaborationId, GetCollaborationByIdHeaders headers) {
62
    return getCollaborationById(collaborationId, new GetCollaborationByIdQueryParams(), headers);
×
63
  }
64

65
  /**
66
   * Retrieves a single collaboration.
67
   *
68
   * @param collaborationId The ID of the collaboration. Example: "1234"
69
   * @param queryParams Query parameters of getCollaborationById method
70
   * @param headers Headers of getCollaborationById method
71
   */
72
  public Collaboration getCollaborationById(
73
      String collaborationId,
74
      GetCollaborationByIdQueryParams queryParams,
75
      GetCollaborationByIdHeaders headers) {
76
    Map<String, String> queryParamsMap =
×
77
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
×
78
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
79
    FetchResponse response =
×
80
        this.networkSession
81
            .getNetworkClient()
×
82
            .fetch(
×
83
                new FetchOptions.Builder(
84
                        String.join(
×
85
                            "",
86
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
87
                            "/2.0/collaborations/",
88
                            convertToString(collaborationId)),
×
89
                        "GET")
90
                    .params(queryParamsMap)
×
91
                    .headers(headersMap)
×
92
                    .responseFormat(ResponseFormat.JSON)
×
93
                    .auth(this.auth)
×
94
                    .networkSession(this.networkSession)
×
95
                    .build());
×
96
    return JsonManager.deserialize(response.getData(), Collaboration.class);
×
97
  }
98

99
  /**
100
   * Updates a collaboration. Can be used to change the owner of an item, or to accept collaboration
101
   * invites. In case of accepting collaboration invite, role is not required.
102
   *
103
   * @param collaborationId The ID of the collaboration. Example: "1234"
104
   */
105
  public Collaboration updateCollaborationById(String collaborationId) {
NEW
106
    return updateCollaborationById(
×
107
        collaborationId,
108
        new UpdateCollaborationByIdRequestBody(),
109
        new UpdateCollaborationByIdHeaders());
110
  }
111

112
  /**
113
   * Updates a collaboration. Can be used to change the owner of an item, or to accept collaboration
114
   * invites. In case of accepting collaboration invite, role is not required.
115
   *
116
   * @param collaborationId The ID of the collaboration. Example: "1234"
117
   * @param requestBody Request body of updateCollaborationById method
118
   */
119
  public Collaboration updateCollaborationById(
120
      String collaborationId, UpdateCollaborationByIdRequestBody requestBody) {
121
    return updateCollaborationById(
×
122
        collaborationId, requestBody, new UpdateCollaborationByIdHeaders());
123
  }
124

125
  /**
126
   * Updates a collaboration. Can be used to change the owner of an item, or to accept collaboration
127
   * invites. In case of accepting collaboration invite, role is not required.
128
   *
129
   * @param collaborationId The ID of the collaboration. Example: "1234"
130
   * @param headers Headers of updateCollaborationById method
131
   */
132
  public Collaboration updateCollaborationById(
133
      String collaborationId, UpdateCollaborationByIdHeaders headers) {
NEW
134
    return updateCollaborationById(
×
135
        collaborationId, new UpdateCollaborationByIdRequestBody(), headers);
136
  }
137

138
  /**
139
   * Updates a collaboration. Can be used to change the owner of an item, or to accept collaboration
140
   * invites. In case of accepting collaboration invite, role is not required.
141
   *
142
   * @param collaborationId The ID of the collaboration. Example: "1234"
143
   * @param requestBody Request body of updateCollaborationById method
144
   * @param headers Headers of updateCollaborationById method
145
   */
146
  public Collaboration updateCollaborationById(
147
      String collaborationId,
148
      UpdateCollaborationByIdRequestBody requestBody,
149
      UpdateCollaborationByIdHeaders headers) {
150
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
151
    FetchResponse response =
×
152
        this.networkSession
153
            .getNetworkClient()
×
154
            .fetch(
×
155
                new FetchOptions.Builder(
156
                        String.join(
×
157
                            "",
158
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
159
                            "/2.0/collaborations/",
160
                            convertToString(collaborationId)),
×
161
                        "PUT")
162
                    .headers(headersMap)
×
163
                    .data(JsonManager.serialize(requestBody))
×
164
                    .contentType("application/json")
×
165
                    .responseFormat(ResponseFormat.JSON)
×
166
                    .auth(this.auth)
×
167
                    .networkSession(this.networkSession)
×
168
                    .build());
×
169
    if (convertToString(response.getStatus()).equals("204")) {
×
170
      return null;
×
171
    }
172
    return JsonManager.deserialize(response.getData(), Collaboration.class);
×
173
  }
174

175
  /**
176
   * Deletes a single collaboration.
177
   *
178
   * @param collaborationId The ID of the collaboration. Example: "1234"
179
   */
180
  public void deleteCollaborationById(String collaborationId) {
181
    deleteCollaborationById(collaborationId, new DeleteCollaborationByIdHeaders());
×
182
  }
×
183

184
  /**
185
   * Deletes a single collaboration.
186
   *
187
   * @param collaborationId The ID of the collaboration. Example: "1234"
188
   * @param headers Headers of deleteCollaborationById method
189
   */
190
  public void deleteCollaborationById(
191
      String collaborationId, DeleteCollaborationByIdHeaders headers) {
192
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
193
    FetchResponse response =
×
194
        this.networkSession
195
            .getNetworkClient()
×
196
            .fetch(
×
197
                new FetchOptions.Builder(
198
                        String.join(
×
199
                            "",
200
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
201
                            "/2.0/collaborations/",
202
                            convertToString(collaborationId)),
×
203
                        "DELETE")
204
                    .headers(headersMap)
×
205
                    .responseFormat(ResponseFormat.NO_CONTENT)
×
206
                    .auth(this.auth)
×
207
                    .networkSession(this.networkSession)
×
208
                    .build());
×
209
  }
×
210

211
  /**
212
   * Adds a collaboration for a single user or a single group to a file or folder.
213
   *
214
   * <p>Collaborations can be created using email address, user IDs, or a group IDs.
215
   *
216
   * <p>If a collaboration is being created with a group, access to this endpoint is dependent on
217
   * the group's ability to be invited.
218
   *
219
   * <p>If collaboration is in `pending` status, the following fields are redacted: - `login` and
220
   * `name` are hidden if a collaboration was created using `user_id`, - `name` is hidden if a
221
   * collaboration was created using `login`.
222
   *
223
   * @param requestBody Request body of createCollaboration method
224
   */
225
  public Collaboration createCollaboration(CreateCollaborationRequestBody requestBody) {
226
    return createCollaboration(
×
227
        requestBody, new CreateCollaborationQueryParams(), new CreateCollaborationHeaders());
228
  }
229

230
  /**
231
   * Adds a collaboration for a single user or a single group to a file or folder.
232
   *
233
   * <p>Collaborations can be created using email address, user IDs, or a group IDs.
234
   *
235
   * <p>If a collaboration is being created with a group, access to this endpoint is dependent on
236
   * the group's ability to be invited.
237
   *
238
   * <p>If collaboration is in `pending` status, the following fields are redacted: - `login` and
239
   * `name` are hidden if a collaboration was created using `user_id`, - `name` is hidden if a
240
   * collaboration was created using `login`.
241
   *
242
   * @param requestBody Request body of createCollaboration method
243
   * @param queryParams Query parameters of createCollaboration method
244
   */
245
  public Collaboration createCollaboration(
246
      CreateCollaborationRequestBody requestBody, CreateCollaborationQueryParams queryParams) {
247
    return createCollaboration(requestBody, queryParams, new CreateCollaborationHeaders());
×
248
  }
249

250
  /**
251
   * Adds a collaboration for a single user or a single group to a file or folder.
252
   *
253
   * <p>Collaborations can be created using email address, user IDs, or a group IDs.
254
   *
255
   * <p>If a collaboration is being created with a group, access to this endpoint is dependent on
256
   * the group's ability to be invited.
257
   *
258
   * <p>If collaboration is in `pending` status, the following fields are redacted: - `login` and
259
   * `name` are hidden if a collaboration was created using `user_id`, - `name` is hidden if a
260
   * collaboration was created using `login`.
261
   *
262
   * @param requestBody Request body of createCollaboration method
263
   * @param headers Headers of createCollaboration method
264
   */
265
  public Collaboration createCollaboration(
266
      CreateCollaborationRequestBody requestBody, CreateCollaborationHeaders headers) {
267
    return createCollaboration(requestBody, new CreateCollaborationQueryParams(), headers);
×
268
  }
269

270
  /**
271
   * Adds a collaboration for a single user or a single group to a file or folder.
272
   *
273
   * <p>Collaborations can be created using email address, user IDs, or a group IDs.
274
   *
275
   * <p>If a collaboration is being created with a group, access to this endpoint is dependent on
276
   * the group's ability to be invited.
277
   *
278
   * <p>If collaboration is in `pending` status, the following fields are redacted: - `login` and
279
   * `name` are hidden if a collaboration was created using `user_id`, - `name` is hidden if a
280
   * collaboration was created using `login`.
281
   *
282
   * @param requestBody Request body of createCollaboration method
283
   * @param queryParams Query parameters of createCollaboration method
284
   * @param headers Headers of createCollaboration method
285
   */
286
  public Collaboration createCollaboration(
287
      CreateCollaborationRequestBody requestBody,
288
      CreateCollaborationQueryParams queryParams,
289
      CreateCollaborationHeaders headers) {
290
    Map<String, String> queryParamsMap =
×
291
        prepareParams(
×
292
            mapOf(
×
293
                entryOf("fields", convertToString(queryParams.getFields())),
×
294
                entryOf("notify", convertToString(queryParams.getNotify()))));
×
295
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
296
    FetchResponse response =
×
297
        this.networkSession
298
            .getNetworkClient()
×
299
            .fetch(
×
300
                new FetchOptions.Builder(
301
                        String.join(
×
302
                            "",
303
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
304
                            "/2.0/collaborations"),
305
                        "POST")
306
                    .params(queryParamsMap)
×
307
                    .headers(headersMap)
×
308
                    .data(JsonManager.serialize(requestBody))
×
309
                    .contentType("application/json")
×
310
                    .responseFormat(ResponseFormat.JSON)
×
311
                    .auth(this.auth)
×
312
                    .networkSession(this.networkSession)
×
313
                    .build());
×
314
    return JsonManager.deserialize(response.getData(), Collaboration.class);
×
315
  }
316

317
  public Authentication getAuth() {
318
    return auth;
×
319
  }
320

321
  public NetworkSession getNetworkSession() {
322
    return networkSession;
×
323
  }
324

325
  public static class Builder {
326

327
    protected Authentication auth;
328

329
    protected NetworkSession networkSession;
330

331
    public Builder() {
×
332
      this.networkSession = new NetworkSession();
×
333
    }
×
334

335
    public Builder auth(Authentication auth) {
336
      this.auth = auth;
×
337
      return this;
×
338
    }
339

340
    public Builder networkSession(NetworkSession networkSession) {
341
      this.networkSession = networkSession;
×
342
      return this;
×
343
    }
344

345
    public UserCollaborationsManager build() {
346
      return new UserCollaborationsManager(this);
×
347
    }
348
  }
349
}
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

© 2025 Coveralls, Inc