• 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/foldermetadata/FolderMetadataManager.java
1
package com.box.sdkgen.managers.foldermetadata;
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 FolderMetadataManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

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

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

35
  /**
36
   * Retrieves all metadata for a given folder. This can not be used on the root folder with ID `0`.
37
   *
38
   * @param folderId The unique identifier that represent a folder.
39
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
40
   *     and copying the ID from the URL. For example, for the URL
41
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
42
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
43
   */
44
  public Metadatas getFolderMetadata(String folderId) {
NEW
45
    return getFolderMetadata(
×
46
        folderId, new GetFolderMetadataQueryParams(), new GetFolderMetadataHeaders());
47
  }
48

49
  /**
50
   * Retrieves all metadata for a given folder. This can not be used on the root folder with ID `0`.
51
   *
52
   * @param folderId The unique identifier that represent a folder.
53
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
54
   *     and copying the ID from the URL. For example, for the URL
55
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
56
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
57
   * @param queryParams Query parameters of getFolderMetadata method
58
   */
59
  public Metadatas getFolderMetadata(String folderId, GetFolderMetadataQueryParams queryParams) {
NEW
60
    return getFolderMetadata(folderId, queryParams, new GetFolderMetadataHeaders());
×
61
  }
62

63
  /**
64
   * Retrieves all metadata for a given folder. This can not be used on the root folder with ID `0`.
65
   *
66
   * @param folderId The unique identifier that represent a folder.
67
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
68
   *     and copying the ID from the URL. For example, for the URL
69
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
70
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
71
   * @param headers Headers of getFolderMetadata method
72
   */
73
  public Metadatas getFolderMetadata(String folderId, GetFolderMetadataHeaders headers) {
NEW
74
    return getFolderMetadata(folderId, new GetFolderMetadataQueryParams(), headers);
×
75
  }
76

77
  /**
78
   * Retrieves all metadata for a given folder. This can not be used on the root folder with ID `0`.
79
   *
80
   * @param folderId The unique identifier that represent a folder.
81
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
82
   *     and copying the ID from the URL. For example, for the URL
83
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
84
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
85
   * @param queryParams Query parameters of getFolderMetadata method
86
   * @param headers Headers of getFolderMetadata method
87
   */
88
  public Metadatas getFolderMetadata(
89
      String folderId, GetFolderMetadataQueryParams queryParams, GetFolderMetadataHeaders headers) {
NEW
90
    Map<String, String> queryParamsMap =
×
NEW
91
        prepareParams(mapOf(entryOf("view", convertToString(queryParams.getView()))));
×
92
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
93
    FetchResponse response =
×
94
        this.networkSession
95
            .getNetworkClient()
×
96
            .fetch(
×
97
                new FetchOptions.Builder(
98
                        String.join(
×
99
                            "",
100
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
101
                            "/2.0/folders/",
102
                            convertToString(folderId),
×
103
                            "/metadata"),
104
                        "GET")
NEW
105
                    .params(queryParamsMap)
×
106
                    .headers(headersMap)
×
107
                    .responseFormat(ResponseFormat.JSON)
×
108
                    .auth(this.auth)
×
109
                    .networkSession(this.networkSession)
×
110
                    .build());
×
111
    return JsonManager.deserialize(response.getData(), Metadatas.class);
×
112
  }
113

114
  /**
115
   * Retrieves the instance of a metadata template that has been applied to a folder. This can not
116
   * be used on the root folder with ID `0`.
117
   *
118
   * @param folderId The unique identifier that represent a folder.
119
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
120
   *     and copying the ID from the URL. For example, for the URL
121
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
122
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
123
   * @param scope The scope of the metadata template. Example: "global"
124
   * @param templateKey The name of the metadata template. Example: "properties"
125
   */
126
  public MetadataFull getFolderMetadataById(
127
      String folderId, GetFolderMetadataByIdScope scope, String templateKey) {
128
    return getFolderMetadataById(folderId, scope, templateKey, new GetFolderMetadataByIdHeaders());
×
129
  }
130

131
  /**
132
   * Retrieves the instance of a metadata template that has been applied to a folder. This can not
133
   * be used on the root folder with ID `0`.
134
   *
135
   * @param folderId The unique identifier that represent a folder.
136
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
137
   *     and copying the ID from the URL. For example, for the URL
138
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
139
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
140
   * @param scope The scope of the metadata template. Example: "global"
141
   * @param templateKey The name of the metadata template. Example: "properties"
142
   * @param headers Headers of getFolderMetadataById method
143
   */
144
  public MetadataFull getFolderMetadataById(
145
      String folderId,
146
      GetFolderMetadataByIdScope scope,
147
      String templateKey,
148
      GetFolderMetadataByIdHeaders headers) {
149
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
150
    FetchResponse response =
×
151
        this.networkSession
152
            .getNetworkClient()
×
153
            .fetch(
×
154
                new FetchOptions.Builder(
155
                        String.join(
×
156
                            "",
157
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
158
                            "/2.0/folders/",
159
                            convertToString(folderId),
×
160
                            "/metadata/",
161
                            convertToString(scope),
×
162
                            "/",
163
                            convertToString(templateKey)),
×
164
                        "GET")
165
                    .headers(headersMap)
×
166
                    .responseFormat(ResponseFormat.JSON)
×
167
                    .auth(this.auth)
×
168
                    .networkSession(this.networkSession)
×
169
                    .build());
×
170
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
171
  }
172

173
  /**
174
   * Applies an instance of a metadata template to a folder.
175
   *
176
   * <p>In most cases only values that are present in the metadata template will be accepted, except
177
   * for the `global.properties` template which accepts any key-value pair.
178
   *
179
   * <p>To display the metadata template in the Box web app the enterprise needs to be configured to
180
   * enable **Cascading Folder Level Metadata** for the user in the admin console.
181
   *
182
   * @param folderId The unique identifier that represent a folder.
183
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
184
   *     and copying the ID from the URL. For example, for the URL
185
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
186
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
187
   * @param scope The scope of the metadata template. Example: "global"
188
   * @param templateKey The name of the metadata template. Example: "properties"
189
   * @param requestBody Request body of createFolderMetadataById method
190
   */
191
  public MetadataFull createFolderMetadataById(
192
      String folderId,
193
      CreateFolderMetadataByIdScope scope,
194
      String templateKey,
195
      Map<String, Object> requestBody) {
196
    return createFolderMetadataById(
×
197
        folderId, scope, templateKey, requestBody, new CreateFolderMetadataByIdHeaders());
198
  }
199

200
  /**
201
   * Applies an instance of a metadata template to a folder.
202
   *
203
   * <p>In most cases only values that are present in the metadata template will be accepted, except
204
   * for the `global.properties` template which accepts any key-value pair.
205
   *
206
   * <p>To display the metadata template in the Box web app the enterprise needs to be configured to
207
   * enable **Cascading Folder Level Metadata** for the user in the admin console.
208
   *
209
   * @param folderId The unique identifier that represent a folder.
210
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
211
   *     and copying the ID from the URL. For example, for the URL
212
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
213
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
214
   * @param scope The scope of the metadata template. Example: "global"
215
   * @param templateKey The name of the metadata template. Example: "properties"
216
   * @param requestBody Request body of createFolderMetadataById method
217
   * @param headers Headers of createFolderMetadataById method
218
   */
219
  public MetadataFull createFolderMetadataById(
220
      String folderId,
221
      CreateFolderMetadataByIdScope scope,
222
      String templateKey,
223
      Map<String, Object> requestBody,
224
      CreateFolderMetadataByIdHeaders headers) {
225
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
226
    FetchResponse response =
×
227
        this.networkSession
228
            .getNetworkClient()
×
229
            .fetch(
×
230
                new FetchOptions.Builder(
231
                        String.join(
×
232
                            "",
233
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
234
                            "/2.0/folders/",
235
                            convertToString(folderId),
×
236
                            "/metadata/",
237
                            convertToString(scope),
×
238
                            "/",
239
                            convertToString(templateKey)),
×
240
                        "POST")
241
                    .headers(headersMap)
×
242
                    .data(JsonManager.serialize(requestBody))
×
243
                    .contentType("application/json")
×
244
                    .responseFormat(ResponseFormat.JSON)
×
245
                    .auth(this.auth)
×
246
                    .networkSession(this.networkSession)
×
247
                    .build());
×
248
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
249
  }
250

251
  /**
252
   * Updates a piece of metadata on a folder.
253
   *
254
   * <p>The metadata instance can only be updated if the template has already been applied to the
255
   * folder before. When editing metadata, only values that match the metadata template schema will
256
   * be accepted.
257
   *
258
   * <p>The update is applied atomically. If any errors occur during the application of the
259
   * operations, the metadata instance will not be changed.
260
   *
261
   * @param folderId The unique identifier that represent a folder.
262
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
263
   *     and copying the ID from the URL. For example, for the URL
264
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
265
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
266
   * @param scope The scope of the metadata template. Example: "global"
267
   * @param templateKey The name of the metadata template. Example: "properties"
268
   * @param requestBody Request body of updateFolderMetadataById method
269
   */
270
  public MetadataFull updateFolderMetadataById(
271
      String folderId,
272
      UpdateFolderMetadataByIdScope scope,
273
      String templateKey,
274
      List<UpdateFolderMetadataByIdRequestBody> requestBody) {
275
    return updateFolderMetadataById(
×
276
        folderId, scope, templateKey, requestBody, new UpdateFolderMetadataByIdHeaders());
277
  }
278

279
  /**
280
   * Updates a piece of metadata on a folder.
281
   *
282
   * <p>The metadata instance can only be updated if the template has already been applied to the
283
   * folder before. When editing metadata, only values that match the metadata template schema will
284
   * be accepted.
285
   *
286
   * <p>The update is applied atomically. If any errors occur during the application of the
287
   * operations, the metadata instance will not be changed.
288
   *
289
   * @param folderId The unique identifier that represent a folder.
290
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
291
   *     and copying the ID from the URL. For example, for the URL
292
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
293
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
294
   * @param scope The scope of the metadata template. Example: "global"
295
   * @param templateKey The name of the metadata template. Example: "properties"
296
   * @param requestBody Request body of updateFolderMetadataById method
297
   * @param headers Headers of updateFolderMetadataById method
298
   */
299
  public MetadataFull updateFolderMetadataById(
300
      String folderId,
301
      UpdateFolderMetadataByIdScope scope,
302
      String templateKey,
303
      List<UpdateFolderMetadataByIdRequestBody> requestBody,
304
      UpdateFolderMetadataByIdHeaders headers) {
305
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
306
    FetchResponse response =
×
307
        this.networkSession
308
            .getNetworkClient()
×
309
            .fetch(
×
310
                new FetchOptions.Builder(
311
                        String.join(
×
312
                            "",
313
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
314
                            "/2.0/folders/",
315
                            convertToString(folderId),
×
316
                            "/metadata/",
317
                            convertToString(scope),
×
318
                            "/",
319
                            convertToString(templateKey)),
×
320
                        "PUT")
321
                    .headers(headersMap)
×
322
                    .data(JsonManager.serialize(requestBody))
×
323
                    .contentType("application/json-patch+json")
×
324
                    .responseFormat(ResponseFormat.JSON)
×
325
                    .auth(this.auth)
×
326
                    .networkSession(this.networkSession)
×
327
                    .build());
×
328
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
×
329
  }
330

331
  /**
332
   * Deletes a piece of folder metadata.
333
   *
334
   * @param folderId The unique identifier that represent a folder.
335
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
336
   *     and copying the ID from the URL. For example, for the URL
337
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
338
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
339
   * @param scope The scope of the metadata template. Example: "global"
340
   * @param templateKey The name of the metadata template. Example: "properties"
341
   */
342
  public void deleteFolderMetadataById(
343
      String folderId, DeleteFolderMetadataByIdScope scope, String templateKey) {
344
    deleteFolderMetadataById(folderId, scope, templateKey, new DeleteFolderMetadataByIdHeaders());
×
345
  }
×
346

347
  /**
348
   * Deletes a piece of folder metadata.
349
   *
350
   * @param folderId The unique identifier that represent a folder.
351
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
352
   *     and copying the ID from the URL. For example, for the URL
353
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
354
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
355
   * @param scope The scope of the metadata template. Example: "global"
356
   * @param templateKey The name of the metadata template. Example: "properties"
357
   * @param headers Headers of deleteFolderMetadataById method
358
   */
359
  public void deleteFolderMetadataById(
360
      String folderId,
361
      DeleteFolderMetadataByIdScope scope,
362
      String templateKey,
363
      DeleteFolderMetadataByIdHeaders headers) {
364
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
365
    FetchResponse response =
×
366
        this.networkSession
367
            .getNetworkClient()
×
368
            .fetch(
×
369
                new FetchOptions.Builder(
370
                        String.join(
×
371
                            "",
372
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
373
                            "/2.0/folders/",
374
                            convertToString(folderId),
×
375
                            "/metadata/",
376
                            convertToString(scope),
×
377
                            "/",
378
                            convertToString(templateKey)),
×
379
                        "DELETE")
380
                    .headers(headersMap)
×
381
                    .responseFormat(ResponseFormat.NO_CONTENT)
×
382
                    .auth(this.auth)
×
383
                    .networkSession(this.networkSession)
×
384
                    .build());
×
385
  }
×
386

387
  public Authentication getAuth() {
388
    return auth;
×
389
  }
390

391
  public NetworkSession getNetworkSession() {
392
    return networkSession;
×
393
  }
394

395
  public static class Builder {
396

397
    protected Authentication auth;
398

399
    protected NetworkSession networkSession;
400

401
    public Builder() {
×
402
      this.networkSession = new NetworkSession();
×
403
    }
×
404

405
    public Builder auth(Authentication auth) {
406
      this.auth = auth;
×
407
      return this;
×
408
    }
409

410
    public Builder networkSession(NetworkSession networkSession) {
411
      this.networkSession = networkSession;
×
412
      return this;
×
413
    }
414

415
    public FolderMetadataManager build() {
416
      return new FolderMetadataManager(this);
×
417
    }
418
  }
419
}
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