001package com.box.sdkgen.managers.docgentemplate; 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.v2025r0.docgenjobsv2025r0.DocGenJobsV2025R0; 015import com.box.sdkgen.schemas.v2025r0.docgentagsv2025r0.DocGenTagsV2025R0; 016import com.box.sdkgen.schemas.v2025r0.docgentemplatebasev2025r0.DocGenTemplateBaseV2025R0; 017import com.box.sdkgen.schemas.v2025r0.docgentemplatecreaterequestv2025r0.DocGenTemplateCreateRequestV2025R0; 018import com.box.sdkgen.schemas.v2025r0.docgentemplatesv2025r0.DocGenTemplatesV2025R0; 019import com.box.sdkgen.schemas.v2025r0.docgentemplatev2025r0.DocGenTemplateV2025R0; 020import com.box.sdkgen.serialization.json.JsonManager; 021import java.util.Map; 022 023public class DocgenTemplateManager { 024 025 public Authentication auth; 026 027 public NetworkSession networkSession; 028 029 public DocgenTemplateManager() { 030 this.networkSession = new NetworkSession(); 031 } 032 033 protected DocgenTemplateManager(Builder builder) { 034 this.auth = builder.auth; 035 this.networkSession = builder.networkSession; 036 } 037 038 /** 039 * Marks a file as a Box Doc Gen template. 040 * 041 * @param requestBody Request body of createDocgenTemplateV2025R0 method 042 */ 043 public DocGenTemplateBaseV2025R0 createDocgenTemplateV2025R0( 044 DocGenTemplateCreateRequestV2025R0 requestBody) { 045 return createDocgenTemplateV2025R0(requestBody, new CreateDocgenTemplateV2025R0Headers()); 046 } 047 048 /** 049 * Marks a file as a Box Doc Gen template. 050 * 051 * @param requestBody Request body of createDocgenTemplateV2025R0 method 052 * @param headers Headers of createDocgenTemplateV2025R0 method 053 */ 054 public DocGenTemplateBaseV2025R0 createDocgenTemplateV2025R0( 055 DocGenTemplateCreateRequestV2025R0 requestBody, CreateDocgenTemplateV2025R0Headers headers) { 056 Map<String, String> headersMap = 057 prepareParams( 058 mergeMaps( 059 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 060 headers.getExtraHeaders())); 061 FetchResponse response = 062 this.networkSession 063 .getNetworkClient() 064 .fetch( 065 new FetchOptions.Builder( 066 String.join( 067 "", 068 this.networkSession.getBaseUrls().getBaseUrl(), 069 "/2.0/docgen_templates"), 070 "POST") 071 .headers(headersMap) 072 .data(JsonManager.serialize(requestBody)) 073 .contentType("application/json") 074 .responseFormat(ResponseFormat.JSON) 075 .auth(this.auth) 076 .networkSession(this.networkSession) 077 .build()); 078 return JsonManager.deserialize(response.getData(), DocGenTemplateBaseV2025R0.class); 079 } 080 081 /** Lists Box Doc Gen templates on which the user is a collaborator. */ 082 public DocGenTemplatesV2025R0 getDocgenTemplatesV2025R0() { 083 return getDocgenTemplatesV2025R0( 084 new GetDocgenTemplatesV2025R0QueryParams(), new GetDocgenTemplatesV2025R0Headers()); 085 } 086 087 /** 088 * Lists Box Doc Gen templates on which the user is a collaborator. 089 * 090 * @param queryParams Query parameters of getDocgenTemplatesV2025R0 method 091 */ 092 public DocGenTemplatesV2025R0 getDocgenTemplatesV2025R0( 093 GetDocgenTemplatesV2025R0QueryParams queryParams) { 094 return getDocgenTemplatesV2025R0(queryParams, new GetDocgenTemplatesV2025R0Headers()); 095 } 096 097 /** 098 * Lists Box Doc Gen templates on which the user is a collaborator. 099 * 100 * @param headers Headers of getDocgenTemplatesV2025R0 method 101 */ 102 public DocGenTemplatesV2025R0 getDocgenTemplatesV2025R0( 103 GetDocgenTemplatesV2025R0Headers headers) { 104 return getDocgenTemplatesV2025R0(new GetDocgenTemplatesV2025R0QueryParams(), headers); 105 } 106 107 /** 108 * Lists Box Doc Gen templates on which the user is a collaborator. 109 * 110 * @param queryParams Query parameters of getDocgenTemplatesV2025R0 method 111 * @param headers Headers of getDocgenTemplatesV2025R0 method 112 */ 113 public DocGenTemplatesV2025R0 getDocgenTemplatesV2025R0( 114 GetDocgenTemplatesV2025R0QueryParams queryParams, GetDocgenTemplatesV2025R0Headers headers) { 115 Map<String, String> queryParamsMap = 116 prepareParams( 117 mapOf( 118 entryOf("marker", convertToString(queryParams.getMarker())), 119 entryOf("limit", convertToString(queryParams.getLimit())))); 120 Map<String, String> headersMap = 121 prepareParams( 122 mergeMaps( 123 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 124 headers.getExtraHeaders())); 125 FetchResponse response = 126 this.networkSession 127 .getNetworkClient() 128 .fetch( 129 new FetchOptions.Builder( 130 String.join( 131 "", 132 this.networkSession.getBaseUrls().getBaseUrl(), 133 "/2.0/docgen_templates"), 134 "GET") 135 .params(queryParamsMap) 136 .headers(headersMap) 137 .responseFormat(ResponseFormat.JSON) 138 .auth(this.auth) 139 .networkSession(this.networkSession) 140 .build()); 141 return JsonManager.deserialize(response.getData(), DocGenTemplatesV2025R0.class); 142 } 143 144 /** 145 * Unmarks file as Box Doc Gen template. 146 * 147 * @param templateId ID of the file which will no longer be marked as a Box Doc Gen template. 148 * Example: "123" 149 */ 150 public void deleteDocgenTemplateByIdV2025R0(String templateId) { 151 deleteDocgenTemplateByIdV2025R0(templateId, new DeleteDocgenTemplateByIdV2025R0Headers()); 152 } 153 154 /** 155 * Unmarks file as Box Doc Gen template. 156 * 157 * @param templateId ID of the file which will no longer be marked as a Box Doc Gen template. 158 * Example: "123" 159 * @param headers Headers of deleteDocgenTemplateByIdV2025R0 method 160 */ 161 public void deleteDocgenTemplateByIdV2025R0( 162 String templateId, DeleteDocgenTemplateByIdV2025R0Headers headers) { 163 Map<String, String> headersMap = 164 prepareParams( 165 mergeMaps( 166 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 167 headers.getExtraHeaders())); 168 FetchResponse response = 169 this.networkSession 170 .getNetworkClient() 171 .fetch( 172 new FetchOptions.Builder( 173 String.join( 174 "", 175 this.networkSession.getBaseUrls().getBaseUrl(), 176 "/2.0/docgen_templates/", 177 convertToString(templateId)), 178 "DELETE") 179 .headers(headersMap) 180 .responseFormat(ResponseFormat.NO_CONTENT) 181 .auth(this.auth) 182 .networkSession(this.networkSession) 183 .build()); 184 } 185 186 /** 187 * Lists details of a specific Box Doc Gen template. 188 * 189 * @param templateId The ID of a Box Doc Gen template. Example: 123 190 */ 191 public DocGenTemplateV2025R0 getDocgenTemplateByIdV2025R0(String templateId) { 192 return getDocgenTemplateByIdV2025R0(templateId, new GetDocgenTemplateByIdV2025R0Headers()); 193 } 194 195 /** 196 * Lists details of a specific Box Doc Gen template. 197 * 198 * @param templateId The ID of a Box Doc Gen template. Example: 123 199 * @param headers Headers of getDocgenTemplateByIdV2025R0 method 200 */ 201 public DocGenTemplateV2025R0 getDocgenTemplateByIdV2025R0( 202 String templateId, GetDocgenTemplateByIdV2025R0Headers headers) { 203 Map<String, String> headersMap = 204 prepareParams( 205 mergeMaps( 206 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 207 headers.getExtraHeaders())); 208 FetchResponse response = 209 this.networkSession 210 .getNetworkClient() 211 .fetch( 212 new FetchOptions.Builder( 213 String.join( 214 "", 215 this.networkSession.getBaseUrls().getBaseUrl(), 216 "/2.0/docgen_templates/", 217 convertToString(templateId)), 218 "GET") 219 .headers(headersMap) 220 .responseFormat(ResponseFormat.JSON) 221 .auth(this.auth) 222 .networkSession(this.networkSession) 223 .build()); 224 return JsonManager.deserialize(response.getData(), DocGenTemplateV2025R0.class); 225 } 226 227 /** 228 * Lists all tags in a Box Doc Gen template. 229 * 230 * @param templateId ID of template. Example: 123 231 */ 232 public DocGenTagsV2025R0 getDocgenTemplateTagsV2025R0(String templateId) { 233 return getDocgenTemplateTagsV2025R0( 234 templateId, 235 new GetDocgenTemplateTagsV2025R0QueryParams(), 236 new GetDocgenTemplateTagsV2025R0Headers()); 237 } 238 239 /** 240 * Lists all tags in a Box Doc Gen template. 241 * 242 * @param templateId ID of template. Example: 123 243 * @param queryParams Query parameters of getDocgenTemplateTagsV2025R0 method 244 */ 245 public DocGenTagsV2025R0 getDocgenTemplateTagsV2025R0( 246 String templateId, GetDocgenTemplateTagsV2025R0QueryParams queryParams) { 247 return getDocgenTemplateTagsV2025R0( 248 templateId, queryParams, new GetDocgenTemplateTagsV2025R0Headers()); 249 } 250 251 /** 252 * Lists all tags in a Box Doc Gen template. 253 * 254 * @param templateId ID of template. Example: 123 255 * @param headers Headers of getDocgenTemplateTagsV2025R0 method 256 */ 257 public DocGenTagsV2025R0 getDocgenTemplateTagsV2025R0( 258 String templateId, GetDocgenTemplateTagsV2025R0Headers headers) { 259 return getDocgenTemplateTagsV2025R0( 260 templateId, new GetDocgenTemplateTagsV2025R0QueryParams(), headers); 261 } 262 263 /** 264 * Lists all tags in a Box Doc Gen template. 265 * 266 * @param templateId ID of template. Example: 123 267 * @param queryParams Query parameters of getDocgenTemplateTagsV2025R0 method 268 * @param headers Headers of getDocgenTemplateTagsV2025R0 method 269 */ 270 public DocGenTagsV2025R0 getDocgenTemplateTagsV2025R0( 271 String templateId, 272 GetDocgenTemplateTagsV2025R0QueryParams queryParams, 273 GetDocgenTemplateTagsV2025R0Headers headers) { 274 Map<String, String> queryParamsMap = 275 prepareParams( 276 mapOf( 277 entryOf("template_version_id", convertToString(queryParams.getTemplateVersionId())), 278 entryOf("marker", convertToString(queryParams.getMarker())), 279 entryOf("limit", convertToString(queryParams.getLimit())))); 280 Map<String, String> headersMap = 281 prepareParams( 282 mergeMaps( 283 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 284 headers.getExtraHeaders())); 285 FetchResponse response = 286 this.networkSession 287 .getNetworkClient() 288 .fetch( 289 new FetchOptions.Builder( 290 String.join( 291 "", 292 this.networkSession.getBaseUrls().getBaseUrl(), 293 "/2.0/docgen_templates/", 294 convertToString(templateId), 295 "/tags"), 296 "GET") 297 .params(queryParamsMap) 298 .headers(headersMap) 299 .responseFormat(ResponseFormat.JSON) 300 .auth(this.auth) 301 .networkSession(this.networkSession) 302 .build()); 303 return JsonManager.deserialize(response.getData(), DocGenTagsV2025R0.class); 304 } 305 306 /** 307 * Lists the users jobs which use this template. 308 * 309 * @param templateId Id of template to fetch jobs for. Example: 123 310 */ 311 public DocGenJobsV2025R0 getDocgenTemplateJobByIdV2025R0(String templateId) { 312 return getDocgenTemplateJobByIdV2025R0( 313 templateId, 314 new GetDocgenTemplateJobByIdV2025R0QueryParams(), 315 new GetDocgenTemplateJobByIdV2025R0Headers()); 316 } 317 318 /** 319 * Lists the users jobs which use this template. 320 * 321 * @param templateId Id of template to fetch jobs for. Example: 123 322 * @param queryParams Query parameters of getDocgenTemplateJobByIdV2025R0 method 323 */ 324 public DocGenJobsV2025R0 getDocgenTemplateJobByIdV2025R0( 325 String templateId, GetDocgenTemplateJobByIdV2025R0QueryParams queryParams) { 326 return getDocgenTemplateJobByIdV2025R0( 327 templateId, queryParams, new GetDocgenTemplateJobByIdV2025R0Headers()); 328 } 329 330 /** 331 * Lists the users jobs which use this template. 332 * 333 * @param templateId Id of template to fetch jobs for. Example: 123 334 * @param headers Headers of getDocgenTemplateJobByIdV2025R0 method 335 */ 336 public DocGenJobsV2025R0 getDocgenTemplateJobByIdV2025R0( 337 String templateId, GetDocgenTemplateJobByIdV2025R0Headers headers) { 338 return getDocgenTemplateJobByIdV2025R0( 339 templateId, new GetDocgenTemplateJobByIdV2025R0QueryParams(), headers); 340 } 341 342 /** 343 * Lists the users jobs which use this template. 344 * 345 * @param templateId Id of template to fetch jobs for. Example: 123 346 * @param queryParams Query parameters of getDocgenTemplateJobByIdV2025R0 method 347 * @param headers Headers of getDocgenTemplateJobByIdV2025R0 method 348 */ 349 public DocGenJobsV2025R0 getDocgenTemplateJobByIdV2025R0( 350 String templateId, 351 GetDocgenTemplateJobByIdV2025R0QueryParams queryParams, 352 GetDocgenTemplateJobByIdV2025R0Headers headers) { 353 Map<String, String> queryParamsMap = 354 prepareParams( 355 mapOf( 356 entryOf("marker", convertToString(queryParams.getMarker())), 357 entryOf("limit", convertToString(queryParams.getLimit())))); 358 Map<String, String> headersMap = 359 prepareParams( 360 mergeMaps( 361 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 362 headers.getExtraHeaders())); 363 FetchResponse response = 364 this.networkSession 365 .getNetworkClient() 366 .fetch( 367 new FetchOptions.Builder( 368 String.join( 369 "", 370 this.networkSession.getBaseUrls().getBaseUrl(), 371 "/2.0/docgen_template_jobs/", 372 convertToString(templateId)), 373 "GET") 374 .params(queryParamsMap) 375 .headers(headersMap) 376 .responseFormat(ResponseFormat.JSON) 377 .auth(this.auth) 378 .networkSession(this.networkSession) 379 .build()); 380 return JsonManager.deserialize(response.getData(), DocGenJobsV2025R0.class); 381 } 382 383 public Authentication getAuth() { 384 return auth; 385 } 386 387 public NetworkSession getNetworkSession() { 388 return networkSession; 389 } 390 391 public static class Builder { 392 393 protected Authentication auth; 394 395 protected NetworkSession networkSession; 396 397 public Builder() {} 398 399 public Builder auth(Authentication auth) { 400 this.auth = auth; 401 return this; 402 } 403 404 public Builder networkSession(NetworkSession networkSession) { 405 this.networkSession = networkSession; 406 return this; 407 } 408 409 public DocgenTemplateManager build() { 410 if (this.networkSession == null) { 411 this.networkSession = new NetworkSession(); 412 } 413 return new DocgenTemplateManager(this); 414 } 415 } 416}