reactive_graph_reactive_service_api/
reactive_flow_manager.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use springtime_di::injectable;
5use uuid::Uuid;
6
7use crate::FlowInstanceProvider;
8use crate::ReactiveFlowCreationError;
9use reactive_graph_graph::FlowInstance;
10use reactive_graph_graph::FlowTypeId;
11use reactive_graph_graph::PropertyInstances;
12use reactive_graph_lifecycle::Lifecycle;
13use reactive_graph_reactive_model_impl::ReactiveFlow;
14
15#[injectable]
16#[async_trait]
17pub trait ReactiveFlowManager: Send + Sync + Lifecycle {
18    /// Returns true, if an flow instance exists with the given UUID.
19    fn has(&self, id: Uuid) -> bool;
20
21    /// Returns the flow instance with the given UUID or None.
22    fn get(&self, id: Uuid) -> Option<ReactiveFlow>;
23
24    /// Returns the flow instance that matches the given label or None.
25    fn get_by_label(&self, label: &str) -> Option<ReactiveFlow>;
26
27    /// Returns all reactive flow instances.
28    fn get_all(&self) -> Vec<ReactiveFlow>;
29
30    /// Returns all reactive entity instances of the given type.
31    fn get_by_type(&self, ty: &FlowTypeId) -> Vec<ReactiveFlow>;
32
33    /// Returns the count of registered reactive flow instances.
34    fn count_flow_instances(&self) -> usize;
35
36    /// Creates a new reactive flow instance from the given flow instance descriptor.
37    ///
38    /// The wrapper entity instance will be created as well as entity and
39    /// relation instances.
40    ///
41    /// All reactive instances will be registered in the ReactiveEntityManager
42    /// and the ReactiveRelationManager.
43    fn create_reactive_flow(&self, flow_instance: FlowInstance) -> Result<ReactiveFlow, ReactiveFlowCreationError>;
44
45    /// Create a new reactive flow instance from the flow type by the given name.
46    ///
47    /// The wrapper entity instance will be created as well as entity and
48    /// relation instances.
49    ///
50    /// The properties are assigned to the wrapper entity instance.
51    ///
52    /// The variables will replace the property value.
53    ///
54    /// All reactive instances will be registered in the ReactiveEntityManager
55    /// and the ReactiveRelationManager.
56    fn create_from_type(
57        &self,
58        ty: &FlowTypeId,
59        id: Option<Uuid>,
60        variables: PropertyInstances,
61        properties: PropertyInstances,
62    ) -> Result<ReactiveFlow, ReactiveFlowCreationError>;
63
64    /// Registers the given reactive flow instance and registers all of the reactive instances
65    /// contained in the given reactive flow instance.
66    fn register_flow_instance_and_reactive_instances(&self, reactive_flow_instance: ReactiveFlow);
67
68    /// Registers the given reactive flow instance. Does not register it's reactive instances except
69    /// the wrapper entity.
70    fn register_flow_instance(&self, reactive_flow_instance: ReactiveFlow);
71
72    // /// The changes of the reactive flow instance with the given id will be written to graph database.
73    // // TODO: return result
74    // fn commit(&self, id: Uuid);
75
76    /// Deletes the flow instance with the given id.
77    fn delete(&self, id: Uuid) -> bool;
78
79    // fn import(&self, path: &str) -> Result<ReactiveFlow, ReactiveFlowImportError>;
80    //
81    // // TODO: return result
82    // fn export(&self, id: Uuid, path: &str);
83
84    /// Registers a flow instance provider.
85    fn register_provider(&self, id: Uuid, flow_instance_provider: Arc<dyn FlowInstanceProvider>);
86
87    /// Unregisters a flow instance provider.
88    fn unregister_provider(&self, id: &Uuid);
89}