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

box / box-java-sdk / #5838

16 Dec 2025 01:57PM UTC coverage: 12.903% (-0.4%) from 13.282%
#5838

Pull #1633

github

web-flow
Merge 39eadee31 into af4861f83
Pull Request #1633: feat(boxsdkgen): Treat nullable fields as Optional (box/box-codegen#906)

0 of 1897 new or added lines in 73 files covered. (0.0%)

19 existing lines in 10 files now uncovered.

8374 of 64898 relevant lines covered (12.9%)

0.13 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/filemetadata/FileMetadataManager.java
1
package com.box.sdkgen.managers.filemetadata;
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.metadatafull.MetadataFull;
15
import com.box.sdkgen.schemas.metadatas.Metadatas;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.util.List;
18
import java.util.Map;
19

20
public class FileMetadataManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

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

30
  protected FileMetadataManager(Builder builder) {
×
31
    this.auth = builder.auth;
×
32
    this.networkSession = builder.networkSession;
×
33
  }
×
34

35
  /**
36
   * Retrieves all metadata for a given file.
37
   *
38
   * @param fileId The unique identifier that represents a file.
39
   *     <p>The ID for any file can be determined by visiting a file in the web application and
40
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
41
   *     `file_id` is `123`. Example: "12345"
42
   */
43
  public Metadatas getFileMetadata(String fileId) {
NEW
44
    return getFileMetadata(fileId, new GetFileMetadataQueryParams(), new GetFileMetadataHeaders());
×
45
  }
46

47
  /**
48
   * Retrieves all metadata for a given file.
49
   *
50
   * @param fileId The unique identifier that represents a file.
51
   *     <p>The ID for any file can be determined by visiting a file in the web application and
52
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
53
   *     `file_id` is `123`. Example: "12345"
54
   * @param queryParams Query parameters of getFileMetadata method
55
   */
56
  public Metadatas getFileMetadata(String fileId, GetFileMetadataQueryParams queryParams) {
NEW
57
    return getFileMetadata(fileId, queryParams, new GetFileMetadataHeaders());
×
58
  }
59

60
  /**
61
   * Retrieves all metadata for a given file.
62
   *
63
   * @param fileId The unique identifier that represents a file.
64
   *     <p>The ID for any file can be determined by visiting a file in the web application and
65
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
66
   *     `file_id` is `123`. Example: "12345"
67
   * @param headers Headers of getFileMetadata method
68
   */
69
  public Metadatas getFileMetadata(String fileId, GetFileMetadataHeaders headers) {
NEW
70
    return getFileMetadata(fileId, new GetFileMetadataQueryParams(), headers);
×
71
  }
72

73
  /**
74
   * Retrieves all metadata for a given file.
75
   *
76
   * @param fileId The unique identifier that represents a file.
77
   *     <p>The ID for any file can be determined by visiting a file in the web application and
78
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
79
   *     `file_id` is `123`. Example: "12345"
80
   * @param queryParams Query parameters of getFileMetadata method
81
   * @param headers Headers of getFileMetadata method
82
   */
83
  public Metadatas getFileMetadata(
84
      String fileId, GetFileMetadataQueryParams queryParams, GetFileMetadataHeaders headers) {
NEW
85
    Map<String, String> queryParamsMap =
×
NEW
86
        prepareParams(mapOf(entryOf("view", convertToString(queryParams.getView()))));
×
87
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
88
    FetchResponse response =
×
89
        this.networkSession
90
            .getNetworkClient()
×
91
            .fetch(
×
92
                new FetchOptions.Builder(
93
                        String.join(
×
94
                            "",
95
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
96
                            "/2.0/files/",
97
                            convertToString(fileId),
×
98
                            "/metadata"),
99
                        "GET")
NEW
100
                    .params(queryParamsMap)
×
101
                    .headers(headersMap)
×
102
                    .responseFormat(ResponseFormat.JSON)
×
103
                    .auth(this.auth)
×
104
                    .networkSession(this.networkSession)
×
105
                    .build());
×
106
    return JsonManager.deserialize(response.getData(), Metadatas.class);
×
107
  }
108

109
  /**
110
   * Retrieves the instance of a metadata template that has been applied to a file.
111
   *
112
   * @param fileId The unique identifier that represents a file.
113
   *     <p>The ID for any file can be determined by visiting a file in the web application and
114
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
115
   *     `file_id` is `123`. Example: "12345"
116
   * @param scope The scope of the metadata template. Example: "global"
117
   * @param templateKey The name of the metadata template. Example: "properties"
118
   */
119
  public MetadataFull getFileMetadataById(
120
      String fileId, GetFileMetadataByIdScope scope, String templateKey) {
NEW
121
    return getFileMetadataById(
×
122
        fileId,
123
        scope,
124
        templateKey,
125
        new GetFileMetadataByIdQueryParams(),
126
        new GetFileMetadataByIdHeaders());
127
  }
128

129
  /**
130
   * Retrieves the instance of a metadata template that has been applied to a file.
131
   *
132
   * @param fileId The unique identifier that represents a file.
133
   *     <p>The ID for any file can be determined by visiting a file in the web application and
134
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
135
   *     `file_id` is `123`. Example: "12345"
136
   * @param scope The scope of the metadata template. Example: "global"
137
   * @param templateKey The name of the metadata template. Example: "properties"
138
   * @param queryParams Query parameters of getFileMetadataById method
139
   */
140
  public MetadataFull getFileMetadataById(
141
      String fileId,
142
      GetFileMetadataByIdScope scope,
143
      String templateKey,
144
      GetFileMetadataByIdQueryParams queryParams) {
NEW
145
    return getFileMetadataById(
×
146
        fileId, scope, templateKey, queryParams, new GetFileMetadataByIdHeaders());
147
  }
148

149
  /**
150
   * Retrieves the instance of a metadata template that has been applied to a file.
151
   *
152
   * @param fileId The unique identifier that represents a file.
153
   *     <p>The ID for any file can be determined by visiting a file in the web application and
154
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
155
   *     `file_id` is `123`. Example: "12345"
156
   * @param scope The scope of the metadata template. Example: "global"
157
   * @param templateKey The name of the metadata template. Example: "properties"
158
   * @param headers Headers of getFileMetadataById method
159
   */
160
  public MetadataFull getFileMetadataById(
161
      String fileId,
162
      GetFileMetadataByIdScope scope,
163
      String templateKey,
164
      GetFileMetadataByIdHeaders headers) {
NEW
165
    return getFileMetadataById(
×
166
        fileId, scope, templateKey, new GetFileMetadataByIdQueryParams(), headers);
167
  }
168

169
  /**
170
   * Retrieves the instance of a metadata template that has been applied to a file.
171
   *
172
   * @param fileId The unique identifier that represents a file.
173
   *     <p>The ID for any file can be determined by visiting a file in the web application and
174
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
175
   *     `file_id` is `123`. Example: "12345"
176
   * @param scope The scope of the metadata template. Example: "global"
177
   * @param templateKey The name of the metadata template. Example: "properties"
178
   * @param queryParams Query parameters of getFileMetadataById method
179
   * @param headers Headers of getFileMetadataById method
180
   */
181
  public MetadataFull getFileMetadataById(
182
      String fileId,
183
      GetFileMetadataByIdScope scope,
184
      String templateKey,
185
      GetFileMetadataByIdQueryParams queryParams,
186
      GetFileMetadataByIdHeaders headers) {
NEW
187
    Map<String, String> queryParamsMap =
×
NEW
188
        prepareParams(mapOf(entryOf("view", convertToString(queryParams.getView()))));
×
189
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
190
    FetchResponse response =
×
191
        this.networkSession
192
            .getNetworkClient()
×
193
            .fetch(
×
194
                new FetchOptions.Builder(
195
                        String.join(
×
196
                            "",
197
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
198
                            "/2.0/files/",
199
                            convertToString(fileId),
×
200
                            "/metadata/",
201
                            convertToString(scope),
×
202
                            "/",
203
                            convertToString(templateKey)),
×
204
                        "GET")
NEW
205
                    .params(queryParamsMap)
×
206
                    .headers(headersMap)
×
207
                    .responseFormat(ResponseFormat.JSON)
×
208
                    .auth(this.auth)
×
209
                    .networkSession(this.networkSession)
×
210
                    .build());
×
211
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
212
  }
213

214
  /**
215
   * Applies an instance of a metadata template to a file.
216
   *
217
   * <p>In most cases only values that are present in the metadata template will be accepted, except
218
   * for the `global.properties` template which accepts any key-value pair.
219
   *
220
   * @param fileId The unique identifier that represents a file.
221
   *     <p>The ID for any file can be determined by visiting a file in the web application and
222
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
223
   *     `file_id` is `123`. Example: "12345"
224
   * @param scope The scope of the metadata template. Example: "global"
225
   * @param templateKey The name of the metadata template. Example: "properties"
226
   * @param requestBody Request body of createFileMetadataById method
227
   */
228
  public MetadataFull createFileMetadataById(
229
      String fileId,
230
      CreateFileMetadataByIdScope scope,
231
      String templateKey,
232
      Map<String, Object> requestBody) {
233
    return createFileMetadataById(
×
234
        fileId, scope, templateKey, requestBody, new CreateFileMetadataByIdHeaders());
235
  }
236

237
  /**
238
   * Applies an instance of a metadata template to a file.
239
   *
240
   * <p>In most cases only values that are present in the metadata template will be accepted, except
241
   * for the `global.properties` template which accepts any key-value pair.
242
   *
243
   * @param fileId The unique identifier that represents a file.
244
   *     <p>The ID for any file can be determined by visiting a file in the web application and
245
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
246
   *     `file_id` is `123`. Example: "12345"
247
   * @param scope The scope of the metadata template. Example: "global"
248
   * @param templateKey The name of the metadata template. Example: "properties"
249
   * @param requestBody Request body of createFileMetadataById method
250
   * @param headers Headers of createFileMetadataById method
251
   */
252
  public MetadataFull createFileMetadataById(
253
      String fileId,
254
      CreateFileMetadataByIdScope scope,
255
      String templateKey,
256
      Map<String, Object> requestBody,
257
      CreateFileMetadataByIdHeaders headers) {
258
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
259
    FetchResponse response =
×
260
        this.networkSession
261
            .getNetworkClient()
×
262
            .fetch(
×
263
                new FetchOptions.Builder(
264
                        String.join(
×
265
                            "",
266
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
267
                            "/2.0/files/",
268
                            convertToString(fileId),
×
269
                            "/metadata/",
270
                            convertToString(scope),
×
271
                            "/",
272
                            convertToString(templateKey)),
×
273
                        "POST")
274
                    .headers(headersMap)
×
275
                    .data(JsonManager.serialize(requestBody))
×
276
                    .contentType("application/json")
×
277
                    .responseFormat(ResponseFormat.JSON)
×
278
                    .auth(this.auth)
×
279
                    .networkSession(this.networkSession)
×
280
                    .build());
×
281
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
282
  }
283

284
  /**
285
   * Updates a piece of metadata on a file.
286
   *
287
   * <p>The metadata instance can only be updated if the template has already been applied to the
288
   * file before. When editing metadata, only values that match the metadata template schema will be
289
   * accepted.
290
   *
291
   * <p>The update is applied atomically. If any errors occur during the application of the
292
   * operations, the metadata instance will not be changed.
293
   *
294
   * @param fileId The unique identifier that represents a file.
295
   *     <p>The ID for any file can be determined by visiting a file in the web application and
296
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
297
   *     `file_id` is `123`. Example: "12345"
298
   * @param scope The scope of the metadata template. Example: "global"
299
   * @param templateKey The name of the metadata template. Example: "properties"
300
   * @param requestBody Request body of updateFileMetadataById method
301
   */
302
  public MetadataFull updateFileMetadataById(
303
      String fileId,
304
      UpdateFileMetadataByIdScope scope,
305
      String templateKey,
306
      List<UpdateFileMetadataByIdRequestBody> requestBody) {
307
    return updateFileMetadataById(
×
308
        fileId, scope, templateKey, requestBody, new UpdateFileMetadataByIdHeaders());
309
  }
310

311
  /**
312
   * Updates a piece of metadata on a file.
313
   *
314
   * <p>The metadata instance can only be updated if the template has already been applied to the
315
   * file before. When editing metadata, only values that match the metadata template schema will be
316
   * accepted.
317
   *
318
   * <p>The update is applied atomically. If any errors occur during the application of the
319
   * operations, the metadata instance will not be changed.
320
   *
321
   * @param fileId The unique identifier that represents a file.
322
   *     <p>The ID for any file can be determined by visiting a file in the web application and
323
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
324
   *     `file_id` is `123`. Example: "12345"
325
   * @param scope The scope of the metadata template. Example: "global"
326
   * @param templateKey The name of the metadata template. Example: "properties"
327
   * @param requestBody Request body of updateFileMetadataById method
328
   * @param headers Headers of updateFileMetadataById method
329
   */
330
  public MetadataFull updateFileMetadataById(
331
      String fileId,
332
      UpdateFileMetadataByIdScope scope,
333
      String templateKey,
334
      List<UpdateFileMetadataByIdRequestBody> requestBody,
335
      UpdateFileMetadataByIdHeaders headers) {
336
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
337
    FetchResponse response =
×
338
        this.networkSession
339
            .getNetworkClient()
×
340
            .fetch(
×
341
                new FetchOptions.Builder(
342
                        String.join(
×
343
                            "",
344
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
345
                            "/2.0/files/",
346
                            convertToString(fileId),
×
347
                            "/metadata/",
348
                            convertToString(scope),
×
349
                            "/",
350
                            convertToString(templateKey)),
×
351
                        "PUT")
352
                    .headers(headersMap)
×
353
                    .data(JsonManager.serialize(requestBody))
×
354
                    .contentType("application/json-patch+json")
×
355
                    .responseFormat(ResponseFormat.JSON)
×
356
                    .auth(this.auth)
×
357
                    .networkSession(this.networkSession)
×
358
                    .build());
×
359
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
360
  }
361

362
  /**
363
   * Deletes a piece of file metadata.
364
   *
365
   * @param fileId The unique identifier that represents a file.
366
   *     <p>The ID for any file can be determined by visiting a file in the web application and
367
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
368
   *     `file_id` is `123`. Example: "12345"
369
   * @param scope The scope of the metadata template. Example: "global"
370
   * @param templateKey The name of the metadata template. Example: "properties"
371
   */
372
  public void deleteFileMetadataById(
373
      String fileId, DeleteFileMetadataByIdScope scope, String templateKey) {
374
    deleteFileMetadataById(fileId, scope, templateKey, new DeleteFileMetadataByIdHeaders());
×
375
  }
×
376

377
  /**
378
   * Deletes a piece of file metadata.
379
   *
380
   * @param fileId The unique identifier that represents a file.
381
   *     <p>The ID for any file can be determined by visiting a file in the web application and
382
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
383
   *     `file_id` is `123`. Example: "12345"
384
   * @param scope The scope of the metadata template. Example: "global"
385
   * @param templateKey The name of the metadata template. Example: "properties"
386
   * @param headers Headers of deleteFileMetadataById method
387
   */
388
  public void deleteFileMetadataById(
389
      String fileId,
390
      DeleteFileMetadataByIdScope scope,
391
      String templateKey,
392
      DeleteFileMetadataByIdHeaders headers) {
393
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
394
    FetchResponse response =
×
395
        this.networkSession
396
            .getNetworkClient()
×
397
            .fetch(
×
398
                new FetchOptions.Builder(
399
                        String.join(
×
400
                            "",
401
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
402
                            "/2.0/files/",
403
                            convertToString(fileId),
×
404
                            "/metadata/",
405
                            convertToString(scope),
×
406
                            "/",
407
                            convertToString(templateKey)),
×
408
                        "DELETE")
409
                    .headers(headersMap)
×
410
                    .responseFormat(ResponseFormat.NO_CONTENT)
×
411
                    .auth(this.auth)
×
412
                    .networkSession(this.networkSession)
×
413
                    .build());
×
414
  }
×
415

416
  public Authentication getAuth() {
417
    return auth;
×
418
  }
419

420
  public NetworkSession getNetworkSession() {
421
    return networkSession;
×
422
  }
423

424
  public static class Builder {
425

426
    protected Authentication auth;
427

428
    protected NetworkSession networkSession;
429

430
    public Builder() {
×
431
      this.networkSession = new NetworkSession();
×
432
    }
×
433

434
    public Builder auth(Authentication auth) {
435
      this.auth = auth;
×
436
      return this;
×
437
    }
438

439
    public Builder networkSession(NetworkSession networkSession) {
440
      this.networkSession = networkSession;
×
441
      return this;
×
442
    }
443

444
    public FileMetadataManager build() {
445
      return new FileMetadataManager(this);
×
446
    }
447
  }
448
}
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