oxigdal_services/wps/
processes.rs1use crate::error::ServiceError;
4use crate::wps::{ProcessInputs, WpsState};
5use axum::{
6 http::header,
7 response::{IntoResponse, Response},
8};
9use serde::Deserialize;
10
11#[derive(Debug, Deserialize)]
13pub struct DescribeProcessParams {
14 pub identifier: String,
16}
17
18#[derive(Debug, Deserialize)]
20pub struct ExecuteParams {
21 pub identifier: String,
23}
24
25pub async fn handle_describe_process(
27 state: &WpsState,
28 _version: &str,
29 params: &serde_json::Value,
30) -> Result<Response, ServiceError> {
31 let params: DescribeProcessParams = serde_json::from_value(params.clone())
32 .map_err(|e| ServiceError::InvalidParameter("identifier".to_string(), e.to_string()))?;
33
34 let process = state
35 .get_process(¶ms.identifier)
36 .ok_or_else(|| ServiceError::NotFound(format!("Process: {}", params.identifier)))?;
37
38 let xml = format!(
39 r#"<?xml version="1.0" encoding="UTF-8"?>
40<wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/2.0">
41 <ProcessDescription>
42 <ows:Identifier>{}</ows:Identifier>
43 <ows:Title>{}</ows:Title>
44 </ProcessDescription>
45</wps:ProcessDescriptions>"#,
46 process.identifier(),
47 process.title()
48 );
49
50 Ok(([(header::CONTENT_TYPE, "application/xml")], xml).into_response())
51}
52
53pub async fn handle_execute(
55 state: &WpsState,
56 _version: &str,
57 params: &serde_json::Value,
58) -> Result<Response, ServiceError> {
59 let params: ExecuteParams = serde_json::from_value(params.clone())
60 .map_err(|e| ServiceError::InvalidParameter("identifier".to_string(), e.to_string()))?;
61
62 let process = state
63 .get_process(¶ms.identifier)
64 .ok_or_else(|| ServiceError::NotFound(format!("Process: {}", params.identifier)))?;
65
66 let inputs = ProcessInputs::default();
67 let _outputs = process.execute(inputs).await?;
68
69 let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
70<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/2.0">
71 <wps:Status>ProcessSucceeded</wps:Status>
72</wps:ExecuteResponse>"#;
73
74 Ok(([(header::CONTENT_TYPE, "application/xml")], xml).into_response())
75}