001package com.box.sdkgen.managers.automateworkflows; 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.v2026r0.automateworkflowstartrequestv2026r0.AutomateWorkflowStartRequestV2026R0; 015import com.box.sdkgen.schemas.v2026r0.automateworkflowsv2026r0.AutomateWorkflowsV2026R0; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class AutomateWorkflowsManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public AutomateWorkflowsManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected AutomateWorkflowsManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Returns workflow actions from Automate for a folder, using the `WORKFLOW` action category. 036 * 037 * @param queryParams Query parameters of getAutomateWorkflowsV2026R0 method 038 */ 039 public AutomateWorkflowsV2026R0 getAutomateWorkflowsV2026R0( 040 GetAutomateWorkflowsV2026R0QueryParams queryParams) { 041 return getAutomateWorkflowsV2026R0(queryParams, new GetAutomateWorkflowsV2026R0Headers()); 042 } 043 044 /** 045 * Returns workflow actions from Automate for a folder, using the `WORKFLOW` action category. 046 * 047 * @param queryParams Query parameters of getAutomateWorkflowsV2026R0 method 048 * @param headers Headers of getAutomateWorkflowsV2026R0 method 049 */ 050 public AutomateWorkflowsV2026R0 getAutomateWorkflowsV2026R0( 051 GetAutomateWorkflowsV2026R0QueryParams queryParams, 052 GetAutomateWorkflowsV2026R0Headers headers) { 053 Map<String, String> queryParamsMap = 054 prepareParams( 055 mapOf( 056 entryOf("folder_id", convertToString(queryParams.getFolderId())), 057 entryOf("limit", convertToString(queryParams.getLimit())), 058 entryOf("marker", convertToString(queryParams.getMarker())))); 059 Map<String, String> headersMap = 060 prepareParams( 061 mergeMaps( 062 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 063 headers.getExtraHeaders())); 064 FetchResponse response = 065 this.networkSession 066 .getNetworkClient() 067 .fetch( 068 new FetchOptions.Builder( 069 String.join( 070 "", 071 this.networkSession.getBaseUrls().getBaseUrl(), 072 "/2.0/automate_workflows"), 073 "GET") 074 .params(queryParamsMap) 075 .headers(headersMap) 076 .responseFormat(ResponseFormat.JSON) 077 .auth(this.auth) 078 .networkSession(this.networkSession) 079 .build()); 080 return JsonManager.deserialize(response.getData(), AutomateWorkflowsV2026R0.class); 081 } 082 083 /** 084 * Starts an Automate workflow manually by using a workflow action ID and file IDs. 085 * 086 * @param workflowId The ID of the workflow. Example: "12345" 087 * @param requestBody Request body of createAutomateWorkflowStartV2026R0 method 088 */ 089 public void createAutomateWorkflowStartV2026R0( 090 String workflowId, AutomateWorkflowStartRequestV2026R0 requestBody) { 091 createAutomateWorkflowStartV2026R0( 092 workflowId, requestBody, new CreateAutomateWorkflowStartV2026R0Headers()); 093 } 094 095 /** 096 * Starts an Automate workflow manually by using a workflow action ID and file IDs. 097 * 098 * @param workflowId The ID of the workflow. Example: "12345" 099 * @param requestBody Request body of createAutomateWorkflowStartV2026R0 method 100 * @param headers Headers of createAutomateWorkflowStartV2026R0 method 101 */ 102 public void createAutomateWorkflowStartV2026R0( 103 String workflowId, 104 AutomateWorkflowStartRequestV2026R0 requestBody, 105 CreateAutomateWorkflowStartV2026R0Headers headers) { 106 Map<String, String> headersMap = 107 prepareParams( 108 mergeMaps( 109 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 110 headers.getExtraHeaders())); 111 FetchResponse response = 112 this.networkSession 113 .getNetworkClient() 114 .fetch( 115 new FetchOptions.Builder( 116 String.join( 117 "", 118 this.networkSession.getBaseUrls().getBaseUrl(), 119 "/2.0/automate_workflows/", 120 convertToString(workflowId), 121 "/start"), 122 "POST") 123 .headers(headersMap) 124 .data(JsonManager.serialize(requestBody)) 125 .contentType("application/json") 126 .responseFormat(ResponseFormat.NO_CONTENT) 127 .auth(this.auth) 128 .networkSession(this.networkSession) 129 .build()); 130 } 131 132 public Authentication getAuth() { 133 return auth; 134 } 135 136 public NetworkSession getNetworkSession() { 137 return networkSession; 138 } 139 140 public static class Builder { 141 142 protected Authentication auth; 143 144 protected NetworkSession networkSession; 145 146 public Builder() {} 147 148 public Builder auth(Authentication auth) { 149 this.auth = auth; 150 return this; 151 } 152 153 public Builder networkSession(NetworkSession networkSession) { 154 this.networkSession = networkSession; 155 return this; 156 } 157 158 public AutomateWorkflowsManager build() { 159 if (this.networkSession == null) { 160 this.networkSession = new NetworkSession(); 161 } 162 return new AutomateWorkflowsManager(this); 163 } 164 } 165}