Skip to content

Commit

Permalink
Better error handling & allow manual OCEL picking
Browse files Browse the repository at this point in the history
  • Loading branch information
aarkue committed Mar 17, 2024
1 parent 5e70385 commit 2c7af45
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 82 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
## Docker


Note: Currently the API web server infrastructure used in the docker version only supports hardcoded included OCEL2 files.
Make sure to include at least some of the following OCEL2 files in `./backend/data/`: `order-management.json`, `ocel2-p2p.json`, `ContainerLogistics.json`(available at https://www.ocel-standard.org/event-logs/overview/).

### Docker Compose
Run `docker compose up --build` in the project root.


### Docker Files

- __backend__:
1. First build using `sudo docker build ./backend -t ocedeclare-backend`
2. Then run with `docker run --init -p 3000:3000 ocedeclare-backend`
- __frontend__:
1. First build using `sudo docker build ./frontend -t ocedeclare-frontend`
2. Then run with `sudo docker run --init -p 4567:4567 ocedeclare-backend`

27 changes: 15 additions & 12 deletions backend/shared/src/constraints/check_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,21 @@ pub fn check_with_tree(
BoundValue::Multiple(_) => todo!(),
}
}
None => linked_ocel
.objects_of_type
.get(&v.object_type)
.unwrap()
.iter()
.map(|obj| {
let mut new_bound_val = bound_val.clone();
new_bound_val
.insert(v.name.clone(), BoundValue::Single(obj.id.clone()));
(add_info.clone(), new_bound_val)
})
.collect_vec(),
None => match linked_ocel.objects_of_type.get(&v.object_type) {
Some(objs) => objs
.iter()
.map(|obj| {
let mut new_bound_val = bound_val.clone();
new_bound_val
.insert(v.name.clone(), BoundValue::Single(obj.id.clone()));
(add_info.clone(), new_bound_val)
})
.collect_vec(),
None =>{
eprintln!("Object type {} not found!",v.object_type);
Vec::new()
},
},
})
.collect();
}
Expand Down
49 changes: 41 additions & 8 deletions backend/web-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{
collections::{HashMap, HashSet},
env,
sync::{Arc, RwLock},
};

use axum::{
extract::State,
body::Bytes,
extract::{DefaultBodyLimit, State},
http::{header::CONTENT_TYPE, Method, StatusCode},
routing::{get, post},
Json, Router,
};
use itertools::Itertools;
use std::{
collections::{HashMap, HashSet},
env,
sync::{Arc, RwLock},
};

use ocedeclare_shared::{
constraints::{check_with_tree, CheckWithTreeRequest, ViolationsWithoutID},
Expand All @@ -24,7 +24,9 @@ use ocedeclare_shared::{
preprocessing::preprocess::link_ocel_info,
OCELInfo,
};
use process_mining::event_log::ocel::ocel_struct::OCEL;
use process_mining::{
event_log::ocel::ocel_struct::OCEL, import_ocel_xml_slice,
};
use tower_http::cors::CorsLayer;

use crate::load_ocel::{
Expand Down Expand Up @@ -55,6 +57,14 @@ async fn main() {
let app = Router::new()
.route("/ocel/load", post(load_ocel_file_req))
.route("/ocel/info", get(get_loaded_ocel_info))
.route(
"/ocel/upload-json",
post(upload_ocel_json).layer(DefaultBodyLimit::disable()),
)
.route(
"/ocel/upload-xml",
post(upload_ocel_xml).layer(DefaultBodyLimit::disable()),
)
.route("/ocel/available", get(get_available_ocels))
.route(
"/ocel/event-qualifiers",
Expand Down Expand Up @@ -88,6 +98,29 @@ pub async fn get_loaded_ocel_info(
}
}

async fn upload_ocel_xml(
State(state): State<AppState>,
ocel_bytes: Bytes,
) -> (StatusCode, Json<OCELInfo>) {
let ocel = import_ocel_xml_slice(&ocel_bytes);
let mut x = state.ocel.write().unwrap();
let ocel_info: OCELInfo = (&ocel).into();
*x = Some(ocel);

(StatusCode::OK, Json(ocel_info))
}

async fn upload_ocel_json(
State(state): State<AppState>,
ocel_bytes: Bytes,
) -> (StatusCode, Json<OCELInfo>) {
let ocel: OCEL = serde_json::from_slice(&ocel_bytes).unwrap();
let mut x = state.ocel.write().unwrap();
let ocel_info: OCELInfo = (&ocel).into();
*x = Some(ocel);
(StatusCode::OK, Json(ocel_info))
}

pub fn with_ocel_from_state<T, F>(State(state): &State<AppState>, f: F) -> Option<T>
where
F: FnOnce(&OCEL) -> T,
Expand Down
Loading

0 comments on commit 2c7af45

Please sign in to comment.