001package com.box.sdkgen.managers.storagepolicyassignments; 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.storagepolicyassignment.StoragePolicyAssignment; 015import com.box.sdkgen.schemas.storagepolicyassignments.StoragePolicyAssignments; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class StoragePolicyAssignmentsManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public StoragePolicyAssignmentsManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected StoragePolicyAssignmentsManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Fetches all the storage policy assignment for an enterprise or user. 036 * 037 * @param queryParams Query parameters of getStoragePolicyAssignments method 038 */ 039 public StoragePolicyAssignments getStoragePolicyAssignments( 040 GetStoragePolicyAssignmentsQueryParams queryParams) { 041 return getStoragePolicyAssignments(queryParams, new GetStoragePolicyAssignmentsHeaders()); 042 } 043 044 /** 045 * Fetches all the storage policy assignment for an enterprise or user. 046 * 047 * @param queryParams Query parameters of getStoragePolicyAssignments method 048 * @param headers Headers of getStoragePolicyAssignments method 049 */ 050 public StoragePolicyAssignments getStoragePolicyAssignments( 051 GetStoragePolicyAssignmentsQueryParams queryParams, 052 GetStoragePolicyAssignmentsHeaders headers) { 053 Map<String, String> queryParamsMap = 054 prepareParams( 055 mapOf( 056 entryOf("marker", convertToString(queryParams.getMarker())), 057 entryOf("resolved_for_type", convertToString(queryParams.getResolvedForType())), 058 entryOf("resolved_for_id", convertToString(queryParams.getResolvedForId())))); 059 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 060 FetchResponse response = 061 this.networkSession 062 .getNetworkClient() 063 .fetch( 064 new FetchOptions.Builder( 065 String.join( 066 "", 067 this.networkSession.getBaseUrls().getBaseUrl(), 068 "/2.0/storage_policy_assignments"), 069 "GET") 070 .params(queryParamsMap) 071 .headers(headersMap) 072 .responseFormat(ResponseFormat.JSON) 073 .auth(this.auth) 074 .networkSession(this.networkSession) 075 .build()); 076 return JsonManager.deserialize(response.getData(), StoragePolicyAssignments.class); 077 } 078 079 /** 080 * Creates a storage policy assignment for an enterprise or user. 081 * 082 * @param requestBody Request body of createStoragePolicyAssignment method 083 */ 084 public StoragePolicyAssignment createStoragePolicyAssignment( 085 CreateStoragePolicyAssignmentRequestBody requestBody) { 086 return createStoragePolicyAssignment(requestBody, new CreateStoragePolicyAssignmentHeaders()); 087 } 088 089 /** 090 * Creates a storage policy assignment for an enterprise or user. 091 * 092 * @param requestBody Request body of createStoragePolicyAssignment method 093 * @param headers Headers of createStoragePolicyAssignment method 094 */ 095 public StoragePolicyAssignment createStoragePolicyAssignment( 096 CreateStoragePolicyAssignmentRequestBody requestBody, 097 CreateStoragePolicyAssignmentHeaders headers) { 098 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 099 FetchResponse response = 100 this.networkSession 101 .getNetworkClient() 102 .fetch( 103 new FetchOptions.Builder( 104 String.join( 105 "", 106 this.networkSession.getBaseUrls().getBaseUrl(), 107 "/2.0/storage_policy_assignments"), 108 "POST") 109 .headers(headersMap) 110 .data(JsonManager.serialize(requestBody)) 111 .contentType("application/json") 112 .responseFormat(ResponseFormat.JSON) 113 .auth(this.auth) 114 .networkSession(this.networkSession) 115 .build()); 116 return JsonManager.deserialize(response.getData(), StoragePolicyAssignment.class); 117 } 118 119 /** 120 * Fetches a specific storage policy assignment. 121 * 122 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 123 */ 124 public StoragePolicyAssignment getStoragePolicyAssignmentById(String storagePolicyAssignmentId) { 125 return getStoragePolicyAssignmentById( 126 storagePolicyAssignmentId, new GetStoragePolicyAssignmentByIdHeaders()); 127 } 128 129 /** 130 * Fetches a specific storage policy assignment. 131 * 132 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 133 * @param headers Headers of getStoragePolicyAssignmentById method 134 */ 135 public StoragePolicyAssignment getStoragePolicyAssignmentById( 136 String storagePolicyAssignmentId, GetStoragePolicyAssignmentByIdHeaders headers) { 137 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 138 FetchResponse response = 139 this.networkSession 140 .getNetworkClient() 141 .fetch( 142 new FetchOptions.Builder( 143 String.join( 144 "", 145 this.networkSession.getBaseUrls().getBaseUrl(), 146 "/2.0/storage_policy_assignments/", 147 convertToString(storagePolicyAssignmentId)), 148 "GET") 149 .headers(headersMap) 150 .responseFormat(ResponseFormat.JSON) 151 .auth(this.auth) 152 .networkSession(this.networkSession) 153 .build()); 154 return JsonManager.deserialize(response.getData(), StoragePolicyAssignment.class); 155 } 156 157 /** 158 * Updates a specific storage policy assignment. 159 * 160 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 161 * @param requestBody Request body of updateStoragePolicyAssignmentById method 162 */ 163 public StoragePolicyAssignment updateStoragePolicyAssignmentById( 164 String storagePolicyAssignmentId, UpdateStoragePolicyAssignmentByIdRequestBody requestBody) { 165 return updateStoragePolicyAssignmentById( 166 storagePolicyAssignmentId, requestBody, new UpdateStoragePolicyAssignmentByIdHeaders()); 167 } 168 169 /** 170 * Updates a specific storage policy assignment. 171 * 172 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 173 * @param requestBody Request body of updateStoragePolicyAssignmentById method 174 * @param headers Headers of updateStoragePolicyAssignmentById method 175 */ 176 public StoragePolicyAssignment updateStoragePolicyAssignmentById( 177 String storagePolicyAssignmentId, 178 UpdateStoragePolicyAssignmentByIdRequestBody requestBody, 179 UpdateStoragePolicyAssignmentByIdHeaders headers) { 180 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 181 FetchResponse response = 182 this.networkSession 183 .getNetworkClient() 184 .fetch( 185 new FetchOptions.Builder( 186 String.join( 187 "", 188 this.networkSession.getBaseUrls().getBaseUrl(), 189 "/2.0/storage_policy_assignments/", 190 convertToString(storagePolicyAssignmentId)), 191 "PUT") 192 .headers(headersMap) 193 .data(JsonManager.serialize(requestBody)) 194 .contentType("application/json") 195 .responseFormat(ResponseFormat.JSON) 196 .auth(this.auth) 197 .networkSession(this.networkSession) 198 .build()); 199 return JsonManager.deserialize(response.getData(), StoragePolicyAssignment.class); 200 } 201 202 /** 203 * Delete a storage policy assignment. 204 * 205 * <p>Deleting a storage policy assignment on a user will have the user inherit the enterprise's 206 * default storage policy. 207 * 208 * <p>There is a rate limit for calling this endpoint of only twice per user in a 24 hour time 209 * frame. 210 * 211 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 212 */ 213 public void deleteStoragePolicyAssignmentById(String storagePolicyAssignmentId) { 214 deleteStoragePolicyAssignmentById( 215 storagePolicyAssignmentId, new DeleteStoragePolicyAssignmentByIdHeaders()); 216 } 217 218 /** 219 * Delete a storage policy assignment. 220 * 221 * <p>Deleting a storage policy assignment on a user will have the user inherit the enterprise's 222 * default storage policy. 223 * 224 * <p>There is a rate limit for calling this endpoint of only twice per user in a 24 hour time 225 * frame. 226 * 227 * @param storagePolicyAssignmentId The ID of the storage policy assignment. Example: "932483" 228 * @param headers Headers of deleteStoragePolicyAssignmentById method 229 */ 230 public void deleteStoragePolicyAssignmentById( 231 String storagePolicyAssignmentId, DeleteStoragePolicyAssignmentByIdHeaders headers) { 232 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 233 FetchResponse response = 234 this.networkSession 235 .getNetworkClient() 236 .fetch( 237 new FetchOptions.Builder( 238 String.join( 239 "", 240 this.networkSession.getBaseUrls().getBaseUrl(), 241 "/2.0/storage_policy_assignments/", 242 convertToString(storagePolicyAssignmentId)), 243 "DELETE") 244 .headers(headersMap) 245 .responseFormat(ResponseFormat.NO_CONTENT) 246 .auth(this.auth) 247 .networkSession(this.networkSession) 248 .build()); 249 } 250 251 public Authentication getAuth() { 252 return auth; 253 } 254 255 public NetworkSession getNetworkSession() { 256 return networkSession; 257 } 258 259 public static class Builder { 260 261 protected Authentication auth; 262 263 protected NetworkSession networkSession; 264 265 public Builder() {} 266 267 public Builder auth(Authentication auth) { 268 this.auth = auth; 269 return this; 270 } 271 272 public Builder networkSession(NetworkSession networkSession) { 273 this.networkSession = networkSession; 274 return this; 275 } 276 277 public StoragePolicyAssignmentsManager build() { 278 if (this.networkSession == null) { 279 this.networkSession = new NetworkSession(); 280 } 281 return new StoragePolicyAssignmentsManager(this); 282 } 283 } 284}