jira_api_v2/apis/
workflows_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_workflow`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateWorkflowError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`delete_inactive_workflow`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteInactiveWorkflowError {
33    Status400(),
34    Status401(),
35    Status403(),
36    Status404(),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`get_all_workflows`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetAllWorkflowsError {
44    Status401(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_workflows_paginated`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetWorkflowsPaginatedError {
52    Status401(),
53    Status403(models::ErrorCollection),
54    UnknownValue(serde_json::Value),
55}
56
57
58/// Creates a workflow. Workflow transitions are created with the default system transition rules.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
59pub async fn create_workflow(configuration: &configuration::Configuration, create_workflow_details: models::CreateWorkflowDetails) -> Result<models::WorkflowId, Error<CreateWorkflowError>> {
60    // add a prefix to parameters to efficiently prevent name collisions
61    let p_create_workflow_details = create_workflow_details;
62
63    let uri_str = format!("{}/rest/api/2/workflow", configuration.base_path);
64    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
65
66    if let Some(ref user_agent) = configuration.user_agent {
67        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68    }
69    if let Some(ref token) = configuration.oauth_access_token {
70        req_builder = req_builder.bearer_auth(token.to_owned());
71    };
72    if let Some(ref auth_conf) = configuration.basic_auth {
73        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
74    };
75    req_builder = req_builder.json(&p_create_workflow_details);
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81
82    if !status.is_client_error() && !status.is_server_error() {
83        let content = resp.text().await?;
84        serde_json::from_str(&content).map_err(Error::from)
85    } else {
86        let content = resp.text().await?;
87        let entity: Option<CreateWorkflowError> = serde_json::from_str(&content).ok();
88        Err(Error::ResponseError(ResponseContent { status, content, entity }))
89    }
90}
91
92/// Deletes a workflow.  The workflow cannot be deleted if it is:   *  an active workflow.  *  a system workflow.  *  associated with any workflow scheme.  *  associated with any draft workflow scheme.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
93pub async fn delete_inactive_workflow(configuration: &configuration::Configuration, entity_id: &str) -> Result<(), Error<DeleteInactiveWorkflowError>> {
94    // add a prefix to parameters to efficiently prevent name collisions
95    let p_entity_id = entity_id;
96
97    let uri_str = format!("{}/rest/api/2/workflow/{entityId}", configuration.base_path, entityId=crate::apis::urlencode(p_entity_id));
98    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
99
100    if let Some(ref user_agent) = configuration.user_agent {
101        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102    }
103    if let Some(ref token) = configuration.oauth_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106    if let Some(ref auth_conf) = configuration.basic_auth {
107        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
108    };
109
110    let req = req_builder.build()?;
111    let resp = configuration.client.execute(req).await?;
112
113    let status = resp.status();
114
115    if !status.is_client_error() && !status.is_server_error() {
116        Ok(())
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<DeleteInactiveWorkflowError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent { status, content, entity }))
121    }
122}
123
124/// Returns all workflows in Jira or a workflow. Deprecated, use [Get workflows paginated](#api-rest-api-2-workflow-search-get).  If the `workflowName` parameter is specified, the workflow is returned as an object (not in an array). Otherwise, an array of workflow objects is returned.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
125pub async fn get_all_workflows(configuration: &configuration::Configuration, workflow_name: Option<&str>) -> Result<Vec<models::DeprecatedWorkflow>, Error<GetAllWorkflowsError>> {
126    // add a prefix to parameters to efficiently prevent name collisions
127    let p_workflow_name = workflow_name;
128
129    let uri_str = format!("{}/rest/api/2/workflow", configuration.base_path);
130    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
131
132    if let Some(ref param_value) = p_workflow_name {
133        req_builder = req_builder.query(&[("workflowName", &param_value.to_string())]);
134    }
135    if let Some(ref user_agent) = configuration.user_agent {
136        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
137    }
138    if let Some(ref token) = configuration.oauth_access_token {
139        req_builder = req_builder.bearer_auth(token.to_owned());
140    };
141    if let Some(ref auth_conf) = configuration.basic_auth {
142        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
143    };
144
145    let req = req_builder.build()?;
146    let resp = configuration.client.execute(req).await?;
147
148    let status = resp.status();
149
150    if !status.is_client_error() && !status.is_server_error() {
151        let content = resp.text().await?;
152        serde_json::from_str(&content).map_err(Error::from)
153    } else {
154        let content = resp.text().await?;
155        let entity: Option<GetAllWorkflowsError> = serde_json::from_str(&content).ok();
156        Err(Error::ResponseError(ResponseContent { status, content, entity }))
157    }
158}
159
160/// Returns a [paginated](#pagination) list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned.  This operation does not return next-gen workflows.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
161pub async fn get_workflows_paginated(configuration: &configuration::Configuration, start_at: Option<i64>, max_results: Option<i32>, workflow_name: Option<Vec<String>>, expand: Option<&str>) -> Result<models::PageBeanWorkflow, Error<GetWorkflowsPaginatedError>> {
162    // add a prefix to parameters to efficiently prevent name collisions
163    let p_start_at = start_at;
164    let p_max_results = max_results;
165    let p_workflow_name = workflow_name;
166    let p_expand = expand;
167
168    let uri_str = format!("{}/rest/api/2/workflow/search", configuration.base_path);
169    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
170
171    if let Some(ref param_value) = p_start_at {
172        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
173    }
174    if let Some(ref param_value) = p_max_results {
175        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
176    }
177    if let Some(ref param_value) = p_workflow_name {
178        req_builder = match "multi" {
179            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("workflowName".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
180            _ => req_builder.query(&[("workflowName", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
181        };
182    }
183    if let Some(ref param_value) = p_expand {
184        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
185    }
186    if let Some(ref user_agent) = configuration.user_agent {
187        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188    }
189    if let Some(ref token) = configuration.oauth_access_token {
190        req_builder = req_builder.bearer_auth(token.to_owned());
191    };
192    if let Some(ref auth_conf) = configuration.basic_auth {
193        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
194    };
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200
201    if !status.is_client_error() && !status.is_server_error() {
202        let content = resp.text().await?;
203        serde_json::from_str(&content).map_err(Error::from)
204    } else {
205        let content = resp.text().await?;
206        let entity: Option<GetWorkflowsPaginatedError> = serde_json::from_str(&content).ok();
207        Err(Error::ResponseError(ResponseContent { status, content, entity }))
208    }
209}
210