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