• 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/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.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 FileMetadataManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

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

29
  protected FileMetadataManager(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 file.
36
   *
37
   * @param fileId The unique identifier that represents a file.
38
   *     <p>The ID for any file can be determined by visiting a file in the web application and
39
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
40
   *     `file_id` is `123`. Example: "12345"
41
   */
42
  public Metadatas getFileMetadata(String fileId) {
43
    return getFileMetadata(fileId, new GetFileMetadataHeaders());
1✔
44
  }
45

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

77
  /**
78
   * Retrieves the instance of a metadata template that has been applied to a file.
79
   *
80
   * @param fileId The unique identifier that represents a file.
81
   *     <p>The ID for any file can be determined by visiting a file in the web application and
82
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
83
   *     `file_id` is `123`. Example: "12345"
84
   * @param scope The scope of the metadata template. Example: "global"
85
   * @param templateKey The name of the metadata template. Example: "properties"
86
   */
87
  public MetadataFull getFileMetadataById(
88
      String fileId, GetFileMetadataByIdScope scope, String templateKey) {
89
    return getFileMetadataById(fileId, scope, templateKey, new GetFileMetadataByIdHeaders());
1✔
90
  }
91

92
  /**
93
   * Retrieves the instance of a metadata template that has been applied to a file.
94
   *
95
   * @param fileId The unique identifier that represents a file.
96
   *     <p>The ID for any file can be determined by visiting a file in the web application and
97
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
98
   *     `file_id` is `123`. Example: "12345"
99
   * @param scope The scope of the metadata template. Example: "global"
100
   * @param templateKey The name of the metadata template. Example: "properties"
101
   * @param headers Headers of getFileMetadataById method
102
   */
103
  public MetadataFull getFileMetadataById(
104
      String fileId,
105
      GetFileMetadataByIdScope scope,
106
      String templateKey,
107
      GetFileMetadataByIdHeaders headers) {
108
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
109
    FetchResponse response =
1✔
110
        this.networkSession
111
            .getNetworkClient()
1✔
112
            .fetch(
1✔
113
                new FetchOptions.Builder(
114
                        String.join(
1✔
115
                            "",
116
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
117
                            "/2.0/files/",
118
                            convertToString(fileId),
1✔
119
                            "/metadata/",
120
                            convertToString(scope),
1✔
121
                            "/",
122
                            convertToString(templateKey)),
1✔
123
                        "GET")
124
                    .headers(headersMap)
1✔
125
                    .responseFormat(ResponseFormat.JSON)
1✔
126
                    .auth(this.auth)
1✔
127
                    .networkSession(this.networkSession)
1✔
128
                    .build());
1✔
129
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
130
  }
131

132
  /**
133
   * Applies an instance of a metadata template to a file.
134
   *
135
   * <p>In most cases only values that are present in the metadata template will be accepted, except
136
   * for the `global.properties` template which accepts any key-value pair.
137
   *
138
   * @param fileId The unique identifier that represents a file.
139
   *     <p>The ID for any file can be determined by visiting a file in the web application and
140
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
141
   *     `file_id` is `123`. Example: "12345"
142
   * @param scope The scope of the metadata template. Example: "global"
143
   * @param templateKey The name of the metadata template. Example: "properties"
144
   * @param requestBody Request body of createFileMetadataById method
145
   */
146
  public MetadataFull createFileMetadataById(
147
      String fileId,
148
      CreateFileMetadataByIdScope scope,
149
      String templateKey,
150
      Map<String, Object> requestBody) {
151
    return createFileMetadataById(
1✔
152
        fileId, scope, templateKey, requestBody, new CreateFileMetadataByIdHeaders());
153
  }
154

155
  /**
156
   * Applies an instance of a metadata template to a file.
157
   *
158
   * <p>In most cases only values that are present in the metadata template will be accepted, except
159
   * for the `global.properties` template which accepts any key-value pair.
160
   *
161
   * @param fileId The unique identifier that represents a file.
162
   *     <p>The ID for any file can be determined by visiting a file in the web application and
163
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
164
   *     `file_id` is `123`. Example: "12345"
165
   * @param scope The scope of the metadata template. Example: "global"
166
   * @param templateKey The name of the metadata template. Example: "properties"
167
   * @param requestBody Request body of createFileMetadataById method
168
   * @param headers Headers of createFileMetadataById method
169
   */
170
  public MetadataFull createFileMetadataById(
171
      String fileId,
172
      CreateFileMetadataByIdScope scope,
173
      String templateKey,
174
      Map<String, Object> requestBody,
175
      CreateFileMetadataByIdHeaders headers) {
176
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
177
    FetchResponse response =
1✔
178
        this.networkSession
179
            .getNetworkClient()
1✔
180
            .fetch(
1✔
181
                new FetchOptions.Builder(
182
                        String.join(
1✔
183
                            "",
184
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
185
                            "/2.0/files/",
186
                            convertToString(fileId),
1✔
187
                            "/metadata/",
188
                            convertToString(scope),
1✔
189
                            "/",
190
                            convertToString(templateKey)),
1✔
191
                        "POST")
192
                    .headers(headersMap)
1✔
193
                    .data(JsonManager.serialize(requestBody))
1✔
194
                    .contentType("application/json")
1✔
195
                    .responseFormat(ResponseFormat.JSON)
1✔
196
                    .auth(this.auth)
1✔
197
                    .networkSession(this.networkSession)
1✔
198
                    .build());
1✔
199
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
200
  }
201

202
  /**
203
   * Updates a piece of metadata on a file.
204
   *
205
   * <p>The metadata instance can only be updated if the template has already been applied to the
206
   * file before. When editing metadata, only values that match the metadata template schema will be
207
   * accepted.
208
   *
209
   * <p>The update is applied atomically. If any errors occur during the application of the
210
   * operations, the metadata instance will not be changed.
211
   *
212
   * @param fileId The unique identifier that represents a file.
213
   *     <p>The ID for any file can be determined by visiting a file in the web application and
214
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
215
   *     `file_id` is `123`. Example: "12345"
216
   * @param scope The scope of the metadata template. Example: "global"
217
   * @param templateKey The name of the metadata template. Example: "properties"
218
   * @param requestBody Request body of updateFileMetadataById method
219
   */
220
  public MetadataFull updateFileMetadataById(
221
      String fileId,
222
      UpdateFileMetadataByIdScope scope,
223
      String templateKey,
224
      List<UpdateFileMetadataByIdRequestBody> requestBody) {
225
    return updateFileMetadataById(
1✔
226
        fileId, scope, templateKey, requestBody, new UpdateFileMetadataByIdHeaders());
227
  }
228

229
  /**
230
   * Updates a piece of metadata on a file.
231
   *
232
   * <p>The metadata instance can only be updated if the template has already been applied to the
233
   * file before. When editing metadata, only values that match the metadata template schema will be
234
   * accepted.
235
   *
236
   * <p>The update is applied atomically. If any errors occur during the application of the
237
   * operations, the metadata instance will not be changed.
238
   *
239
   * @param fileId The unique identifier that represents a file.
240
   *     <p>The ID for any file can be determined by visiting a file in the web application and
241
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
242
   *     `file_id` is `123`. Example: "12345"
243
   * @param scope The scope of the metadata template. Example: "global"
244
   * @param templateKey The name of the metadata template. Example: "properties"
245
   * @param requestBody Request body of updateFileMetadataById method
246
   * @param headers Headers of updateFileMetadataById method
247
   */
248
  public MetadataFull updateFileMetadataById(
249
      String fileId,
250
      UpdateFileMetadataByIdScope scope,
251
      String templateKey,
252
      List<UpdateFileMetadataByIdRequestBody> requestBody,
253
      UpdateFileMetadataByIdHeaders headers) {
254
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
255
    FetchResponse response =
1✔
256
        this.networkSession
257
            .getNetworkClient()
1✔
258
            .fetch(
1✔
259
                new FetchOptions.Builder(
260
                        String.join(
1✔
261
                            "",
262
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
263
                            "/2.0/files/",
264
                            convertToString(fileId),
1✔
265
                            "/metadata/",
266
                            convertToString(scope),
1✔
267
                            "/",
268
                            convertToString(templateKey)),
1✔
269
                        "PUT")
270
                    .headers(headersMap)
1✔
271
                    .data(JsonManager.serialize(requestBody))
1✔
272
                    .contentType("application/json-patch+json")
1✔
273
                    .responseFormat(ResponseFormat.JSON)
1✔
274
                    .auth(this.auth)
1✔
275
                    .networkSession(this.networkSession)
1✔
276
                    .build());
1✔
277
    return JsonManager.deserialize(response.getData(), MetadataFull.class);
1✔
278
  }
279

280
  /**
281
   * Deletes a piece of file metadata.
282
   *
283
   * @param fileId The unique identifier that represents a file.
284
   *     <p>The ID for any file can be determined by visiting a file in the web application and
285
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
286
   *     `file_id` is `123`. Example: "12345"
287
   * @param scope The scope of the metadata template. Example: "global"
288
   * @param templateKey The name of the metadata template. Example: "properties"
289
   */
290
  public void deleteFileMetadataById(
291
      String fileId, DeleteFileMetadataByIdScope scope, String templateKey) {
292
    deleteFileMetadataById(fileId, scope, templateKey, new DeleteFileMetadataByIdHeaders());
1✔
293
  }
1✔
294

295
  /**
296
   * Deletes a piece of file metadata.
297
   *
298
   * @param fileId The unique identifier that represents a file.
299
   *     <p>The ID for any file can be determined by visiting a file in the web application and
300
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
301
   *     `file_id` is `123`. Example: "12345"
302
   * @param scope The scope of the metadata template. Example: "global"
303
   * @param templateKey The name of the metadata template. Example: "properties"
304
   * @param headers Headers of deleteFileMetadataById method
305
   */
306
  public void deleteFileMetadataById(
307
      String fileId,
308
      DeleteFileMetadataByIdScope scope,
309
      String templateKey,
310
      DeleteFileMetadataByIdHeaders headers) {
311
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
312
    FetchResponse response =
1✔
313
        this.networkSession
314
            .getNetworkClient()
1✔
315
            .fetch(
1✔
316
                new FetchOptions.Builder(
317
                        String.join(
1✔
318
                            "",
319
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
320
                            "/2.0/files/",
321
                            convertToString(fileId),
1✔
322
                            "/metadata/",
323
                            convertToString(scope),
1✔
324
                            "/",
325
                            convertToString(templateKey)),
1✔
326
                        "DELETE")
327
                    .headers(headersMap)
1✔
328
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
329
                    .auth(this.auth)
1✔
330
                    .networkSession(this.networkSession)
1✔
331
                    .build());
1✔
332
  }
1✔
333

334
  public Authentication getAuth() {
335
    return auth;
×
336
  }
337

338
  public NetworkSession getNetworkSession() {
339
    return networkSession;
×
340
  }
341

342
  public static class Builder {
343

344
    protected Authentication auth;
345

346
    protected NetworkSession networkSession;
347

348
    public Builder() {
1✔
349
      this.networkSession = new NetworkSession();
1✔
350
    }
1✔
351

352
    public Builder auth(Authentication auth) {
353
      this.auth = auth;
1✔
354
      return this;
1✔
355
    }
356

357
    public Builder networkSession(NetworkSession networkSession) {
358
      this.networkSession = networkSession;
1✔
359
      return this;
1✔
360
    }
361

362
    public FileMetadataManager build() {
363
      return new FileMetadataManager(this);
1✔
364
    }
365
  }
366
}
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