001package com.box.sdkgen.managers.trasheditems; 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.items.Items; 015import com.box.sdkgen.serialization.json.JsonManager; 016import java.util.Map; 017 018public class TrashedItemsManager { 019 020 public Authentication auth; 021 022 public NetworkSession networkSession; 023 024 public TrashedItemsManager() { 025 this.networkSession = new NetworkSession(); 026 } 027 028 protected TrashedItemsManager(Builder builder) { 029 this.auth = builder.auth; 030 this.networkSession = builder.networkSession; 031 } 032 033 /** 034 * Retrieves the files and folders that have been moved to the trash. 035 * 036 * <p>Any attribute in the full files or folders objects can be passed in with the `fields` 037 * parameter to retrieve those specific attributes that are not returned by default. 038 * 039 * <p>This endpoint defaults to use offset-based pagination, yet also supports marker-based 040 * pagination using the `marker` parameter. 041 * 042 * <p>The number of entries returned may be less than `total_count`. For example, if a user 043 * deletes items from a shared folder and is later removed as a collaborator, those deleted items 044 * will no longer appear in this endpoint’s results, even though they are still included in 045 * `total_count`. 046 */ 047 public Items getTrashedItems() { 048 return getTrashedItems(new GetTrashedItemsQueryParams(), new GetTrashedItemsHeaders()); 049 } 050 051 /** 052 * Retrieves the files and folders that have been moved to the trash. 053 * 054 * <p>Any attribute in the full files or folders objects can be passed in with the `fields` 055 * parameter to retrieve those specific attributes that are not returned by default. 056 * 057 * <p>This endpoint defaults to use offset-based pagination, yet also supports marker-based 058 * pagination using the `marker` parameter. 059 * 060 * <p>The number of entries returned may be less than `total_count`. For example, if a user 061 * deletes items from a shared folder and is later removed as a collaborator, those deleted items 062 * will no longer appear in this endpoint’s results, even though they are still included in 063 * `total_count`. 064 * 065 * @param queryParams Query parameters of getTrashedItems method 066 */ 067 public Items getTrashedItems(GetTrashedItemsQueryParams queryParams) { 068 return getTrashedItems(queryParams, new GetTrashedItemsHeaders()); 069 } 070 071 /** 072 * Retrieves the files and folders that have been moved to the trash. 073 * 074 * <p>Any attribute in the full files or folders objects can be passed in with the `fields` 075 * parameter to retrieve those specific attributes that are not returned by default. 076 * 077 * <p>This endpoint defaults to use offset-based pagination, yet also supports marker-based 078 * pagination using the `marker` parameter. 079 * 080 * <p>The number of entries returned may be less than `total_count`. For example, if a user 081 * deletes items from a shared folder and is later removed as a collaborator, those deleted items 082 * will no longer appear in this endpoint’s results, even though they are still included in 083 * `total_count`. 084 * 085 * @param headers Headers of getTrashedItems method 086 */ 087 public Items getTrashedItems(GetTrashedItemsHeaders headers) { 088 return getTrashedItems(new GetTrashedItemsQueryParams(), headers); 089 } 090 091 /** 092 * Retrieves the files and folders that have been moved to the trash. 093 * 094 * <p>Any attribute in the full files or folders objects can be passed in with the `fields` 095 * parameter to retrieve those specific attributes that are not returned by default. 096 * 097 * <p>This endpoint defaults to use offset-based pagination, yet also supports marker-based 098 * pagination using the `marker` parameter. 099 * 100 * <p>The number of entries returned may be less than `total_count`. For example, if a user 101 * deletes items from a shared folder and is later removed as a collaborator, those deleted items 102 * will no longer appear in this endpoint’s results, even though they are still included in 103 * `total_count`. 104 * 105 * @param queryParams Query parameters of getTrashedItems method 106 * @param headers Headers of getTrashedItems method 107 */ 108 public Items getTrashedItems( 109 GetTrashedItemsQueryParams queryParams, GetTrashedItemsHeaders headers) { 110 Map<String, String> queryParamsMap = 111 prepareParams( 112 mapOf( 113 entryOf("fields", convertToString(queryParams.getFields())), 114 entryOf("limit", convertToString(queryParams.getLimit())), 115 entryOf("offset", convertToString(queryParams.getOffset())), 116 entryOf("usemarker", convertToString(queryParams.getUsemarker())), 117 entryOf("marker", convertToString(queryParams.getMarker())), 118 entryOf("direction", convertToString(queryParams.getDirection())), 119 entryOf("sort", convertToString(queryParams.getSort())))); 120 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 121 FetchResponse response = 122 this.networkSession 123 .getNetworkClient() 124 .fetch( 125 new FetchOptions.Builder( 126 String.join( 127 "", 128 this.networkSession.getBaseUrls().getBaseUrl(), 129 "/2.0/folders/trash/items"), 130 "GET") 131 .params(queryParamsMap) 132 .headers(headersMap) 133 .responseFormat(ResponseFormat.JSON) 134 .auth(this.auth) 135 .networkSession(this.networkSession) 136 .build()); 137 return JsonManager.deserialize(response.getData(), Items.class); 138 } 139 140 public Authentication getAuth() { 141 return auth; 142 } 143 144 public NetworkSession getNetworkSession() { 145 return networkSession; 146 } 147 148 public static class Builder { 149 150 protected Authentication auth; 151 152 protected NetworkSession networkSession; 153 154 public Builder() {} 155 156 public Builder auth(Authentication auth) { 157 this.auth = auth; 158 return this; 159 } 160 161 public Builder networkSession(NetworkSession networkSession) { 162 this.networkSession = networkSession; 163 return this; 164 } 165 166 public TrashedItemsManager build() { 167 if (this.networkSession == null) { 168 this.networkSession = new NetworkSession(); 169 } 170 return new TrashedItemsManager(this); 171 } 172 } 173}