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

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

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

95.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.mapOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
6
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
7

8
import com.box.sdkgen.networking.auth.Authentication;
9
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
10
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
11
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
12
import com.box.sdkgen.networking.network.NetworkSession;
13
import com.box.sdkgen.schemas.metadatafull.MetadataFull;
14
import com.box.sdkgen.schemas.metadatas.Metadatas;
15
import com.box.sdkgen.serialization.json.JsonManager;
16
import java.util.List;
17
import java.util.Map;
18

19
public class FolderMetadataManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

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

29
  protected FolderMetadataManager(Builder builder) {
1✔
30
    this.auth = builder.auth;
1✔
31
    this.networkSession = builder.networkSession;
1✔
32
  }
1✔
33

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

47
  /**
48
   * Retrieves all metadata for a given folder. This can not be used on the root folder with ID `0`.
49
   *
50
   * @param folderId The unique identifier that represent a folder.
51
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
52
   *     and copying the ID from the URL. For example, for the URL
53
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
54
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
55
   * @param headers Headers of getFolderMetadata method
56
   */
57
  public Metadatas getFolderMetadata(String folderId, GetFolderMetadataHeaders headers) {
58
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
59
    FetchResponse response =
1✔
60
        this.networkSession
61
            .getNetworkClient()
1✔
62
            .fetch(
1✔
63
                new FetchOptions.Builder(
64
                        String.join(
1✔
65
                            "",
66
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
67
                            "/2.0/folders/",
68
                            convertToString(folderId),
1✔
69
                            "/metadata"),
70
                        "GET")
71
                    .headers(headersMap)
1✔
72
                    .responseFormat(ResponseFormat.JSON)
1✔
73
                    .auth(this.auth)
1✔
74
                    .networkSession(this.networkSession)
1✔
75
                    .build());
1✔
76
    return JsonManager.deserialize(response.getData(), Metadatas.class);
1✔
77
  }
78

79
  /**
80
   * Retrieves the instance of a metadata template that has been applied to a folder. This can not
81
   * be used on the root folder with ID `0`.
82
   *
83
   * @param folderId The unique identifier that represent a folder.
84
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
85
   *     and copying the ID from the URL. For example, for the URL
86
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
87
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
88
   * @param scope The scope of the metadata template. Example: "global"
89
   * @param templateKey The name of the metadata template. Example: "properties"
90
   */
91
  public MetadataFull getFolderMetadataById(
92
      String folderId, GetFolderMetadataByIdScope scope, String templateKey) {
93
    return getFolderMetadataById(folderId, scope, templateKey, new GetFolderMetadataByIdHeaders());
1✔
94
  }
95

96
  /**
97
   * Retrieves the instance of a metadata template that has been applied to a folder. This can not
98
   * be used on the root folder with ID `0`.
99
   *
100
   * @param folderId The unique identifier that represent a folder.
101
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
102
   *     and copying the ID from the URL. For example, for the URL
103
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
104
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
105
   * @param scope The scope of the metadata template. Example: "global"
106
   * @param templateKey The name of the metadata template. Example: "properties"
107
   * @param headers Headers of getFolderMetadataById method
108
   */
109
  public MetadataFull getFolderMetadataById(
110
      String folderId,
111
      GetFolderMetadataByIdScope scope,
112
      String templateKey,
113
      GetFolderMetadataByIdHeaders headers) {
114
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
115
    FetchResponse response =
1✔
116
        this.networkSession
117
            .getNetworkClient()
1✔
118
            .fetch(
1✔
119
                new FetchOptions.Builder(
120
                        String.join(
1✔
121
                            "",
122
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
123
                            "/2.0/folders/",
124
                            convertToString(folderId),
1✔
125
                            "/metadata/",
126
                            convertToString(scope),
1✔
127
                            "/",
128
                            convertToString(templateKey)),
1✔
129
                        "GET")
130
                    .headers(headersMap)
1✔
131
                    .responseFormat(ResponseFormat.JSON)
1✔
132
                    .auth(this.auth)
1✔
133
                    .networkSession(this.networkSession)
1✔
134
                    .build());
1✔
135
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
136
  }
137

138
  /**
139
   * Applies an instance of a metadata template to a folder.
140
   *
141
   * <p>In most cases only values that are present in the metadata template will be accepted, except
142
   * for the `global.properties` template which accepts any key-value pair.
143
   *
144
   * <p>To display the metadata template in the Box web app the enterprise needs to be configured to
145
   * enable **Cascading Folder Level Metadata** for the user in the admin console.
146
   *
147
   * @param folderId The unique identifier that represent a folder.
148
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
149
   *     and copying the ID from the URL. For example, for the URL
150
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
151
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
152
   * @param scope The scope of the metadata template. Example: "global"
153
   * @param templateKey The name of the metadata template. Example: "properties"
154
   * @param requestBody Request body of createFolderMetadataById method
155
   */
156
  public MetadataFull createFolderMetadataById(
157
      String folderId,
158
      CreateFolderMetadataByIdScope scope,
159
      String templateKey,
160
      Map<String, Object> requestBody) {
161
    return createFolderMetadataById(
1✔
162
        folderId, scope, templateKey, requestBody, new CreateFolderMetadataByIdHeaders());
163
  }
164

165
  /**
166
   * Applies an instance of a metadata template to a folder.
167
   *
168
   * <p>In most cases only values that are present in the metadata template will be accepted, except
169
   * for the `global.properties` template which accepts any key-value pair.
170
   *
171
   * <p>To display the metadata template in the Box web app the enterprise needs to be configured to
172
   * enable **Cascading Folder Level Metadata** for the user in the admin console.
173
   *
174
   * @param folderId The unique identifier that represent a folder.
175
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
176
   *     and copying the ID from the URL. For example, for the URL
177
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
178
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
179
   * @param scope The scope of the metadata template. Example: "global"
180
   * @param templateKey The name of the metadata template. Example: "properties"
181
   * @param requestBody Request body of createFolderMetadataById method
182
   * @param headers Headers of createFolderMetadataById method
183
   */
184
  public MetadataFull createFolderMetadataById(
185
      String folderId,
186
      CreateFolderMetadataByIdScope scope,
187
      String templateKey,
188
      Map<String, Object> requestBody,
189
      CreateFolderMetadataByIdHeaders headers) {
190
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
191
    FetchResponse response =
1✔
192
        this.networkSession
193
            .getNetworkClient()
1✔
194
            .fetch(
1✔
195
                new FetchOptions.Builder(
196
                        String.join(
1✔
197
                            "",
198
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
199
                            "/2.0/folders/",
200
                            convertToString(folderId),
1✔
201
                            "/metadata/",
202
                            convertToString(scope),
1✔
203
                            "/",
204
                            convertToString(templateKey)),
1✔
205
                        "POST")
206
                    .headers(headersMap)
1✔
207
                    .data(JsonManager.serialize(requestBody))
1✔
208
                    .contentType("application/json")
1✔
209
                    .responseFormat(ResponseFormat.JSON)
1✔
210
                    .auth(this.auth)
1✔
211
                    .networkSession(this.networkSession)
1✔
212
                    .build());
1✔
213
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
214
  }
215

216
  /**
217
   * Updates a piece of metadata on a folder.
218
   *
219
   * <p>The metadata instance can only be updated if the template has already been applied to the
220
   * folder before. When editing metadata, only values that match the metadata template schema will
221
   * be accepted.
222
   *
223
   * <p>The update is applied atomically. If any errors occur during the application of the
224
   * operations, the metadata instance will not be changed.
225
   *
226
   * @param folderId The unique identifier that represent a folder.
227
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
228
   *     and copying the ID from the URL. For example, for the URL
229
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
230
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
231
   * @param scope The scope of the metadata template. Example: "global"
232
   * @param templateKey The name of the metadata template. Example: "properties"
233
   * @param requestBody Request body of updateFolderMetadataById method
234
   */
235
  public MetadataFull updateFolderMetadataById(
236
      String folderId,
237
      UpdateFolderMetadataByIdScope scope,
238
      String templateKey,
239
      List<UpdateFolderMetadataByIdRequestBody> requestBody) {
240
    return updateFolderMetadataById(
1✔
241
        folderId, scope, templateKey, requestBody, new UpdateFolderMetadataByIdHeaders());
242
  }
243

244
  /**
245
   * Updates a piece of metadata on a folder.
246
   *
247
   * <p>The metadata instance can only be updated if the template has already been applied to the
248
   * folder before. When editing metadata, only values that match the metadata template schema will
249
   * be accepted.
250
   *
251
   * <p>The update is applied atomically. If any errors occur during the application of the
252
   * operations, the metadata instance will not be changed.
253
   *
254
   * @param folderId The unique identifier that represent a folder.
255
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
256
   *     and copying the ID from the URL. For example, for the URL
257
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
258
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
259
   * @param scope The scope of the metadata template. Example: "global"
260
   * @param templateKey The name of the metadata template. Example: "properties"
261
   * @param requestBody Request body of updateFolderMetadataById method
262
   * @param headers Headers of updateFolderMetadataById method
263
   */
264
  public MetadataFull updateFolderMetadataById(
265
      String folderId,
266
      UpdateFolderMetadataByIdScope scope,
267
      String templateKey,
268
      List<UpdateFolderMetadataByIdRequestBody> requestBody,
269
      UpdateFolderMetadataByIdHeaders headers) {
270
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
271
    FetchResponse response =
1✔
272
        this.networkSession
273
            .getNetworkClient()
1✔
274
            .fetch(
1✔
275
                new FetchOptions.Builder(
276
                        String.join(
1✔
277
                            "",
278
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
279
                            "/2.0/folders/",
280
                            convertToString(folderId),
1✔
281
                            "/metadata/",
282
                            convertToString(scope),
1✔
283
                            "/",
284
                            convertToString(templateKey)),
1✔
285
                        "PUT")
286
                    .headers(headersMap)
1✔
287
                    .data(JsonManager.serialize(requestBody))
1✔
288
                    .contentType("application/json-patch+json")
1✔
289
                    .responseFormat(ResponseFormat.JSON)
1✔
290
                    .auth(this.auth)
1✔
291
                    .networkSession(this.networkSession)
1✔
292
                    .build());
1✔
293
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
294
  }
295

296
  /**
297
   * Deletes a piece of folder metadata.
298
   *
299
   * @param folderId The unique identifier that represent a folder.
300
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
301
   *     and copying the ID from the URL. For example, for the URL
302
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
303
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
304
   * @param scope The scope of the metadata template. Example: "global"
305
   * @param templateKey The name of the metadata template. Example: "properties"
306
   */
307
  public void deleteFolderMetadataById(
308
      String folderId, DeleteFolderMetadataByIdScope scope, String templateKey) {
309
    deleteFolderMetadataById(folderId, scope, templateKey, new DeleteFolderMetadataByIdHeaders());
1✔
310
  }
1✔
311

312
  /**
313
   * Deletes a piece of folder metadata.
314
   *
315
   * @param folderId The unique identifier that represent a folder.
316
   *     <p>The ID for any folder can be determined by visiting this folder in the web application
317
   *     and copying the ID from the URL. For example, for the URL
318
   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
319
   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
320
   * @param scope The scope of the metadata template. Example: "global"
321
   * @param templateKey The name of the metadata template. Example: "properties"
322
   * @param headers Headers of deleteFolderMetadataById method
323
   */
324
  public void deleteFolderMetadataById(
325
      String folderId,
326
      DeleteFolderMetadataByIdScope scope,
327
      String templateKey,
328
      DeleteFolderMetadataByIdHeaders headers) {
329
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
330
    FetchResponse response =
1✔
331
        this.networkSession
332
            .getNetworkClient()
1✔
333
            .fetch(
1✔
334
                new FetchOptions.Builder(
335
                        String.join(
1✔
336
                            "",
337
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
338
                            "/2.0/folders/",
339
                            convertToString(folderId),
1✔
340
                            "/metadata/",
341
                            convertToString(scope),
1✔
342
                            "/",
343
                            convertToString(templateKey)),
1✔
344
                        "DELETE")
345
                    .headers(headersMap)
1✔
346
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
347
                    .auth(this.auth)
1✔
348
                    .networkSession(this.networkSession)
1✔
349
                    .build());
1✔
350
  }
1✔
351

352
  public Authentication getAuth() {
353
    return auth;
×
354
  }
355

356
  public NetworkSession getNetworkSession() {
357
    return networkSession;
×
358
  }
359

360
  public static class Builder {
361

362
    protected Authentication auth;
363

364
    protected NetworkSession networkSession;
365

366
    public Builder() {
1✔
367
      this.networkSession = new NetworkSession();
1✔
368
    }
1✔
369

370
    public Builder auth(Authentication auth) {
371
      this.auth = auth;
1✔
372
      return this;
1✔
373
    }
374

375
    public Builder networkSession(NetworkSession networkSession) {
376
      this.networkSession = networkSession;
1✔
377
      return this;
1✔
378
    }
379

380
    public FolderMetadataManager build() {
381
      return new FolderMetadataManager(this);
1✔
382
    }
383
  }
384
}
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