Skip to content
Snippets Groups Projects
Commit 22058fa2 authored by Benguria Elguezabal, Gorka's avatar Benguria Elguezabal, Gorka
Browse files

public release

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 484 additions and 0 deletions
pub mod model;
pub mod usecases;
\ No newline at end of file
use serde_json;
use serde::Serialize;
use failure::Fail;
#[derive(Fail, Debug)]
pub enum UserJourneyError
{
#[fail(display = "The JSON String could not be created. ({})", _0)]
SerializationFailed(serde_json::error::Error)
}
#[derive(Serialize)]
pub struct UserJourney
{
// file_name: String,
pub origin_country: Option<String>,
pub destination_country: Option<String>,
pub workflow_type: Option<String>,
pub description: Vec<LocaleValue>,
pub phases: Vec<Phase>
}
impl UserJourney
{
pub fn new_empty() -> UserJourney
{
UserJourney
{
origin_country: None,
destination_country: None,
workflow_type: None,
description: Vec::new(),
phases: Vec::new()
}
}
pub fn is_concrete(&self) -> bool
{
self.origin_country.is_some()
&& self.destination_country.is_some()
&& self.workflow_type.is_some()
&& !self.get_origin_country().unwrap_or_default().trim().eq("")
&& !self.get_destination_country().unwrap_or_default().trim().eq("")
&& !self.get_workflow_type().unwrap_or_default().trim().eq("")
&& self.has_all_touchpoints()
&& self.has_all_english_values()
}
pub fn has_all_english_values(&self) -> bool
{
for phase in self.phases.iter()
{
for name in phase.get_name().iter()
{
if name.locale == "en" && name.value.trim() == ""
{
return false;
}
}
for action in phase.actions.iter()
{
for name in action.get_name().iter()
{
if name.locale == "en" && name.value.trim() == ""
{
return false;
}
}
for description in action.get_description().iter()
{
if description.locale == "en" && description.value.trim() == ""
{
return false;
}
}
}
}
for description in self.description.iter()
{
if description.locale == "en" && description.value.trim() == ""
{
return false;
}
}
return true;
}
pub fn has_all_touchpoints(&self) -> bool
{
for phase in self.phases.iter()
{
for action in phase.actions.iter()
{
if action.touchpoints.is_empty()
{
return false;
}
}
}
return true;
}
pub fn set_origin_country(&mut self, origin_country : Option<String>)
{
self.origin_country = origin_country;
}
pub fn set_destination_country(&mut self, destination_country : Option<String>)
{
self.destination_country = destination_country;
}
pub fn set_user_journey_description(&mut self, description : Vec<LocaleValue>)
{
self.description = description;
}
pub fn set_workflow_type(&mut self, workflow_type : Option<String>)
{
self.workflow_type = workflow_type;
}
pub fn get_workflow_type(&self) -> Option<String> {
if let Some(workflow_type) = &self.workflow_type {
return Some(workflow_type.to_string());
} else {
return None;
}
}
pub fn get_origin_country(&self) -> Option<String> {
if let Some(origin_country) = &self.origin_country {
return Some(origin_country.to_string());
} else {
return None;
}
}
pub fn get_destination_country(&self) -> Option<String> {
if let Some(destination_country) = &self.destination_country {
return Some(destination_country.to_string());
} else {
return None;
}
}
pub fn contains_phase(&self, drawio_id: &str) -> bool {
for phase in self.phases.iter()
{
if phase.get_drawio_id().eq(drawio_id) {
return true;
}
}
return false;
}
pub fn add_phase(&mut self, phase: Phase) {
self.phases.push(phase)
}
}
#[derive(Serialize)]
pub struct Phase
{
order: u32,
drawio_id: String,
name: Vec<LocaleValue>,
pub actions: Vec<Action>
}
impl Phase
{
pub fn new(drawio_id: String, index: u32, name: Vec<LocaleValue>, actions: Vec<Action>) -> Phase
{
Phase
{
order: index,
drawio_id: drawio_id,
name: name,
actions: actions
}
}
pub fn get_drawio_id(&self) -> String {
return self.drawio_id.to_string();
}
pub fn get_name(&self) -> &Vec<LocaleValue> {
return &self.name;
}
pub fn add_action(&mut self, action: Action) {
self.actions.push(action)
}
}
#[derive(Serialize)]
pub struct Action
{
order: u32,
pub drawio_id: String,
pub name: Vec<LocaleValue>,
pub description: Vec<LocaleValue>,
pub touchpoints: Vec<Touchpoint>,
pub is_mandatory: bool
}
impl Action
{
pub fn new_optional(drawio_id: String, index: u32, name: Vec<LocaleValue>, description: Vec<LocaleValue>,
touchpoints: Vec<Touchpoint>) -> Action
{
Action
{
order: index,
drawio_id: drawio_id,
name: name,
description: description,
touchpoints: touchpoints,
is_mandatory: false
}
}
pub fn new_mandatory(drawio_id: String, index: u32, name: Vec<LocaleValue>, description: Vec<LocaleValue>,
touchpoints: Vec<Touchpoint>) -> Action
{
Action
{
order: index,
drawio_id: drawio_id,
name: name,
description: description,
touchpoints: touchpoints,
is_mandatory: true
}
}
pub fn add_touchpoints(&mut self, touchpoint: Touchpoint) {
self.touchpoints.push(touchpoint)
}
pub fn get_drawio_id(&self) -> String {
return self.drawio_id.to_string();
}
pub fn get_name(&self) -> &Vec<LocaleValue> {
return &self.name;
}
pub fn get_description(&self) -> &Vec<LocaleValue> {
return &self.description;
}
}
#[derive(Serialize)]
pub struct Touchpoint
{
pub drawio_id: String,
pub service_id: String,
service_url: String,
pub location: String,
name: Option<String>,
description: Option<String>
}
impl Touchpoint
{
pub fn new(drawio_id: String, service_id: String, service_url: String, location: String,
name: Option<String>, description: Option<String>) -> Touchpoint
{
Touchpoint
{
drawio_id: drawio_id,
service_id: service_id,
service_url: service_url,
location: location,
name: name,
description: description
}
}
pub fn get_drawio_id(&self) -> String {
return self.drawio_id.to_string();
}
}
#[derive(Serialize)]
pub struct LocaleValue
{
locale: String,
value: String
}
impl LocaleValue
{
pub fn new(locale: String, value: String) -> LocaleValue
{
LocaleValue
{
locale: locale,
value: value
}
}
}
pub fn serialize(user_journey: UserJourney) -> Result<String, UserJourneyError>{
let user_journey = serde_json::to_string(&user_journey)
.map_err(|error| UserJourneyError::SerializationFailed(error))?;
Ok(user_journey)
}
\ No newline at end of file
use super::UseCaseExecError;
use crate::entities;
/*pub fn to_workflow(input: String) -> Result<entities::workflow::Workflow, UseCaseExecError> {
return entities::workflow::deserialize(input)
.map_err(|error| UseCaseExecError::WorkflowDeserializationFailed(error));
}*/
pub fn to_mx_graph_model(input: String) -> Result<entities::drawio_xml::MxGraphModel, UseCaseExecError> {
return entities::drawio_xml::deserialize(input)
.map_err(|error| UseCaseExecError::DrawioDeserializationFailed(error));
}
\ No newline at end of file
This diff is collapsed.
use crate::domain::model;
use serde_json;
pub fn from_user_journey(user_journey: &model::UserJourney) -> Result<String, serde_json::error::Error>
{
let user_journey_string = serde_json::to_string(&user_journey)?;
Ok(user_journey_string)
}
\ No newline at end of file
This diff is collapsed.
use super::UseCaseExecError;
use crate::entities::{drawio_xml, workflow::{Workflow, Action}};
use std::collections::HashMap;
pub fn from_drawio_xml(mx_graph_model: &drawio_xml::MxGraphModel) -> Result<Workflow, UseCaseExecError> {
let mut workflow = Workflow::new();
let actions_by_parent = mx_graph_model.get_actions_by_parent_map();
let edges_by_source = mx_graph_model.get_edge_mx_cells_ref_by_source_map();
let phase_by_id = mx_graph_model.get_phase_by_id_map();
let touchpoints_by_parent = mx_graph_model.get_touchpoints_by_parent_map();
let obejcts_by_parent = mx_graph_model.get_obejcts_by_parent_map();
// get start phase
let start_phases = mx_graph_model.get_start_phases();
let start_phase = start_phases.get(0).unwrap(); // start_phases must have one phase if graph is valid.
let start_phase_id = start_phase.get_id();
set_actions(start_phase_id, &mut workflow, &actions_by_parent, &edges_by_source,
&phase_by_id, &touchpoints_by_parent, &obejcts_by_parent);
// try to read properties from user objects
if let Some(user_objects) = mx_graph_model.get_user_objects() {
for user_object in user_objects {
if user_object.has_workflow_properties()
{
workflow.origin_country = user_object.get_origin_country().unwrap_or_default();
workflow.destination_country = user_object.get_destination_country().unwrap_or_default();
workflow.workflow_type = user_object.get_workflow_type().unwrap_or_default();
break;
}
}
}
return Ok(workflow);
}
fn set_actions(phase_id: String, workflow: &mut Workflow,
actions_by_parent: &HashMap<String, Vec<&drawio_xml::datatypes::Action>>,
edges_by_source: &HashMap<String, &drawio_xml::datatypes::MxCell>,
phase_by_id: &HashMap<String, &drawio_xml::datatypes::Phase>,
touchpoints_by_parent: &HashMap<String, &drawio_xml::datatypes::Touchpoints>,
obejcts_by_parent: &HashMap<String, Vec<&drawio_xml::datatypes::Obejct>>) {
// get actions
for phase_action in actions_by_parent.get(&phase_id).unwrap() {
let mut action = Action::new_initial(phase_action.get_id(), phase_action.get_obj_title());
// get touchpoints
let action_touchpoint = touchpoints_by_parent.get(&phase_action.get_id()).unwrap();
// get obejcts/services
if let Some(obejcts) = obejcts_by_parent.get(&action_touchpoint.get_id()) {
for action_obejct in obejcts {
action.add_service_id(action_obejct.get_service_id().unwrap());
}
}
workflow.add_action(action);
}
// get next phases
if let Some(phase_edge) = edges_by_source.get(&phase_id) {
if let Some(phase_edge_target) = phase_edge.get_target() {
let next_phase = phase_by_id.get(&phase_edge_target).unwrap();
set_actions(next_phase.get_id(), workflow, actions_by_parent, edges_by_source,
phase_by_id, touchpoints_by_parent, obejcts_by_parent)
}
}
}
This diff is collapsed.
pub const EXPORTER:&str = "org.eclipse.bpmn2.modeler.core";
pub const EXPORTER_VERSION:&str = "1.4.2.Final-v20171109-1930-B1";
pub const EXPRESSION_LANGUAGE:&str = "http://www.w3.org/1999/XPath";
pub const IS_EXECUTABLE:&str = "true";
pub const PROCESS_TYPE:&str = "Private";
pub const TNS_PACKAGE_NAME:&str = "defaultPackage";
pub const TARGET_NAMESPACE:&str = "http://www.jboss.org/drools";
pub const TYPE_LANGUAGE:&str = "http://www.w3.org/2001/XMLSchema";
pub const XMLNS:&str = "http://www.omg.org/spec/BPMN/20100524/MODEL";
pub const XMLNS_ACTIVITI:&str = "http://activiti.org/bpmn";
pub const XMLNS_BPMNDI:&str = "http://www.omg.org/spec/BPMN/20100524/DI";
pub const XMLNS_BPMN2:&str = XMLNS;
pub const XMLNS_CAMUNDA:&str = "http://camunda.org/schema/1.0/bpmn";
pub const XMLNS_DI:&str = "http://www.omg.org/spec/DD/20100524/DI";
pub const XMLNS_DC:&str = "http://www.omg.org/spec/DD/20100524/DC";
pub const XMLNS_G:&str = "http://www.jboss.org/drools/flow/gpd";
pub const XMLNS_JAVA:&str = "http://www.java.com/javaTypes";
pub const XMLNS_OMGDI:&str = XMLNS_DI;
pub const XMLNS_OMGDC:&str = XMLNS_DC;
pub const XMLNS_TNS:&str = TARGET_NAMESPACE;
pub const XMLNS_XSI:&str = "http://www.w3.org/2001/XMLSchema-instance";
pub const XMLNS_XSD:&str = TYPE_LANGUAGE;
pub const XSI_SCHEMA_LOCATION:&str = "http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd";
pub const DEF_EVENT_WIDTH:u32 = 36;
pub const DEF_EVENT_HIGHT:u32 = 36;
pub const DEF_TASK_WIDTH:u32 = 127;
pub const DEF_TASK_HIGHT:u32 = 65;
pub const DEF_SEQUENCE_FLOW_SIZE:u32 = 57;
pub const DEF_START_EVENT_X_POS:u32 = 0;
pub const DEF_SUB_PROCESS_OFFSET:u32 = 36;
pub const DEF_END_EVENT_ID:&str = "def_end_event";
pub const DEF_END_EVENT_NAME:&str = "Default End Event";
pub const DEF_START_EVENT_ID:&str = "def_start_event";
pub const DEF_START_EVENT_NAME:&str = "Default Start Event";
\ No newline at end of file
This diff is collapsed.
use crate::entities::bpmn::YaSerialize;
use crate::entities::bpmn::datatypes::events::ExtensionElements;
#[derive(Clone, Debug, YaSerialize, PartialEq)]
pub struct EndEvent {
#[yaserde(attribute)]
pub id: String,
#[yaserde(attribute)]
pub name: String,
#[yaserde(child, rename = "bpmn2:extensionElements")]
pub extension_elements: Option<ExtensionElements>
}
impl EndEvent {
pub fn init(id: String, name: String) -> EndEvent {
EndEvent {
id: id,
name: name.clone(),
extension_elements: Some(ExtensionElements::init(name.clone()))
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
pub mod sequence_flow;
\ No newline at end of file
This diff is collapsed.
pub mod events;
pub mod flows;
pub mod process;
pub mod tasks;
pub mod bpmndi_bpmn_diagram;
\ No newline at end of file
This diff is collapsed.
pub mod service_task;
pub mod sub_process;
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment