Skip to main content

oxigdal_services/wps/
processes.rs

1//! WPS process description and execution
2
3use crate::error::ServiceError;
4use crate::wps::{ProcessInputs, WpsState};
5use axum::{
6    http::header,
7    response::{IntoResponse, Response},
8};
9use serde::Deserialize;
10
11/// Parameters for DescribeProcess request
12#[derive(Debug, Deserialize)]
13pub struct DescribeProcessParams {
14    /// Process identifier
15    pub identifier: String,
16}
17
18/// Parameters for Execute request
19#[derive(Debug, Deserialize)]
20pub struct ExecuteParams {
21    /// Process identifier
22    pub identifier: String,
23}
24
25/// Handle DescribeProcess request
26pub 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(&params.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
53/// Handle Execute request
54pub 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(&params.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}