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

box / box-java-sdk / #5922

17 Dec 2025 05:03PM UTC coverage: 35.498% (-0.4%) from 35.917%
#5922

push

github

web-flow
fix: add taxonomy to Metadata Field (read) definition (box/box-openapi#572) (#1644)

Co-authored-by: box-sdk-build <box-sdk-build@box.com>

2 of 2 new or added lines in 1 file covered. (100.0%)

535 existing lines in 31 files now uncovered.

18926 of 53316 relevant lines covered (35.5%)

0.35 hits per line

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

93.33
/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();
×
UNCOV
28
  }
×
29

30
  protected FolderMetadataManager(Builder builder) {
1✔
31
    this.auth = builder.auth;
1✔
32
    this.networkSession = builder.networkSession;
1✔
33
  }
1✔
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) {
45
    return getFolderMetadata(
1✔
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) {
UNCOV
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) {
UNCOV
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) {
90
    Map<String, String> queryParamsMap =
1✔
91
        prepareParams(mapOf(entryOf("view", convertToString(queryParams.getView()))));
1✔
92
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
93
    FetchResponse response =
1✔
94
        this.networkSession
95
            .getNetworkClient()
1✔
96
            .fetch(
1✔
97
                new FetchOptions.Builder(
98
                        String.join(
1✔
99
                            "",
100
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
101
                            "/2.0/folders/",
102
                            convertToString(folderId),
1✔
103
                            "/metadata"),
104
                        "GET")
105
                    .params(queryParamsMap)
1✔
106
                    .headers(headersMap)
1✔
107
                    .responseFormat(ResponseFormat.JSON)
1✔
108
                    .auth(this.auth)
1✔
109
                    .networkSession(this.networkSession)
1✔
110
                    .build());
1✔
111
    return JsonManager.deserialize(response.getData(), Metadatas.class);
1✔
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());
1✔
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()));
1✔
150
    FetchResponse response =
1✔
151
        this.networkSession
152
            .getNetworkClient()
1✔
153
            .fetch(
1✔
154
                new FetchOptions.Builder(
155
                        String.join(
1✔
156
                            "",
157
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
158
                            "/2.0/folders/",
159
                            convertToString(folderId),
1✔
160
                            "/metadata/",
161
                            convertToString(scope),
1✔
162
                            "/",
163
                            convertToString(templateKey)),
1✔
164
                        "GET")
165
                    .headers(headersMap)
1✔
166
                    .responseFormat(ResponseFormat.JSON)
1✔
167
                    .auth(this.auth)
1✔
168
                    .networkSession(this.networkSession)
1✔
169
                    .build());
1✔
170
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
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(
1✔
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()));
1✔
226
    FetchResponse response =
1✔
227
        this.networkSession
228
            .getNetworkClient()
1✔
229
            .fetch(
1✔
230
                new FetchOptions.Builder(
231
                        String.join(
1✔
232
                            "",
233
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
234
                            "/2.0/folders/",
235
                            convertToString(folderId),
1✔
236
                            "/metadata/",
237
                            convertToString(scope),
1✔
238
                            "/",
239
                            convertToString(templateKey)),
1✔
240
                        "POST")
241
                    .headers(headersMap)
1✔
242
                    .data(JsonManager.serialize(requestBody))
1✔
243
                    .contentType("application/json")
1✔
244
                    .responseFormat(ResponseFormat.JSON)
1✔
245
                    .auth(this.auth)
1✔
246
                    .networkSession(this.networkSession)
1✔
247
                    .build());
1✔
248
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
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(
1✔
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()));
1✔
306
    FetchResponse response =
1✔
307
        this.networkSession
308
            .getNetworkClient()
1✔
309
            .fetch(
1✔
310
                new FetchOptions.Builder(
311
                        String.join(
1✔
312
                            "",
313
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
314
                            "/2.0/folders/",
315
                            convertToString(folderId),
1✔
316
                            "/metadata/",
317
                            convertToString(scope),
1✔
318
                            "/",
319
                            convertToString(templateKey)),
1✔
320
                        "PUT")
321
                    .headers(headersMap)
1✔
322
                    .data(JsonManager.serialize(requestBody))
1✔
323
                    .contentType("application/json-patch+json")
1✔
324
                    .responseFormat(ResponseFormat.JSON)
1✔
325
                    .auth(this.auth)
1✔
326
                    .networkSession(this.networkSession)
1✔
327
                    .build());
1✔
328
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
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());
1✔
345
  }
1✔
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()));
1✔
365
    FetchResponse response =
1✔
366
        this.networkSession
367
            .getNetworkClient()
1✔
368
            .fetch(
1✔
369
                new FetchOptions.Builder(
370
                        String.join(
1✔
371
                            "",
372
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
373
                            "/2.0/folders/",
374
                            convertToString(folderId),
1✔
375
                            "/metadata/",
376
                            convertToString(scope),
1✔
377
                            "/",
378
                            convertToString(templateKey)),
1✔
379
                        "DELETE")
380
                    .headers(headersMap)
1✔
381
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
382
                    .auth(this.auth)
1✔
383
                    .networkSession(this.networkSession)
1✔
384
                    .build());
1✔
385
  }
1✔
386

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

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

395
  public static class Builder {
396

397
    protected Authentication auth;
398

399
    protected NetworkSession networkSession;
400

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

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

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

415
    public FolderMetadataManager build() {
416
      return new FolderMetadataManager(this);
1✔
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