001package com.box.sdkgen.managers.trashedfolders; 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.trashfolder.TrashFolder; 015import com.box.sdkgen.schemas.trashfolderrestored.TrashFolderRestored; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class TrashedFoldersManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public TrashedFoldersManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected TrashedFoldersManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Restores a folder that has been moved to the trash. 036 * 037 * <p>An optional new parent ID can be provided to restore the folder to in case the original 038 * folder has been deleted. 039 * 040 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 041 * all of its descendants, as well as the destination folder. 042 * 043 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 044 * performed on any of the locked folders. 045 * 046 * @param folderId The unique identifier that represent a folder. 047 * <p>The ID for any folder can be determined by visiting this folder in the web application 048 * and copying the ID from the URL. For example, for the URL 049 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 050 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 051 */ 052 public TrashFolderRestored restoreFolderFromTrash(String folderId) { 053 return restoreFolderFromTrash( 054 folderId, 055 new RestoreFolderFromTrashRequestBody(), 056 new RestoreFolderFromTrashQueryParams(), 057 new RestoreFolderFromTrashHeaders()); 058 } 059 060 /** 061 * Restores a folder that has been moved to the trash. 062 * 063 * <p>An optional new parent ID can be provided to restore the folder to in case the original 064 * folder has been deleted. 065 * 066 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 067 * all of its descendants, as well as the destination folder. 068 * 069 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 070 * performed on any of the locked folders. 071 * 072 * @param folderId The unique identifier that represent a folder. 073 * <p>The ID for any folder can be determined by visiting this folder in the web application 074 * and copying the ID from the URL. For example, for the URL 075 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 076 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 077 * @param requestBody Request body of restoreFolderFromTrash method 078 */ 079 public TrashFolderRestored restoreFolderFromTrash( 080 String folderId, RestoreFolderFromTrashRequestBody requestBody) { 081 return restoreFolderFromTrash( 082 folderId, 083 requestBody, 084 new RestoreFolderFromTrashQueryParams(), 085 new RestoreFolderFromTrashHeaders()); 086 } 087 088 /** 089 * Restores a folder that has been moved to the trash. 090 * 091 * <p>An optional new parent ID can be provided to restore the folder to in case the original 092 * folder has been deleted. 093 * 094 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 095 * all of its descendants, as well as the destination folder. 096 * 097 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 098 * performed on any of the locked folders. 099 * 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 queryParams Query parameters of restoreFolderFromTrash method 106 */ 107 public TrashFolderRestored restoreFolderFromTrash( 108 String folderId, RestoreFolderFromTrashQueryParams queryParams) { 109 return restoreFolderFromTrash( 110 folderId, 111 new RestoreFolderFromTrashRequestBody(), 112 queryParams, 113 new RestoreFolderFromTrashHeaders()); 114 } 115 116 /** 117 * Restores a folder that has been moved to the trash. 118 * 119 * <p>An optional new parent ID can be provided to restore the folder to in case the original 120 * folder has been deleted. 121 * 122 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 123 * all of its descendants, as well as the destination folder. 124 * 125 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 126 * performed on any of the locked folders. 127 * 128 * @param folderId The unique identifier that represent a folder. 129 * <p>The ID for any folder can be determined by visiting this folder in the web application 130 * and copying the ID from the URL. For example, for the URL 131 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 132 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 133 * @param requestBody Request body of restoreFolderFromTrash method 134 * @param queryParams Query parameters of restoreFolderFromTrash method 135 */ 136 public TrashFolderRestored restoreFolderFromTrash( 137 String folderId, 138 RestoreFolderFromTrashRequestBody requestBody, 139 RestoreFolderFromTrashQueryParams queryParams) { 140 return restoreFolderFromTrash( 141 folderId, requestBody, queryParams, new RestoreFolderFromTrashHeaders()); 142 } 143 144 /** 145 * Restores a folder that has been moved to the trash. 146 * 147 * <p>An optional new parent ID can be provided to restore the folder to in case the original 148 * folder has been deleted. 149 * 150 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 151 * all of its descendants, as well as the destination folder. 152 * 153 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 154 * performed on any of the locked folders. 155 * 156 * @param folderId The unique identifier that represent a folder. 157 * <p>The ID for any folder can be determined by visiting this folder in the web application 158 * and copying the ID from the URL. For example, for the URL 159 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 160 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 161 * @param headers Headers of restoreFolderFromTrash method 162 */ 163 public TrashFolderRestored restoreFolderFromTrash( 164 String folderId, RestoreFolderFromTrashHeaders headers) { 165 return restoreFolderFromTrash( 166 folderId, 167 new RestoreFolderFromTrashRequestBody(), 168 new RestoreFolderFromTrashQueryParams(), 169 headers); 170 } 171 172 /** 173 * Restores a folder that has been moved to the trash. 174 * 175 * <p>An optional new parent ID can be provided to restore the folder to in case the original 176 * folder has been deleted. 177 * 178 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 179 * all of its descendants, as well as the destination folder. 180 * 181 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 182 * performed on any of the locked folders. 183 * 184 * @param folderId The unique identifier that represent a folder. 185 * <p>The ID for any folder can be determined by visiting this folder in the web application 186 * and copying the ID from the URL. For example, for the URL 187 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 188 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 189 * @param requestBody Request body of restoreFolderFromTrash method 190 * @param headers Headers of restoreFolderFromTrash method 191 */ 192 public TrashFolderRestored restoreFolderFromTrash( 193 String folderId, 194 RestoreFolderFromTrashRequestBody requestBody, 195 RestoreFolderFromTrashHeaders headers) { 196 return restoreFolderFromTrash( 197 folderId, requestBody, new RestoreFolderFromTrashQueryParams(), headers); 198 } 199 200 /** 201 * Restores a folder that has been moved to the trash. 202 * 203 * <p>An optional new parent ID can be provided to restore the folder to in case the original 204 * folder has been deleted. 205 * 206 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 207 * all of its descendants, as well as the destination folder. 208 * 209 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 210 * performed on any of the locked folders. 211 * 212 * @param folderId The unique identifier that represent a folder. 213 * <p>The ID for any folder can be determined by visiting this folder in the web application 214 * and copying the ID from the URL. For example, for the URL 215 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 216 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 217 * @param queryParams Query parameters of restoreFolderFromTrash method 218 * @param headers Headers of restoreFolderFromTrash method 219 */ 220 public TrashFolderRestored restoreFolderFromTrash( 221 String folderId, 222 RestoreFolderFromTrashQueryParams queryParams, 223 RestoreFolderFromTrashHeaders headers) { 224 return restoreFolderFromTrash( 225 folderId, new RestoreFolderFromTrashRequestBody(), queryParams, headers); 226 } 227 228 /** 229 * Restores a folder that has been moved to the trash. 230 * 231 * <p>An optional new parent ID can be provided to restore the folder to in case the original 232 * folder has been deleted. 233 * 234 * <p>During this operation, part of the file tree will be locked, mainly the source folder and 235 * all of its descendants, as well as the destination folder. 236 * 237 * <p>For the duration of the operation, no other move, copy, delete, or restore operation can 238 * performed on any of the locked folders. 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 restoreFolderFromTrash method 246 * @param queryParams Query parameters of restoreFolderFromTrash method 247 * @param headers Headers of restoreFolderFromTrash method 248 */ 249 public TrashFolderRestored restoreFolderFromTrash( 250 String folderId, 251 RestoreFolderFromTrashRequestBody requestBody, 252 RestoreFolderFromTrashQueryParams queryParams, 253 RestoreFolderFromTrashHeaders headers) { 254 Map<String, String> queryParamsMap = 255 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 256 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 257 FetchResponse response = 258 this.networkSession 259 .getNetworkClient() 260 .fetch( 261 new FetchOptions.Builder( 262 String.join( 263 "", 264 this.networkSession.getBaseUrls().getBaseUrl(), 265 "/2.0/folders/", 266 convertToString(folderId)), 267 "POST") 268 .params(queryParamsMap) 269 .headers(headersMap) 270 .data(JsonManager.serialize(requestBody)) 271 .contentType("application/json") 272 .responseFormat(ResponseFormat.JSON) 273 .auth(this.auth) 274 .networkSession(this.networkSession) 275 .build()); 276 return JsonManager.deserialize(response.getData(), TrashFolderRestored.class); 277 } 278 279 /** 280 * Retrieves a folder that has been moved to the trash. 281 * 282 * <p>Please note that only if the folder itself has been moved to the trash can it be retrieved 283 * with this API call. If instead one of its parent folders was moved to the trash, only that 284 * folder can be inspected using the [`GET 285 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 286 * 287 * <p>To list all items that have been moved to the trash, please use the [`GET 288 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 289 * 290 * @param folderId The unique identifier that represent a folder. 291 * <p>The ID for any folder can be determined by visiting this folder in the web application 292 * and copying the ID from the URL. For example, for the URL 293 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 294 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 295 */ 296 public TrashFolder getTrashedFolderById(String folderId) { 297 return getTrashedFolderById( 298 folderId, new GetTrashedFolderByIdQueryParams(), new GetTrashedFolderByIdHeaders()); 299 } 300 301 /** 302 * Retrieves a folder that has been moved to the trash. 303 * 304 * <p>Please note that only if the folder itself has been moved to the trash can it be retrieved 305 * with this API call. If instead one of its parent folders was moved to the trash, only that 306 * folder can be inspected using the [`GET 307 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 308 * 309 * <p>To list all items that have been moved to the trash, please use the [`GET 310 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 311 * 312 * @param folderId The unique identifier that represent a folder. 313 * <p>The ID for any folder can be determined by visiting this folder in the web application 314 * and copying the ID from the URL. For example, for the URL 315 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 316 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 317 * @param queryParams Query parameters of getTrashedFolderById method 318 */ 319 public TrashFolder getTrashedFolderById( 320 String folderId, GetTrashedFolderByIdQueryParams queryParams) { 321 return getTrashedFolderById(folderId, queryParams, new GetTrashedFolderByIdHeaders()); 322 } 323 324 /** 325 * Retrieves a folder that has been moved to the trash. 326 * 327 * <p>Please note that only if the folder itself has been moved to the trash can it be retrieved 328 * with this API call. If instead one of its parent folders was moved to the trash, only that 329 * folder can be inspected using the [`GET 330 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 331 * 332 * <p>To list all items that have been moved to the trash, please use the [`GET 333 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 334 * 335 * @param folderId The unique identifier that represent a folder. 336 * <p>The ID for any folder can be determined by visiting this folder in the web application 337 * and copying the ID from the URL. For example, for the URL 338 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 339 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 340 * @param headers Headers of getTrashedFolderById method 341 */ 342 public TrashFolder getTrashedFolderById(String folderId, GetTrashedFolderByIdHeaders headers) { 343 return getTrashedFolderById(folderId, new GetTrashedFolderByIdQueryParams(), headers); 344 } 345 346 /** 347 * Retrieves a folder that has been moved to the trash. 348 * 349 * <p>Please note that only if the folder itself has been moved to the trash can it be retrieved 350 * with this API call. If instead one of its parent folders was moved to the trash, only that 351 * folder can be inspected using the [`GET 352 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 353 * 354 * <p>To list all items that have been moved to the trash, please use the [`GET 355 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 356 * 357 * @param folderId The unique identifier that represent a folder. 358 * <p>The ID for any folder can be determined by visiting this folder in the web application 359 * and copying the ID from the URL. For example, for the URL 360 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 361 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 362 * @param queryParams Query parameters of getTrashedFolderById method 363 * @param headers Headers of getTrashedFolderById method 364 */ 365 public TrashFolder getTrashedFolderById( 366 String folderId, 367 GetTrashedFolderByIdQueryParams queryParams, 368 GetTrashedFolderByIdHeaders headers) { 369 Map<String, String> queryParamsMap = 370 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 371 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 372 FetchResponse response = 373 this.networkSession 374 .getNetworkClient() 375 .fetch( 376 new FetchOptions.Builder( 377 String.join( 378 "", 379 this.networkSession.getBaseUrls().getBaseUrl(), 380 "/2.0/folders/", 381 convertToString(folderId), 382 "/trash"), 383 "GET") 384 .params(queryParamsMap) 385 .headers(headersMap) 386 .responseFormat(ResponseFormat.JSON) 387 .auth(this.auth) 388 .networkSession(this.networkSession) 389 .build()); 390 return JsonManager.deserialize(response.getData(), TrashFolder.class); 391 } 392 393 /** 394 * Permanently deletes a folder that is in the trash. This action cannot be undone. 395 * 396 * @param folderId The unique identifier that represent a folder. 397 * <p>The ID for any folder can be determined by visiting this folder in the web application 398 * and copying the ID from the URL. For example, for the URL 399 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 400 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 401 */ 402 public void deleteTrashedFolderById(String folderId) { 403 deleteTrashedFolderById(folderId, new DeleteTrashedFolderByIdHeaders()); 404 } 405 406 /** 407 * Permanently deletes a folder that is in the trash. This action cannot be undone. 408 * 409 * @param folderId The unique identifier that represent a folder. 410 * <p>The ID for any folder can be determined by visiting this folder in the web application 411 * and copying the ID from the URL. For example, for the URL 412 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 413 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 414 * @param headers Headers of deleteTrashedFolderById method 415 */ 416 public void deleteTrashedFolderById(String folderId, DeleteTrashedFolderByIdHeaders headers) { 417 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 418 FetchResponse response = 419 this.networkSession 420 .getNetworkClient() 421 .fetch( 422 new FetchOptions.Builder( 423 String.join( 424 "", 425 this.networkSession.getBaseUrls().getBaseUrl(), 426 "/2.0/folders/", 427 convertToString(folderId), 428 "/trash"), 429 "DELETE") 430 .headers(headersMap) 431 .responseFormat(ResponseFormat.NO_CONTENT) 432 .auth(this.auth) 433 .networkSession(this.networkSession) 434 .build()); 435 } 436 437 public Authentication getAuth() { 438 return auth; 439 } 440 441 public NetworkSession getNetworkSession() { 442 return networkSession; 443 } 444 445 public static class Builder { 446 447 protected Authentication auth; 448 449 protected NetworkSession networkSession; 450 451 public Builder() {} 452 453 public Builder auth(Authentication auth) { 454 this.auth = auth; 455 return this; 456 } 457 458 public Builder networkSession(NetworkSession networkSession) { 459 this.networkSession = networkSession; 460 return this; 461 } 462 463 public TrashedFoldersManager build() { 464 if (this.networkSession == null) { 465 this.networkSession = new NetworkSession(); 466 } 467 return new TrashedFoldersManager(this); 468 } 469 } 470}