001package com.box.sdkgen.managers.folderclassifications; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 006import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 007 008import com.box.sdkgen.networking.auth.Authentication; 009import com.box.sdkgen.networking.fetchoptions.FetchOptions; 010import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 011import com.box.sdkgen.networking.fetchresponse.FetchResponse; 012import com.box.sdkgen.networking.network.NetworkSession; 013import com.box.sdkgen.schemas.classification.Classification; 014import com.box.sdkgen.serialization.json.JsonManager; 015import java.util.List; 016import java.util.Map; 017 018public class FolderClassificationsManager { 019 020 public Authentication auth; 021 022 public NetworkSession networkSession; 023 024 public FolderClassificationsManager() { 025 this.networkSession = new NetworkSession(); 026 } 027 028 protected FolderClassificationsManager(Builder builder) { 029 this.auth = builder.auth; 030 this.networkSession = builder.networkSession; 031 } 032 033 /** 034 * Retrieves the classification metadata instance that has been applied to a folder. 035 * 036 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 037 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 038 * 039 * @param folderId The unique identifier that represent a folder. 040 * <p>The ID for any folder can be determined by visiting this folder in the web application 041 * and copying the ID from the URL. For example, for the URL 042 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 043 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 044 */ 045 public Classification getClassificationOnFolder(String folderId) { 046 return getClassificationOnFolder(folderId, new GetClassificationOnFolderHeaders()); 047 } 048 049 /** 050 * Retrieves the classification metadata instance that has been applied to a folder. 051 * 052 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 053 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 054 * 055 * @param folderId The unique identifier that represent a folder. 056 * <p>The ID for any folder can be determined by visiting this folder in the web application 057 * and copying the ID from the URL. For example, for the URL 058 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 059 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 060 * @param headers Headers of getClassificationOnFolder method 061 */ 062 public Classification getClassificationOnFolder( 063 String folderId, GetClassificationOnFolderHeaders headers) { 064 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 065 FetchResponse response = 066 this.networkSession 067 .getNetworkClient() 068 .fetch( 069 new FetchOptions.Builder( 070 String.join( 071 "", 072 this.networkSession.getBaseUrls().getBaseUrl(), 073 "/2.0/folders/", 074 convertToString(folderId), 075 "/metadata/enterprise/securityClassification-6VMVochwUWo"), 076 "GET") 077 .headers(headersMap) 078 .responseFormat(ResponseFormat.JSON) 079 .auth(this.auth) 080 .networkSession(this.networkSession) 081 .build()); 082 return JsonManager.deserialize(response.getData(), Classification.class); 083 } 084 085 /** 086 * Adds a classification to a folder by specifying the label of the classification to add. 087 * 088 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 089 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 090 * 091 * @param folderId The unique identifier that represent a folder. 092 * <p>The ID for any folder can be determined by visiting this folder in the web application 093 * and copying the ID from the URL. For example, for the URL 094 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 095 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 096 */ 097 public Classification addClassificationToFolder(String folderId) { 098 return addClassificationToFolder( 099 folderId, 100 new AddClassificationToFolderRequestBody(), 101 new AddClassificationToFolderHeaders()); 102 } 103 104 /** 105 * Adds a classification to a folder by specifying the label of the classification to add. 106 * 107 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 108 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 109 * 110 * @param folderId The unique identifier that represent a folder. 111 * <p>The ID for any folder can be determined by visiting this folder in the web application 112 * and copying the ID from the URL. For example, for the URL 113 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 114 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 115 * @param requestBody Request body of addClassificationToFolder method 116 */ 117 public Classification addClassificationToFolder( 118 String folderId, AddClassificationToFolderRequestBody requestBody) { 119 return addClassificationToFolder(folderId, requestBody, new AddClassificationToFolderHeaders()); 120 } 121 122 /** 123 * Adds a classification to a folder by specifying the label of the classification to add. 124 * 125 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 126 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 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 headers Headers of addClassificationToFolder method 134 */ 135 public Classification addClassificationToFolder( 136 String folderId, AddClassificationToFolderHeaders headers) { 137 return addClassificationToFolder(folderId, new AddClassificationToFolderRequestBody(), headers); 138 } 139 140 /** 141 * Adds a classification to a folder by specifying the label of the classification to add. 142 * 143 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 144 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 145 * 146 * @param folderId The unique identifier that represent a folder. 147 * <p>The ID for any folder can be determined by visiting this folder in the web application 148 * and copying the ID from the URL. For example, for the URL 149 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 150 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 151 * @param requestBody Request body of addClassificationToFolder method 152 * @param headers Headers of addClassificationToFolder method 153 */ 154 public Classification addClassificationToFolder( 155 String folderId, 156 AddClassificationToFolderRequestBody requestBody, 157 AddClassificationToFolderHeaders headers) { 158 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 159 FetchResponse response = 160 this.networkSession 161 .getNetworkClient() 162 .fetch( 163 new FetchOptions.Builder( 164 String.join( 165 "", 166 this.networkSession.getBaseUrls().getBaseUrl(), 167 "/2.0/folders/", 168 convertToString(folderId), 169 "/metadata/enterprise/securityClassification-6VMVochwUWo"), 170 "POST") 171 .headers(headersMap) 172 .data(JsonManager.serialize(requestBody)) 173 .contentType("application/json") 174 .responseFormat(ResponseFormat.JSON) 175 .auth(this.auth) 176 .networkSession(this.networkSession) 177 .build()); 178 return JsonManager.deserialize(response.getData(), Classification.class); 179 } 180 181 /** 182 * Updates a classification on a folder. 183 * 184 * <p>The classification can only be updated if a classification has already been applied to the 185 * folder before. When editing classifications, only values are defined for the enterprise will be 186 * accepted. 187 * 188 * @param folderId The unique identifier that represent a folder. 189 * <p>The ID for any folder can be determined by visiting this folder in the web application 190 * and copying the ID from the URL. For example, for the URL 191 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 192 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 193 * @param requestBody Request body of updateClassificationOnFolder method 194 */ 195 public Classification updateClassificationOnFolder( 196 String folderId, List<UpdateClassificationOnFolderRequestBody> requestBody) { 197 return updateClassificationOnFolder( 198 folderId, requestBody, new UpdateClassificationOnFolderHeaders()); 199 } 200 201 /** 202 * Updates a classification on a folder. 203 * 204 * <p>The classification can only be updated if a classification has already been applied to the 205 * folder before. When editing classifications, only values are defined for the enterprise will be 206 * accepted. 207 * 208 * @param folderId The unique identifier that represent a folder. 209 * <p>The ID for any folder can be determined by visiting this folder in the web application 210 * and copying the ID from the URL. For example, for the URL 211 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 212 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 213 * @param requestBody Request body of updateClassificationOnFolder method 214 * @param headers Headers of updateClassificationOnFolder method 215 */ 216 public Classification updateClassificationOnFolder( 217 String folderId, 218 List<UpdateClassificationOnFolderRequestBody> requestBody, 219 UpdateClassificationOnFolderHeaders headers) { 220 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 221 FetchResponse response = 222 this.networkSession 223 .getNetworkClient() 224 .fetch( 225 new FetchOptions.Builder( 226 String.join( 227 "", 228 this.networkSession.getBaseUrls().getBaseUrl(), 229 "/2.0/folders/", 230 convertToString(folderId), 231 "/metadata/enterprise/securityClassification-6VMVochwUWo"), 232 "PUT") 233 .headers(headersMap) 234 .data(JsonManager.serialize(requestBody)) 235 .contentType("application/json-patch+json") 236 .responseFormat(ResponseFormat.JSON) 237 .auth(this.auth) 238 .networkSession(this.networkSession) 239 .build()); 240 return JsonManager.deserialize(response.getData(), Classification.class); 241 } 242 243 /** 244 * Removes any classifications from a folder. 245 * 246 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 247 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 248 * 249 * @param folderId The unique identifier that represent a folder. 250 * <p>The ID for any folder can be determined by visiting this folder in the web application 251 * and copying the ID from the URL. For example, for the URL 252 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 253 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 254 */ 255 public void deleteClassificationFromFolder(String folderId) { 256 deleteClassificationFromFolder(folderId, new DeleteClassificationFromFolderHeaders()); 257 } 258 259 /** 260 * Removes any classifications from a folder. 261 * 262 * <p>This API can also be called by including the enterprise ID in the URL explicitly, for 263 * example `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`. 264 * 265 * @param folderId The unique identifier that represent a folder. 266 * <p>The ID for any folder can be determined by visiting this folder in the web application 267 * and copying the ID from the URL. For example, for the URL 268 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 269 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 270 * @param headers Headers of deleteClassificationFromFolder method 271 */ 272 public void deleteClassificationFromFolder( 273 String folderId, DeleteClassificationFromFolderHeaders headers) { 274 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 275 FetchResponse response = 276 this.networkSession 277 .getNetworkClient() 278 .fetch( 279 new FetchOptions.Builder( 280 String.join( 281 "", 282 this.networkSession.getBaseUrls().getBaseUrl(), 283 "/2.0/folders/", 284 convertToString(folderId), 285 "/metadata/enterprise/securityClassification-6VMVochwUWo"), 286 "DELETE") 287 .headers(headersMap) 288 .responseFormat(ResponseFormat.NO_CONTENT) 289 .auth(this.auth) 290 .networkSession(this.networkSession) 291 .build()); 292 } 293 294 public Authentication getAuth() { 295 return auth; 296 } 297 298 public NetworkSession getNetworkSession() { 299 return networkSession; 300 } 301 302 public static class Builder { 303 304 protected Authentication auth; 305 306 protected NetworkSession networkSession; 307 308 public Builder() {} 309 310 public Builder auth(Authentication auth) { 311 this.auth = auth; 312 return this; 313 } 314 315 public Builder networkSession(NetworkSession networkSession) { 316 this.networkSession = networkSession; 317 return this; 318 } 319 320 public FolderClassificationsManager build() { 321 if (this.networkSession == null) { 322 this.networkSession = new NetworkSession(); 323 } 324 return new FolderClassificationsManager(this); 325 } 326 } 327}