• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 10182401222

31 Jul 2024 02:42PM UTC coverage: 91.14% (+0.07%) from 91.068%
10182401222

Pull #970

github

web-flow
Merge f0fcf6203 into c97f87c56
Pull Request #970: FAIR dataset deletion

1798 of 1863 new or added lines in 13 files covered. (96.51%)

16 existing lines in 9 files now uncovered.

132740 of 145644 relevant lines covered (91.14%)

52956.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.96
/services/src/datasets/external/netcdfcf/ebvportal_api.rs
1
//! GEO BON EBV Portal catalog lookup service
2
//!
3
//! Connects to <https://portal.geobon.org/api/v1/>.
4

5
use crate::datasets::external::netcdfcf::{error, NetCdfOverview};
6
use crate::error::Result;
7
use error::NetCdfCf4DProviderError;
8
use geoengine_datatypes::dataset::DataProviderId;
9
use log::debug;
10
#[allow(unused_imports)]
11
use serde::{Deserialize, Serialize};
12
use url::Url;
13

14
mod portal_responses {
15
    use serde::Deserialize;
16

17
    #[derive(Debug, Deserialize)]
8✔
18
    pub struct EbvClassesResponse {
19
        pub data: Vec<EbvClassesResponseClass>,
20
    }
21

22
    #[derive(Debug, Deserialize)]
24✔
23
    pub struct EbvClassesResponseClass {
24
        pub ebv_class: String,
25
        pub ebv_name: Vec<String>,
26
    }
27

28
    #[derive(Debug, Deserialize)]
16✔
29
    pub struct EbvDatasetsResponse {
30
        pub data: Vec<EbvDatasetsResponseData>,
31
    }
32

33
    #[derive(Debug, Deserialize)]
132✔
34
    pub struct EbvDatasetsResponseData {
35
        pub id: String,
36
        pub title: String,
37
        pub summary: String,
38
        pub creator: EbvDatasetsResponseCreator,
39
        pub license: String,
40
        pub dataset: EbvDatasetsResponseDataset,
41
        pub ebv: EbvDatasetsResponseEbv,
42
        pub ebv_scenario: EbvDatasetsResponseEbvScenario,
43
    }
44

45
    #[derive(Debug, Deserialize)]
20✔
46
    pub struct EbvDatasetsResponseCreator {
47
        pub creator_name: String,
48
        pub creator_institution: String,
49
    }
50

51
    #[derive(Debug, Deserialize)]
20✔
52
    pub struct EbvDatasetsResponseDataset {
53
        pub pathname: String,
54
    }
55

56
    #[derive(Debug, Deserialize)]
12✔
57
    pub struct EbvDatasetsResponseEbv {
58
        pub ebv_class: String,
59
        pub ebv_name: String,
60
    }
61

62
    #[derive(Debug, Deserialize)]
63
    #[serde(untagged)]
64
    #[allow(dead_code)]
65
    pub enum EbvDatasetsResponseEbvScenario {
66
        String(String),
67
        Value(EbvDatasetsResponseEbvScenarioValue),
68
    }
69

70
    #[derive(Debug, Deserialize)]
3✔
71
    #[allow(dead_code)]
72
    pub struct EbvDatasetsResponseEbvScenarioValue {
73
        pub ebv_scenario_classification_name: String,
74
    }
75
}
76

77
#[derive(Debug, Serialize)]
78
#[serde(rename_all = "camelCase")]
79
pub struct EbvClass {
80
    pub name: String,
81
    pub ebv_names: Vec<String>,
82
}
83

84
#[derive(Debug, Serialize)]
85
#[serde(rename_all = "camelCase")]
86
#[allow(dead_code)]
87
struct EbvClasses {
88
    classes: Vec<EbvClass>,
89
}
90

91
#[derive(Debug)]
92
pub struct EbvPortalApi {
93
    base_url: Url,
94
}
95

96
impl EbvPortalApi {
97
    pub fn new(base_url: Url) -> Self {
6✔
98
        Self { base_url }
6✔
99
    }
6✔
100

101
    pub async fn get_classes(&self) -> Result<Vec<EbvClass>> {
2✔
102
        let url = format!("{}/ebv-map", self.base_url);
2✔
103

2✔
104
        debug!("Calling {url}");
2✔
105

106
        let response = reqwest::get(url)
2✔
107
            .await?
2✔
108
            .json::<portal_responses::EbvClassesResponse>()
2✔
109
            .await?;
×
110

111
        Ok(response
2✔
112
            .data
2✔
113
            .into_iter()
2✔
114
            .map(|c| EbvClass {
8✔
115
                name: c.ebv_class,
8✔
116
                ebv_names: c.ebv_name,
8✔
117
            })
8✔
118
            .collect())
2✔
119
    }
2✔
120

121
    pub async fn get_ebv_datasets(&self, ebv_name: &str) -> Result<Vec<EbvDataset>> {
2✔
122
        let url = format!("{}/datasets/filter", self.base_url);
2✔
123

2✔
124
        debug!("Calling {url}");
2✔
125

126
        let response = reqwest::Client::new()
2✔
127
            .get(url)
2✔
128
            .query(&[("ebvName", ebv_name)])
2✔
129
            .send()
2✔
130
            .await?
1✔
131
            .json::<portal_responses::EbvDatasetsResponse>()
2✔
132
            .await?;
1✔
133

134
        Ok(response
2✔
135
            .data
2✔
136
            .into_iter()
2✔
137
            .map(|data| EbvDataset {
2✔
138
                id: data.id,
2✔
139
                name: data.title,
2✔
140
                author_name: data.creator.creator_name,
2✔
141
                author_institution: data.creator.creator_institution,
2✔
142
                description: data.summary,
2✔
143
                license: data.license,
2✔
144
                dataset_path: data.dataset.pathname,
2✔
145
                ebv_class: data.ebv.ebv_class,
2✔
146
                ebv_name: data.ebv.ebv_name,
2✔
147
                has_scenario: matches!(
2✔
148
                    data.ebv_scenario,
2✔
149
                    portal_responses::EbvDatasetsResponseEbvScenario::Value(_)
150
                ),
151
            })
2✔
152
            .collect())
2✔
153
    }
2✔
154

155
    pub async fn get_dataset_metadata(&self, id: &str) -> Result<EbvDataset> {
2✔
156
        let url = format!("{}/datasets/{id}", self.base_url);
2✔
157

2✔
158
        debug!("Calling {url}");
2✔
159

160
        let response = reqwest::get(url)
2✔
UNCOV
161
            .await?
×
162
            .json::<portal_responses::EbvDatasetsResponse>()
2✔
163
            .await?;
×
164

165
        let dataset: Option<EbvDataset> = response
2✔
166
            .data
2✔
167
            .into_iter()
2✔
168
            .map(|data| EbvDataset {
2✔
169
                id: data.id,
2✔
170
                name: data.title,
2✔
171
                author_name: data.creator.creator_name,
2✔
172
                author_institution: data.creator.creator_institution,
2✔
173
                description: data.summary,
2✔
174
                license: data.license,
2✔
175
                dataset_path: data.dataset.pathname,
2✔
176
                ebv_class: data.ebv.ebv_class,
2✔
177
                ebv_name: data.ebv.ebv_name,
2✔
178
                has_scenario: matches!(
2✔
179
                    data.ebv_scenario,
2✔
180
                    portal_responses::EbvDatasetsResponseEbvScenario::Value(_)
181
                ),
182
            })
2✔
183
            .next();
2✔
184

2✔
185
        match dataset {
2✔
186
            Some(dataset) => Ok(dataset),
2✔
187
            None => Err(NetCdfCf4DProviderError::CannotLookupDataset { id: id.to_string() }.into()),
×
188
        }
189
    }
2✔
190
}
191

192
#[derive(Debug, Serialize)]
193
#[serde(rename_all = "camelCase")]
194
pub struct EbvDataset {
195
    pub id: String,
196
    pub name: String,
197
    pub author_name: String,
198
    pub author_institution: String,
199
    pub description: String,
200
    pub license: String,
201
    pub dataset_path: String,
202
    pub ebv_class: String,
203
    pub ebv_name: String,
204
    pub has_scenario: bool,
205
}
206

207
#[derive(Debug, Serialize)]
208
#[serde(rename_all = "camelCase")]
209
pub struct EbvHierarchy {
210
    pub provider_id: DataProviderId,
211
    pub tree: NetCdfOverview,
212
}
213

214
#[cfg(test)]
215
mod tests {
216
    use super::portal_responses::EbvDatasetsResponseEbvScenario;
217

218
    #[test]
219
    fn it_parses_ebv_scenario() {
1✔
220
        let value: EbvDatasetsResponseEbvScenario = serde_json::from_str(
1✔
221
            r#"{
1✔
222
                "ebv_scenario_classification_name": "foo",
1✔
223
                "other_field": "bar"
1✔
224
            }"#,
1✔
225
        )
1✔
226
        .unwrap();
1✔
227

228
        matches!(value, EbvDatasetsResponseEbvScenario::Value(_));
1✔
229

230
        let value: EbvDatasetsResponseEbvScenario = serde_json::from_str(r#""N/A""#).unwrap();
1✔
231

232
        matches!(value, EbvDatasetsResponseEbvScenario::String(_));
1✔
233
    }
1✔
234
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc