001package com.box.sdkgen.managers.trashedfiles; 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.trashfile.TrashFile; 015import com.box.sdkgen.schemas.trashfilerestored.TrashFileRestored; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class TrashedFilesManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public TrashedFilesManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected TrashedFilesManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Restores a file that has been moved to the trash. 036 * 037 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 038 * has been deleted. 039 * 040 * @param fileId The unique identifier that represents a file. 041 * <p>The ID for any file can be determined by visiting a file in the web application and 042 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 043 * `file_id` is `123`. Example: "12345" 044 */ 045 public TrashFileRestored restoreFileFromTrash(String fileId) { 046 return restoreFileFromTrash( 047 fileId, 048 new RestoreFileFromTrashRequestBody(), 049 new RestoreFileFromTrashQueryParams(), 050 new RestoreFileFromTrashHeaders()); 051 } 052 053 /** 054 * Restores a file that has been moved to the trash. 055 * 056 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 057 * has been deleted. 058 * 059 * @param fileId The unique identifier that represents a file. 060 * <p>The ID for any file can be determined by visiting a file in the web application and 061 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 062 * `file_id` is `123`. Example: "12345" 063 * @param requestBody Request body of restoreFileFromTrash method 064 */ 065 public TrashFileRestored restoreFileFromTrash( 066 String fileId, RestoreFileFromTrashRequestBody requestBody) { 067 return restoreFileFromTrash( 068 fileId, 069 requestBody, 070 new RestoreFileFromTrashQueryParams(), 071 new RestoreFileFromTrashHeaders()); 072 } 073 074 /** 075 * Restores a file that has been moved to the trash. 076 * 077 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 078 * has been deleted. 079 * 080 * @param fileId The unique identifier that represents a file. 081 * <p>The ID for any file can be determined by visiting a file in the web application and 082 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 083 * `file_id` is `123`. Example: "12345" 084 * @param queryParams Query parameters of restoreFileFromTrash method 085 */ 086 public TrashFileRestored restoreFileFromTrash( 087 String fileId, RestoreFileFromTrashQueryParams queryParams) { 088 return restoreFileFromTrash( 089 fileId, 090 new RestoreFileFromTrashRequestBody(), 091 queryParams, 092 new RestoreFileFromTrashHeaders()); 093 } 094 095 /** 096 * Restores a file that has been moved to the trash. 097 * 098 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 099 * has been deleted. 100 * 101 * @param fileId The unique identifier that represents a file. 102 * <p>The ID for any file can be determined by visiting a file in the web application and 103 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 104 * `file_id` is `123`. Example: "12345" 105 * @param requestBody Request body of restoreFileFromTrash method 106 * @param queryParams Query parameters of restoreFileFromTrash method 107 */ 108 public TrashFileRestored restoreFileFromTrash( 109 String fileId, 110 RestoreFileFromTrashRequestBody requestBody, 111 RestoreFileFromTrashQueryParams queryParams) { 112 return restoreFileFromTrash( 113 fileId, requestBody, queryParams, new RestoreFileFromTrashHeaders()); 114 } 115 116 /** 117 * Restores a file that has been moved to the trash. 118 * 119 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 120 * has been deleted. 121 * 122 * @param fileId The unique identifier that represents a file. 123 * <p>The ID for any file can be determined by visiting a file in the web application and 124 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 125 * `file_id` is `123`. Example: "12345" 126 * @param headers Headers of restoreFileFromTrash method 127 */ 128 public TrashFileRestored restoreFileFromTrash( 129 String fileId, RestoreFileFromTrashHeaders headers) { 130 return restoreFileFromTrash( 131 fileId, 132 new RestoreFileFromTrashRequestBody(), 133 new RestoreFileFromTrashQueryParams(), 134 headers); 135 } 136 137 /** 138 * Restores a file that has been moved to the trash. 139 * 140 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 141 * has been deleted. 142 * 143 * @param fileId The unique identifier that represents a file. 144 * <p>The ID for any file can be determined by visiting a file in the web application and 145 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 146 * `file_id` is `123`. Example: "12345" 147 * @param requestBody Request body of restoreFileFromTrash method 148 * @param headers Headers of restoreFileFromTrash method 149 */ 150 public TrashFileRestored restoreFileFromTrash( 151 String fileId, 152 RestoreFileFromTrashRequestBody requestBody, 153 RestoreFileFromTrashHeaders headers) { 154 return restoreFileFromTrash( 155 fileId, requestBody, new RestoreFileFromTrashQueryParams(), headers); 156 } 157 158 /** 159 * Restores a file that has been moved to the trash. 160 * 161 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 162 * has been deleted. 163 * 164 * @param fileId The unique identifier that represents a file. 165 * <p>The ID for any file can be determined by visiting a file in the web application and 166 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 167 * `file_id` is `123`. Example: "12345" 168 * @param queryParams Query parameters of restoreFileFromTrash method 169 * @param headers Headers of restoreFileFromTrash method 170 */ 171 public TrashFileRestored restoreFileFromTrash( 172 String fileId, 173 RestoreFileFromTrashQueryParams queryParams, 174 RestoreFileFromTrashHeaders headers) { 175 return restoreFileFromTrash( 176 fileId, new RestoreFileFromTrashRequestBody(), queryParams, headers); 177 } 178 179 /** 180 * Restores a file that has been moved to the trash. 181 * 182 * <p>An optional new parent ID can be provided to restore the file to in case the original folder 183 * has been deleted. 184 * 185 * @param fileId The unique identifier that represents a file. 186 * <p>The ID for any file can be determined by visiting a file in the web application and 187 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 188 * `file_id` is `123`. Example: "12345" 189 * @param requestBody Request body of restoreFileFromTrash method 190 * @param queryParams Query parameters of restoreFileFromTrash method 191 * @param headers Headers of restoreFileFromTrash method 192 */ 193 public TrashFileRestored restoreFileFromTrash( 194 String fileId, 195 RestoreFileFromTrashRequestBody requestBody, 196 RestoreFileFromTrashQueryParams queryParams, 197 RestoreFileFromTrashHeaders headers) { 198 Map<String, String> queryParamsMap = 199 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 200 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 201 FetchResponse response = 202 this.networkSession 203 .getNetworkClient() 204 .fetch( 205 new FetchOptions.Builder( 206 String.join( 207 "", 208 this.networkSession.getBaseUrls().getBaseUrl(), 209 "/2.0/files/", 210 convertToString(fileId)), 211 "POST") 212 .params(queryParamsMap) 213 .headers(headersMap) 214 .data(JsonManager.serialize(requestBody)) 215 .contentType("application/json") 216 .responseFormat(ResponseFormat.JSON) 217 .auth(this.auth) 218 .networkSession(this.networkSession) 219 .build()); 220 return JsonManager.deserialize(response.getData(), TrashFileRestored.class); 221 } 222 223 /** 224 * Retrieves a file that has been moved to the trash. 225 * 226 * <p>Please note that only if the file itself has been moved to the trash can it be retrieved 227 * with this API call. If instead one of its parent folders was moved to the trash, only that 228 * folder can be inspected using the [`GET 229 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 230 * 231 * <p>To list all items that have been moved to the trash, please use the [`GET 232 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 233 * 234 * @param fileId The unique identifier that represents a file. 235 * <p>The ID for any file can be determined by visiting a file in the web application and 236 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 237 * `file_id` is `123`. Example: "12345" 238 */ 239 public TrashFile getTrashedFileById(String fileId) { 240 return getTrashedFileById( 241 fileId, new GetTrashedFileByIdQueryParams(), new GetTrashedFileByIdHeaders()); 242 } 243 244 /** 245 * Retrieves a file that has been moved to the trash. 246 * 247 * <p>Please note that only if the file itself has been moved to the trash can it be retrieved 248 * with this API call. If instead one of its parent folders was moved to the trash, only that 249 * folder can be inspected using the [`GET 250 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 251 * 252 * <p>To list all items that have been moved to the trash, please use the [`GET 253 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 254 * 255 * @param fileId The unique identifier that represents a file. 256 * <p>The ID for any file can be determined by visiting a file in the web application and 257 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 258 * `file_id` is `123`. Example: "12345" 259 * @param queryParams Query parameters of getTrashedFileById method 260 */ 261 public TrashFile getTrashedFileById(String fileId, GetTrashedFileByIdQueryParams queryParams) { 262 return getTrashedFileById(fileId, queryParams, new GetTrashedFileByIdHeaders()); 263 } 264 265 /** 266 * Retrieves a file that has been moved to the trash. 267 * 268 * <p>Please note that only if the file itself has been moved to the trash can it be retrieved 269 * with this API call. If instead one of its parent folders was moved to the trash, only that 270 * folder can be inspected using the [`GET 271 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 272 * 273 * <p>To list all items that have been moved to the trash, please use the [`GET 274 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 275 * 276 * @param fileId The unique identifier that represents a file. 277 * <p>The ID for any file can be determined by visiting a file in the web application and 278 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 279 * `file_id` is `123`. Example: "12345" 280 * @param headers Headers of getTrashedFileById method 281 */ 282 public TrashFile getTrashedFileById(String fileId, GetTrashedFileByIdHeaders headers) { 283 return getTrashedFileById(fileId, new GetTrashedFileByIdQueryParams(), headers); 284 } 285 286 /** 287 * Retrieves a file that has been moved to the trash. 288 * 289 * <p>Please note that only if the file itself has been moved to the trash can it be retrieved 290 * with this API call. If instead one of its parent folders was moved to the trash, only that 291 * folder can be inspected using the [`GET 292 * /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API. 293 * 294 * <p>To list all items that have been moved to the trash, please use the [`GET 295 * /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/) API. 296 * 297 * @param fileId The unique identifier that represents a file. 298 * <p>The ID for any file can be determined by visiting a file in the web application and 299 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 300 * `file_id` is `123`. Example: "12345" 301 * @param queryParams Query parameters of getTrashedFileById method 302 * @param headers Headers of getTrashedFileById method 303 */ 304 public TrashFile getTrashedFileById( 305 String fileId, GetTrashedFileByIdQueryParams queryParams, GetTrashedFileByIdHeaders headers) { 306 Map<String, String> queryParamsMap = 307 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 308 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 309 FetchResponse response = 310 this.networkSession 311 .getNetworkClient() 312 .fetch( 313 new FetchOptions.Builder( 314 String.join( 315 "", 316 this.networkSession.getBaseUrls().getBaseUrl(), 317 "/2.0/files/", 318 convertToString(fileId), 319 "/trash"), 320 "GET") 321 .params(queryParamsMap) 322 .headers(headersMap) 323 .responseFormat(ResponseFormat.JSON) 324 .auth(this.auth) 325 .networkSession(this.networkSession) 326 .build()); 327 return JsonManager.deserialize(response.getData(), TrashFile.class); 328 } 329 330 /** 331 * Permanently deletes a file that is in the trash. This action cannot be undone. 332 * 333 * @param fileId The unique identifier that represents a file. 334 * <p>The ID for any file can be determined by visiting a file in the web application and 335 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 336 * `file_id` is `123`. Example: "12345" 337 */ 338 public void deleteTrashedFileById(String fileId) { 339 deleteTrashedFileById(fileId, new DeleteTrashedFileByIdHeaders()); 340 } 341 342 /** 343 * Permanently deletes a file that is in the trash. This action cannot be undone. 344 * 345 * @param fileId The unique identifier that represents a file. 346 * <p>The ID for any file can be determined by visiting a file in the web application and 347 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 348 * `file_id` is `123`. Example: "12345" 349 * @param headers Headers of deleteTrashedFileById method 350 */ 351 public void deleteTrashedFileById(String fileId, DeleteTrashedFileByIdHeaders headers) { 352 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 353 FetchResponse response = 354 this.networkSession 355 .getNetworkClient() 356 .fetch( 357 new FetchOptions.Builder( 358 String.join( 359 "", 360 this.networkSession.getBaseUrls().getBaseUrl(), 361 "/2.0/files/", 362 convertToString(fileId), 363 "/trash"), 364 "DELETE") 365 .headers(headersMap) 366 .responseFormat(ResponseFormat.NO_CONTENT) 367 .auth(this.auth) 368 .networkSession(this.networkSession) 369 .build()); 370 } 371 372 public Authentication getAuth() { 373 return auth; 374 } 375 376 public NetworkSession getNetworkSession() { 377 return networkSession; 378 } 379 380 public static class Builder { 381 382 protected Authentication auth; 383 384 protected NetworkSession networkSession; 385 386 public Builder() {} 387 388 public Builder auth(Authentication auth) { 389 this.auth = auth; 390 return this; 391 } 392 393 public Builder networkSession(NetworkSession networkSession) { 394 this.networkSession = networkSession; 395 return this; 396 } 397 398 public TrashedFilesManager build() { 399 if (this.networkSession == null) { 400 this.networkSession = new NetworkSession(); 401 } 402 return new TrashedFilesManager(this); 403 } 404 } 405}