1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use super::{
api::api_client::ApiClient, application_info::application_info_client::ApplicationInfoClient,
correlation::correlation_client::CorrelationClient, event::event_client::EventClient,
process_definition::process_definition_client::ProcessDefinitionClient,
process_model::process_model_client::ProcessModelClient,
};
/// A factory for creating clients for the ProcessCube® Engine.
pub struct ClientFactory {
/// The client used to communicate with the ProcessCube® Engine.
pub api_client: ApiClient,
}
impl ClientFactory {
/// Creates a new instance of the ClientFactory.
///
/// # Arguments
/// * `engine_url` - The URL of the ProcessCube® Engine.
/// * `auth_token` - The authentication token to use when communicating with the ProcessCube® Engine.
///
/// # Example
/// ```
/// use processcube_engine_client::clients::{client_factory::ClientFactory, error::EngineError};
/// const DUMMY_TOKEN: &str = "Bearer ZHVtbXlfdG9rZW4=";
/// const ENGINE_URL: &str = "http://localhost:10560";
/// // Be sure to have a running ProcessCube® Engine at the given URL
///
/// #[tokio::main]
/// async fn main() -> Result<(), EngineError> {
/// let client_factory = ClientFactory::new(ENGINE_URL, DUMMY_TOKEN);
/// // Create a new ApplicationInfoClient
/// let application_info_client = client_factory.create_application_info_client();
/// // Create a new ProcessDefinitionClient
/// let process_definition_client = client_factory.create_process_definition_client();
/// // Create a new ProcessModelClient
/// let process_model_client = client_factory.create_process_model_client();
/// // Create a new EventClient
/// let event_client = client_factory.create_event_client();
/// Ok(())
/// }
/// ```
pub fn new(engine_url: &str, auth_token: &str) -> ClientFactory {
let api_client = ApiClient::new(engine_url, auth_token);
ClientFactory { api_client }
}
/// Creates a new instance of the ApplicationInfoClient.
pub fn create_application_info_client(&self) -> ApplicationInfoClient {
ApplicationInfoClient::new(self.api_client.clone())
}
/// Creates a new instance of the CorrelationClient.
pub fn create_correlation_client(&self) -> CorrelationClient {
CorrelationClient::new(self.api_client.clone())
}
/// Creates a new instance of the ProcessDefinitionClient.
pub fn create_process_definition_client(&self) -> ProcessDefinitionClient {
ProcessDefinitionClient::new(self.api_client.clone())
}
/// Creates a new instance of the ProcessModelClient.
pub fn create_process_model_client(&self) -> ProcessModelClient {
ProcessModelClient::new(self.api_client.clone())
}
/// Creates a new instance of the EventClient.
pub fn create_event_client(&self) -> EventClient {
EventClient::new(self.api_client.clone())
}
}