• 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

94.27
/src/main/java/com/box/sdkgen/managers/metadatatemplates/MetadataTemplatesManager.java
1
package com.box.sdkgen.managers.metadatatemplates;
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.metadatatemplate.MetadataTemplate;
15
import com.box.sdkgen.schemas.metadatatemplates.MetadataTemplates;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.util.List;
18
import java.util.Map;
19

20
public class MetadataTemplatesManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

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

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

35
  /**
36
   * Finds a metadata template by searching for the ID of an instance of the template.
37
   *
38
   * @param queryParams Query parameters of getMetadataTemplatesByInstanceId method
39
   */
40
  public MetadataTemplates getMetadataTemplatesByInstanceId(
41
      GetMetadataTemplatesByInstanceIdQueryParams queryParams) {
42
    return getMetadataTemplatesByInstanceId(
1✔
43
        queryParams, new GetMetadataTemplatesByInstanceIdHeaders());
44
  }
45

46
  /**
47
   * Finds a metadata template by searching for the ID of an instance of the template.
48
   *
49
   * @param queryParams Query parameters of getMetadataTemplatesByInstanceId method
50
   * @param headers Headers of getMetadataTemplatesByInstanceId method
51
   */
52
  public MetadataTemplates getMetadataTemplatesByInstanceId(
53
      GetMetadataTemplatesByInstanceIdQueryParams queryParams,
54
      GetMetadataTemplatesByInstanceIdHeaders headers) {
55
    Map<String, String> queryParamsMap =
1✔
56
        prepareParams(
1✔
57
            mapOf(
1✔
58
                entryOf(
1✔
59
                    "metadata_instance_id", convertToString(queryParams.getMetadataInstanceId())),
1✔
60
                entryOf("marker", convertToString(queryParams.getMarker())),
1✔
61
                entryOf("limit", convertToString(queryParams.getLimit()))));
1✔
62
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
63
    FetchResponse response =
1✔
64
        this.networkSession
65
            .getNetworkClient()
1✔
66
            .fetch(
1✔
67
                new FetchOptions.Builder(
68
                        String.join(
1✔
69
                            "",
70
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
71
                            "/2.0/metadata_templates"),
72
                        "GET")
73
                    .params(queryParamsMap)
1✔
74
                    .headers(headersMap)
1✔
75
                    .responseFormat(ResponseFormat.JSON)
1✔
76
                    .auth(this.auth)
1✔
77
                    .networkSession(this.networkSession)
1✔
78
                    .build());
1✔
79
    return JsonManager.deserialize(response.getData(), MetadataTemplates.class);
1✔
80
  }
81

82
  /**
83
   * Retrieves a metadata template by its `scope` and `templateKey` values.
84
   *
85
   * <p>To find the `scope` and `templateKey` for a template, list all templates for an enterprise
86
   * or globally, or list all templates applied to a file or folder.
87
   *
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 MetadataTemplate getMetadataTemplate(GetMetadataTemplateScope scope, String templateKey) {
92
    return getMetadataTemplate(scope, templateKey, new GetMetadataTemplateHeaders());
1✔
93
  }
94

95
  /**
96
   * Retrieves a metadata template by its `scope` and `templateKey` values.
97
   *
98
   * <p>To find the `scope` and `templateKey` for a template, list all templates for an enterprise
99
   * or globally, or list all templates applied to a file or folder.
100
   *
101
   * @param scope The scope of the metadata template. Example: "global"
102
   * @param templateKey The name of the metadata template. Example: "properties"
103
   * @param headers Headers of getMetadataTemplate method
104
   */
105
  public MetadataTemplate getMetadataTemplate(
106
      GetMetadataTemplateScope scope, String templateKey, GetMetadataTemplateHeaders headers) {
107
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
108
    FetchResponse response =
1✔
109
        this.networkSession
110
            .getNetworkClient()
1✔
111
            .fetch(
1✔
112
                new FetchOptions.Builder(
113
                        String.join(
1✔
114
                            "",
115
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
116
                            "/2.0/metadata_templates/",
117
                            convertToString(scope),
1✔
118
                            "/",
119
                            convertToString(templateKey),
1✔
120
                            "/schema"),
121
                        "GET")
122
                    .headers(headersMap)
1✔
123
                    .responseFormat(ResponseFormat.JSON)
1✔
124
                    .auth(this.auth)
1✔
125
                    .networkSession(this.networkSession)
1✔
126
                    .build());
1✔
127
    return JsonManager.deserialize(response.getData(), MetadataTemplate.class);
1✔
128
  }
129

130
  /**
131
   * Updates a metadata template.
132
   *
133
   * <p>The metadata template can only be updated if the template already exists.
134
   *
135
   * <p>The update is applied atomically. If any errors occur during the application of the
136
   * operations, the metadata template will not be changed.
137
   *
138
   * @param scope The scope of the metadata template. Example: "global"
139
   * @param templateKey The name of the metadata template. Example: "properties"
140
   * @param requestBody Request body of updateMetadataTemplate method
141
   */
142
  public MetadataTemplate updateMetadataTemplate(
143
      UpdateMetadataTemplateScope scope,
144
      String templateKey,
145
      List<UpdateMetadataTemplateRequestBody> requestBody) {
146
    return updateMetadataTemplate(
1✔
147
        scope, templateKey, requestBody, new UpdateMetadataTemplateHeaders());
148
  }
149

150
  /**
151
   * Updates a metadata template.
152
   *
153
   * <p>The metadata template can only be updated if the template already exists.
154
   *
155
   * <p>The update is applied atomically. If any errors occur during the application of the
156
   * operations, the metadata template will not be changed.
157
   *
158
   * @param scope The scope of the metadata template. Example: "global"
159
   * @param templateKey The name of the metadata template. Example: "properties"
160
   * @param requestBody Request body of updateMetadataTemplate method
161
   * @param headers Headers of updateMetadataTemplate method
162
   */
163
  public MetadataTemplate updateMetadataTemplate(
164
      UpdateMetadataTemplateScope scope,
165
      String templateKey,
166
      List<UpdateMetadataTemplateRequestBody> requestBody,
167
      UpdateMetadataTemplateHeaders headers) {
168
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
169
    FetchResponse response =
1✔
170
        this.networkSession
171
            .getNetworkClient()
1✔
172
            .fetch(
1✔
173
                new FetchOptions.Builder(
174
                        String.join(
1✔
175
                            "",
176
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
177
                            "/2.0/metadata_templates/",
178
                            convertToString(scope),
1✔
179
                            "/",
180
                            convertToString(templateKey),
1✔
181
                            "/schema"),
182
                        "PUT")
183
                    .headers(headersMap)
1✔
184
                    .data(JsonManager.serialize(requestBody))
1✔
185
                    .contentType("application/json-patch+json")
1✔
186
                    .responseFormat(ResponseFormat.JSON)
1✔
187
                    .auth(this.auth)
1✔
188
                    .networkSession(this.networkSession)
1✔
189
                    .build());
1✔
190
    return JsonManager.deserialize(response.getData(), MetadataTemplate.class);
1✔
191
  }
192

193
  /**
194
   * Delete a metadata template and its instances. This deletion is permanent and can not be
195
   * reversed.
196
   *
197
   * @param scope The scope of the metadata template. Example: "global"
198
   * @param templateKey The name of the metadata template. Example: "properties"
199
   */
200
  public void deleteMetadataTemplate(DeleteMetadataTemplateScope scope, String templateKey) {
201
    deleteMetadataTemplate(scope, templateKey, new DeleteMetadataTemplateHeaders());
1✔
202
  }
1✔
203

204
  /**
205
   * Delete a metadata template and its instances. This deletion is permanent and can not be
206
   * reversed.
207
   *
208
   * @param scope The scope of the metadata template. Example: "global"
209
   * @param templateKey The name of the metadata template. Example: "properties"
210
   * @param headers Headers of deleteMetadataTemplate method
211
   */
212
  public void deleteMetadataTemplate(
213
      DeleteMetadataTemplateScope scope,
214
      String templateKey,
215
      DeleteMetadataTemplateHeaders headers) {
216
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
217
    FetchResponse response =
1✔
218
        this.networkSession
219
            .getNetworkClient()
1✔
220
            .fetch(
1✔
221
                new FetchOptions.Builder(
222
                        String.join(
1✔
223
                            "",
224
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
225
                            "/2.0/metadata_templates/",
226
                            convertToString(scope),
1✔
227
                            "/",
228
                            convertToString(templateKey),
1✔
229
                            "/schema"),
230
                        "DELETE")
231
                    .headers(headersMap)
1✔
232
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
233
                    .auth(this.auth)
1✔
234
                    .networkSession(this.networkSession)
1✔
235
                    .build());
1✔
236
  }
1✔
237

238
  /**
239
   * Retrieves a metadata template by its ID.
240
   *
241
   * @param templateId The ID of the template. Example: "f7a9891f"
242
   */
243
  public MetadataTemplate getMetadataTemplateById(String templateId) {
244
    return getMetadataTemplateById(templateId, new GetMetadataTemplateByIdHeaders());
1✔
245
  }
246

247
  /**
248
   * Retrieves a metadata template by its ID.
249
   *
250
   * @param templateId The ID of the template. Example: "f7a9891f"
251
   * @param headers Headers of getMetadataTemplateById method
252
   */
253
  public MetadataTemplate getMetadataTemplateById(
254
      String templateId, GetMetadataTemplateByIdHeaders headers) {
255
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
256
    FetchResponse response =
1✔
257
        this.networkSession
258
            .getNetworkClient()
1✔
259
            .fetch(
1✔
260
                new FetchOptions.Builder(
261
                        String.join(
1✔
262
                            "",
263
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
264
                            "/2.0/metadata_templates/",
265
                            convertToString(templateId)),
1✔
266
                        "GET")
267
                    .headers(headersMap)
1✔
268
                    .responseFormat(ResponseFormat.JSON)
1✔
269
                    .auth(this.auth)
1✔
270
                    .networkSession(this.networkSession)
1✔
271
                    .build());
1✔
272
    return JsonManager.deserialize(response.getData(), MetadataTemplate.class);
1✔
273
  }
274

275
  /**
276
   * Used to retrieve all generic, global metadata templates available to all enterprises using Box.
277
   */
278
  public MetadataTemplates getGlobalMetadataTemplates() {
279
    return getGlobalMetadataTemplates(
1✔
280
        new GetGlobalMetadataTemplatesQueryParams(), new GetGlobalMetadataTemplatesHeaders());
281
  }
282

283
  /**
284
   * Used to retrieve all generic, global metadata templates available to all enterprises using Box.
285
   *
286
   * @param queryParams Query parameters of getGlobalMetadataTemplates method
287
   */
288
  public MetadataTemplates getGlobalMetadataTemplates(
289
      GetGlobalMetadataTemplatesQueryParams queryParams) {
290
    return getGlobalMetadataTemplates(queryParams, new GetGlobalMetadataTemplatesHeaders());
×
291
  }
292

293
  /**
294
   * Used to retrieve all generic, global metadata templates available to all enterprises using Box.
295
   *
296
   * @param headers Headers of getGlobalMetadataTemplates method
297
   */
298
  public MetadataTemplates getGlobalMetadataTemplates(GetGlobalMetadataTemplatesHeaders headers) {
299
    return getGlobalMetadataTemplates(new GetGlobalMetadataTemplatesQueryParams(), headers);
×
300
  }
301

302
  /**
303
   * Used to retrieve all generic, global metadata templates available to all enterprises using Box.
304
   *
305
   * @param queryParams Query parameters of getGlobalMetadataTemplates method
306
   * @param headers Headers of getGlobalMetadataTemplates method
307
   */
308
  public MetadataTemplates getGlobalMetadataTemplates(
309
      GetGlobalMetadataTemplatesQueryParams queryParams,
310
      GetGlobalMetadataTemplatesHeaders headers) {
311
    Map<String, String> queryParamsMap =
1✔
312
        prepareParams(
1✔
313
            mapOf(
1✔
314
                entryOf("marker", convertToString(queryParams.getMarker())),
1✔
315
                entryOf("limit", convertToString(queryParams.getLimit()))));
1✔
316
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
317
    FetchResponse response =
1✔
318
        this.networkSession
319
            .getNetworkClient()
1✔
320
            .fetch(
1✔
321
                new FetchOptions.Builder(
322
                        String.join(
1✔
323
                            "",
324
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
325
                            "/2.0/metadata_templates/global"),
326
                        "GET")
327
                    .params(queryParamsMap)
1✔
328
                    .headers(headersMap)
1✔
329
                    .responseFormat(ResponseFormat.JSON)
1✔
330
                    .auth(this.auth)
1✔
331
                    .networkSession(this.networkSession)
1✔
332
                    .build());
1✔
333
    return JsonManager.deserialize(response.getData(), MetadataTemplates.class);
1✔
334
  }
335

336
  /**
337
   * Used to retrieve all metadata templates created to be used specifically within the user's
338
   * enterprise.
339
   */
340
  public MetadataTemplates getEnterpriseMetadataTemplates() {
341
    return getEnterpriseMetadataTemplates(
1✔
342
        new GetEnterpriseMetadataTemplatesQueryParams(),
343
        new GetEnterpriseMetadataTemplatesHeaders());
344
  }
345

346
  /**
347
   * Used to retrieve all metadata templates created to be used specifically within the user's
348
   * enterprise.
349
   *
350
   * @param queryParams Query parameters of getEnterpriseMetadataTemplates method
351
   */
352
  public MetadataTemplates getEnterpriseMetadataTemplates(
353
      GetEnterpriseMetadataTemplatesQueryParams queryParams) {
354
    return getEnterpriseMetadataTemplates(queryParams, new GetEnterpriseMetadataTemplatesHeaders());
×
355
  }
356

357
  /**
358
   * Used to retrieve all metadata templates created to be used specifically within the user's
359
   * enterprise.
360
   *
361
   * @param headers Headers of getEnterpriseMetadataTemplates method
362
   */
363
  public MetadataTemplates getEnterpriseMetadataTemplates(
364
      GetEnterpriseMetadataTemplatesHeaders headers) {
365
    return getEnterpriseMetadataTemplates(new GetEnterpriseMetadataTemplatesQueryParams(), headers);
×
366
  }
367

368
  /**
369
   * Used to retrieve all metadata templates created to be used specifically within the user's
370
   * enterprise.
371
   *
372
   * @param queryParams Query parameters of getEnterpriseMetadataTemplates method
373
   * @param headers Headers of getEnterpriseMetadataTemplates method
374
   */
375
  public MetadataTemplates getEnterpriseMetadataTemplates(
376
      GetEnterpriseMetadataTemplatesQueryParams queryParams,
377
      GetEnterpriseMetadataTemplatesHeaders headers) {
378
    Map<String, String> queryParamsMap =
1✔
379
        prepareParams(
1✔
380
            mapOf(
1✔
381
                entryOf("marker", convertToString(queryParams.getMarker())),
1✔
382
                entryOf("limit", convertToString(queryParams.getLimit()))));
1✔
383
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
384
    FetchResponse response =
1✔
385
        this.networkSession
386
            .getNetworkClient()
1✔
387
            .fetch(
1✔
388
                new FetchOptions.Builder(
389
                        String.join(
1✔
390
                            "",
391
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
392
                            "/2.0/metadata_templates/enterprise"),
393
                        "GET")
394
                    .params(queryParamsMap)
1✔
395
                    .headers(headersMap)
1✔
396
                    .responseFormat(ResponseFormat.JSON)
1✔
397
                    .auth(this.auth)
1✔
398
                    .networkSession(this.networkSession)
1✔
399
                    .build());
1✔
400
    return JsonManager.deserialize(response.getData(), MetadataTemplates.class);
1✔
401
  }
402

403
  /**
404
   * Creates a new metadata template that can be applied to files and folders.
405
   *
406
   * @param requestBody Request body of createMetadataTemplate method
407
   */
408
  public MetadataTemplate createMetadataTemplate(CreateMetadataTemplateRequestBody requestBody) {
409
    return createMetadataTemplate(requestBody, new CreateMetadataTemplateHeaders());
1✔
410
  }
411

412
  /**
413
   * Creates a new metadata template that can be applied to files and folders.
414
   *
415
   * @param requestBody Request body of createMetadataTemplate method
416
   * @param headers Headers of createMetadataTemplate method
417
   */
418
  public MetadataTemplate createMetadataTemplate(
419
      CreateMetadataTemplateRequestBody requestBody, CreateMetadataTemplateHeaders headers) {
420
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
421
    FetchResponse response =
1✔
422
        this.networkSession
423
            .getNetworkClient()
1✔
424
            .fetch(
1✔
425
                new FetchOptions.Builder(
426
                        String.join(
1✔
427
                            "",
428
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
429
                            "/2.0/metadata_templates/schema"),
430
                        "POST")
431
                    .headers(headersMap)
1✔
432
                    .data(JsonManager.serialize(requestBody))
1✔
433
                    .contentType("application/json")
1✔
434
                    .responseFormat(ResponseFormat.JSON)
1✔
435
                    .auth(this.auth)
1✔
436
                    .networkSession(this.networkSession)
1✔
437
                    .build());
1✔
438
    return JsonManager.deserialize(response.getData(), MetadataTemplate.class);
1✔
439
  }
440

441
  public Authentication getAuth() {
442
    return auth;
×
443
  }
444

445
  public NetworkSession getNetworkSession() {
446
    return networkSession;
×
447
  }
448

449
  public static class Builder {
450

451
    protected Authentication auth;
452

453
    protected NetworkSession networkSession;
454

455
    public Builder() {
1✔
456
      this.networkSession = new NetworkSession();
1✔
457
    }
1✔
458

459
    public Builder auth(Authentication auth) {
460
      this.auth = auth;
1✔
461
      return this;
1✔
462
    }
463

464
    public Builder networkSession(NetworkSession networkSession) {
465
      this.networkSession = networkSession;
1✔
466
      return this;
1✔
467
    }
468

469
    public MetadataTemplatesManager build() {
470
      return new MetadataTemplatesManager(this);
1✔
471
    }
472
  }
473
}
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