001package com.box.sdkgen.managers.folders; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 008 009import com.box.sdkgen.networking.auth.Authentication; 010import com.box.sdkgen.networking.fetchoptions.FetchOptions; 011import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 012import com.box.sdkgen.networking.fetchresponse.FetchResponse; 013import com.box.sdkgen.networking.network.NetworkSession; 014import com.box.sdkgen.schemas.folderfull.FolderFull; 015import com.box.sdkgen.schemas.items.Items; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class FoldersManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public FoldersManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected FoldersManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Retrieves details for a folder, including the first 100 entries in the folder. 036 * 037 * <p>Passing `sort`, `direction`, `offset`, and `limit` parameters in query allows you to manage 038 * the list of returned [folder 039 * items](https://developer.box.com/reference/resources/folder--full#param-item-collection). 040 * 041 * <p>To fetch more items within the folder, use the [Get items in a 042 * folder](https://developer.box.com/reference/get-folders-id-items) endpoint. 043 * 044 * @param folderId The unique identifier that represent a folder. 045 * <p>The ID for any folder can be determined by visiting this folder in the web application 046 * and copying the ID from the URL. For example, for the URL 047 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 048 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 049 */ 050 public FolderFull getFolderById(String folderId) { 051 return getFolderById(folderId, new GetFolderByIdQueryParams(), new GetFolderByIdHeaders()); 052 } 053 054 /** 055 * Retrieves details for a folder, including the first 100 entries in the folder. 056 * 057 * <p>Passing `sort`, `direction`, `offset`, and `limit` parameters in query allows you to manage 058 * the list of returned [folder 059 * items](https://developer.box.com/reference/resources/folder--full#param-item-collection). 060 * 061 * <p>To fetch more items within the folder, use the [Get items in a 062 * folder](https://developer.box.com/reference/get-folders-id-items) endpoint. 063 * 064 * @param folderId The unique identifier that represent a folder. 065 * <p>The ID for any folder can be determined by visiting this folder in the web application 066 * and copying the ID from the URL. For example, for the URL 067 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 068 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 069 * @param queryParams Query parameters of getFolderById method 070 */ 071 public FolderFull getFolderById(String folderId, GetFolderByIdQueryParams queryParams) { 072 return getFolderById(folderId, queryParams, new GetFolderByIdHeaders()); 073 } 074 075 /** 076 * Retrieves details for a folder, including the first 100 entries in the folder. 077 * 078 * <p>Passing `sort`, `direction`, `offset`, and `limit` parameters in query allows you to manage 079 * the list of returned [folder 080 * items](https://developer.box.com/reference/resources/folder--full#param-item-collection). 081 * 082 * <p>To fetch more items within the folder, use the [Get items in a 083 * folder](https://developer.box.com/reference/get-folders-id-items) endpoint. 084 * 085 * @param folderId The unique identifier that represent a folder. 086 * <p>The ID for any folder can be determined by visiting this folder in the web application 087 * and copying the ID from the URL. For example, for the URL 088 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 089 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 090 * @param headers Headers of getFolderById method 091 */ 092 public FolderFull getFolderById(String folderId, GetFolderByIdHeaders headers) { 093 return getFolderById(folderId, new GetFolderByIdQueryParams(), headers); 094 } 095 096 /** 097 * Retrieves details for a folder, including the first 100 entries in the folder. 098 * 099 * <p>Passing `sort`, `direction`, `offset`, and `limit` parameters in query allows you to manage 100 * the list of returned [folder 101 * items](https://developer.box.com/reference/resources/folder--full#param-item-collection). 102 * 103 * <p>To fetch more items within the folder, use the [Get items in a 104 * folder](https://developer.box.com/reference/get-folders-id-items) endpoint. 105 * 106 * @param folderId The unique identifier that represent a folder. 107 * <p>The ID for any folder can be determined by visiting this folder in the web application 108 * and copying the ID from the URL. For example, for the URL 109 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 110 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 111 * @param queryParams Query parameters of getFolderById method 112 * @param headers Headers of getFolderById method 113 */ 114 public FolderFull getFolderById( 115 String folderId, GetFolderByIdQueryParams queryParams, GetFolderByIdHeaders headers) { 116 Map<String, String> queryParamsMap = 117 prepareParams( 118 mapOf( 119 entryOf("fields", convertToString(queryParams.getFields())), 120 entryOf("sort", convertToString(queryParams.getSort())), 121 entryOf("direction", convertToString(queryParams.getDirection())), 122 entryOf("offset", convertToString(queryParams.getOffset())), 123 entryOf("limit", convertToString(queryParams.getLimit())))); 124 Map<String, String> headersMap = 125 prepareParams( 126 mergeMaps( 127 mapOf( 128 entryOf("if-none-match", convertToString(headers.getIfNoneMatch())), 129 entryOf("boxapi", convertToString(headers.getBoxapi()))), 130 headers.getExtraHeaders())); 131 FetchResponse response = 132 this.networkSession 133 .getNetworkClient() 134 .fetch( 135 new FetchOptions.Builder( 136 String.join( 137 "", 138 this.networkSession.getBaseUrls().getBaseUrl(), 139 "/2.0/folders/", 140 convertToString(folderId)), 141 "GET") 142 .params(queryParamsMap) 143 .headers(headersMap) 144 .responseFormat(ResponseFormat.JSON) 145 .auth(this.auth) 146 .networkSession(this.networkSession) 147 .build()); 148 return JsonManager.deserialize(response.getData(), FolderFull.class); 149 } 150 151 /** 152 * Updates a folder. This can be also be used to move the folder, create shared links, update 153 * collaborations, and more. 154 * 155 * @param folderId The unique identifier that represent a folder. 156 * <p>The ID for any folder can be determined by visiting this folder in the web application 157 * and copying the ID from the URL. For example, for the URL 158 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 159 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 160 */ 161 public FolderFull updateFolderById(String folderId) { 162 return updateFolderById( 163 folderId, 164 new UpdateFolderByIdRequestBody(), 165 new UpdateFolderByIdQueryParams(), 166 new UpdateFolderByIdHeaders()); 167 } 168 169 /** 170 * Updates a folder. This can be also be used to move the folder, create shared links, update 171 * collaborations, and more. 172 * 173 * @param folderId The unique identifier that represent a folder. 174 * <p>The ID for any folder can be determined by visiting this folder in the web application 175 * and copying the ID from the URL. For example, for the URL 176 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 177 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 178 * @param requestBody Request body of updateFolderById method 179 */ 180 public FolderFull updateFolderById(String folderId, UpdateFolderByIdRequestBody requestBody) { 181 return updateFolderById( 182 folderId, requestBody, new UpdateFolderByIdQueryParams(), new UpdateFolderByIdHeaders()); 183 } 184 185 /** 186 * Updates a folder. This can be also be used to move the folder, create shared links, update 187 * collaborations, and more. 188 * 189 * @param folderId The unique identifier that represent a folder. 190 * <p>The ID for any folder can be determined by visiting this folder in the web application 191 * and copying the ID from the URL. For example, for the URL 192 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 193 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 194 * @param queryParams Query parameters of updateFolderById method 195 */ 196 public FolderFull updateFolderById(String folderId, UpdateFolderByIdQueryParams queryParams) { 197 return updateFolderById( 198 folderId, new UpdateFolderByIdRequestBody(), queryParams, new UpdateFolderByIdHeaders()); 199 } 200 201 /** 202 * Updates a folder. This can be also be used to move the folder, create shared links, update 203 * collaborations, and more. 204 * 205 * @param folderId The unique identifier that represent a folder. 206 * <p>The ID for any folder can be determined by visiting this folder in the web application 207 * and copying the ID from the URL. For example, for the URL 208 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 209 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 210 * @param requestBody Request body of updateFolderById method 211 * @param queryParams Query parameters of updateFolderById method 212 */ 213 public FolderFull updateFolderById( 214 String folderId, 215 UpdateFolderByIdRequestBody requestBody, 216 UpdateFolderByIdQueryParams queryParams) { 217 return updateFolderById(folderId, requestBody, queryParams, new UpdateFolderByIdHeaders()); 218 } 219 220 /** 221 * Updates a folder. This can be also be used to move the folder, create shared links, update 222 * collaborations, and more. 223 * 224 * @param folderId The unique identifier that represent a folder. 225 * <p>The ID for any folder can be determined by visiting this folder in the web application 226 * and copying the ID from the URL. For example, for the URL 227 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 228 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 229 * @param headers Headers of updateFolderById method 230 */ 231 public FolderFull updateFolderById(String folderId, UpdateFolderByIdHeaders headers) { 232 return updateFolderById( 233 folderId, new UpdateFolderByIdRequestBody(), new UpdateFolderByIdQueryParams(), headers); 234 } 235 236 /** 237 * Updates a folder. This can be also be used to move the folder, create shared links, update 238 * collaborations, and more. 239 * 240 * @param folderId The unique identifier that represent a folder. 241 * <p>The ID for any folder can be determined by visiting this folder in the web application 242 * and copying the ID from the URL. For example, for the URL 243 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 244 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 245 * @param requestBody Request body of updateFolderById method 246 * @param headers Headers of updateFolderById method 247 */ 248 public FolderFull updateFolderById( 249 String folderId, UpdateFolderByIdRequestBody requestBody, UpdateFolderByIdHeaders headers) { 250 return updateFolderById(folderId, requestBody, new UpdateFolderByIdQueryParams(), headers); 251 } 252 253 /** 254 * Updates a folder. This can be also be used to move the folder, create shared links, update 255 * collaborations, and more. 256 * 257 * @param folderId The unique identifier that represent a folder. 258 * <p>The ID for any folder can be determined by visiting this folder in the web application 259 * and copying the ID from the URL. For example, for the URL 260 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 261 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 262 * @param queryParams Query parameters of updateFolderById method 263 * @param headers Headers of updateFolderById method 264 */ 265 public FolderFull updateFolderById( 266 String folderId, UpdateFolderByIdQueryParams queryParams, UpdateFolderByIdHeaders headers) { 267 return updateFolderById(folderId, new UpdateFolderByIdRequestBody(), queryParams, headers); 268 } 269 270 /** 271 * Updates a folder. This can be also be used to move the folder, create shared links, update 272 * collaborations, and more. 273 * 274 * @param folderId The unique identifier that represent a folder. 275 * <p>The ID for any folder can be determined by visiting this folder in the web application 276 * and copying the ID from the URL. For example, for the URL 277 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 278 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 279 * @param requestBody Request body of updateFolderById method 280 * @param queryParams Query parameters of updateFolderById method 281 * @param headers Headers of updateFolderById method 282 */ 283 public FolderFull updateFolderById( 284 String folderId, 285 UpdateFolderByIdRequestBody requestBody, 286 UpdateFolderByIdQueryParams queryParams, 287 UpdateFolderByIdHeaders headers) { 288 Map<String, String> queryParamsMap = 289 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 290 Map<String, String> headersMap = 291 prepareParams( 292 mergeMaps( 293 mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))), 294 headers.getExtraHeaders())); 295 FetchResponse response = 296 this.networkSession 297 .getNetworkClient() 298 .fetch( 299 new FetchOptions.Builder( 300 String.join( 301 "", 302 this.networkSession.getBaseUrls().getBaseUrl(), 303 "/2.0/folders/", 304 convertToString(folderId)), 305 "PUT") 306 .params(queryParamsMap) 307 .headers(headersMap) 308 .data(JsonManager.serialize(requestBody)) 309 .contentType("application/json") 310 .responseFormat(ResponseFormat.JSON) 311 .auth(this.auth) 312 .networkSession(this.networkSession) 313 .build()); 314 return JsonManager.deserialize(response.getData(), FolderFull.class); 315 } 316 317 /** 318 * Deletes a folder, either permanently or by moving it to the trash. 319 * 320 * @param folderId The unique identifier that represent a folder. 321 * <p>The ID for any folder can be determined by visiting this folder in the web application 322 * and copying the ID from the URL. For example, for the URL 323 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 324 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 325 */ 326 public void deleteFolderById(String folderId) { 327 deleteFolderById(folderId, new DeleteFolderByIdQueryParams(), new DeleteFolderByIdHeaders()); 328 } 329 330 /** 331 * Deletes a folder, either permanently or by moving it to the trash. 332 * 333 * @param folderId The unique identifier that represent a folder. 334 * <p>The ID for any folder can be determined by visiting this folder in the web application 335 * and copying the ID from the URL. For example, for the URL 336 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 337 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 338 * @param queryParams Query parameters of deleteFolderById method 339 */ 340 public void deleteFolderById(String folderId, DeleteFolderByIdQueryParams queryParams) { 341 deleteFolderById(folderId, queryParams, new DeleteFolderByIdHeaders()); 342 } 343 344 /** 345 * Deletes a folder, either permanently or by moving it to the trash. 346 * 347 * @param folderId The unique identifier that represent a folder. 348 * <p>The ID for any folder can be determined by visiting this folder in the web application 349 * and copying the ID from the URL. For example, for the URL 350 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 351 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 352 * @param headers Headers of deleteFolderById method 353 */ 354 public void deleteFolderById(String folderId, DeleteFolderByIdHeaders headers) { 355 deleteFolderById(folderId, new DeleteFolderByIdQueryParams(), headers); 356 } 357 358 /** 359 * Deletes a folder, either permanently or by moving it to the trash. 360 * 361 * @param folderId The unique identifier that represent a folder. 362 * <p>The ID for any folder can be determined by visiting this folder in the web application 363 * and copying the ID from the URL. For example, for the URL 364 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 365 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 366 * @param queryParams Query parameters of deleteFolderById method 367 * @param headers Headers of deleteFolderById method 368 */ 369 public void deleteFolderById( 370 String folderId, DeleteFolderByIdQueryParams queryParams, DeleteFolderByIdHeaders headers) { 371 Map<String, String> queryParamsMap = 372 prepareParams(mapOf(entryOf("recursive", convertToString(queryParams.getRecursive())))); 373 Map<String, String> headersMap = 374 prepareParams( 375 mergeMaps( 376 mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))), 377 headers.getExtraHeaders())); 378 FetchResponse response = 379 this.networkSession 380 .getNetworkClient() 381 .fetch( 382 new FetchOptions.Builder( 383 String.join( 384 "", 385 this.networkSession.getBaseUrls().getBaseUrl(), 386 "/2.0/folders/", 387 convertToString(folderId)), 388 "DELETE") 389 .params(queryParamsMap) 390 .headers(headersMap) 391 .responseFormat(ResponseFormat.NO_CONTENT) 392 .auth(this.auth) 393 .networkSession(this.networkSession) 394 .build()); 395 } 396 397 /** 398 * Retrieves a page of items in a folder. These items can be files, folders, and web links. 399 * 400 * <p>To request more information about the folder itself, like its size, use the [Get a 401 * folder](https://developer.box.com/reference/get-folders-id) endpoint instead. 402 * 403 * @param folderId The unique identifier that represent a folder. 404 * <p>The ID for any folder can be determined by visiting this folder in the web application 405 * and copying the ID from the URL. For example, for the URL 406 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 407 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 408 */ 409 public Items getFolderItems(String folderId) { 410 return getFolderItems(folderId, new GetFolderItemsQueryParams(), new GetFolderItemsHeaders()); 411 } 412 413 /** 414 * Retrieves a page of items in a folder. These items can be files, folders, and web links. 415 * 416 * <p>To request more information about the folder itself, like its size, use the [Get a 417 * folder](https://developer.box.com/reference/get-folders-id) endpoint instead. 418 * 419 * @param folderId The unique identifier that represent a folder. 420 * <p>The ID for any folder can be determined by visiting this folder in the web application 421 * and copying the ID from the URL. For example, for the URL 422 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 423 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 424 * @param queryParams Query parameters of getFolderItems method 425 */ 426 public Items getFolderItems(String folderId, GetFolderItemsQueryParams queryParams) { 427 return getFolderItems(folderId, queryParams, new GetFolderItemsHeaders()); 428 } 429 430 /** 431 * Retrieves a page of items in a folder. These items can be files, folders, and web links. 432 * 433 * <p>To request more information about the folder itself, like its size, use the [Get a 434 * folder](https://developer.box.com/reference/get-folders-id) endpoint instead. 435 * 436 * @param folderId The unique identifier that represent a folder. 437 * <p>The ID for any folder can be determined by visiting this folder in the web application 438 * and copying the ID from the URL. For example, for the URL 439 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 440 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 441 * @param headers Headers of getFolderItems method 442 */ 443 public Items getFolderItems(String folderId, GetFolderItemsHeaders headers) { 444 return getFolderItems(folderId, new GetFolderItemsQueryParams(), headers); 445 } 446 447 /** 448 * Retrieves a page of items in a folder. These items can be files, folders, and web links. 449 * 450 * <p>To request more information about the folder itself, like its size, use the [Get a 451 * folder](https://developer.box.com/reference/get-folders-id) endpoint instead. 452 * 453 * @param folderId The unique identifier that represent a folder. 454 * <p>The ID for any folder can be determined by visiting this folder in the web application 455 * and copying the ID from the URL. For example, for the URL 456 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 457 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 458 * @param queryParams Query parameters of getFolderItems method 459 * @param headers Headers of getFolderItems method 460 */ 461 public Items getFolderItems( 462 String folderId, GetFolderItemsQueryParams queryParams, GetFolderItemsHeaders headers) { 463 Map<String, String> queryParamsMap = 464 prepareParams( 465 mapOf( 466 entryOf("fields", convertToString(queryParams.getFields())), 467 entryOf("usemarker", convertToString(queryParams.getUsemarker())), 468 entryOf("marker", convertToString(queryParams.getMarker())), 469 entryOf("offset", convertToString(queryParams.getOffset())), 470 entryOf("limit", convertToString(queryParams.getLimit())), 471 entryOf("sort", convertToString(queryParams.getSort())), 472 entryOf("direction", convertToString(queryParams.getDirection())))); 473 Map<String, String> headersMap = 474 prepareParams( 475 mergeMaps( 476 mapOf(entryOf("boxapi", convertToString(headers.getBoxapi()))), 477 headers.getExtraHeaders())); 478 FetchResponse response = 479 this.networkSession 480 .getNetworkClient() 481 .fetch( 482 new FetchOptions.Builder( 483 String.join( 484 "", 485 this.networkSession.getBaseUrls().getBaseUrl(), 486 "/2.0/folders/", 487 convertToString(folderId), 488 "/items"), 489 "GET") 490 .params(queryParamsMap) 491 .headers(headersMap) 492 .responseFormat(ResponseFormat.JSON) 493 .auth(this.auth) 494 .networkSession(this.networkSession) 495 .build()); 496 return JsonManager.deserialize(response.getData(), Items.class); 497 } 498 499 /** 500 * Creates a new empty folder within the specified parent folder. 501 * 502 * @param requestBody Request body of createFolder method 503 */ 504 public FolderFull createFolder(CreateFolderRequestBody requestBody) { 505 return createFolder(requestBody, new CreateFolderQueryParams(), new CreateFolderHeaders()); 506 } 507 508 /** 509 * Creates a new empty folder within the specified parent folder. 510 * 511 * @param requestBody Request body of createFolder method 512 * @param queryParams Query parameters of createFolder method 513 */ 514 public FolderFull createFolder( 515 CreateFolderRequestBody requestBody, CreateFolderQueryParams queryParams) { 516 return createFolder(requestBody, queryParams, new CreateFolderHeaders()); 517 } 518 519 /** 520 * Creates a new empty folder within the specified parent folder. 521 * 522 * @param requestBody Request body of createFolder method 523 * @param headers Headers of createFolder method 524 */ 525 public FolderFull createFolder(CreateFolderRequestBody requestBody, CreateFolderHeaders headers) { 526 return createFolder(requestBody, new CreateFolderQueryParams(), headers); 527 } 528 529 /** 530 * Creates a new empty folder within the specified parent folder. 531 * 532 * @param requestBody Request body of createFolder method 533 * @param queryParams Query parameters of createFolder method 534 * @param headers Headers of createFolder method 535 */ 536 public FolderFull createFolder( 537 CreateFolderRequestBody requestBody, 538 CreateFolderQueryParams queryParams, 539 CreateFolderHeaders headers) { 540 Map<String, String> queryParamsMap = 541 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 542 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 543 FetchResponse response = 544 this.networkSession 545 .getNetworkClient() 546 .fetch( 547 new FetchOptions.Builder( 548 String.join( 549 "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/folders"), 550 "POST") 551 .params(queryParamsMap) 552 .headers(headersMap) 553 .data(JsonManager.serialize(requestBody)) 554 .contentType("application/json") 555 .responseFormat(ResponseFormat.JSON) 556 .auth(this.auth) 557 .networkSession(this.networkSession) 558 .build()); 559 return JsonManager.deserialize(response.getData(), FolderFull.class); 560 } 561 562 /** 563 * Creates a copy of a folder within a destination folder. 564 * 565 * <p>The original folder will not be changed. 566 * 567 * @param folderId The unique identifier of the folder to copy. 568 * <p>The ID for any folder can be determined by visiting this folder in the web application 569 * and copying the ID from the URL. For example, for the URL 570 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 571 * <p>The root folder with the ID `0` can not be copied. Example: "0" 572 * @param requestBody Request body of copyFolder method 573 */ 574 public FolderFull copyFolder(String folderId, CopyFolderRequestBody requestBody) { 575 return copyFolder(folderId, requestBody, new CopyFolderQueryParams(), new CopyFolderHeaders()); 576 } 577 578 /** 579 * Creates a copy of a folder within a destination folder. 580 * 581 * <p>The original folder will not be changed. 582 * 583 * @param folderId The unique identifier of the folder to copy. 584 * <p>The ID for any folder can be determined by visiting this folder in the web application 585 * and copying the ID from the URL. For example, for the URL 586 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 587 * <p>The root folder with the ID `0` can not be copied. Example: "0" 588 * @param requestBody Request body of copyFolder method 589 * @param queryParams Query parameters of copyFolder method 590 */ 591 public FolderFull copyFolder( 592 String folderId, CopyFolderRequestBody requestBody, CopyFolderQueryParams queryParams) { 593 return copyFolder(folderId, requestBody, queryParams, new CopyFolderHeaders()); 594 } 595 596 /** 597 * Creates a copy of a folder within a destination folder. 598 * 599 * <p>The original folder will not be changed. 600 * 601 * @param folderId The unique identifier of the folder to copy. 602 * <p>The ID for any folder can be determined by visiting this folder in the web application 603 * and copying the ID from the URL. For example, for the URL 604 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 605 * <p>The root folder with the ID `0` can not be copied. Example: "0" 606 * @param requestBody Request body of copyFolder method 607 * @param headers Headers of copyFolder method 608 */ 609 public FolderFull copyFolder( 610 String folderId, CopyFolderRequestBody requestBody, CopyFolderHeaders headers) { 611 return copyFolder(folderId, requestBody, new CopyFolderQueryParams(), headers); 612 } 613 614 /** 615 * Creates a copy of a folder within a destination folder. 616 * 617 * <p>The original folder will not be changed. 618 * 619 * @param folderId The unique identifier of the folder to copy. 620 * <p>The ID for any folder can be determined by visiting this folder in the web application 621 * and copying the ID from the URL. For example, for the URL 622 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 623 * <p>The root folder with the ID `0` can not be copied. Example: "0" 624 * @param requestBody Request body of copyFolder method 625 * @param queryParams Query parameters of copyFolder method 626 * @param headers Headers of copyFolder method 627 */ 628 public FolderFull copyFolder( 629 String folderId, 630 CopyFolderRequestBody requestBody, 631 CopyFolderQueryParams queryParams, 632 CopyFolderHeaders headers) { 633 Map<String, String> queryParamsMap = 634 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 635 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 636 FetchResponse response = 637 this.networkSession 638 .getNetworkClient() 639 .fetch( 640 new FetchOptions.Builder( 641 String.join( 642 "", 643 this.networkSession.getBaseUrls().getBaseUrl(), 644 "/2.0/folders/", 645 convertToString(folderId), 646 "/copy"), 647 "POST") 648 .params(queryParamsMap) 649 .headers(headersMap) 650 .data(JsonManager.serialize(requestBody)) 651 .contentType("application/json") 652 .responseFormat(ResponseFormat.JSON) 653 .auth(this.auth) 654 .networkSession(this.networkSession) 655 .build()); 656 return JsonManager.deserialize(response.getData(), FolderFull.class); 657 } 658 659 public Authentication getAuth() { 660 return auth; 661 } 662 663 public NetworkSession getNetworkSession() { 664 return networkSession; 665 } 666 667 public static class Builder { 668 669 protected Authentication auth; 670 671 protected NetworkSession networkSession; 672 673 public Builder() {} 674 675 public Builder auth(Authentication auth) { 676 this.auth = auth; 677 return this; 678 } 679 680 public Builder networkSession(NetworkSession networkSession) { 681 this.networkSession = networkSession; 682 return this; 683 } 684 685 public FoldersManager build() { 686 if (this.networkSession == null) { 687 this.networkSession = new NetworkSession(); 688 } 689 return new FoldersManager(this); 690 } 691 } 692}