001package com.box.sdkgen.managers.skills; 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.skillcardsmetadata.SkillCardsMetadata; 014import com.box.sdkgen.serialization.json.JsonManager; 015import java.util.List; 016import java.util.Map; 017 018public class SkillsManager { 019 020 public Authentication auth; 021 022 public NetworkSession networkSession; 023 024 public SkillsManager() { 025 this.networkSession = new NetworkSession(); 026 } 027 028 protected SkillsManager(Builder builder) { 029 this.auth = builder.auth; 030 this.networkSession = builder.networkSession; 031 } 032 033 /** 034 * List the Box Skills metadata cards that are attached to a file. 035 * 036 * @param fileId The unique identifier that represents a file. 037 * <p>The ID for any file can be determined by visiting a file in the web application and 038 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 039 * `file_id` is `123`. Example: "12345" 040 */ 041 public SkillCardsMetadata getBoxSkillCardsOnFile(String fileId) { 042 return getBoxSkillCardsOnFile(fileId, new GetBoxSkillCardsOnFileHeaders()); 043 } 044 045 /** 046 * List the Box Skills metadata cards that are attached to a file. 047 * 048 * @param fileId The unique identifier that represents a file. 049 * <p>The ID for any file can be determined by visiting a file in the web application and 050 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 051 * `file_id` is `123`. Example: "12345" 052 * @param headers Headers of getBoxSkillCardsOnFile method 053 */ 054 public SkillCardsMetadata getBoxSkillCardsOnFile( 055 String fileId, GetBoxSkillCardsOnFileHeaders headers) { 056 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 057 FetchResponse response = 058 this.networkSession 059 .getNetworkClient() 060 .fetch( 061 new FetchOptions.Builder( 062 String.join( 063 "", 064 this.networkSession.getBaseUrls().getBaseUrl(), 065 "/2.0/files/", 066 convertToString(fileId), 067 "/metadata/global/boxSkillsCards"), 068 "GET") 069 .headers(headersMap) 070 .responseFormat(ResponseFormat.JSON) 071 .auth(this.auth) 072 .networkSession(this.networkSession) 073 .build()); 074 return JsonManager.deserialize(response.getData(), SkillCardsMetadata.class); 075 } 076 077 /** 078 * Applies one or more Box Skills metadata cards to a file. 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 requestBody Request body of createBoxSkillCardsOnFile method 085 */ 086 public SkillCardsMetadata createBoxSkillCardsOnFile( 087 String fileId, CreateBoxSkillCardsOnFileRequestBody requestBody) { 088 return createBoxSkillCardsOnFile(fileId, requestBody, new CreateBoxSkillCardsOnFileHeaders()); 089 } 090 091 /** 092 * Applies one or more Box Skills metadata cards to a file. 093 * 094 * @param fileId The unique identifier that represents a file. 095 * <p>The ID for any file can be determined by visiting a file in the web application and 096 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 097 * `file_id` is `123`. Example: "12345" 098 * @param requestBody Request body of createBoxSkillCardsOnFile method 099 * @param headers Headers of createBoxSkillCardsOnFile method 100 */ 101 public SkillCardsMetadata createBoxSkillCardsOnFile( 102 String fileId, 103 CreateBoxSkillCardsOnFileRequestBody requestBody, 104 CreateBoxSkillCardsOnFileHeaders headers) { 105 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 106 FetchResponse response = 107 this.networkSession 108 .getNetworkClient() 109 .fetch( 110 new FetchOptions.Builder( 111 String.join( 112 "", 113 this.networkSession.getBaseUrls().getBaseUrl(), 114 "/2.0/files/", 115 convertToString(fileId), 116 "/metadata/global/boxSkillsCards"), 117 "POST") 118 .headers(headersMap) 119 .data(JsonManager.serialize(requestBody)) 120 .contentType("application/json") 121 .responseFormat(ResponseFormat.JSON) 122 .auth(this.auth) 123 .networkSession(this.networkSession) 124 .build()); 125 return JsonManager.deserialize(response.getData(), SkillCardsMetadata.class); 126 } 127 128 /** 129 * Updates one or more Box Skills metadata cards to a file. 130 * 131 * @param fileId The unique identifier that represents a file. 132 * <p>The ID for any file can be determined by visiting a file in the web application and 133 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 134 * `file_id` is `123`. Example: "12345" 135 * @param requestBody Request body of updateBoxSkillCardsOnFile method 136 */ 137 public SkillCardsMetadata updateBoxSkillCardsOnFile( 138 String fileId, List<UpdateBoxSkillCardsOnFileRequestBody> requestBody) { 139 return updateBoxSkillCardsOnFile(fileId, requestBody, new UpdateBoxSkillCardsOnFileHeaders()); 140 } 141 142 /** 143 * Updates one or more Box Skills metadata cards to a file. 144 * 145 * @param fileId The unique identifier that represents a file. 146 * <p>The ID for any file can be determined by visiting a file in the web application and 147 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 148 * `file_id` is `123`. Example: "12345" 149 * @param requestBody Request body of updateBoxSkillCardsOnFile method 150 * @param headers Headers of updateBoxSkillCardsOnFile method 151 */ 152 public SkillCardsMetadata updateBoxSkillCardsOnFile( 153 String fileId, 154 List<UpdateBoxSkillCardsOnFileRequestBody> requestBody, 155 UpdateBoxSkillCardsOnFileHeaders headers) { 156 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 157 FetchResponse response = 158 this.networkSession 159 .getNetworkClient() 160 .fetch( 161 new FetchOptions.Builder( 162 String.join( 163 "", 164 this.networkSession.getBaseUrls().getBaseUrl(), 165 "/2.0/files/", 166 convertToString(fileId), 167 "/metadata/global/boxSkillsCards"), 168 "PUT") 169 .headers(headersMap) 170 .data(JsonManager.serialize(requestBody)) 171 .contentType("application/json-patch+json") 172 .responseFormat(ResponseFormat.JSON) 173 .auth(this.auth) 174 .networkSession(this.networkSession) 175 .build()); 176 return JsonManager.deserialize(response.getData(), SkillCardsMetadata.class); 177 } 178 179 /** 180 * Removes any Box Skills cards metadata from a file. 181 * 182 * @param fileId The unique identifier that represents a file. 183 * <p>The ID for any file can be determined by visiting a file in the web application and 184 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 185 * `file_id` is `123`. Example: "12345" 186 */ 187 public void deleteBoxSkillCardsFromFile(String fileId) { 188 deleteBoxSkillCardsFromFile(fileId, new DeleteBoxSkillCardsFromFileHeaders()); 189 } 190 191 /** 192 * Removes any Box Skills cards metadata from a file. 193 * 194 * @param fileId The unique identifier that represents a file. 195 * <p>The ID for any file can be determined by visiting a file in the web application and 196 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 197 * `file_id` is `123`. Example: "12345" 198 * @param headers Headers of deleteBoxSkillCardsFromFile method 199 */ 200 public void deleteBoxSkillCardsFromFile( 201 String fileId, DeleteBoxSkillCardsFromFileHeaders headers) { 202 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 203 FetchResponse response = 204 this.networkSession 205 .getNetworkClient() 206 .fetch( 207 new FetchOptions.Builder( 208 String.join( 209 "", 210 this.networkSession.getBaseUrls().getBaseUrl(), 211 "/2.0/files/", 212 convertToString(fileId), 213 "/metadata/global/boxSkillsCards"), 214 "DELETE") 215 .headers(headersMap) 216 .responseFormat(ResponseFormat.NO_CONTENT) 217 .auth(this.auth) 218 .networkSession(this.networkSession) 219 .build()); 220 } 221 222 /** 223 * An alternative method that can be used to overwrite and update all Box Skill metadata cards on 224 * a file. 225 * 226 * @param skillId The ID of the skill to apply this metadata for. Example: "33243242" 227 * @param requestBody Request body of updateAllSkillCardsOnFile method 228 */ 229 public void updateAllSkillCardsOnFile( 230 String skillId, UpdateAllSkillCardsOnFileRequestBody requestBody) { 231 updateAllSkillCardsOnFile(skillId, requestBody, new UpdateAllSkillCardsOnFileHeaders()); 232 } 233 234 /** 235 * An alternative method that can be used to overwrite and update all Box Skill metadata cards on 236 * a file. 237 * 238 * @param skillId The ID of the skill to apply this metadata for. Example: "33243242" 239 * @param requestBody Request body of updateAllSkillCardsOnFile method 240 * @param headers Headers of updateAllSkillCardsOnFile method 241 */ 242 public void updateAllSkillCardsOnFile( 243 String skillId, 244 UpdateAllSkillCardsOnFileRequestBody requestBody, 245 UpdateAllSkillCardsOnFileHeaders headers) { 246 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 247 FetchResponse response = 248 this.networkSession 249 .getNetworkClient() 250 .fetch( 251 new FetchOptions.Builder( 252 String.join( 253 "", 254 this.networkSession.getBaseUrls().getBaseUrl(), 255 "/2.0/skill_invocations/", 256 convertToString(skillId)), 257 "PUT") 258 .headers(headersMap) 259 .data(JsonManager.serialize(requestBody)) 260 .contentType("application/json") 261 .responseFormat(ResponseFormat.NO_CONTENT) 262 .auth(this.auth) 263 .networkSession(this.networkSession) 264 .build()); 265 } 266 267 public Authentication getAuth() { 268 return auth; 269 } 270 271 public NetworkSession getNetworkSession() { 272 return networkSession; 273 } 274 275 public static class Builder { 276 277 protected Authentication auth; 278 279 protected NetworkSession networkSession; 280 281 public Builder() {} 282 283 public Builder auth(Authentication auth) { 284 this.auth = auth; 285 return this; 286 } 287 288 public Builder networkSession(NetworkSession networkSession) { 289 this.networkSession = networkSession; 290 return this; 291 } 292 293 public SkillsManager build() { 294 if (this.networkSession == null) { 295 this.networkSession = new NetworkSession(); 296 } 297 return new SkillsManager(this); 298 } 299 } 300}