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

geo-engine / geoengine / 5901396696

18 Aug 2023 10:07AM UTC coverage: 89.818% (+0.03%) from 89.789%
5901396696

push

github

web-flow
Merge pull request #857 from geo-engine/remove-feature-gates

remove feature gates

1 of 1 new or added line in 1 file covered. (100.0%)

105613 of 117586 relevant lines covered (89.82%)

61575.87 hits per line

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

98.05
/services/src/contexts/postgres.rs
1
use crate::api::model::datatypes::DatasetName;
2
use crate::contexts::{ApplicationContext, QueryContextImpl, SessionId, SimpleSession};
3
use crate::contexts::{GeoEngineDb, SessionContext};
4
use crate::datasets::add_from_directory::{
5
    add_datasets_from_directory, add_providers_from_directory,
6
};
7
use crate::datasets::upload::{Volume, Volumes};
8
use crate::error::{self, Error, Result};
9
use crate::layers::add_from_directory::{
10
    add_layer_collections_from_directory, add_layers_from_directory, UNSORTED_COLLECTION_ID,
11
};
12
use crate::layers::storage::INTERNAL_LAYER_DB_ROOT_COLLECTION_ID;
13

14
use crate::projects::{ProjectId, STRectangle};
15
use crate::tasks::{SimpleTaskManager, SimpleTaskManagerBackend, SimpleTaskManagerContext};
16
use crate::util::config::get_config_element;
17
use async_trait::async_trait;
18
use bb8_postgres::{
19
    bb8::Pool,
20
    bb8::PooledConnection,
21
    tokio_postgres::{error::SqlState, tls::MakeTlsConnect, tls::TlsConnect, Config, Socket},
22
    PostgresConnectionManager,
23
};
24
use geoengine_datatypes::raster::TilingSpecification;
25
use geoengine_operators::engine::ChunkByteSize;
26
use geoengine_operators::util::create_rayon_thread_pool;
27
use log::{debug, info};
28
use rayon::ThreadPool;
29
use std::path::PathBuf;
30
use std::sync::Arc;
31

32
use super::{ExecutionContextImpl, Session, SimpleApplicationContext};
33

34
// TODO: distinguish user-facing errors from system-facing error messages
35

36
/// A context with references to Postgres backends of the database.
37
#[derive(Clone)]
619✔
38
pub struct PostgresContext<Tls>
39
where
40
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
41
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
42
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
43
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
44
{
45
    default_session_id: SessionId,
46
    thread_pool: Arc<ThreadPool>,
47
    exe_ctx_tiling_spec: TilingSpecification,
48
    query_ctx_chunk_size: ChunkByteSize,
49
    task_manager: Arc<SimpleTaskManagerBackend>,
50
    pool: Pool<PostgresConnectionManager<Tls>>,
51
    volumes: Volumes,
52
}
53

54
enum DatabaseStatus {
55
    Unitialized,
56
    InitializedClearDatabase,
57
    InitializedKeepDatabase,
58
}
59

60
impl<Tls> PostgresContext<Tls>
61
where
62
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
63
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
64
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
65
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
66
{
67
    pub async fn new_with_context_spec(
228✔
68
        config: Config,
228✔
69
        tls: Tls,
228✔
70
        exe_ctx_tiling_spec: TilingSpecification,
228✔
71
        query_ctx_chunk_size: ChunkByteSize,
228✔
72
    ) -> Result<Self> {
228✔
73
        let pg_mgr = PostgresConnectionManager::new(config, tls);
228✔
74

75
        let pool = Pool::builder().build(pg_mgr).await?;
228✔
76
        let created_schema = Self::create_schema(pool.get().await?).await?;
2,736✔
77

78
        let session = if created_schema {
228✔
79
            let session = SimpleSession::default();
228✔
80
            Self::create_default_session(pool.get().await?, session.id()).await?;
456✔
81
            session
228✔
82
        } else {
83
            Self::load_default_session(pool.get().await?).await?
×
84
        };
85

86
        Ok(PostgresContext {
228✔
87
            default_session_id: session.id(),
228✔
88
            task_manager: Default::default(),
228✔
89
            thread_pool: create_rayon_thread_pool(0),
228✔
90
            exe_ctx_tiling_spec,
228✔
91
            query_ctx_chunk_size,
228✔
92
            pool,
228✔
93
            volumes: Default::default(),
228✔
94
        })
228✔
95
    }
228✔
96

97
    // TODO: check if the datasets exist already and don't output warnings when skipping them
98
    #[allow(clippy::too_many_arguments)]
99
    pub async fn new_with_data(
×
100
        config: Config,
×
101
        tls: Tls,
×
102
        dataset_defs_path: PathBuf,
×
103
        provider_defs_path: PathBuf,
×
104
        layer_defs_path: PathBuf,
×
105
        layer_collection_defs_path: PathBuf,
×
106
        exe_ctx_tiling_spec: TilingSpecification,
×
107
        query_ctx_chunk_size: ChunkByteSize,
×
108
    ) -> Result<Self> {
×
109
        let pg_mgr = PostgresConnectionManager::new(config, tls);
×
110

111
        let pool = Pool::builder().build(pg_mgr).await?;
×
112
        let created_schema = Self::create_schema(pool.get().await?).await?;
×
113

114
        let session = if created_schema {
×
115
            let session = SimpleSession::default();
×
116
            Self::create_default_session(pool.get().await?, session.id()).await?;
×
117
            session
×
118
        } else {
119
            Self::load_default_session(pool.get().await?).await?
×
120
        };
121

122
        let app_ctx = PostgresContext {
×
123
            default_session_id: session.id(),
×
124
            task_manager: Default::default(),
×
125
            thread_pool: create_rayon_thread_pool(0),
×
126
            exe_ctx_tiling_spec,
×
127
            query_ctx_chunk_size,
×
128
            pool,
×
129
            volumes: Default::default(),
×
130
        };
×
131

×
132
        if created_schema {
×
133
            info!("Populating database with initial data...");
×
134

135
            let ctx = app_ctx.session_context(session);
×
136

×
137
            let mut db = ctx.db();
×
138
            add_layers_from_directory(&mut db, layer_defs_path).await;
×
139
            add_layer_collections_from_directory(&mut db, layer_collection_defs_path).await;
×
140

141
            add_datasets_from_directory(&mut db, dataset_defs_path).await;
×
142

143
            add_providers_from_directory(&mut db, provider_defs_path, &[]).await;
×
144
        }
×
145

146
        Ok(app_ctx)
×
147
    }
×
148

149
    async fn check_schema_status(
319✔
150
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
319✔
151
    ) -> Result<DatabaseStatus> {
319✔
152
        let stmt = match conn
319✔
153
            .prepare("SELECT clear_database_on_start from geoengine;")
319✔
154
            .await
319✔
155
        {
156
            Ok(stmt) => stmt,
×
157
            Err(e) => {
319✔
158
                if let Some(code) = e.code() {
319✔
159
                    if *code == SqlState::UNDEFINED_TABLE {
319✔
160
                        info!("Initializing schema.");
×
161
                        return Ok(DatabaseStatus::Unitialized);
319✔
162
                    }
×
163
                }
×
164
                return Err(error::Error::TokioPostgres { source: e });
×
165
            }
166
        };
167

168
        let row = conn.query_one(&stmt, &[]).await?;
×
169

170
        if row.get(0) {
×
171
            Ok(DatabaseStatus::InitializedClearDatabase)
×
172
        } else {
173
            Ok(DatabaseStatus::InitializedKeepDatabase)
×
174
        }
175
    }
319✔
176

177
    #[allow(clippy::too_many_lines)]
178
    /// Creates the database schema. Returns true if the schema was created, false if it already existed.
179
    pub(crate) async fn create_schema(
319✔
180
        mut conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
319✔
181
    ) -> Result<bool> {
319✔
182
        let postgres_config = get_config_element::<crate::util::config::Postgres>()?;
319✔
183

184
        let database_status = Self::check_schema_status(&conn).await?;
319✔
185

186
        match database_status {
×
187
            DatabaseStatus::InitializedClearDatabase if postgres_config.clear_database_on_start => {
×
188
                let schema_name = postgres_config.schema;
×
189
                info!("Clearing schema {}.", schema_name);
×
190
                conn.batch_execute(&format!(
×
191
                    "DROP SCHEMA {schema_name} CASCADE; CREATE SCHEMA {schema_name};"
×
192
                ))
×
193
                .await?;
×
194
            }
195
            DatabaseStatus::InitializedKeepDatabase if postgres_config.clear_database_on_start => {
×
196
                return Err(Error::ClearDatabaseOnStartupNotAllowed)
×
197
            }
198
            DatabaseStatus::InitializedClearDatabase | DatabaseStatus::InitializedKeepDatabase => {
199
                return Ok(false)
×
200
            }
201
            DatabaseStatus::Unitialized => (),
319✔
202
        };
203

204
        let tx = conn.build_transaction().start().await?;
319✔
205

206
        tx.batch_execute(include_str!("schema.sql")).await?;
319✔
207

208
        let stmt = tx
319✔
209
            .prepare(
319✔
210
                "
319✔
211
            INSERT INTO geoengine (clear_database_on_start) VALUES ($1);",
319✔
212
            )
319✔
213
            .await?;
319✔
214

215
        tx.execute(&stmt, &[&postgres_config.clear_database_on_start])
319✔
216
            .await?;
319✔
217

218
        let stmt = tx
319✔
219
            .prepare(
319✔
220
                r#"
319✔
221
            INSERT INTO layer_collections (
319✔
222
                id,
319✔
223
                name,
319✔
224
                description,
319✔
225
                properties
319✔
226
            ) VALUES (
319✔
227
                $1,
319✔
228
                'Layers',
319✔
229
                'All available Geo Engine layers',
319✔
230
                ARRAY[]::"PropertyType"[]
319✔
231
            );"#,
319✔
232
            )
319✔
233
            .await?;
319✔
234

235
        tx.execute(&stmt, &[&INTERNAL_LAYER_DB_ROOT_COLLECTION_ID])
319✔
236
            .await?;
319✔
237

238
        let stmt = tx
319✔
239
            .prepare(
319✔
240
                r#"INSERT INTO layer_collections (
319✔
241
                id,
319✔
242
                name,
319✔
243
                description,
319✔
244
                properties
319✔
245
            ) VALUES (
319✔
246
                $1,
319✔
247
                'Unsorted',
319✔
248
                'Unsorted Layers',
319✔
249
                ARRAY[]::"PropertyType"[]
319✔
250
            );"#,
319✔
251
            )
319✔
252
            .await?;
319✔
253

254
        tx.execute(&stmt, &[&UNSORTED_COLLECTION_ID]).await?;
319✔
255

256
        let stmt = tx
319✔
257
            .prepare(
319✔
258
                r#"
319✔
259
            INSERT INTO collection_children (parent, child) 
319✔
260
            VALUES ($1, $2);"#,
319✔
261
            )
319✔
262
            .await?;
319✔
263

264
        tx.execute(
319✔
265
            &stmt,
319✔
266
            &[
319✔
267
                &INTERNAL_LAYER_DB_ROOT_COLLECTION_ID,
319✔
268
                &UNSORTED_COLLECTION_ID,
319✔
269
            ],
319✔
270
        )
319✔
271
        .await?;
319✔
272

273
        tx.commit().await?;
319✔
274

275
        debug!("Created database schema");
×
276

277
        Ok(true)
319✔
278
    }
319✔
279

280
    async fn create_default_session(
228✔
281
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
228✔
282
        session_id: SessionId,
228✔
283
    ) -> Result<()> {
228✔
284
        let stmt = conn
228✔
285
            .prepare("INSERT INTO sessions (id, project_id, view) VALUES ($1, NULL ,NULL);")
228✔
286
            .await?;
228✔
287

288
        conn.execute(&stmt, &[&session_id]).await?;
228✔
289

290
        Ok(())
228✔
291
    }
228✔
292
    async fn load_default_session(
65✔
293
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
65✔
294
    ) -> Result<SimpleSession> {
65✔
295
        let stmt = conn
65✔
296
            .prepare("SELECT id, project_id, view FROM sessions LIMIT 1;")
65✔
297
            .await?;
364✔
298

299
        let row = conn.query_one(&stmt, &[]).await?;
65✔
300

301
        Ok(SimpleSession::new(row.get(0), row.get(1), row.get(2)))
65✔
302
    }
65✔
303
}
304

305
#[async_trait]
306
impl<Tls> SimpleApplicationContext for PostgresContext<Tls>
307
where
308
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
309
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
310
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
311
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
312
{
313
    async fn default_session_id(&self) -> SessionId {
78✔
314
        self.default_session_id
78✔
315
    }
78✔
316

317
    async fn default_session(&self) -> Result<SimpleSession> {
65✔
318
        Self::load_default_session(self.pool.get().await?).await
428✔
319
    }
130✔
320

321
    async fn update_default_session_project(&self, project: ProjectId) -> Result<()> {
1✔
322
        let conn = self.pool.get().await?;
1✔
323

324
        let stmt = conn
1✔
325
            .prepare("UPDATE sessions SET project_id = $1 WHERE id = $2;")
1✔
326
            .await?;
×
327

328
        conn.execute(&stmt, &[&project, &self.default_session_id])
1✔
329
            .await?;
1✔
330

331
        Ok(())
1✔
332
    }
2✔
333

334
    async fn update_default_session_view(&self, view: STRectangle) -> Result<()> {
1✔
335
        let conn = self.pool.get().await?;
1✔
336

337
        let stmt = conn
1✔
338
            .prepare("UPDATE sessions SET view = $1 WHERE id = $2;")
1✔
339
            .await?;
1✔
340

341
        conn.execute(&stmt, &[&view, &self.default_session_id])
1✔
342
            .await?;
1✔
343

344
        Ok(())
1✔
345
    }
2✔
346

347
    async fn default_session_context(&self) -> Result<Self::SessionContext> {
277✔
348
        Ok(self.session_context(self.session_by_id(self.default_session_id).await?))
4,015✔
349
    }
554✔
350
}
351

352
#[async_trait]
353
impl<Tls> ApplicationContext for PostgresContext<Tls>
354
where
355
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
356
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
357
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
358
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
359
{
360
    type SessionContext = PostgresSessionContext<Tls>;
361
    type Session = SimpleSession;
362

363
    fn session_context(&self, session: Self::Session) -> Self::SessionContext {
441✔
364
        PostgresSessionContext {
441✔
365
            session,
441✔
366
            context: self.clone(),
441✔
367
        }
441✔
368
    }
441✔
369

370
    async fn session_by_id(&self, session_id: SessionId) -> Result<Self::Session> {
379✔
371
        let mut conn = self.pool.get().await?;
379✔
372

373
        let tx = conn.build_transaction().start().await?;
375✔
374

375
        let stmt = tx
374✔
376
            .prepare(
374✔
377
                "
374✔
378
            SELECT           
374✔
379
                project_id,
374✔
380
                view
374✔
381
            FROM sessions
374✔
382
            WHERE id = $1;",
374✔
383
            )
374✔
384
            .await?;
3,280✔
385

386
        let row = tx
374✔
387
            .query_one(&stmt, &[&session_id])
374✔
388
            .await
352✔
389
            .map_err(|_error| error::Error::InvalidSession)?;
374✔
390

391
        Ok(SimpleSession::new(session_id, row.get(0), row.get(1)))
374✔
392
    }
753✔
393
}
394

395
#[derive(Clone)]
×
396
pub struct PostgresSessionContext<Tls>
397
where
398
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
399
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
400
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
401
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
402
{
403
    session: SimpleSession,
404
    context: PostgresContext<Tls>,
405
}
406

407
#[async_trait]
408
impl<Tls> SessionContext for PostgresSessionContext<Tls>
409
where
410
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
411
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
412
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
413
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
414
{
415
    type Session = SimpleSession;
416
    type GeoEngineDB = PostgresDb<Tls>;
417

418
    type TaskContext = SimpleTaskManagerContext;
419
    type TaskManager = SimpleTaskManager; // this does not persist across restarts
420
    type QueryContext = QueryContextImpl;
421
    type ExecutionContext = ExecutionContextImpl<Self::GeoEngineDB>;
422

423
    fn db(&self) -> Self::GeoEngineDB {
388✔
424
        PostgresDb::new(self.context.pool.clone())
388✔
425
    }
388✔
426

427
    fn tasks(&self) -> Self::TaskManager {
36✔
428
        SimpleTaskManager::new(self.context.task_manager.clone())
36✔
429
    }
36✔
430

431
    fn query_context(&self) -> Result<Self::QueryContext> {
27✔
432
        Ok(QueryContextImpl::new(
27✔
433
            self.context.query_ctx_chunk_size,
27✔
434
            self.context.thread_pool.clone(),
27✔
435
        ))
27✔
436
    }
27✔
437

438
    fn execution_context(&self) -> Result<Self::ExecutionContext> {
50✔
439
        Ok(ExecutionContextImpl::<PostgresDb<Tls>>::new(
50✔
440
            self.db(),
50✔
441
            self.context.thread_pool.clone(),
50✔
442
            self.context.exe_ctx_tiling_spec,
50✔
443
        ))
50✔
444
    }
50✔
445

446
    fn volumes(&self) -> Result<Vec<Volume>> {
×
447
        Ok(self.context.volumes.volumes.clone())
×
448
    }
×
449

450
    fn session(&self) -> &Self::Session {
110✔
451
        &self.session
110✔
452
    }
110✔
453
}
454

455
pub struct PostgresDb<Tls>
456
where
457
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
458
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
459
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
460
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
461
{
462
    pub(crate) conn_pool: Pool<PostgresConnectionManager<Tls>>,
463
}
464

465
impl<Tls> PostgresDb<Tls>
466
where
467
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
468
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
469
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
470
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
471
{
472
    pub fn new(conn_pool: Pool<PostgresConnectionManager<Tls>>) -> Self {
388✔
473
        Self { conn_pool }
388✔
474
    }
388✔
475

476
    /// Check whether the namepsace of the given dataset is allowed for insertion
477
    /// Check whether the namepsace of the given dataset is allowed for insertion
478
    pub(crate) fn check_namespace(id: &DatasetName) -> Result<()> {
68✔
479
        // due to a lack of users, etc., we only allow one namespace for now
68✔
480
        if id.namespace.is_none() {
68✔
481
            Ok(())
68✔
482
        } else {
483
            Err(Error::InvalidDatasetIdNamespace)
×
484
        }
485
    }
68✔
486
}
487

488
impl<Tls> GeoEngineDb for PostgresDb<Tls>
489
where
490
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
491
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
492
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
493
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
494
{
495
}
496

497
#[cfg(test)]
498
mod tests {
499
    use std::collections::HashMap;
500
    use std::marker::PhantomData;
501
    use std::str::FromStr;
502

503
    use super::*;
504
    use crate::api::model::datatypes::{
505
        Breakpoint, ClassificationMeasurement, Colorizer, ContinuousMeasurement, DataProviderId,
506
        DatasetName, DefaultColors, LayerId, LinearGradient, LogarithmicGradient, Measurement,
507
        MultiLineString, MultiPoint, MultiPolygon, NoGeometry, NotNanF64, OverUnderColors, Palette,
508
        RasterPropertiesEntryType, RasterPropertiesKey, RgbaColor, SpatialPartition2D, StringPair,
509
    };
510
    use crate::api::model::operators::{
511
        GdalSourceTimePlaceholder, PlotResultDescriptor, TimeReference, UnixTimeStampType,
512
    };
513
    use crate::api::model::responses::datasets::DatasetIdAndName;
514
    use crate::api::model::services::AddDataset;
515
    use crate::api::model::{ColorizerTypeDbType, HashMapTextTextDbType};
516
    use crate::datasets::external::mock::{MockCollection, MockExternalLayerProviderDefinition};
517
    use crate::datasets::listing::{DatasetListOptions, DatasetListing, ProvenanceOutput};
518
    use crate::datasets::listing::{DatasetProvider, Provenance};
519
    use crate::datasets::storage::{DatasetStore, MetaDataDefinition};
520
    use crate::datasets::upload::{FileId, UploadId};
521
    use crate::datasets::upload::{FileUpload, Upload, UploadDb};
522
    use crate::layers::layer::{
523
        AddLayer, AddLayerCollection, CollectionItem, LayerCollection, LayerCollectionListOptions,
524
        LayerCollectionListing, LayerListing, ProviderLayerCollectionId, ProviderLayerId,
525
    };
526
    use crate::layers::listing::{LayerCollectionId, LayerCollectionProvider};
527
    use crate::layers::storage::{
528
        LayerDb, LayerProviderDb, LayerProviderListing, LayerProviderListingOptions,
529
        INTERNAL_PROVIDER_ID,
530
    };
531
    use crate::projects::{
532
        ColorParam, CreateProject, DerivedColor, DerivedNumber, LayerUpdate, LineSymbology,
533
        LoadVersion, NumberParam, OrderBy, Plot, PlotUpdate, PointSymbology, PolygonSymbology,
534
        ProjectDb, ProjectFilter, ProjectId, ProjectLayer, ProjectListOptions, ProjectListing,
535
        RasterSymbology, STRectangle, StrokeParam, Symbology, TextSymbology, UpdateProject,
536
    };
537
    use crate::util::tests::register_ndvi_workflow_helper;
538
    use crate::util::tests::with_temp_context;
539
    use crate::workflows::registry::WorkflowRegistry;
540
    use crate::workflows::workflow::Workflow;
541
    use bb8_postgres::tokio_postgres::NoTls;
542
    use futures::join;
543
    use geoengine_datatypes::collections::VectorDataType;
544
    use geoengine_datatypes::primitives::CacheTtlSeconds;
545
    use geoengine_datatypes::primitives::{
546
        BoundingBox2D, Coordinate2D, FeatureDataType, RasterQueryRectangle, SpatialResolution,
547
        TimeGranularity, TimeInstance, TimeInterval, TimeStep, VectorQueryRectangle,
548
    };
549
    use geoengine_datatypes::raster::RasterDataType;
550
    use geoengine_datatypes::spatial_reference::{SpatialReference, SpatialReferenceOption};
551
    use geoengine_operators::engine::{
552
        MetaData, MetaDataProvider, MultipleRasterOrSingleVectorSource, PlotOperator,
553
        RasterResultDescriptor, StaticMetaData, TypedOperator, TypedResultDescriptor,
554
        VectorColumnInfo, VectorOperator, VectorResultDescriptor,
555
    };
556
    use geoengine_operators::mock::{MockPointSource, MockPointSourceParams};
557
    use geoengine_operators::plot::{Statistics, StatisticsParams};
558
    use geoengine_operators::source::{
559
        CsvHeader, FileNotFoundHandling, FormatSpecifics, GdalDatasetGeoTransform,
560
        GdalDatasetParameters, GdalLoadingInfo, GdalMetaDataList, GdalMetaDataRegular,
561
        GdalMetaDataStatic, GdalMetadataNetCdfCf, OgrSourceColumnSpec, OgrSourceDataset,
562
        OgrSourceDatasetTimeType, OgrSourceDurationSpec, OgrSourceErrorSpec, OgrSourceTimeFormat,
563
    };
564
    use geoengine_operators::util::input::MultiRasterOrVectorOperator::Raster;
565
    use ordered_float::NotNan;
566
    use serde_json::json;
567

568
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
569
    async fn test() {
1✔
570
        with_temp_context(|app_ctx, _| async move {
1✔
571
            let session = app_ctx.default_session().await.unwrap();
18✔
572

1✔
573
            create_projects(&app_ctx, &session).await;
74✔
574

575
            let projects = list_projects(&app_ctx, &session).await;
11✔
576

577
            let project_id = projects[0].id;
1✔
578

1✔
579
            update_projects(&app_ctx, &session, project_id).await;
155✔
580

581
            delete_project(&app_ctx, &session, project_id).await;
6✔
582
        })
1✔
583
        .await;
10✔
584
    }
585

586
    async fn delete_project(
1✔
587
        app_ctx: &PostgresContext<NoTls>,
1✔
588
        session: &SimpleSession,
1✔
589
        project_id: ProjectId,
1✔
590
    ) {
1✔
591
        let db = app_ctx.session_context(session.clone()).db();
1✔
592

1✔
593
        db.delete_project(project_id).await.unwrap();
3✔
594

1✔
595
        assert!(db.load_project(project_id).await.is_err());
3✔
596
    }
1✔
597

598
    #[allow(clippy::too_many_lines)]
599
    async fn update_projects(
1✔
600
        app_ctx: &PostgresContext<NoTls>,
1✔
601
        session: &SimpleSession,
1✔
602
        project_id: ProjectId,
1✔
603
    ) {
1✔
604
        let db = app_ctx.session_context(session.clone()).db();
1✔
605

606
        let project = db
1✔
607
            .load_project_version(project_id, LoadVersion::Latest)
1✔
608
            .await
37✔
609
            .unwrap();
1✔
610

611
        let layer_workflow_id = db
1✔
612
            .register_workflow(Workflow {
1✔
613
                operator: TypedOperator::Vector(
1✔
614
                    MockPointSource {
1✔
615
                        params: MockPointSourceParams {
1✔
616
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
617
                        },
1✔
618
                    }
1✔
619
                    .boxed(),
1✔
620
                ),
1✔
621
            })
1✔
622
            .await
3✔
623
            .unwrap();
1✔
624

1✔
625
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
3✔
626

627
        let plot_workflow_id = db
1✔
628
            .register_workflow(Workflow {
1✔
629
                operator: Statistics {
1✔
630
                    params: StatisticsParams {
1✔
631
                        column_names: vec![],
1✔
632
                    },
1✔
633
                    sources: MultipleRasterOrSingleVectorSource {
1✔
634
                        source: Raster(vec![]),
1✔
635
                    },
1✔
636
                }
1✔
637
                .boxed()
1✔
638
                .into(),
1✔
639
            })
1✔
640
            .await
3✔
641
            .unwrap();
1✔
642

1✔
643
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
3✔
644

645
        // add a plot
646
        let update = UpdateProject {
1✔
647
            id: project.id,
1✔
648
            name: Some("Test9 Updated".into()),
1✔
649
            description: None,
1✔
650
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
651
                workflow: layer_workflow_id,
1✔
652
                name: "TestLayer".into(),
1✔
653
                symbology: PointSymbology::default().into(),
1✔
654
                visibility: Default::default(),
1✔
655
            })]),
1✔
656
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
657
                workflow: plot_workflow_id,
1✔
658
                name: "Test Plot".into(),
1✔
659
            })]),
1✔
660
            bounds: None,
1✔
661
            time_step: None,
1✔
662
        };
1✔
663
        db.update_project(update).await.unwrap();
65✔
664

665
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
666
        assert_eq!(versions.len(), 2);
1✔
667

668
        // add second plot
669
        let update = UpdateProject {
1✔
670
            id: project.id,
1✔
671
            name: Some("Test9 Updated".into()),
1✔
672
            description: None,
1✔
673
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
674
                workflow: layer_workflow_id,
1✔
675
                name: "TestLayer".into(),
1✔
676
                symbology: PointSymbology::default().into(),
1✔
677
                visibility: Default::default(),
1✔
678
            })]),
1✔
679
            plots: Some(vec![
1✔
680
                PlotUpdate::UpdateOrInsert(Plot {
1✔
681
                    workflow: plot_workflow_id,
1✔
682
                    name: "Test Plot".into(),
1✔
683
                }),
1✔
684
                PlotUpdate::UpdateOrInsert(Plot {
1✔
685
                    workflow: plot_workflow_id,
1✔
686
                    name: "Test Plot".into(),
1✔
687
                }),
1✔
688
            ]),
1✔
689
            bounds: None,
1✔
690
            time_step: None,
1✔
691
        };
1✔
692
        db.update_project(update).await.unwrap();
18✔
693

694
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
695
        assert_eq!(versions.len(), 3);
1✔
696

697
        // delete plots
698
        let update = UpdateProject {
1✔
699
            id: project.id,
1✔
700
            name: None,
1✔
701
            description: None,
1✔
702
            layers: None,
1✔
703
            plots: Some(vec![]),
1✔
704
            bounds: None,
1✔
705
            time_step: None,
1✔
706
        };
1✔
707
        db.update_project(update).await.unwrap();
14✔
708

709
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
710
        assert_eq!(versions.len(), 4);
1✔
711
    }
1✔
712

713
    async fn list_projects(
1✔
714
        app_ctx: &PostgresContext<NoTls>,
1✔
715
        session: &SimpleSession,
1✔
716
    ) -> Vec<ProjectListing> {
1✔
717
        let options = ProjectListOptions {
1✔
718
            filter: ProjectFilter::None,
1✔
719
            order: OrderBy::NameDesc,
1✔
720
            offset: 0,
1✔
721
            limit: 2,
1✔
722
        };
1✔
723

1✔
724
        let db = app_ctx.session_context(session.clone()).db();
1✔
725

726
        let projects = db.list_projects(options).await.unwrap();
11✔
727

1✔
728
        assert_eq!(projects.len(), 2);
1✔
729
        assert_eq!(projects[0].name, "Test9");
1✔
730
        assert_eq!(projects[1].name, "Test8");
1✔
731
        projects
1✔
732
    }
1✔
733

734
    async fn create_projects(app_ctx: &PostgresContext<NoTls>, session: &SimpleSession) {
1✔
735
        let db = app_ctx.session_context(session.clone()).db();
1✔
736

737
        for i in 0..10 {
11✔
738
            let create = CreateProject {
10✔
739
                name: format!("Test{i}"),
10✔
740
                description: format!("Test{}", 10 - i),
10✔
741
                bounds: STRectangle::new(
10✔
742
                    SpatialReferenceOption::Unreferenced,
10✔
743
                    0.,
10✔
744
                    0.,
10✔
745
                    1.,
10✔
746
                    1.,
10✔
747
                    0,
10✔
748
                    1,
10✔
749
                )
10✔
750
                .unwrap(),
10✔
751
                time_step: None,
10✔
752
            };
10✔
753
            db.create_project(create).await.unwrap();
74✔
754
        }
755
    }
1✔
756

757
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
758
    async fn it_persists_workflows() {
1✔
759
        with_temp_context(|app_ctx, _pg_config| async move {
1✔
760
            let workflow = Workflow {
1✔
761
                operator: TypedOperator::Vector(
1✔
762
                    MockPointSource {
1✔
763
                        params: MockPointSourceParams {
1✔
764
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
765
                        },
1✔
766
                    }
1✔
767
                    .boxed(),
1✔
768
                ),
1✔
769
            };
1✔
770

771
            let session = app_ctx.default_session().await.unwrap();
18✔
772
        let ctx = app_ctx.session_context(session);
1✔
773

1✔
774
            let db = ctx
1✔
775
                .db();
1✔
776
            let id = db
1✔
777
                .register_workflow(workflow)
1✔
778
                .await
3✔
779
                .unwrap();
1✔
780

1✔
781
            drop(ctx);
1✔
782

783
            let workflow = db.load_workflow(&id).await.unwrap();
3✔
784

1✔
785
            let json = serde_json::to_string(&workflow).unwrap();
1✔
786
            assert_eq!(json, r#"{"type":"Vector","operator":{"type":"MockPointSource","params":{"points":[{"x":1.0,"y":2.0},{"x":1.0,"y":2.0},{"x":1.0,"y":2.0}]}}}"#);
1✔
787
        })
1✔
788
        .await;
9✔
789
    }
790

791
    #[allow(clippy::too_many_lines)]
792
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
793
    async fn it_persists_datasets() {
1✔
794
        with_temp_context(|app_ctx, _| async move {
1✔
795
            let loading_info = OgrSourceDataset {
1✔
796
                file_name: PathBuf::from("test.csv"),
1✔
797
                layer_name: "test.csv".to_owned(),
1✔
798
                data_type: Some(VectorDataType::MultiPoint),
1✔
799
                time: OgrSourceDatasetTimeType::Start {
1✔
800
                    start_field: "start".to_owned(),
1✔
801
                    start_format: OgrSourceTimeFormat::Auto,
1✔
802
                    duration: OgrSourceDurationSpec::Zero,
1✔
803
                },
1✔
804
                default_geometry: None,
1✔
805
                columns: Some(OgrSourceColumnSpec {
1✔
806
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
807
                        header: CsvHeader::Auto,
1✔
808
                    }),
1✔
809
                    x: "x".to_owned(),
1✔
810
                    y: None,
1✔
811
                    int: vec![],
1✔
812
                    float: vec![],
1✔
813
                    text: vec![],
1✔
814
                    bool: vec![],
1✔
815
                    datetime: vec![],
1✔
816
                    rename: None,
1✔
817
                }),
1✔
818
                force_ogr_time_filter: false,
1✔
819
                force_ogr_spatial_filter: false,
1✔
820
                on_error: OgrSourceErrorSpec::Ignore,
1✔
821
                sql_query: None,
1✔
822
                attribute_query: None,
1✔
823
                cache_ttl: CacheTtlSeconds::default(),
1✔
824
            };
1✔
825

1✔
826
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
827
                OgrSourceDataset,
1✔
828
                VectorResultDescriptor,
1✔
829
                VectorQueryRectangle,
1✔
830
            > {
1✔
831
                loading_info: loading_info.clone(),
1✔
832
                result_descriptor: VectorResultDescriptor {
1✔
833
                    data_type: VectorDataType::MultiPoint,
1✔
834
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
835
                    columns: [(
1✔
836
                        "foo".to_owned(),
1✔
837
                        VectorColumnInfo {
1✔
838
                            data_type: FeatureDataType::Float,
1✔
839
                            measurement: Measurement::Unitless.into(),
1✔
840
                        },
1✔
841
                    )]
1✔
842
                    .into_iter()
1✔
843
                    .collect(),
1✔
844
                    time: None,
1✔
845
                    bbox: None,
1✔
846
                },
1✔
847
                phantom: Default::default(),
1✔
848
            });
1✔
849

850
            let session = app_ctx.default_session().await.unwrap();
18✔
851

1✔
852
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
853

1✔
854
            let db = app_ctx.session_context(session.clone()).db();
1✔
855
            let wrap = db.wrap_meta_data(meta_data);
1✔
856
            let DatasetIdAndName {
857
                id: dataset_id,
1✔
858
                name: dataset_name,
1✔
859
            } = db
1✔
860
                .add_dataset(
1✔
861
                    AddDataset {
1✔
862
                        name: Some(dataset_name.clone()),
1✔
863
                        display_name: "Ogr Test".to_owned(),
1✔
864
                        description: "desc".to_owned(),
1✔
865
                        source_operator: "OgrSource".to_owned(),
1✔
866
                        symbology: None,
1✔
867
                        provenance: Some(vec![Provenance {
1✔
868
                            citation: "citation".to_owned(),
1✔
869
                            license: "license".to_owned(),
1✔
870
                            uri: "uri".to_owned(),
1✔
871
                        }]),
1✔
872
                    },
1✔
873
                    wrap,
1✔
874
                )
1✔
875
                .await
152✔
876
                .unwrap();
1✔
877

878
            let datasets = db
1✔
879
                .list_datasets(DatasetListOptions {
1✔
880
                    filter: None,
1✔
881
                    order: crate::datasets::listing::OrderBy::NameAsc,
1✔
882
                    offset: 0,
1✔
883
                    limit: 10,
1✔
884
                })
1✔
885
                .await
3✔
886
                .unwrap();
1✔
887

1✔
888
            assert_eq!(datasets.len(), 1);
1✔
889

890
            assert_eq!(
1✔
891
                datasets[0],
1✔
892
                DatasetListing {
1✔
893
                    id: dataset_id,
1✔
894
                    name: dataset_name,
1✔
895
                    display_name: "Ogr Test".to_owned(),
1✔
896
                    description: "desc".to_owned(),
1✔
897
                    source_operator: "OgrSource".to_owned(),
1✔
898
                    symbology: None,
1✔
899
                    tags: vec![],
1✔
900
                    result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
901
                        data_type: VectorDataType::MultiPoint,
1✔
902
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
903
                        columns: [(
1✔
904
                            "foo".to_owned(),
1✔
905
                            VectorColumnInfo {
1✔
906
                                data_type: FeatureDataType::Float,
1✔
907
                                measurement: Measurement::Unitless.into()
1✔
908
                            }
1✔
909
                        )]
1✔
910
                        .into_iter()
1✔
911
                        .collect(),
1✔
912
                        time: None,
1✔
913
                        bbox: None,
1✔
914
                    })
1✔
915
                    .into(),
1✔
916
                },
1✔
917
            );
1✔
918

919
            let provenance = db.load_provenance(&dataset_id).await.unwrap();
3✔
920

1✔
921
            assert_eq!(
1✔
922
                provenance,
1✔
923
                ProvenanceOutput {
1✔
924
                    data: dataset_id.into(),
1✔
925
                    provenance: Some(vec![Provenance {
1✔
926
                        citation: "citation".to_owned(),
1✔
927
                        license: "license".to_owned(),
1✔
928
                        uri: "uri".to_owned(),
1✔
929
                    }])
1✔
930
                }
1✔
931
            );
1✔
932

933
            let meta_data: Box<dyn MetaData<OgrSourceDataset, _, _>> =
1✔
934
                db.meta_data(&dataset_id.into()).await.unwrap();
3✔
935

936
            assert_eq!(
1✔
937
                meta_data
1✔
938
                    .loading_info(VectorQueryRectangle {
1✔
939
                        spatial_bounds: BoundingBox2D::new_unchecked(
1✔
940
                            (-180., -90.).into(),
1✔
941
                            (180., 90.).into()
1✔
942
                        ),
1✔
943
                        time_interval: TimeInterval::default(),
1✔
944
                        spatial_resolution: SpatialResolution::zero_point_one(),
1✔
945
                    })
1✔
946
                    .await
×
947
                    .unwrap(),
1✔
948
                loading_info
949
            );
950
        })
1✔
951
        .await;
11✔
952
    }
953

954
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
955
    async fn it_persists_uploads() {
1✔
956
        with_temp_context(|app_ctx, _| async move {
1✔
957
            let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
958
            let input = Upload {
1✔
959
                id,
1✔
960
                files: vec![FileUpload {
1✔
961
                    id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
962
                    name: "test.csv".to_owned(),
1✔
963
                    byte_size: 1337,
1✔
964
                }],
1✔
965
            };
1✔
966

967
            let session = app_ctx.default_session().await.unwrap();
18✔
968

1✔
969
            let db = app_ctx.session_context(session.clone()).db();
1✔
970

1✔
971
            db.create_upload(input.clone()).await.unwrap();
6✔
972

973
            let upload = db.load_upload(id).await.unwrap();
3✔
974

1✔
975
            assert_eq!(upload, input);
1✔
976
        })
1✔
977
        .await;
10✔
978
    }
979

980
    #[allow(clippy::too_many_lines)]
981
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
982
    async fn it_persists_layer_providers() {
1✔
983
        with_temp_context(|app_ctx, _| async move {
1✔
984
            let db = app_ctx.default_session_context().await.unwrap().db();
19✔
985

1✔
986
            let provider_id =
1✔
987
                DataProviderId::from_str("7b20c8d7-d754-4f8f-ad44-dddd25df22d2").unwrap();
1✔
988

1✔
989
            let loading_info = OgrSourceDataset {
1✔
990
                file_name: PathBuf::from("test.csv"),
1✔
991
                layer_name: "test.csv".to_owned(),
1✔
992
                data_type: Some(VectorDataType::MultiPoint),
1✔
993
                time: OgrSourceDatasetTimeType::Start {
1✔
994
                    start_field: "start".to_owned(),
1✔
995
                    start_format: OgrSourceTimeFormat::Auto,
1✔
996
                    duration: OgrSourceDurationSpec::Zero,
1✔
997
                },
1✔
998
                default_geometry: None,
1✔
999
                columns: Some(OgrSourceColumnSpec {
1✔
1000
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1001
                        header: CsvHeader::Auto,
1✔
1002
                    }),
1✔
1003
                    x: "x".to_owned(),
1✔
1004
                    y: None,
1✔
1005
                    int: vec![],
1✔
1006
                    float: vec![],
1✔
1007
                    text: vec![],
1✔
1008
                    bool: vec![],
1✔
1009
                    datetime: vec![],
1✔
1010
                    rename: None,
1✔
1011
                }),
1✔
1012
                force_ogr_time_filter: false,
1✔
1013
                force_ogr_spatial_filter: false,
1✔
1014
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1015
                sql_query: None,
1✔
1016
                attribute_query: None,
1✔
1017
                cache_ttl: CacheTtlSeconds::default(),
1✔
1018
            };
1✔
1019

1✔
1020
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1021
                OgrSourceDataset,
1✔
1022
                VectorResultDescriptor,
1✔
1023
                VectorQueryRectangle,
1✔
1024
            > {
1✔
1025
                loading_info: loading_info.clone(),
1✔
1026
                result_descriptor: VectorResultDescriptor {
1✔
1027
                    data_type: VectorDataType::MultiPoint,
1✔
1028
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1029
                    columns: [(
1✔
1030
                        "foo".to_owned(),
1✔
1031
                        VectorColumnInfo {
1✔
1032
                            data_type: FeatureDataType::Float,
1✔
1033
                            measurement: Measurement::Unitless.into(),
1✔
1034
                        },
1✔
1035
                    )]
1✔
1036
                    .into_iter()
1✔
1037
                    .collect(),
1✔
1038
                    time: None,
1✔
1039
                    bbox: None,
1✔
1040
                },
1✔
1041
                phantom: Default::default(),
1✔
1042
            });
1✔
1043

1✔
1044
            let provider = MockExternalLayerProviderDefinition {
1✔
1045
                id: provider_id,
1✔
1046
                root_collection: MockCollection {
1✔
1047
                    id: LayerCollectionId("b5f82c7c-9133-4ac1-b4ae-8faac3b9a6df".to_owned()),
1✔
1048
                    name: "Mock Collection A".to_owned(),
1✔
1049
                    description: "Some description".to_owned(),
1✔
1050
                    collections: vec![MockCollection {
1✔
1051
                        id: LayerCollectionId("21466897-37a1-4666-913a-50b5244699ad".to_owned()),
1✔
1052
                        name: "Mock Collection B".to_owned(),
1✔
1053
                        description: "Some description".to_owned(),
1✔
1054
                        collections: vec![],
1✔
1055
                        layers: vec![],
1✔
1056
                    }],
1✔
1057
                    layers: vec![],
1✔
1058
                },
1✔
1059
                data: [("myData".to_owned(), meta_data)].into_iter().collect(),
1✔
1060
            };
1✔
1061

1✔
1062
            db.add_layer_provider(Box::new(provider)).await.unwrap();
3✔
1063

1064
            let providers = db
1✔
1065
                .list_layer_providers(LayerProviderListingOptions {
1✔
1066
                    offset: 0,
1✔
1067
                    limit: 10,
1✔
1068
                })
1✔
1069
                .await
3✔
1070
                .unwrap();
1✔
1071

1✔
1072
            assert_eq!(providers.len(), 1);
1✔
1073

1074
            assert_eq!(
1✔
1075
                providers[0],
1✔
1076
                LayerProviderListing {
1✔
1077
                    id: provider_id,
1✔
1078
                    name: "MockName".to_owned(),
1✔
1079
                    description: "MockType".to_owned(),
1✔
1080
                }
1✔
1081
            );
1✔
1082

1083
            let provider = db.load_layer_provider(provider_id).await.unwrap();
3✔
1084

1085
            let datasets = provider
1✔
1086
                .load_layer_collection(
1087
                    &provider.get_root_layer_collection_id().await.unwrap(),
1✔
1088
                    LayerCollectionListOptions {
1✔
1089
                        offset: 0,
1✔
1090
                        limit: 10,
1✔
1091
                    },
1✔
1092
                )
1093
                .await
×
1094
                .unwrap();
1✔
1095

1✔
1096
            assert_eq!(datasets.items.len(), 1);
1✔
1097
        })
1✔
1098
        .await;
10✔
1099
    }
1100

1101
    #[allow(clippy::too_many_lines)]
1102
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1103
    async fn it_loads_all_meta_data_types() {
1✔
1104
        with_temp_context(|app_ctx, _| async move {
1✔
1105
            let session = app_ctx.default_session().await.unwrap();
18✔
1106

1✔
1107
            let db = app_ctx.session_context(session.clone()).db();
1✔
1108

1✔
1109
            let vector_descriptor = VectorResultDescriptor {
1✔
1110
                data_type: VectorDataType::Data,
1✔
1111
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1112
                columns: Default::default(),
1✔
1113
                time: None,
1✔
1114
                bbox: None,
1✔
1115
            };
1✔
1116

1✔
1117
            let raster_descriptor = RasterResultDescriptor {
1✔
1118
                data_type: RasterDataType::U8,
1✔
1119
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1120
                measurement: Default::default(),
1✔
1121
                time: None,
1✔
1122
                bbox: None,
1✔
1123
                resolution: None,
1✔
1124
            };
1✔
1125

1✔
1126
            let vector_ds = AddDataset {
1✔
1127
                name: None,
1✔
1128
                display_name: "OgrDataset".to_string(),
1✔
1129
                description: "My Ogr dataset".to_string(),
1✔
1130
                source_operator: "OgrSource".to_string(),
1✔
1131
                symbology: None,
1✔
1132
                provenance: None,
1✔
1133
            };
1✔
1134

1✔
1135
            let raster_ds = AddDataset {
1✔
1136
                name: None,
1✔
1137
                display_name: "GdalDataset".to_string(),
1✔
1138
                description: "My Gdal dataset".to_string(),
1✔
1139
                source_operator: "GdalSource".to_string(),
1✔
1140
                symbology: None,
1✔
1141
                provenance: None,
1✔
1142
            };
1✔
1143

1✔
1144
            let gdal_params = GdalDatasetParameters {
1✔
1145
                file_path: Default::default(),
1✔
1146
                rasterband_channel: 0,
1✔
1147
                geo_transform: GdalDatasetGeoTransform {
1✔
1148
                    origin_coordinate: Default::default(),
1✔
1149
                    x_pixel_size: 0.0,
1✔
1150
                    y_pixel_size: 0.0,
1✔
1151
                },
1✔
1152
                width: 0,
1✔
1153
                height: 0,
1✔
1154
                file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1155
                no_data_value: None,
1✔
1156
                properties_mapping: None,
1✔
1157
                gdal_open_options: None,
1✔
1158
                gdal_config_options: None,
1✔
1159
                allow_alphaband_as_mask: false,
1✔
1160
                retry: None,
1✔
1161
            };
1✔
1162

1✔
1163
            let meta = StaticMetaData {
1✔
1164
                loading_info: OgrSourceDataset {
1✔
1165
                    file_name: Default::default(),
1✔
1166
                    layer_name: String::new(),
1✔
1167
                    data_type: None,
1✔
1168
                    time: Default::default(),
1✔
1169
                    default_geometry: None,
1✔
1170
                    columns: None,
1✔
1171
                    force_ogr_time_filter: false,
1✔
1172
                    force_ogr_spatial_filter: false,
1✔
1173
                    on_error: OgrSourceErrorSpec::Ignore,
1✔
1174
                    sql_query: None,
1✔
1175
                    attribute_query: None,
1✔
1176
                    cache_ttl: CacheTtlSeconds::default(),
1✔
1177
                },
1✔
1178
                result_descriptor: vector_descriptor.clone(),
1✔
1179
                phantom: Default::default(),
1✔
1180
            };
1✔
1181

1✔
1182
            let meta = db.wrap_meta_data(MetaDataDefinition::OgrMetaData(meta));
1✔
1183

1184
            let id = db.add_dataset(vector_ds, meta).await.unwrap().id;
152✔
1185

1186
            let meta: geoengine_operators::util::Result<
1✔
1187
                Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1188
            > = db.meta_data(&id.into()).await;
3✔
1189

1190
            assert!(meta.is_ok());
1✔
1191

1192
            let meta = GdalMetaDataRegular {
1✔
1193
                result_descriptor: raster_descriptor.clone(),
1✔
1194
                params: gdal_params.clone(),
1✔
1195
                time_placeholders: Default::default(),
1✔
1196
                data_time: Default::default(),
1✔
1197
                step: TimeStep {
1✔
1198
                    granularity: TimeGranularity::Millis,
1✔
1199
                    step: 0,
1✔
1200
                },
1✔
1201
                cache_ttl: CacheTtlSeconds::default(),
1✔
1202
            };
1✔
1203

1✔
1204
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataRegular(meta));
1✔
1205

1206
            let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1207

1208
            let meta: geoengine_operators::util::Result<
1✔
1209
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1210
            > = db.meta_data(&id.into()).await;
3✔
1211

1212
            assert!(meta.is_ok());
1✔
1213

1214
            let meta = GdalMetaDataStatic {
1✔
1215
                time: None,
1✔
1216
                params: gdal_params.clone(),
1✔
1217
                result_descriptor: raster_descriptor.clone(),
1✔
1218
                cache_ttl: CacheTtlSeconds::default(),
1✔
1219
            };
1✔
1220

1✔
1221
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalStatic(meta));
1✔
1222

1223
            let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1224

1225
            let meta: geoengine_operators::util::Result<
1✔
1226
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1227
            > = db.meta_data(&id.into()).await;
3✔
1228

1229
            assert!(meta.is_ok());
1✔
1230

1231
            let meta = GdalMetaDataList {
1✔
1232
                result_descriptor: raster_descriptor.clone(),
1✔
1233
                params: vec![],
1✔
1234
            };
1✔
1235

1✔
1236
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataList(meta));
1✔
1237

1238
            let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1239

1240
            let meta: geoengine_operators::util::Result<
1✔
1241
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1242
            > = db.meta_data(&id.into()).await;
4✔
1243

1244
            assert!(meta.is_ok());
1✔
1245

1246
            let meta = GdalMetadataNetCdfCf {
1✔
1247
                result_descriptor: raster_descriptor.clone(),
1✔
1248
                params: gdal_params.clone(),
1✔
1249
                start: TimeInstance::MIN,
1✔
1250
                end: TimeInstance::MAX,
1✔
1251
                step: TimeStep {
1✔
1252
                    granularity: TimeGranularity::Millis,
1✔
1253
                    step: 0,
1✔
1254
                },
1✔
1255
                band_offset: 0,
1✔
1256
                cache_ttl: CacheTtlSeconds::default(),
1✔
1257
            };
1✔
1258

1✔
1259
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetadataNetCdfCf(meta));
1✔
1260

1261
            let id = db.add_dataset(raster_ds.clone(), meta).await.unwrap().id;
3✔
1262

1263
            let meta: geoengine_operators::util::Result<
1✔
1264
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1265
            > = db.meta_data(&id.into()).await;
3✔
1266

1267
            assert!(meta.is_ok());
1✔
1268
        })
1✔
1269
        .await;
12✔
1270
    }
1271

1272
    #[allow(clippy::too_many_lines)]
1273
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1274
    async fn it_collects_layers() {
1✔
1275
        with_temp_context(|app_ctx, _| async move {
1✔
1276
            let session = app_ctx.default_session().await.unwrap();
18✔
1277

1✔
1278
            let layer_db = app_ctx.session_context(session).db();
1✔
1279

1✔
1280
            let workflow = Workflow {
1✔
1281
                operator: TypedOperator::Vector(
1✔
1282
                    MockPointSource {
1✔
1283
                        params: MockPointSourceParams {
1✔
1284
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1285
                        },
1✔
1286
                    }
1✔
1287
                    .boxed(),
1✔
1288
                ),
1✔
1289
            };
1✔
1290

1291
            let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1292

1293
            let layer1 = layer_db
1✔
1294
                .add_layer(
1✔
1295
                    AddLayer {
1✔
1296
                        name: "Layer1".to_string(),
1✔
1297
                        description: "Layer 1".to_string(),
1✔
1298
                        symbology: None,
1✔
1299
                        workflow: workflow.clone(),
1✔
1300
                        metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1301
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1302
                    },
1✔
1303
                    &root_collection_id,
1✔
1304
                )
1✔
1305
                .await
43✔
1306
                .unwrap();
1✔
1307

1308
            assert_eq!(
1✔
1309
                layer_db.load_layer(&layer1).await.unwrap(),
3✔
1310
                crate::layers::layer::Layer {
1✔
1311
                    id: ProviderLayerId {
1✔
1312
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1313
                        layer_id: layer1.clone(),
1✔
1314
                    },
1✔
1315
                    name: "Layer1".to_string(),
1✔
1316
                    description: "Layer 1".to_string(),
1✔
1317
                    symbology: None,
1✔
1318
                    workflow: workflow.clone(),
1✔
1319
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1320
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1321
                }
1✔
1322
            );
1323

1324
            let collection1_id = layer_db
1✔
1325
                .add_layer_collection(
1✔
1326
                    AddLayerCollection {
1✔
1327
                        name: "Collection1".to_string(),
1✔
1328
                        description: "Collection 1".to_string(),
1✔
1329
                        properties: Default::default(),
1✔
1330
                    },
1✔
1331
                    &root_collection_id,
1✔
1332
                )
1✔
1333
                .await
7✔
1334
                .unwrap();
1✔
1335

1336
            let layer2 = layer_db
1✔
1337
                .add_layer(
1✔
1338
                    AddLayer {
1✔
1339
                        name: "Layer2".to_string(),
1✔
1340
                        description: "Layer 2".to_string(),
1✔
1341
                        symbology: None,
1✔
1342
                        workflow: workflow.clone(),
1✔
1343
                        metadata: Default::default(),
1✔
1344
                        properties: Default::default(),
1✔
1345
                    },
1✔
1346
                    &collection1_id,
1✔
1347
                )
1✔
1348
                .await
9✔
1349
                .unwrap();
1✔
1350

1351
            let collection2_id = layer_db
1✔
1352
                .add_layer_collection(
1✔
1353
                    AddLayerCollection {
1✔
1354
                        name: "Collection2".to_string(),
1✔
1355
                        description: "Collection 2".to_string(),
1✔
1356
                        properties: Default::default(),
1✔
1357
                    },
1✔
1358
                    &collection1_id,
1✔
1359
                )
1✔
1360
                .await
7✔
1361
                .unwrap();
1✔
1362

1✔
1363
            layer_db
1✔
1364
                .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1365
                .await
3✔
1366
                .unwrap();
1✔
1367

1368
            let root_collection = layer_db
1✔
1369
                .load_layer_collection(
1✔
1370
                    &root_collection_id,
1✔
1371
                    LayerCollectionListOptions {
1✔
1372
                        offset: 0,
1✔
1373
                        limit: 20,
1✔
1374
                    },
1✔
1375
                )
1✔
1376
                .await
5✔
1377
                .unwrap();
1✔
1378

1✔
1379
            assert_eq!(
1✔
1380
                root_collection,
1✔
1381
                LayerCollection {
1✔
1382
                    id: ProviderLayerCollectionId {
1✔
1383
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1384
                        collection_id: root_collection_id,
1✔
1385
                    },
1✔
1386
                    name: "Layers".to_string(),
1✔
1387
                    description: "All available Geo Engine layers".to_string(),
1✔
1388
                    items: vec![
1✔
1389
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1390
                            id: ProviderLayerCollectionId {
1✔
1391
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1392
                                collection_id: collection1_id.clone(),
1✔
1393
                            },
1✔
1394
                            name: "Collection1".to_string(),
1✔
1395
                            description: "Collection 1".to_string(),
1✔
1396
                            properties: Default::default(),
1✔
1397
                        }),
1✔
1398
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1399
                            id: ProviderLayerCollectionId {
1✔
1400
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1401
                                collection_id: LayerCollectionId(
1✔
1402
                                    UNSORTED_COLLECTION_ID.to_string()
1✔
1403
                                ),
1✔
1404
                            },
1✔
1405
                            name: "Unsorted".to_string(),
1✔
1406
                            description: "Unsorted Layers".to_string(),
1✔
1407
                            properties: Default::default(),
1✔
1408
                        }),
1✔
1409
                        CollectionItem::Layer(LayerListing {
1✔
1410
                            id: ProviderLayerId {
1✔
1411
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1412
                                layer_id: layer1,
1✔
1413
                            },
1✔
1414
                            name: "Layer1".to_string(),
1✔
1415
                            description: "Layer 1".to_string(),
1✔
1416
                            properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1417
                        })
1✔
1418
                    ],
1✔
1419
                    entry_label: None,
1✔
1420
                    properties: vec![],
1✔
1421
                }
1✔
1422
            );
1✔
1423

1424
            let collection1 = layer_db
1✔
1425
                .load_layer_collection(
1✔
1426
                    &collection1_id,
1✔
1427
                    LayerCollectionListOptions {
1✔
1428
                        offset: 0,
1✔
1429
                        limit: 20,
1✔
1430
                    },
1✔
1431
                )
1✔
1432
                .await
5✔
1433
                .unwrap();
1✔
1434

1✔
1435
            assert_eq!(
1✔
1436
                collection1,
1✔
1437
                LayerCollection {
1✔
1438
                    id: ProviderLayerCollectionId {
1✔
1439
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1440
                        collection_id: collection1_id,
1✔
1441
                    },
1✔
1442
                    name: "Collection1".to_string(),
1✔
1443
                    description: "Collection 1".to_string(),
1✔
1444
                    items: vec![
1✔
1445
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1446
                            id: ProviderLayerCollectionId {
1✔
1447
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1448
                                collection_id: collection2_id,
1✔
1449
                            },
1✔
1450
                            name: "Collection2".to_string(),
1✔
1451
                            description: "Collection 2".to_string(),
1✔
1452
                            properties: Default::default(),
1✔
1453
                        }),
1✔
1454
                        CollectionItem::Layer(LayerListing {
1✔
1455
                            id: ProviderLayerId {
1✔
1456
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1457
                                layer_id: layer2,
1✔
1458
                            },
1✔
1459
                            name: "Layer2".to_string(),
1✔
1460
                            description: "Layer 2".to_string(),
1✔
1461
                            properties: vec![],
1✔
1462
                        })
1✔
1463
                    ],
1✔
1464
                    entry_label: None,
1✔
1465
                    properties: vec![],
1✔
1466
                }
1✔
1467
            );
1✔
1468
        })
1✔
1469
        .await;
12✔
1470
    }
1471

1472
    #[allow(clippy::too_many_lines)]
1473
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1474
    async fn it_removes_layer_collections() {
1✔
1475
        with_temp_context(|app_ctx, _| async move {
1✔
1476
            let session = app_ctx.default_session().await.unwrap();
18✔
1477

1✔
1478
            let layer_db = app_ctx.session_context(session).db();
1✔
1479

1✔
1480
            let layer = AddLayer {
1✔
1481
                name: "layer".to_string(),
1✔
1482
                description: "description".to_string(),
1✔
1483
                workflow: Workflow {
1✔
1484
                    operator: TypedOperator::Vector(
1✔
1485
                        MockPointSource {
1✔
1486
                            params: MockPointSourceParams {
1✔
1487
                                points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1488
                            },
1✔
1489
                        }
1✔
1490
                        .boxed(),
1✔
1491
                    ),
1✔
1492
                },
1✔
1493
                symbology: None,
1✔
1494
                metadata: Default::default(),
1✔
1495
                properties: Default::default(),
1✔
1496
            };
1✔
1497

1498
            let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1499

1✔
1500
            let collection = AddLayerCollection {
1✔
1501
                name: "top collection".to_string(),
1✔
1502
                description: "description".to_string(),
1✔
1503
                properties: Default::default(),
1✔
1504
            };
1✔
1505

1506
            let top_c_id = layer_db
1✔
1507
                .add_layer_collection(collection, root_collection)
1✔
1508
                .await
10✔
1509
                .unwrap();
1✔
1510

1511
            let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
40✔
1512

1✔
1513
            let collection = AddLayerCollection {
1✔
1514
                name: "empty collection".to_string(),
1✔
1515
                description: "description".to_string(),
1✔
1516
                properties: Default::default(),
1✔
1517
            };
1✔
1518

1519
            let empty_c_id = layer_db
1✔
1520
                .add_layer_collection(collection, &top_c_id)
1✔
1521
                .await
7✔
1522
                .unwrap();
1✔
1523

1524
            let items = layer_db
1✔
1525
                .load_layer_collection(
1✔
1526
                    &top_c_id,
1✔
1527
                    LayerCollectionListOptions {
1✔
1528
                        offset: 0,
1✔
1529
                        limit: 20,
1✔
1530
                    },
1✔
1531
                )
1✔
1532
                .await
5✔
1533
                .unwrap();
1✔
1534

1✔
1535
            assert_eq!(
1✔
1536
                items,
1✔
1537
                LayerCollection {
1✔
1538
                    id: ProviderLayerCollectionId {
1✔
1539
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1540
                        collection_id: top_c_id.clone(),
1✔
1541
                    },
1✔
1542
                    name: "top collection".to_string(),
1✔
1543
                    description: "description".to_string(),
1✔
1544
                    items: vec![
1✔
1545
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1546
                            id: ProviderLayerCollectionId {
1✔
1547
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1548
                                collection_id: empty_c_id.clone(),
1✔
1549
                            },
1✔
1550
                            name: "empty collection".to_string(),
1✔
1551
                            description: "description".to_string(),
1✔
1552
                            properties: Default::default(),
1✔
1553
                        }),
1✔
1554
                        CollectionItem::Layer(LayerListing {
1✔
1555
                            id: ProviderLayerId {
1✔
1556
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1557
                                layer_id: l_id.clone(),
1✔
1558
                            },
1✔
1559
                            name: "layer".to_string(),
1✔
1560
                            description: "description".to_string(),
1✔
1561
                            properties: vec![],
1✔
1562
                        })
1✔
1563
                    ],
1✔
1564
                    entry_label: None,
1✔
1565
                    properties: vec![],
1✔
1566
                }
1✔
1567
            );
1✔
1568

1569
            // remove empty collection
1570
            layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
9✔
1571

1572
            let items = layer_db
1✔
1573
                .load_layer_collection(
1✔
1574
                    &top_c_id,
1✔
1575
                    LayerCollectionListOptions {
1✔
1576
                        offset: 0,
1✔
1577
                        limit: 20,
1✔
1578
                    },
1✔
1579
                )
1✔
1580
                .await
5✔
1581
                .unwrap();
1✔
1582

1✔
1583
            assert_eq!(
1✔
1584
                items,
1✔
1585
                LayerCollection {
1✔
1586
                    id: ProviderLayerCollectionId {
1✔
1587
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1588
                        collection_id: top_c_id.clone(),
1✔
1589
                    },
1✔
1590
                    name: "top collection".to_string(),
1✔
1591
                    description: "description".to_string(),
1✔
1592
                    items: vec![CollectionItem::Layer(LayerListing {
1✔
1593
                        id: ProviderLayerId {
1✔
1594
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1595
                            layer_id: l_id.clone(),
1✔
1596
                        },
1✔
1597
                        name: "layer".to_string(),
1✔
1598
                        description: "description".to_string(),
1✔
1599
                        properties: vec![],
1✔
1600
                    })],
1✔
1601
                    entry_label: None,
1✔
1602
                    properties: vec![],
1✔
1603
                }
1✔
1604
            );
1✔
1605

1606
            // remove top (not root) collection
1607
            layer_db.remove_layer_collection(&top_c_id).await.unwrap();
9✔
1608

1✔
1609
            layer_db
1✔
1610
                .load_layer_collection(
1✔
1611
                    &top_c_id,
1✔
1612
                    LayerCollectionListOptions {
1✔
1613
                        offset: 0,
1✔
1614
                        limit: 20,
1✔
1615
                    },
1✔
1616
                )
1✔
1617
                .await
3✔
1618
                .unwrap_err();
1✔
1619

1✔
1620
            // should be deleted automatically
1✔
1621
            layer_db.load_layer(&l_id).await.unwrap_err();
3✔
1622

1✔
1623
            // it is not allowed to remove the root collection
1✔
1624
            layer_db
1✔
1625
                .remove_layer_collection(root_collection)
1✔
1626
                .await
×
1627
                .unwrap_err();
1✔
1628
            layer_db
1✔
1629
                .load_layer_collection(
1✔
1630
                    root_collection,
1✔
1631
                    LayerCollectionListOptions {
1✔
1632
                        offset: 0,
1✔
1633
                        limit: 20,
1✔
1634
                    },
1✔
1635
                )
1✔
1636
                .await
5✔
1637
                .unwrap();
1✔
1638
        })
1✔
1639
        .await;
11✔
1640
    }
1641

1642
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1643
    #[allow(clippy::too_many_lines)]
1644
    async fn it_removes_collections_from_collections() {
1✔
1645
        with_temp_context(|app_ctx, _| async move {
1✔
1646
            let session = app_ctx.default_session().await.unwrap();
18✔
1647

1✔
1648
            let db = app_ctx.session_context(session).db();
1✔
1649

1650
            let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
1651

1652
            let mid_collection_id = db
1✔
1653
                .add_layer_collection(
1✔
1654
                    AddLayerCollection {
1✔
1655
                        name: "mid collection".to_string(),
1✔
1656
                        description: "description".to_string(),
1✔
1657
                        properties: Default::default(),
1✔
1658
                    },
1✔
1659
                    root_collection_id,
1✔
1660
                )
1✔
1661
                .await
10✔
1662
                .unwrap();
1✔
1663

1664
            let bottom_collection_id = db
1✔
1665
                .add_layer_collection(
1✔
1666
                    AddLayerCollection {
1✔
1667
                        name: "bottom collection".to_string(),
1✔
1668
                        description: "description".to_string(),
1✔
1669
                        properties: Default::default(),
1✔
1670
                    },
1✔
1671
                    &mid_collection_id,
1✔
1672
                )
1✔
1673
                .await
7✔
1674
                .unwrap();
1✔
1675

1676
            let layer_id = db
1✔
1677
                .add_layer(
1✔
1678
                    AddLayer {
1✔
1679
                        name: "layer".to_string(),
1✔
1680
                        description: "description".to_string(),
1✔
1681
                        workflow: Workflow {
1✔
1682
                            operator: TypedOperator::Vector(
1✔
1683
                                MockPointSource {
1✔
1684
                                    params: MockPointSourceParams {
1✔
1685
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1686
                                    },
1✔
1687
                                }
1✔
1688
                                .boxed(),
1✔
1689
                            ),
1✔
1690
                        },
1✔
1691
                        symbology: None,
1✔
1692
                        metadata: Default::default(),
1✔
1693
                        properties: Default::default(),
1✔
1694
                    },
1✔
1695
                    &mid_collection_id,
1✔
1696
                )
1✔
1697
                .await
41✔
1698
                .unwrap();
1✔
1699

1✔
1700
            // removing the mid collection…
1✔
1701
            db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
1702
                .await
11✔
1703
                .unwrap();
1✔
1704

1✔
1705
            // …should remove itself
1✔
1706
            db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
1707
                .await
3✔
1708
                .unwrap_err();
1✔
1709

1✔
1710
            // …should remove the bottom collection
1✔
1711
            db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
1712
                .await
3✔
1713
                .unwrap_err();
1✔
1714

1✔
1715
            // … and should remove the layer of the bottom collection
1✔
1716
            db.load_layer(&layer_id).await.unwrap_err();
3✔
1717

1✔
1718
            // the root collection is still there
1✔
1719
            db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
1720
                .await
5✔
1721
                .unwrap();
1✔
1722
        })
1✔
1723
        .await;
11✔
1724
    }
1725

1726
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1727
    #[allow(clippy::too_many_lines)]
1728
    async fn it_removes_layers_from_collections() {
1✔
1729
        with_temp_context(|app_ctx, _| async move {
1✔
1730
            let session = app_ctx.default_session().await.unwrap();
18✔
1731

1✔
1732
            let db = app_ctx.session_context(session).db();
1✔
1733

1734
            let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
1735

1736
            let another_collection = db
1✔
1737
                .add_layer_collection(
1✔
1738
                    AddLayerCollection {
1✔
1739
                        name: "top collection".to_string(),
1✔
1740
                        description: "description".to_string(),
1✔
1741
                        properties: Default::default(),
1✔
1742
                    },
1✔
1743
                    root_collection,
1✔
1744
                )
1✔
1745
                .await
10✔
1746
                .unwrap();
1✔
1747

1748
            let layer_in_one_collection = db
1✔
1749
                .add_layer(
1✔
1750
                    AddLayer {
1✔
1751
                        name: "layer 1".to_string(),
1✔
1752
                        description: "description".to_string(),
1✔
1753
                        workflow: Workflow {
1✔
1754
                            operator: TypedOperator::Vector(
1✔
1755
                                MockPointSource {
1✔
1756
                                    params: MockPointSourceParams {
1✔
1757
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1758
                                    },
1✔
1759
                                }
1✔
1760
                                .boxed(),
1✔
1761
                            ),
1✔
1762
                        },
1✔
1763
                        symbology: None,
1✔
1764
                        metadata: Default::default(),
1✔
1765
                        properties: Default::default(),
1✔
1766
                    },
1✔
1767
                    &another_collection,
1✔
1768
                )
1✔
1769
                .await
41✔
1770
                .unwrap();
1✔
1771

1772
            let layer_in_two_collections = db
1✔
1773
                .add_layer(
1✔
1774
                    AddLayer {
1✔
1775
                        name: "layer 2".to_string(),
1✔
1776
                        description: "description".to_string(),
1✔
1777
                        workflow: Workflow {
1✔
1778
                            operator: TypedOperator::Vector(
1✔
1779
                                MockPointSource {
1✔
1780
                                    params: MockPointSourceParams {
1✔
1781
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1782
                                    },
1✔
1783
                                }
1✔
1784
                                .boxed(),
1✔
1785
                            ),
1✔
1786
                        },
1✔
1787
                        symbology: None,
1✔
1788
                        metadata: Default::default(),
1✔
1789
                        properties: Default::default(),
1✔
1790
                    },
1✔
1791
                    &another_collection,
1✔
1792
                )
1✔
1793
                .await
9✔
1794
                .unwrap();
1✔
1795

1✔
1796
            db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
1797
                .await
3✔
1798
                .unwrap();
1✔
1799

1✔
1800
            // remove first layer --> should be deleted entirely
1✔
1801

1✔
1802
            db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
1803
                .await
7✔
1804
                .unwrap();
1✔
1805

1806
            let number_of_layer_in_collection = db
1✔
1807
                .load_layer_collection(
1✔
1808
                    &another_collection,
1✔
1809
                    LayerCollectionListOptions {
1✔
1810
                        offset: 0,
1✔
1811
                        limit: 20,
1✔
1812
                    },
1✔
1813
                )
1✔
1814
                .await
5✔
1815
                .unwrap()
1✔
1816
                .items
1✔
1817
                .len();
1✔
1818
            assert_eq!(
1✔
1819
                number_of_layer_in_collection,
1✔
1820
                1 /* only the other collection should be here */
1✔
1821
            );
1✔
1822

1823
            db.load_layer(&layer_in_one_collection).await.unwrap_err();
3✔
1824

1✔
1825
            // remove second layer --> should only be gone in collection
1✔
1826

1✔
1827
            db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
1828
                .await
7✔
1829
                .unwrap();
1✔
1830

1831
            let number_of_layer_in_collection = db
1✔
1832
                .load_layer_collection(
1✔
1833
                    &another_collection,
1✔
1834
                    LayerCollectionListOptions {
1✔
1835
                        offset: 0,
1✔
1836
                        limit: 20,
1✔
1837
                    },
1✔
1838
                )
1✔
1839
                .await
5✔
1840
                .unwrap()
1✔
1841
                .items
1✔
1842
                .len();
1✔
1843
            assert_eq!(
1✔
1844
                number_of_layer_in_collection,
1✔
1845
                0 /* both layers were deleted */
1✔
1846
            );
1✔
1847

1848
            db.load_layer(&layer_in_two_collections).await.unwrap();
3✔
1849
        })
1✔
1850
        .await;
11✔
1851
    }
1852

1853
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1854
    #[allow(clippy::too_many_lines)]
1855
    async fn it_deletes_dataset() {
1✔
1856
        with_temp_context(|app_ctx, _| async move {
1✔
1857
            let loading_info = OgrSourceDataset {
1✔
1858
                file_name: PathBuf::from("test.csv"),
1✔
1859
                layer_name: "test.csv".to_owned(),
1✔
1860
                data_type: Some(VectorDataType::MultiPoint),
1✔
1861
                time: OgrSourceDatasetTimeType::Start {
1✔
1862
                    start_field: "start".to_owned(),
1✔
1863
                    start_format: OgrSourceTimeFormat::Auto,
1✔
1864
                    duration: OgrSourceDurationSpec::Zero,
1✔
1865
                },
1✔
1866
                default_geometry: None,
1✔
1867
                columns: Some(OgrSourceColumnSpec {
1✔
1868
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1869
                        header: CsvHeader::Auto,
1✔
1870
                    }),
1✔
1871
                    x: "x".to_owned(),
1✔
1872
                    y: None,
1✔
1873
                    int: vec![],
1✔
1874
                    float: vec![],
1✔
1875
                    text: vec![],
1✔
1876
                    bool: vec![],
1✔
1877
                    datetime: vec![],
1✔
1878
                    rename: None,
1✔
1879
                }),
1✔
1880
                force_ogr_time_filter: false,
1✔
1881
                force_ogr_spatial_filter: false,
1✔
1882
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1883
                sql_query: None,
1✔
1884
                attribute_query: None,
1✔
1885
                cache_ttl: CacheTtlSeconds::default(),
1✔
1886
            };
1✔
1887

1✔
1888
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1889
                OgrSourceDataset,
1✔
1890
                VectorResultDescriptor,
1✔
1891
                VectorQueryRectangle,
1✔
1892
            > {
1✔
1893
                loading_info: loading_info.clone(),
1✔
1894
                result_descriptor: VectorResultDescriptor {
1✔
1895
                    data_type: VectorDataType::MultiPoint,
1✔
1896
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1897
                    columns: [(
1✔
1898
                        "foo".to_owned(),
1✔
1899
                        VectorColumnInfo {
1✔
1900
                            data_type: FeatureDataType::Float,
1✔
1901
                            measurement: Measurement::Unitless.into(),
1✔
1902
                        },
1✔
1903
                    )]
1✔
1904
                    .into_iter()
1✔
1905
                    .collect(),
1✔
1906
                    time: None,
1✔
1907
                    bbox: None,
1✔
1908
                },
1✔
1909
                phantom: Default::default(),
1✔
1910
            });
1✔
1911

1912
            let session = app_ctx.default_session().await.unwrap();
18✔
1913

1✔
1914
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1915

1✔
1916
            let db = app_ctx.session_context(session.clone()).db();
1✔
1917
            let wrap = db.wrap_meta_data(meta_data);
1✔
1918
            let dataset_id = db
1✔
1919
                .add_dataset(
1✔
1920
                    AddDataset {
1✔
1921
                        name: Some(dataset_name),
1✔
1922
                        display_name: "Ogr Test".to_owned(),
1✔
1923
                        description: "desc".to_owned(),
1✔
1924
                        source_operator: "OgrSource".to_owned(),
1✔
1925
                        symbology: None,
1✔
1926
                        provenance: Some(vec![Provenance {
1✔
1927
                            citation: "citation".to_owned(),
1✔
1928
                            license: "license".to_owned(),
1✔
1929
                            uri: "uri".to_owned(),
1✔
1930
                        }]),
1✔
1931
                    },
1✔
1932
                    wrap,
1✔
1933
                )
1✔
1934
                .await
152✔
1935
                .unwrap()
1✔
1936
                .id;
1937

1938
            assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
1939

1940
            db.delete_dataset(dataset_id).await.unwrap();
3✔
1941

1942
            assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
1943
        })
1✔
1944
        .await;
11✔
1945
    }
1946

1947
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1948
    #[allow(clippy::too_many_lines)]
1949
    async fn it_deletes_admin_dataset() {
1✔
1950
        with_temp_context(|app_ctx, _| async move {
1✔
1951
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1952

1✔
1953
            let loading_info = OgrSourceDataset {
1✔
1954
                file_name: PathBuf::from("test.csv"),
1✔
1955
                layer_name: "test.csv".to_owned(),
1✔
1956
                data_type: Some(VectorDataType::MultiPoint),
1✔
1957
                time: OgrSourceDatasetTimeType::Start {
1✔
1958
                    start_field: "start".to_owned(),
1✔
1959
                    start_format: OgrSourceTimeFormat::Auto,
1✔
1960
                    duration: OgrSourceDurationSpec::Zero,
1✔
1961
                },
1✔
1962
                default_geometry: None,
1✔
1963
                columns: Some(OgrSourceColumnSpec {
1✔
1964
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1965
                        header: CsvHeader::Auto,
1✔
1966
                    }),
1✔
1967
                    x: "x".to_owned(),
1✔
1968
                    y: None,
1✔
1969
                    int: vec![],
1✔
1970
                    float: vec![],
1✔
1971
                    text: vec![],
1✔
1972
                    bool: vec![],
1✔
1973
                    datetime: vec![],
1✔
1974
                    rename: None,
1✔
1975
                }),
1✔
1976
                force_ogr_time_filter: false,
1✔
1977
                force_ogr_spatial_filter: false,
1✔
1978
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1979
                sql_query: None,
1✔
1980
                attribute_query: None,
1✔
1981
                cache_ttl: CacheTtlSeconds::default(),
1✔
1982
            };
1✔
1983

1✔
1984
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1985
                OgrSourceDataset,
1✔
1986
                VectorResultDescriptor,
1✔
1987
                VectorQueryRectangle,
1✔
1988
            > {
1✔
1989
                loading_info: loading_info.clone(),
1✔
1990
                result_descriptor: VectorResultDescriptor {
1✔
1991
                    data_type: VectorDataType::MultiPoint,
1✔
1992
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1993
                    columns: [(
1✔
1994
                        "foo".to_owned(),
1✔
1995
                        VectorColumnInfo {
1✔
1996
                            data_type: FeatureDataType::Float,
1✔
1997
                            measurement: Measurement::Unitless.into(),
1✔
1998
                        },
1✔
1999
                    )]
1✔
2000
                    .into_iter()
1✔
2001
                    .collect(),
1✔
2002
                    time: None,
1✔
2003
                    bbox: None,
1✔
2004
                },
1✔
2005
                phantom: Default::default(),
1✔
2006
            });
1✔
2007

2008
            let session = app_ctx.default_session().await.unwrap();
18✔
2009

1✔
2010
            let db = app_ctx.session_context(session).db();
1✔
2011
            let wrap = db.wrap_meta_data(meta_data);
1✔
2012
            let dataset_id = db
1✔
2013
                .add_dataset(
1✔
2014
                    AddDataset {
1✔
2015
                        name: Some(dataset_name),
1✔
2016
                        display_name: "Ogr Test".to_owned(),
1✔
2017
                        description: "desc".to_owned(),
1✔
2018
                        source_operator: "OgrSource".to_owned(),
1✔
2019
                        symbology: None,
1✔
2020
                        provenance: Some(vec![Provenance {
1✔
2021
                            citation: "citation".to_owned(),
1✔
2022
                            license: "license".to_owned(),
1✔
2023
                            uri: "uri".to_owned(),
1✔
2024
                        }]),
1✔
2025
                    },
1✔
2026
                    wrap,
1✔
2027
                )
1✔
2028
                .await
152✔
2029
                .unwrap()
1✔
2030
                .id;
2031

2032
            assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
2033

2034
            db.delete_dataset(dataset_id).await.unwrap();
3✔
2035

2036
            assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2037
        })
1✔
2038
        .await;
10✔
2039
    }
2040

2041
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2042
    async fn test_missing_layer_dataset_in_collection_listing() {
1✔
2043
        with_temp_context(|app_ctx, _| async move {
1✔
2044
            let session = app_ctx.default_session().await.unwrap();
18✔
2045
            let db = app_ctx.session_context(session).db();
1✔
2046

2047
            let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2048

2049
            let top_collection_id = db
1✔
2050
                .add_layer_collection(
1✔
2051
                    AddLayerCollection {
1✔
2052
                        name: "top collection".to_string(),
1✔
2053
                        description: "description".to_string(),
1✔
2054
                        properties: Default::default(),
1✔
2055
                    },
1✔
2056
                    root_collection_id,
1✔
2057
                )
1✔
2058
                .await
10✔
2059
                .unwrap();
1✔
2060

1✔
2061
            let faux_layer = LayerId("faux".to_string());
1✔
2062

1✔
2063
            // this should fail
1✔
2064
            db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
2065
                .await
×
2066
                .unwrap_err();
1✔
2067

2068
            let root_collection_layers = db
1✔
2069
                .load_layer_collection(
1✔
2070
                    &top_collection_id,
1✔
2071
                    LayerCollectionListOptions {
1✔
2072
                        offset: 0,
1✔
2073
                        limit: 20,
1✔
2074
                    },
1✔
2075
                )
1✔
2076
                .await
5✔
2077
                .unwrap();
1✔
2078

1✔
2079
            assert_eq!(
1✔
2080
                root_collection_layers,
1✔
2081
                LayerCollection {
1✔
2082
                    id: ProviderLayerCollectionId {
1✔
2083
                        provider_id: DataProviderId(
1✔
2084
                            "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
2085
                        ),
1✔
2086
                        collection_id: top_collection_id.clone(),
1✔
2087
                    },
1✔
2088
                    name: "top collection".to_string(),
1✔
2089
                    description: "description".to_string(),
1✔
2090
                    items: vec![],
1✔
2091
                    entry_label: None,
1✔
2092
                    properties: vec![],
1✔
2093
                }
1✔
2094
            );
1✔
2095
        })
1✔
2096
        .await;
10✔
2097
    }
2098

2099
    #[allow(clippy::too_many_lines)]
2100
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2101
    async fn it_updates_project_layer_symbology() {
1✔
2102
        with_temp_context(|app_ctx, _| async move {
1✔
2103
            let session = app_ctx.default_session().await.unwrap();
18✔
2104

2105
            let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
162✔
2106

2107
            let db = app_ctx.session_context(session.clone()).db();
1✔
2108

1✔
2109
            let create_project: CreateProject = serde_json::from_value(json!({
1✔
2110
                "name": "Default",
1✔
2111
                "description": "Default project",
1✔
2112
                "bounds": {
1✔
2113
                    "boundingBox": {
1✔
2114
                        "lowerLeftCoordinate": {
1✔
2115
                            "x": -180,
1✔
2116
                            "y": -90
1✔
2117
                        },
1✔
2118
                        "upperRightCoordinate": {
1✔
2119
                            "x": 180,
1✔
2120
                            "y": 90
1✔
2121
                        }
1✔
2122
                    },
1✔
2123
                    "spatialReference": "EPSG:4326",
1✔
2124
                    "timeInterval": {
1✔
2125
                        "start": 1_396_353_600_000i64,
1✔
2126
                        "end": 1_396_353_600_000i64
1✔
2127
                    }
1✔
2128
                },
1✔
2129
                "timeStep": {
1✔
2130
                    "step": 1,
1✔
2131
                    "granularity": "months"
1✔
2132
                }
1✔
2133
            }))
1✔
2134
            .unwrap();
1✔
2135

2136
            let project_id = db.create_project(create_project).await.unwrap();
7✔
2137

1✔
2138
            let update: UpdateProject = serde_json::from_value(json!({
1✔
2139
                "id": project_id.to_string(),
1✔
2140
                "layers": [{
1✔
2141
                    "name": "NDVI",
1✔
2142
                    "workflow": workflow_id.to_string(),
1✔
2143
                    "visibility": {
1✔
2144
                        "data": true,
1✔
2145
                        "legend": false
1✔
2146
                    },
1✔
2147
                    "symbology": {
1✔
2148
                        "type": "raster",
1✔
2149
                        "opacity": 1,
1✔
2150
                        "colorizer": {
1✔
2151
                            "type": "linearGradient",
1✔
2152
                            "breakpoints": [{
1✔
2153
                                "value": 1,
1✔
2154
                                "color": [0, 0, 0, 255]
1✔
2155
                            }, {
1✔
2156
                                "value": 255,
1✔
2157
                                "color": [255, 255, 255, 255]
1✔
2158
                            }],
1✔
2159
                            "noDataColor": [0, 0, 0, 0],
1✔
2160
                            "overColor": [255, 255, 255, 127],
1✔
2161
                            "underColor": [255, 255, 255, 127]
1✔
2162
                        }
1✔
2163
                    }
1✔
2164
                }]
1✔
2165
            }))
1✔
2166
            .unwrap();
1✔
2167

1✔
2168
            db.update_project(update).await.unwrap();
65✔
2169

1✔
2170
            let update: UpdateProject = serde_json::from_value(json!({
1✔
2171
                "id": project_id.to_string(),
1✔
2172
                "layers": [{
1✔
2173
                    "name": "NDVI",
1✔
2174
                    "workflow": workflow_id.to_string(),
1✔
2175
                    "visibility": {
1✔
2176
                        "data": true,
1✔
2177
                        "legend": false
1✔
2178
                    },
1✔
2179
                    "symbology": {
1✔
2180
                        "type": "raster",
1✔
2181
                        "opacity": 1,
1✔
2182
                        "colorizer": {
1✔
2183
                            "type": "linearGradient",
1✔
2184
                            "breakpoints": [{
1✔
2185
                                "value": 1,
1✔
2186
                                "color": [0, 0, 4, 255]
1✔
2187
                            }, {
1✔
2188
                                "value": 17.866_666_666_666_667,
1✔
2189
                                "color": [11, 9, 36, 255]
1✔
2190
                            }, {
1✔
2191
                                "value": 34.733_333_333_333_334,
1✔
2192
                                "color": [32, 17, 75, 255]
1✔
2193
                            }, {
1✔
2194
                                "value": 51.6,
1✔
2195
                                "color": [59, 15, 112, 255]
1✔
2196
                            }, {
1✔
2197
                                "value": 68.466_666_666_666_67,
1✔
2198
                                "color": [87, 21, 126, 255]
1✔
2199
                            }, {
1✔
2200
                                "value": 85.333_333_333_333_33,
1✔
2201
                                "color": [114, 31, 129, 255]
1✔
2202
                            }, {
1✔
2203
                                "value": 102.199_999_999_999_99,
1✔
2204
                                "color": [140, 41, 129, 255]
1✔
2205
                            }, {
1✔
2206
                                "value": 119.066_666_666_666_65,
1✔
2207
                                "color": [168, 50, 125, 255]
1✔
2208
                            }, {
1✔
2209
                                "value": 135.933_333_333_333_34,
1✔
2210
                                "color": [196, 60, 117, 255]
1✔
2211
                            }, {
1✔
2212
                                "value": 152.799_999_999_999_98,
1✔
2213
                                "color": [222, 73, 104, 255]
1✔
2214
                            }, {
1✔
2215
                                "value": 169.666_666_666_666_66,
1✔
2216
                                "color": [241, 96, 93, 255]
1✔
2217
                            }, {
1✔
2218
                                "value": 186.533_333_333_333_33,
1✔
2219
                                "color": [250, 127, 94, 255]
1✔
2220
                            }, {
1✔
2221
                                "value": 203.399_999_999_999_98,
1✔
2222
                                "color": [254, 159, 109, 255]
1✔
2223
                            }, {
1✔
2224
                                "value": 220.266_666_666_666_65,
1✔
2225
                                "color": [254, 191, 132, 255]
1✔
2226
                            }, {
1✔
2227
                                "value": 237.133_333_333_333_3,
1✔
2228
                                "color": [253, 222, 160, 255]
1✔
2229
                            }, {
1✔
2230
                                "value": 254,
1✔
2231
                                "color": [252, 253, 191, 255]
1✔
2232
                            }],
1✔
2233
                            "noDataColor": [0, 0, 0, 0],
1✔
2234
                            "overColor": [255, 255, 255, 127],
1✔
2235
                            "underColor": [255, 255, 255, 127]
1✔
2236
                        }
1✔
2237
                    }
1✔
2238
                }]
1✔
2239
            }))
1✔
2240
            .unwrap();
1✔
2241

1✔
2242
            db.update_project(update).await.unwrap();
14✔
2243

1✔
2244
            let update: UpdateProject = serde_json::from_value(json!({
1✔
2245
                "id": project_id.to_string(),
1✔
2246
                "layers": [{
1✔
2247
                    "name": "NDVI",
1✔
2248
                    "workflow": workflow_id.to_string(),
1✔
2249
                    "visibility": {
1✔
2250
                        "data": true,
1✔
2251
                        "legend": false
1✔
2252
                    },
1✔
2253
                    "symbology": {
1✔
2254
                        "type": "raster",
1✔
2255
                        "opacity": 1,
1✔
2256
                        "colorizer": {
1✔
2257
                            "type": "linearGradient",
1✔
2258
                            "breakpoints": [{
1✔
2259
                                "value": 1,
1✔
2260
                                "color": [0, 0, 4, 255]
1✔
2261
                            }, {
1✔
2262
                                "value": 17.866_666_666_666_667,
1✔
2263
                                "color": [11, 9, 36, 255]
1✔
2264
                            }, {
1✔
2265
                                "value": 34.733_333_333_333_334,
1✔
2266
                                "color": [32, 17, 75, 255]
1✔
2267
                            }, {
1✔
2268
                                "value": 51.6,
1✔
2269
                                "color": [59, 15, 112, 255]
1✔
2270
                            }, {
1✔
2271
                                "value": 68.466_666_666_666_67,
1✔
2272
                                "color": [87, 21, 126, 255]
1✔
2273
                            }, {
1✔
2274
                                "value": 85.333_333_333_333_33,
1✔
2275
                                "color": [114, 31, 129, 255]
1✔
2276
                            }, {
1✔
2277
                                "value": 102.199_999_999_999_99,
1✔
2278
                                "color": [140, 41, 129, 255]
1✔
2279
                            }, {
1✔
2280
                                "value": 119.066_666_666_666_65,
1✔
2281
                                "color": [168, 50, 125, 255]
1✔
2282
                            }, {
1✔
2283
                                "value": 135.933_333_333_333_34,
1✔
2284
                                "color": [196, 60, 117, 255]
1✔
2285
                            }, {
1✔
2286
                                "value": 152.799_999_999_999_98,
1✔
2287
                                "color": [222, 73, 104, 255]
1✔
2288
                            }, {
1✔
2289
                                "value": 169.666_666_666_666_66,
1✔
2290
                                "color": [241, 96, 93, 255]
1✔
2291
                            }, {
1✔
2292
                                "value": 186.533_333_333_333_33,
1✔
2293
                                "color": [250, 127, 94, 255]
1✔
2294
                            }, {
1✔
2295
                                "value": 203.399_999_999_999_98,
1✔
2296
                                "color": [254, 159, 109, 255]
1✔
2297
                            }, {
1✔
2298
                                "value": 220.266_666_666_666_65,
1✔
2299
                                "color": [254, 191, 132, 255]
1✔
2300
                            }, {
1✔
2301
                                "value": 237.133_333_333_333_3,
1✔
2302
                                "color": [253, 222, 160, 255]
1✔
2303
                            }, {
1✔
2304
                                "value": 254,
1✔
2305
                                "color": [252, 253, 191, 255]
1✔
2306
                            }],
1✔
2307
                            "noDataColor": [0, 0, 0, 0],
1✔
2308
                            "overColor": [255, 255, 255, 127],
1✔
2309
                            "underColor": [255, 255, 255, 127]
1✔
2310
                        }
1✔
2311
                    }
1✔
2312
                }]
1✔
2313
            }))
1✔
2314
            .unwrap();
1✔
2315

1✔
2316
            db.update_project(update).await.unwrap();
14✔
2317

1✔
2318
            let update: UpdateProject = serde_json::from_value(json!({
1✔
2319
                "id": project_id.to_string(),
1✔
2320
                "layers": [{
1✔
2321
                    "name": "NDVI",
1✔
2322
                    "workflow": workflow_id.to_string(),
1✔
2323
                    "visibility": {
1✔
2324
                        "data": true,
1✔
2325
                        "legend": false
1✔
2326
                    },
1✔
2327
                    "symbology": {
1✔
2328
                        "type": "raster",
1✔
2329
                        "opacity": 1,
1✔
2330
                        "colorizer": {
1✔
2331
                            "type": "linearGradient",
1✔
2332
                            "breakpoints": [{
1✔
2333
                                "value": 1,
1✔
2334
                                "color": [0, 0, 4, 255]
1✔
2335
                            }, {
1✔
2336
                                "value": 17.933_333_333_333_334,
1✔
2337
                                "color": [11, 9, 36, 255]
1✔
2338
                            }, {
1✔
2339
                                "value": 34.866_666_666_666_67,
1✔
2340
                                "color": [32, 17, 75, 255]
1✔
2341
                            }, {
1✔
2342
                                "value": 51.800_000_000_000_004,
1✔
2343
                                "color": [59, 15, 112, 255]
1✔
2344
                            }, {
1✔
2345
                                "value": 68.733_333_333_333_33,
1✔
2346
                                "color": [87, 21, 126, 255]
1✔
2347
                            }, {
1✔
2348
                                "value": 85.666_666_666_666_66,
1✔
2349
                                "color": [114, 31, 129, 255]
1✔
2350
                            }, {
1✔
2351
                                "value": 102.6,
1✔
2352
                                "color": [140, 41, 129, 255]
1✔
2353
                            }, {
1✔
2354
                                "value": 119.533_333_333_333_32,
1✔
2355
                                "color": [168, 50, 125, 255]
1✔
2356
                            }, {
1✔
2357
                                "value": 136.466_666_666_666_67,
1✔
2358
                                "color": [196, 60, 117, 255]
1✔
2359
                            }, {
1✔
2360
                                "value": 153.4,
1✔
2361
                                "color": [222, 73, 104, 255]
1✔
2362
                            }, {
1✔
2363
                                "value": 170.333_333_333_333_31,
1✔
2364
                                "color": [241, 96, 93, 255]
1✔
2365
                            }, {
1✔
2366
                                "value": 187.266_666_666_666_65,
1✔
2367
                                "color": [250, 127, 94, 255]
1✔
2368
                            }, {
1✔
2369
                                "value": 204.2,
1✔
2370
                                "color": [254, 159, 109, 255]
1✔
2371
                            }, {
1✔
2372
                                "value": 221.133_333_333_333_33,
1✔
2373
                                "color": [254, 191, 132, 255]
1✔
2374
                            }, {
1✔
2375
                                "value": 238.066_666_666_666_63,
1✔
2376
                                "color": [253, 222, 160, 255]
1✔
2377
                            }, {
1✔
2378
                                "value": 255,
1✔
2379
                                "color": [252, 253, 191, 255]
1✔
2380
                            }],
1✔
2381
                            "noDataColor": [0, 0, 0, 0],
1✔
2382
                            "overColor": [255, 255, 255, 127],
1✔
2383
                            "underColor": [255, 255, 255, 127]
1✔
2384
                        }
1✔
2385
                    }
1✔
2386
                }]
1✔
2387
            }))
1✔
2388
            .unwrap();
1✔
2389

1✔
2390
            let update = update;
1✔
2391

2392
            // run two updates concurrently
2393
            let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
1✔
2394

2395
            assert!(r0.is_ok());
1✔
2396
            assert!(r1.is_ok());
1✔
2397
        })
1✔
2398
        .await;
12✔
2399
    }
2400

2401
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2402
    #[allow(clippy::too_many_lines)]
2403
    async fn it_resolves_dataset_names_to_ids() {
1✔
2404
        with_temp_context(|app_ctx, _| async move {
1✔
2405
            let session = app_ctx.default_session().await.unwrap();
18✔
2406
            let db = app_ctx.session_context(session.clone()).db();
1✔
2407

1✔
2408
            let loading_info = OgrSourceDataset {
1✔
2409
                file_name: PathBuf::from("test.csv"),
1✔
2410
                layer_name: "test.csv".to_owned(),
1✔
2411
                data_type: Some(VectorDataType::MultiPoint),
1✔
2412
                time: OgrSourceDatasetTimeType::Start {
1✔
2413
                    start_field: "start".to_owned(),
1✔
2414
                    start_format: OgrSourceTimeFormat::Auto,
1✔
2415
                    duration: OgrSourceDurationSpec::Zero,
1✔
2416
                },
1✔
2417
                default_geometry: None,
1✔
2418
                columns: Some(OgrSourceColumnSpec {
1✔
2419
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
2420
                        header: CsvHeader::Auto,
1✔
2421
                    }),
1✔
2422
                    x: "x".to_owned(),
1✔
2423
                    y: None,
1✔
2424
                    int: vec![],
1✔
2425
                    float: vec![],
1✔
2426
                    text: vec![],
1✔
2427
                    bool: vec![],
1✔
2428
                    datetime: vec![],
1✔
2429
                    rename: None,
1✔
2430
                }),
1✔
2431
                force_ogr_time_filter: false,
1✔
2432
                force_ogr_spatial_filter: false,
1✔
2433
                on_error: OgrSourceErrorSpec::Ignore,
1✔
2434
                sql_query: None,
1✔
2435
                attribute_query: None,
1✔
2436
                cache_ttl: CacheTtlSeconds::default(),
1✔
2437
            };
1✔
2438

1✔
2439
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2440
                OgrSourceDataset,
1✔
2441
                VectorResultDescriptor,
1✔
2442
                VectorQueryRectangle,
1✔
2443
            > {
1✔
2444
                loading_info: loading_info.clone(),
1✔
2445
                result_descriptor: VectorResultDescriptor {
1✔
2446
                    data_type: VectorDataType::MultiPoint,
1✔
2447
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2448
                    columns: [(
1✔
2449
                        "foo".to_owned(),
1✔
2450
                        VectorColumnInfo {
1✔
2451
                            data_type: FeatureDataType::Float,
1✔
2452
                            measurement: Measurement::Unitless.into(),
1✔
2453
                        },
1✔
2454
                    )]
1✔
2455
                    .into_iter()
1✔
2456
                    .collect(),
1✔
2457
                    time: None,
1✔
2458
                    bbox: None,
1✔
2459
                },
1✔
2460
                phantom: Default::default(),
1✔
2461
            });
1✔
2462

2463
            let DatasetIdAndName {
2464
                id: dataset_id1,
1✔
2465
                name: dataset_name1,
1✔
2466
            } = db
1✔
2467
                .add_dataset(
1✔
2468
                    AddDataset {
1✔
2469
                        name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2470
                        display_name: "Ogr Test".to_owned(),
1✔
2471
                        description: "desc".to_owned(),
1✔
2472
                        source_operator: "OgrSource".to_owned(),
1✔
2473
                        symbology: None,
1✔
2474
                        provenance: Some(vec![Provenance {
1✔
2475
                            citation: "citation".to_owned(),
1✔
2476
                            license: "license".to_owned(),
1✔
2477
                            uri: "uri".to_owned(),
1✔
2478
                        }]),
1✔
2479
                    },
1✔
2480
                    db.wrap_meta_data(meta_data.clone()),
1✔
2481
                )
1✔
2482
                .await
153✔
2483
                .unwrap();
1✔
2484

2485
            assert_eq!(
1✔
2486
                db.resolve_dataset_name_to_id(&dataset_name1).await.unwrap(),
3✔
2487
                dataset_id1
2488
            );
2489
        })
1✔
2490
        .await;
12✔
2491
    }
2492

2493
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2494
    #[allow(clippy::too_many_lines)]
2495
    async fn test_postgres_type_serialization() {
1✔
2496
        pub async fn test_type<T>(
51✔
2497
            conn: &PooledConnection<'_, PostgresConnectionManager<tokio_postgres::NoTls>>,
51✔
2498
            sql_type: &str,
51✔
2499
            checks: impl IntoIterator<Item = T>,
51✔
2500
        ) where
51✔
2501
            T: PartialEq + postgres_types::FromSqlOwned + postgres_types::ToSql + Sync,
51✔
2502
        {
51✔
2503
            const UNQUOTED: [&str; 3] = ["double precision", "int", "point[]"];
1✔
2504

1✔
2505
            // don't quote built-in types
1✔
2506
            let quote = if UNQUOTED.contains(&sql_type) || sql_type.contains('[') {
51✔
2507
                ""
6✔
2508
            } else {
1✔
2509
                "\""
45✔
2510
            };
1✔
2511

1✔
2512
            for value in checks {
152✔
2513
                let stmt = conn
101✔
2514
                    .prepare(&format!("SELECT $1::{quote}{sql_type}{quote}"))
101✔
2515
                    .await
259✔
2516
                    .unwrap();
101✔
2517
                let result: T = conn.query_one(&stmt, &[&value]).await.unwrap().get(0);
105✔
2518

101✔
2519
                assert_eq!(value, result);
101✔
2520
            }
1✔
2521
        }
51✔
2522

1✔
2523
        with_temp_context(|app_ctx, _| async move {
1✔
2524
            let pool = app_ctx.pool.get().await.unwrap();
1✔
2525

1✔
2526
            test_type(&pool, "RgbaColor", [RgbaColor([0, 1, 2, 3])]).await;
4✔
2527

2528
            test_type(
1✔
2529
                &pool,
1✔
2530
                "double precision",
1✔
2531
                [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
2532
            )
1✔
2533
            .await;
2✔
2534

2535
            test_type(
1✔
2536
                &pool,
1✔
2537
                "Breakpoint",
1✔
2538
                [Breakpoint {
1✔
2539
                    value: NotNan::<f64>::new(1.0).unwrap().into(),
1✔
2540
                    color: RgbaColor([0, 0, 0, 0]),
1✔
2541
                }],
1✔
2542
            )
1✔
2543
            .await;
5✔
2544

2545
            test_type(
1✔
2546
                &pool,
1✔
2547
                "DefaultColors",
1✔
2548
                [
1✔
2549
                    DefaultColors::DefaultColor {
1✔
2550
                        default_color: RgbaColor([0, 10, 20, 30]),
1✔
2551
                    },
1✔
2552
                    DefaultColors::OverUnder(OverUnderColors {
1✔
2553
                        over_color: RgbaColor([1, 2, 3, 4]),
1✔
2554
                        under_color: RgbaColor([5, 6, 7, 8]),
1✔
2555
                    }),
1✔
2556
                ],
1✔
2557
            )
1✔
2558
            .await;
6✔
2559

2560
            test_type(
1✔
2561
                &pool,
1✔
2562
                "ColorizerType",
1✔
2563
                [
1✔
2564
                    ColorizerTypeDbType::LinearGradient,
1✔
2565
                    ColorizerTypeDbType::LogarithmicGradient,
1✔
2566
                    ColorizerTypeDbType::Palette,
1✔
2567
                    ColorizerTypeDbType::Rgba,
1✔
2568
                ],
1✔
2569
            )
1✔
2570
            .await;
11✔
2571

2572
            test_type(
1✔
2573
                &pool,
1✔
2574
                "Colorizer",
1✔
2575
                [
1✔
2576
                    Colorizer::LinearGradient(LinearGradient {
1✔
2577
                        breakpoints: vec![
1✔
2578
                            Breakpoint {
1✔
2579
                                value: NotNan::<f64>::new(-10.0).unwrap().into(),
1✔
2580
                                color: RgbaColor([0, 0, 0, 0]),
1✔
2581
                            },
1✔
2582
                            Breakpoint {
1✔
2583
                                value: NotNan::<f64>::new(2.0).unwrap().into(),
1✔
2584
                                color: RgbaColor([255, 0, 0, 255]),
1✔
2585
                            },
1✔
2586
                        ],
1✔
2587
                        no_data_color: RgbaColor([0, 10, 20, 30]),
1✔
2588
                        color_fields: DefaultColors::OverUnder(OverUnderColors {
1✔
2589
                            over_color: RgbaColor([1, 2, 3, 4]),
1✔
2590
                            under_color: RgbaColor([5, 6, 7, 8]),
1✔
2591
                        }),
1✔
2592
                    }),
1✔
2593
                    Colorizer::LogarithmicGradient(LogarithmicGradient {
1✔
2594
                        breakpoints: vec![
1✔
2595
                            Breakpoint {
1✔
2596
                                value: NotNan::<f64>::new(1.0).unwrap().into(),
1✔
2597
                                color: RgbaColor([0, 0, 0, 0]),
1✔
2598
                            },
1✔
2599
                            Breakpoint {
1✔
2600
                                value: NotNan::<f64>::new(2.0).unwrap().into(),
1✔
2601
                                color: RgbaColor([255, 0, 0, 255]),
1✔
2602
                            },
1✔
2603
                        ],
1✔
2604
                        no_data_color: RgbaColor([0, 10, 20, 30]),
1✔
2605
                        color_fields: DefaultColors::OverUnder(OverUnderColors {
1✔
2606
                            over_color: RgbaColor([1, 2, 3, 4]),
1✔
2607
                            under_color: RgbaColor([5, 6, 7, 8]),
1✔
2608
                        }),
1✔
2609
                    }),
1✔
2610
                    Colorizer::Palette {
1✔
2611
                        colors: Palette(
1✔
2612
                            [
1✔
2613
                                (NotNan::<f64>::new(1.0).unwrap(), RgbaColor([0, 0, 0, 0])),
1✔
2614
                                (
1✔
2615
                                    NotNan::<f64>::new(2.0).unwrap(),
1✔
2616
                                    RgbaColor([255, 0, 0, 255]),
1✔
2617
                                ),
1✔
2618
                                (NotNan::<f64>::new(3.0).unwrap(), RgbaColor([0, 10, 20, 30])),
1✔
2619
                            ]
1✔
2620
                            .into(),
1✔
2621
                        ),
1✔
2622
                        no_data_color: RgbaColor([1, 2, 3, 4]),
1✔
2623
                        default_color: RgbaColor([5, 6, 7, 8]),
1✔
2624
                    },
1✔
2625
                    Colorizer::Rgba,
1✔
2626
                ],
1✔
2627
            )
1✔
2628
            .await;
11✔
2629

2630
            test_type(
1✔
2631
                &pool,
1✔
2632
                "ColorParam",
1✔
2633
                [
1✔
2634
                    ColorParam::Static {
1✔
2635
                        color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2636
                    },
1✔
2637
                    ColorParam::Derived(DerivedColor {
1✔
2638
                        attribute: "foobar".to_string(),
1✔
2639
                        colorizer: Colorizer::Rgba,
1✔
2640
                    }),
1✔
2641
                ],
1✔
2642
            )
1✔
2643
            .await;
6✔
2644

2645
            test_type(
1✔
2646
                &pool,
1✔
2647
                "NumberParam",
1✔
2648
                [
1✔
2649
                    NumberParam::Static { value: 42 },
1✔
2650
                    NumberParam::Derived(DerivedNumber {
1✔
2651
                        attribute: "foobar".to_string(),
1✔
2652
                        factor: 1.0,
1✔
2653
                        default_value: 42.,
1✔
2654
                    }),
1✔
2655
                ],
1✔
2656
            )
1✔
2657
            .await;
7✔
2658

2659
            test_type(
1✔
2660
                &pool,
1✔
2661
                "StrokeParam",
1✔
2662
                [StrokeParam {
1✔
2663
                    width: NumberParam::Static { value: 42 },
1✔
2664
                    color: ColorParam::Static {
1✔
2665
                        color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2666
                    },
1✔
2667
                }],
1✔
2668
            )
1✔
2669
            .await;
4✔
2670

2671
            test_type(
1✔
2672
                &pool,
1✔
2673
                "TextSymbology",
1✔
2674
                [TextSymbology {
1✔
2675
                    attribute: "attribute".to_string(),
1✔
2676
                    fill_color: ColorParam::Static {
1✔
2677
                        color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2678
                    },
1✔
2679
                    stroke: StrokeParam {
1✔
2680
                        width: NumberParam::Static { value: 42 },
1✔
2681
                        color: ColorParam::Static {
1✔
2682
                            color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2683
                        },
1✔
2684
                    },
1✔
2685
                }],
1✔
2686
            )
1✔
2687
            .await;
4✔
2688

2689
            test_type(
1✔
2690
                &pool,
1✔
2691
                "Symbology",
1✔
2692
                [
1✔
2693
                    Symbology::Point(PointSymbology {
1✔
2694
                        fill_color: ColorParam::Static {
1✔
2695
                            color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2696
                        },
1✔
2697
                        stroke: StrokeParam {
1✔
2698
                            width: NumberParam::Static { value: 42 },
1✔
2699
                            color: ColorParam::Static {
1✔
2700
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2701
                            },
1✔
2702
                        },
1✔
2703
                        radius: NumberParam::Static { value: 42 },
1✔
2704
                        text: Some(TextSymbology {
1✔
2705
                            attribute: "attribute".to_string(),
1✔
2706
                            fill_color: ColorParam::Static {
1✔
2707
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2708
                            },
1✔
2709
                            stroke: StrokeParam {
1✔
2710
                                width: NumberParam::Static { value: 42 },
1✔
2711
                                color: ColorParam::Static {
1✔
2712
                                    color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2713
                                },
1✔
2714
                            },
1✔
2715
                        }),
1✔
2716
                    }),
1✔
2717
                    Symbology::Line(LineSymbology {
1✔
2718
                        stroke: StrokeParam {
1✔
2719
                            width: NumberParam::Static { value: 42 },
1✔
2720
                            color: ColorParam::Static {
1✔
2721
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2722
                            },
1✔
2723
                        },
1✔
2724
                        text: Some(TextSymbology {
1✔
2725
                            attribute: "attribute".to_string(),
1✔
2726
                            fill_color: ColorParam::Static {
1✔
2727
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2728
                            },
1✔
2729
                            stroke: StrokeParam {
1✔
2730
                                width: NumberParam::Static { value: 42 },
1✔
2731
                                color: ColorParam::Static {
1✔
2732
                                    color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2733
                                },
1✔
2734
                            },
1✔
2735
                        }),
1✔
2736
                        auto_simplified: true,
1✔
2737
                    }),
1✔
2738
                    Symbology::Polygon(PolygonSymbology {
1✔
2739
                        fill_color: ColorParam::Static {
1✔
2740
                            color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2741
                        },
1✔
2742
                        stroke: StrokeParam {
1✔
2743
                            width: NumberParam::Static { value: 42 },
1✔
2744
                            color: ColorParam::Static {
1✔
2745
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2746
                            },
1✔
2747
                        },
1✔
2748
                        text: Some(TextSymbology {
1✔
2749
                            attribute: "attribute".to_string(),
1✔
2750
                            fill_color: ColorParam::Static {
1✔
2751
                                color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2752
                            },
1✔
2753
                            stroke: StrokeParam {
1✔
2754
                                width: NumberParam::Static { value: 42 },
1✔
2755
                                color: ColorParam::Static {
1✔
2756
                                    color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2757
                                },
1✔
2758
                            },
1✔
2759
                        }),
1✔
2760
                        auto_simplified: true,
1✔
2761
                    }),
1✔
2762
                    Symbology::Raster(RasterSymbology {
1✔
2763
                        opacity: 1.0,
1✔
2764
                        colorizer: Colorizer::LinearGradient(LinearGradient {
1✔
2765
                            breakpoints: vec![
1✔
2766
                                Breakpoint {
1✔
2767
                                    value: NotNan::<f64>::new(-10.0).unwrap().into(),
1✔
2768
                                    color: RgbaColor([0, 0, 0, 0]),
1✔
2769
                                },
1✔
2770
                                Breakpoint {
1✔
2771
                                    value: NotNan::<f64>::new(2.0).unwrap().into(),
1✔
2772
                                    color: RgbaColor([255, 0, 0, 255]),
1✔
2773
                                },
1✔
2774
                            ],
1✔
2775
                            no_data_color: RgbaColor([0, 10, 20, 30]),
1✔
2776
                            color_fields: DefaultColors::OverUnder(OverUnderColors {
1✔
2777
                                over_color: RgbaColor([1, 2, 3, 4]),
1✔
2778
                                under_color: RgbaColor([5, 6, 7, 8]),
1✔
2779
                            }),
1✔
2780
                        }),
1✔
2781
                    }),
1✔
2782
                ],
1✔
2783
            )
1✔
2784
            .await;
18✔
2785

2786
            test_type(
1✔
2787
                &pool,
1✔
2788
                "RasterDataType",
1✔
2789
                [
1✔
2790
                    crate::api::model::datatypes::RasterDataType::U8,
1✔
2791
                    crate::api::model::datatypes::RasterDataType::U16,
1✔
2792
                    crate::api::model::datatypes::RasterDataType::U32,
1✔
2793
                    crate::api::model::datatypes::RasterDataType::U64,
1✔
2794
                    crate::api::model::datatypes::RasterDataType::I8,
1✔
2795
                    crate::api::model::datatypes::RasterDataType::I16,
1✔
2796
                    crate::api::model::datatypes::RasterDataType::I32,
1✔
2797
                    crate::api::model::datatypes::RasterDataType::I64,
1✔
2798
                    crate::api::model::datatypes::RasterDataType::F32,
1✔
2799
                    crate::api::model::datatypes::RasterDataType::F64,
1✔
2800
                ],
1✔
2801
            )
1✔
2802
            .await;
22✔
2803

2804
            test_type(
1✔
2805
                &pool,
1✔
2806
                "Measurement",
1✔
2807
                [
1✔
2808
                    Measurement::Unitless,
1✔
2809
                    Measurement::Continuous(ContinuousMeasurement {
1✔
2810
                        measurement: "Temperature".to_string(),
1✔
2811
                        unit: Some("°C".to_string()),
1✔
2812
                    }),
1✔
2813
                    Measurement::Classification(ClassificationMeasurement {
1✔
2814
                        measurement: "Color".to_string(),
1✔
2815
                        classes: [(1, "Grayscale".to_string()), (2, "Colorful".to_string())].into(),
1✔
2816
                    }),
1✔
2817
                ],
1✔
2818
            )
1✔
2819
            .await;
15✔
2820

2821
            test_type(
1✔
2822
                &pool,
1✔
2823
                "Coordinate2D",
1✔
2824
                [crate::api::model::datatypes::Coordinate2D::from(
1✔
2825
                    Coordinate2D::new(0.0f64, 1.),
1✔
2826
                )],
1✔
2827
            )
1✔
2828
            .await;
4✔
2829

2830
            test_type(
1✔
2831
                &pool,
1✔
2832
                "SpatialPartition2D",
1✔
2833
                [crate::api::model::datatypes::SpatialPartition2D {
1✔
2834
                    upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
2835
                    lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
2836
                }],
1✔
2837
            )
1✔
2838
            .await;
5✔
2839

2840
            test_type(
1✔
2841
                &pool,
1✔
2842
                "BoundingBox2D",
1✔
2843
                [crate::api::model::datatypes::BoundingBox2D {
1✔
2844
                    lower_left_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
2845
                    upper_right_coordinate: Coordinate2D::new(2., 1.0).into(),
1✔
2846
                }],
1✔
2847
            )
1✔
2848
            .await;
4✔
2849

2850
            test_type(
1✔
2851
                &pool,
1✔
2852
                "SpatialResolution",
1✔
2853
                [crate::api::model::datatypes::SpatialResolution { x: 1.2, y: 2.3 }],
1✔
2854
            )
1✔
2855
            .await;
4✔
2856

2857
            test_type(
1✔
2858
                &pool,
1✔
2859
                "VectorDataType",
1✔
2860
                [
1✔
2861
                    crate::api::model::datatypes::VectorDataType::Data,
1✔
2862
                    crate::api::model::datatypes::VectorDataType::MultiPoint,
1✔
2863
                    crate::api::model::datatypes::VectorDataType::MultiLineString,
1✔
2864
                    crate::api::model::datatypes::VectorDataType::MultiPolygon,
1✔
2865
                ],
1✔
2866
            )
1✔
2867
            .await;
10✔
2868

2869
            test_type(
1✔
2870
                &pool,
1✔
2871
                "FeatureDataType",
1✔
2872
                [
1✔
2873
                    crate::api::model::datatypes::FeatureDataType::Category,
1✔
2874
                    crate::api::model::datatypes::FeatureDataType::Int,
1✔
2875
                    crate::api::model::datatypes::FeatureDataType::Float,
1✔
2876
                    crate::api::model::datatypes::FeatureDataType::Text,
1✔
2877
                    crate::api::model::datatypes::FeatureDataType::Bool,
1✔
2878
                    crate::api::model::datatypes::FeatureDataType::DateTime,
1✔
2879
                ],
1✔
2880
            )
1✔
2881
            .await;
14✔
2882

2883
            test_type(
1✔
2884
                &pool,
1✔
2885
                "TimeInterval",
1✔
2886
                [crate::api::model::datatypes::TimeInterval::from(
1✔
2887
                    TimeInterval::default(),
1✔
2888
                )],
1✔
2889
            )
1✔
2890
            .await;
4✔
2891

2892
            test_type(
1✔
2893
                &pool,
1✔
2894
                "SpatialReference",
1✔
2895
                [
1✔
2896
                    crate::api::model::datatypes::SpatialReferenceOption::Unreferenced,
1✔
2897
                    crate::api::model::datatypes::SpatialReferenceOption::SpatialReference(
1✔
2898
                        SpatialReference::epsg_4326().into(),
1✔
2899
                    ),
1✔
2900
                ],
1✔
2901
            )
1✔
2902
            .await;
8✔
2903

2904
            test_type(
1✔
2905
                &pool,
1✔
2906
                "PlotResultDescriptor",
1✔
2907
                [PlotResultDescriptor {
1✔
2908
                    spatial_reference: SpatialReferenceOption::Unreferenced.into(),
1✔
2909
                    time: None,
1✔
2910
                    bbox: None,
1✔
2911
                }],
1✔
2912
            )
1✔
2913
            .await;
4✔
2914

2915
            test_type(
1✔
2916
                &pool,
1✔
2917
                "VectorResultDescriptor",
1✔
2918
                [crate::api::model::operators::VectorResultDescriptor {
1✔
2919
                    data_type: VectorDataType::MultiPoint.into(),
1✔
2920
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2921
                        SpatialReference::epsg_4326(),
1✔
2922
                    )
1✔
2923
                    .into(),
1✔
2924
                    columns: [(
1✔
2925
                        "foo".to_string(),
1✔
2926
                        VectorColumnInfo {
1✔
2927
                            data_type: FeatureDataType::Int,
1✔
2928
                            measurement: Measurement::Unitless.into(),
1✔
2929
                        }
1✔
2930
                        .into(),
1✔
2931
                    )]
1✔
2932
                    .into(),
1✔
2933
                    time: Some(TimeInterval::default().into()),
1✔
2934
                    bbox: Some(
1✔
2935
                        BoundingBox2D::new(
1✔
2936
                            Coordinate2D::new(0.0f64, 0.5),
1✔
2937
                            Coordinate2D::new(2., 1.0),
1✔
2938
                        )
1✔
2939
                        .unwrap()
1✔
2940
                        .into(),
1✔
2941
                    ),
1✔
2942
                }],
1✔
2943
            )
1✔
2944
            .await;
7✔
2945

2946
            test_type(
1✔
2947
                &pool,
1✔
2948
                "RasterResultDescriptor",
1✔
2949
                [crate::api::model::operators::RasterResultDescriptor {
1✔
2950
                    data_type: RasterDataType::U8.into(),
1✔
2951
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2952
                        SpatialReference::epsg_4326(),
1✔
2953
                    )
1✔
2954
                    .into(),
1✔
2955
                    measurement: Measurement::Unitless,
1✔
2956
                    time: Some(TimeInterval::default().into()),
1✔
2957
                    bbox: Some(SpatialPartition2D {
1✔
2958
                        upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
2959
                        lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
2960
                    }),
1✔
2961
                    resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }.into()),
1✔
2962
                }],
1✔
2963
            )
1✔
2964
            .await;
4✔
2965

2966
            test_type(
1✔
2967
                &pool,
1✔
2968
                "ResultDescriptor",
1✔
2969
                [
1✔
2970
                    crate::api::model::operators::TypedResultDescriptor::Vector(
1✔
2971
                        VectorResultDescriptor {
1✔
2972
                            data_type: VectorDataType::MultiPoint,
1✔
2973
                            spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2974
                                SpatialReference::epsg_4326(),
1✔
2975
                            ),
1✔
2976
                            columns: [(
1✔
2977
                                "foo".to_string(),
1✔
2978
                                VectorColumnInfo {
1✔
2979
                                    data_type: FeatureDataType::Int,
1✔
2980
                                    measurement: Measurement::Unitless.into(),
1✔
2981
                                },
1✔
2982
                            )]
1✔
2983
                            .into(),
1✔
2984
                            time: Some(TimeInterval::default()),
1✔
2985
                            bbox: Some(
1✔
2986
                                BoundingBox2D::new(
1✔
2987
                                    Coordinate2D::new(0.0f64, 0.5),
1✔
2988
                                    Coordinate2D::new(2., 1.0),
1✔
2989
                                )
1✔
2990
                                .unwrap(),
1✔
2991
                            ),
1✔
2992
                        }
1✔
2993
                        .into(),
1✔
2994
                    ),
1✔
2995
                    crate::api::model::operators::TypedResultDescriptor::Raster(
1✔
2996
                        crate::api::model::operators::RasterResultDescriptor {
1✔
2997
                            data_type: RasterDataType::U8.into(),
1✔
2998
                            spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2999
                                SpatialReference::epsg_4326(),
1✔
3000
                            )
1✔
3001
                            .into(),
1✔
3002
                            measurement: Measurement::Unitless,
1✔
3003
                            time: Some(TimeInterval::default().into()),
1✔
3004
                            bbox: Some(SpatialPartition2D {
1✔
3005
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3006
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3007
                            }),
1✔
3008
                            resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }.into()),
1✔
3009
                        },
1✔
3010
                    ),
1✔
3011
                    crate::api::model::operators::TypedResultDescriptor::Plot(
1✔
3012
                        PlotResultDescriptor {
1✔
3013
                            spatial_reference: SpatialReferenceOption::Unreferenced.into(),
1✔
3014
                            time: None,
1✔
3015
                            bbox: None,
1✔
3016
                        },
1✔
3017
                    ),
1✔
3018
                ],
1✔
3019
            )
1✔
3020
            .await;
8✔
3021

3022
            test_type(
1✔
3023
                &pool,
1✔
3024
                "\"TextTextKeyValue\"[]",
1✔
3025
                [HashMapTextTextDbType::from(
1✔
3026
                    &HashMap::<String, String>::from([
1✔
3027
                        ("foo".to_string(), "bar".to_string()),
1✔
3028
                        ("baz".to_string(), "fuu".to_string()),
1✔
3029
                    ]),
1✔
3030
                )],
1✔
3031
            )
1✔
3032
            .await;
5✔
3033

3034
            test_type(
1✔
3035
                &pool,
1✔
3036
                "MockDatasetDataSourceLoadingInfo",
1✔
3037
                [
1✔
3038
                    crate::api::model::operators::MockDatasetDataSourceLoadingInfo {
1✔
3039
                        points: vec![
1✔
3040
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3041
                            Coordinate2D::new(2., 1.0).into(),
1✔
3042
                        ],
1✔
3043
                    },
1✔
3044
                ],
1✔
3045
            )
1✔
3046
            .await;
6✔
3047

3048
            test_type(
1✔
3049
                &pool,
1✔
3050
                "OgrSourceTimeFormat",
1✔
3051
                [
1✔
3052
                    crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3053
                    crate::api::model::operators::OgrSourceTimeFormat::Custom {
1✔
3054
                        custom_format:
1✔
3055
                            geoengine_datatypes::primitives::DateTimeParseFormat::custom(
1✔
3056
                                "%Y-%m-%dT%H:%M:%S%.3fZ".to_string(),
1✔
3057
                            )
1✔
3058
                            .into(),
1✔
3059
                    },
1✔
3060
                    crate::api::model::operators::OgrSourceTimeFormat::UnixTimeStamp {
1✔
3061
                        timestamp_type: UnixTimeStampType::EpochSeconds,
1✔
3062
                        fmt: geoengine_datatypes::primitives::DateTimeParseFormat::unix().into(),
1✔
3063
                    },
1✔
3064
                ],
1✔
3065
            )
1✔
3066
            .await;
16✔
3067

3068
            test_type(
1✔
3069
                &pool,
1✔
3070
                "OgrSourceDurationSpec",
1✔
3071
                [
1✔
3072
                    crate::api::model::operators::OgrSourceDurationSpec::Infinite,
1✔
3073
                    crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3074
                    crate::api::model::operators::OgrSourceDurationSpec::Value(
1✔
3075
                        TimeStep {
1✔
3076
                            granularity: TimeGranularity::Millis,
1✔
3077
                            step: 1000,
1✔
3078
                        }
1✔
3079
                        .into(),
1✔
3080
                    ),
1✔
3081
                ],
1✔
3082
            )
1✔
3083
            .await;
12✔
3084

3085
            test_type(
1✔
3086
                &pool,
1✔
3087
                "OgrSourceDatasetTimeType",
1✔
3088
                [
1✔
3089
                    crate::api::model::operators::OgrSourceDatasetTimeType::None,
1✔
3090
                    crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3091
                        start_field: "start".to_string(),
1✔
3092
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3093
                        duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3094
                    },
1✔
3095
                    crate::api::model::operators::OgrSourceDatasetTimeType::StartEnd {
1✔
3096
                        start_field: "start".to_string(),
1✔
3097
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3098
                        end_field: "end".to_string(),
1✔
3099
                        end_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3100
                    },
1✔
3101
                    crate::api::model::operators::OgrSourceDatasetTimeType::StartDuration {
1✔
3102
                        start_field: "start".to_string(),
1✔
3103
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3104
                        duration_field: "duration".to_string(),
1✔
3105
                    },
1✔
3106
                ],
1✔
3107
            )
1✔
3108
            .await;
16✔
3109

3110
            test_type(
1✔
3111
                &pool,
1✔
3112
                "FormatSpecifics",
1✔
3113
                [crate::api::model::operators::FormatSpecifics::Csv {
1✔
3114
                    header: CsvHeader::Yes.into(),
1✔
3115
                }],
1✔
3116
            )
1✔
3117
            .await;
8✔
3118

3119
            test_type(
1✔
3120
                &pool,
1✔
3121
                "OgrSourceColumnSpec",
1✔
3122
                [crate::api::model::operators::OgrSourceColumnSpec {
1✔
3123
                    format_specifics: Some(crate::api::model::operators::FormatSpecifics::Csv {
1✔
3124
                        header: CsvHeader::Auto.into(),
1✔
3125
                    }),
1✔
3126
                    x: "x".to_string(),
1✔
3127
                    y: Some("y".to_string()),
1✔
3128
                    int: vec!["int".to_string()],
1✔
3129
                    float: vec!["float".to_string()],
1✔
3130
                    text: vec!["text".to_string()],
1✔
3131
                    bool: vec!["bool".to_string()],
1✔
3132
                    datetime: vec!["datetime".to_string()],
1✔
3133
                    rename: Some(
1✔
3134
                        [
1✔
3135
                            ("xx".to_string(), "xx_renamed".to_string()),
1✔
3136
                            ("yx".to_string(), "yy_renamed".to_string()),
1✔
3137
                        ]
1✔
3138
                        .into(),
1✔
3139
                    ),
1✔
3140
                }],
1✔
3141
            )
1✔
3142
            .await;
4✔
3143

3144
            test_type(
1✔
3145
                &pool,
1✔
3146
                "point[]",
1✔
3147
                [MultiPoint {
1✔
3148
                    coordinates: vec![
1✔
3149
                        Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3150
                        Coordinate2D::new(2., 1.0).into(),
1✔
3151
                    ],
1✔
3152
                }],
1✔
3153
            )
1✔
3154
            .await;
2✔
3155

3156
            test_type(
1✔
3157
                &pool,
1✔
3158
                "path[]",
1✔
3159
                [MultiLineString {
1✔
3160
                    coordinates: vec![
1✔
3161
                        vec![
1✔
3162
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3163
                            Coordinate2D::new(2., 1.0).into(),
1✔
3164
                        ],
1✔
3165
                        vec![
1✔
3166
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3167
                            Coordinate2D::new(2., 1.0).into(),
1✔
3168
                        ],
1✔
3169
                    ],
1✔
3170
                }],
1✔
3171
            )
1✔
3172
            .await;
2✔
3173

3174
            test_type(
1✔
3175
                &pool,
1✔
3176
                "\"Polygon\"[]",
1✔
3177
                [MultiPolygon {
1✔
3178
                    polygons: vec![
1✔
3179
                        vec![
1✔
3180
                            vec![
1✔
3181
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3182
                                Coordinate2D::new(2., 1.0).into(),
1✔
3183
                                Coordinate2D::new(2., 1.0).into(),
1✔
3184
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3185
                            ],
1✔
3186
                            vec![
1✔
3187
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3188
                                Coordinate2D::new(2., 1.0).into(),
1✔
3189
                                Coordinate2D::new(2., 1.0).into(),
1✔
3190
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3191
                            ],
1✔
3192
                        ],
1✔
3193
                        vec![
1✔
3194
                            vec![
1✔
3195
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3196
                                Coordinate2D::new(2., 1.0).into(),
1✔
3197
                                Coordinate2D::new(2., 1.0).into(),
1✔
3198
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3199
                            ],
1✔
3200
                            vec![
1✔
3201
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3202
                                Coordinate2D::new(2., 1.0).into(),
1✔
3203
                                Coordinate2D::new(2., 1.0).into(),
1✔
3204
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3205
                            ],
1✔
3206
                        ],
1✔
3207
                    ],
1✔
3208
                }],
1✔
3209
            )
1✔
3210
            .await;
4✔
3211

3212
            test_type(
1✔
3213
                &pool,
1✔
3214
                "TypedGeometry",
1✔
3215
                [
1✔
3216
                    crate::api::model::operators::TypedGeometry::Data(NoGeometry),
1✔
3217
                    crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3218
                        coordinates: vec![
1✔
3219
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3220
                            Coordinate2D::new(2., 1.0).into(),
1✔
3221
                        ],
1✔
3222
                    }),
1✔
3223
                    crate::api::model::operators::TypedGeometry::MultiLineString(MultiLineString {
1✔
3224
                        coordinates: vec![
1✔
3225
                            vec![
1✔
3226
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3227
                                Coordinate2D::new(2., 1.0).into(),
1✔
3228
                            ],
1✔
3229
                            vec![
1✔
3230
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3231
                                Coordinate2D::new(2., 1.0).into(),
1✔
3232
                            ],
1✔
3233
                        ],
1✔
3234
                    }),
1✔
3235
                    crate::api::model::operators::TypedGeometry::MultiPolygon(MultiPolygon {
1✔
3236
                        polygons: vec![
1✔
3237
                            vec![
1✔
3238
                                vec![
1✔
3239
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3240
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3241
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3242
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3243
                                ],
1✔
3244
                                vec![
1✔
3245
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3246
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3247
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3248
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3249
                                ],
1✔
3250
                            ],
1✔
3251
                            vec![
1✔
3252
                                vec![
1✔
3253
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3254
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3255
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3256
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3257
                                ],
1✔
3258
                                vec![
1✔
3259
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3260
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3261
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3262
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3263
                                ],
1✔
3264
                            ],
1✔
3265
                        ],
1✔
3266
                    }),
1✔
3267
                ],
1✔
3268
            )
1✔
3269
            .await;
11✔
3270

3271
            test_type(&pool, "int", [CacheTtlSeconds::new(100)]).await;
2✔
3272

3273
            test_type(
1✔
3274
                &pool,
1✔
3275
                "OgrSourceDataset",
1✔
3276
                [crate::api::model::operators::OgrSourceDataset {
1✔
3277
                    file_name: "test".into(),
1✔
3278
                    layer_name: "test".to_string(),
1✔
3279
                    data_type: Some(VectorDataType::MultiPoint.into()),
1✔
3280
                    time: crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3281
                        start_field: "start".to_string(),
1✔
3282
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3283
                        duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3284
                    },
1✔
3285
                    default_geometry: Some(
1✔
3286
                        crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3287
                            coordinates: vec![
1✔
3288
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3289
                                Coordinate2D::new(2., 1.0).into(),
1✔
3290
                            ],
1✔
3291
                        }),
1✔
3292
                    ),
1✔
3293
                    columns: Some(crate::api::model::operators::OgrSourceColumnSpec {
1✔
3294
                        format_specifics: Some(
1✔
3295
                            crate::api::model::operators::FormatSpecifics::Csv {
1✔
3296
                                header: CsvHeader::Auto.into(),
1✔
3297
                            },
1✔
3298
                        ),
1✔
3299
                        x: "x".to_string(),
1✔
3300
                        y: Some("y".to_string()),
1✔
3301
                        int: vec!["int".to_string()],
1✔
3302
                        float: vec!["float".to_string()],
1✔
3303
                        text: vec!["text".to_string()],
1✔
3304
                        bool: vec!["bool".to_string()],
1✔
3305
                        datetime: vec!["datetime".to_string()],
1✔
3306
                        rename: Some(
1✔
3307
                            [
1✔
3308
                                ("xx".to_string(), "xx_renamed".to_string()),
1✔
3309
                                ("yx".to_string(), "yy_renamed".to_string()),
1✔
3310
                            ]
1✔
3311
                            .into(),
1✔
3312
                        ),
1✔
3313
                    }),
1✔
3314
                    force_ogr_time_filter: false,
1✔
3315
                    force_ogr_spatial_filter: true,
1✔
3316
                    on_error: crate::api::model::operators::OgrSourceErrorSpec::Abort,
1✔
3317
                    sql_query: None,
1✔
3318
                    attribute_query: Some("foo = 'bar'".to_string()),
1✔
3319
                    cache_ttl: CacheTtlSeconds::new(5),
1✔
3320
                }],
1✔
3321
            )
1✔
3322
            .await;
6✔
3323

3324
            test_type(
1✔
3325
                &pool,
1✔
3326
                "MockMetaData",
1✔
3327
                [crate::api::model::operators::MockMetaData {
1✔
3328
                    loading_info: crate::api::model::operators::MockDatasetDataSourceLoadingInfo {
1✔
3329
                        points: vec![
1✔
3330
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3331
                            Coordinate2D::new(2., 1.0).into(),
1✔
3332
                        ],
1✔
3333
                    },
1✔
3334
                    result_descriptor: VectorResultDescriptor {
1✔
3335
                        data_type: VectorDataType::MultiPoint,
1✔
3336
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3337
                            SpatialReference::epsg_4326(),
1✔
3338
                        ),
1✔
3339
                        columns: [(
1✔
3340
                            "foo".to_string(),
1✔
3341
                            VectorColumnInfo {
1✔
3342
                                data_type: FeatureDataType::Int,
1✔
3343
                                measurement: Measurement::Unitless.into(),
1✔
3344
                            },
1✔
3345
                        )]
1✔
3346
                        .into(),
1✔
3347
                        time: Some(TimeInterval::default()),
1✔
3348
                        bbox: Some(
1✔
3349
                            BoundingBox2D::new(
1✔
3350
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3351
                                Coordinate2D::new(2., 1.0),
1✔
3352
                            )
1✔
3353
                            .unwrap(),
1✔
3354
                        ),
1✔
3355
                    }
1✔
3356
                    .into(),
1✔
3357
                    phantom: PhantomData,
1✔
3358
                }],
1✔
3359
            )
1✔
3360
            .await;
4✔
3361

3362
            test_type(
1✔
3363
                &pool,
1✔
3364
                "OgrMetaData",
1✔
3365
                [crate::api::model::operators::OgrMetaData {
1✔
3366
                    loading_info: crate::api::model::operators::OgrSourceDataset {
1✔
3367
                        file_name: "test".into(),
1✔
3368
                        layer_name: "test".to_string(),
1✔
3369
                        data_type: Some(VectorDataType::MultiPoint.into()),
1✔
3370
                        time: crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3371
                            start_field: "start".to_string(),
1✔
3372
                            start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3373
                            duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3374
                        },
1✔
3375
                        default_geometry: Some(
1✔
3376
                            crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3377
                                coordinates: vec![
1✔
3378
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3379
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3380
                                ],
1✔
3381
                            }),
1✔
3382
                        ),
1✔
3383
                        columns: Some(crate::api::model::operators::OgrSourceColumnSpec {
1✔
3384
                            format_specifics: Some(
1✔
3385
                                crate::api::model::operators::FormatSpecifics::Csv {
1✔
3386
                                    header: CsvHeader::Auto.into(),
1✔
3387
                                },
1✔
3388
                            ),
1✔
3389
                            x: "x".to_string(),
1✔
3390
                            y: Some("y".to_string()),
1✔
3391
                            int: vec!["int".to_string()],
1✔
3392
                            float: vec!["float".to_string()],
1✔
3393
                            text: vec!["text".to_string()],
1✔
3394
                            bool: vec!["bool".to_string()],
1✔
3395
                            datetime: vec!["datetime".to_string()],
1✔
3396
                            rename: Some(
1✔
3397
                                [
1✔
3398
                                    ("xx".to_string(), "xx_renamed".to_string()),
1✔
3399
                                    ("yx".to_string(), "yy_renamed".to_string()),
1✔
3400
                                ]
1✔
3401
                                .into(),
1✔
3402
                            ),
1✔
3403
                        }),
1✔
3404
                        force_ogr_time_filter: false,
1✔
3405
                        force_ogr_spatial_filter: true,
1✔
3406
                        on_error: crate::api::model::operators::OgrSourceErrorSpec::Abort,
1✔
3407
                        sql_query: None,
1✔
3408
                        attribute_query: Some("foo = 'bar'".to_string()),
1✔
3409
                        cache_ttl: CacheTtlSeconds::new(5),
1✔
3410
                    },
1✔
3411
                    result_descriptor: VectorResultDescriptor {
1✔
3412
                        data_type: VectorDataType::MultiPoint,
1✔
3413
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3414
                            SpatialReference::epsg_4326(),
1✔
3415
                        ),
1✔
3416
                        columns: [(
1✔
3417
                            "foo".to_string(),
1✔
3418
                            VectorColumnInfo {
1✔
3419
                                data_type: FeatureDataType::Int,
1✔
3420
                                measurement: Measurement::Unitless.into(),
1✔
3421
                            },
1✔
3422
                        )]
1✔
3423
                        .into(),
1✔
3424
                        time: Some(TimeInterval::default()),
1✔
3425
                        bbox: Some(
1✔
3426
                            BoundingBox2D::new(
1✔
3427
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3428
                                Coordinate2D::new(2., 1.0),
1✔
3429
                            )
1✔
3430
                            .unwrap(),
1✔
3431
                        ),
1✔
3432
                    }
1✔
3433
                    .into(),
1✔
3434
                    phantom: PhantomData,
1✔
3435
                }],
1✔
3436
            )
1✔
3437
            .await;
4✔
3438

3439
            test_type(
1✔
3440
                &pool,
1✔
3441
                "GdalDatasetGeoTransform",
1✔
3442
                [crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3443
                    origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3444
                    x_pixel_size: 1.0,
1✔
3445
                    y_pixel_size: 2.0,
1✔
3446
                }],
1✔
3447
            )
1✔
3448
            .await;
4✔
3449

3450
            test_type(
1✔
3451
                &pool,
1✔
3452
                "FileNotFoundHandling",
1✔
3453
                [
1✔
3454
                    crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3455
                    crate::api::model::operators::FileNotFoundHandling::Error,
1✔
3456
                ],
1✔
3457
            )
1✔
3458
            .await;
6✔
3459

3460
            test_type(
1✔
3461
                &pool,
1✔
3462
                "GdalMetadataMapping",
1✔
3463
                [crate::api::model::operators::GdalMetadataMapping {
1✔
3464
                    source_key: RasterPropertiesKey {
1✔
3465
                        domain: None,
1✔
3466
                        key: "foo".to_string(),
1✔
3467
                    },
1✔
3468
                    target_key: RasterPropertiesKey {
1✔
3469
                        domain: Some("bar".to_string()),
1✔
3470
                        key: "foo".to_string(),
1✔
3471
                    },
1✔
3472
                    target_type: RasterPropertiesEntryType::String,
1✔
3473
                }],
1✔
3474
            )
1✔
3475
            .await;
8✔
3476

3477
            test_type(
1✔
3478
                &pool,
1✔
3479
                "StringPair",
1✔
3480
                [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3481
            )
1✔
3482
            .await;
3✔
3483

3484
            test_type(
1✔
3485
                &pool,
1✔
3486
                "GdalDatasetParameters",
1✔
3487
                [crate::api::model::operators::GdalDatasetParameters {
1✔
3488
                    file_path: "text".into(),
1✔
3489
                    rasterband_channel: 1,
1✔
3490
                    geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3491
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3492
                        x_pixel_size: 1.0,
1✔
3493
                        y_pixel_size: 2.0,
1✔
3494
                    },
1✔
3495
                    width: 42,
1✔
3496
                    height: 23,
1✔
3497
                    file_not_found_handling:
1✔
3498
                        crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3499
                    no_data_value: Some(42.0),
1✔
3500
                    properties_mapping: Some(vec![
1✔
3501
                        crate::api::model::operators::GdalMetadataMapping {
1✔
3502
                            source_key: RasterPropertiesKey {
1✔
3503
                                domain: None,
1✔
3504
                                key: "foo".to_string(),
1✔
3505
                            },
1✔
3506
                            target_key: RasterPropertiesKey {
1✔
3507
                                domain: Some("bar".to_string()),
1✔
3508
                                key: "foo".to_string(),
1✔
3509
                            },
1✔
3510
                            target_type: RasterPropertiesEntryType::String,
1✔
3511
                        },
1✔
3512
                    ]),
1✔
3513
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3514
                    gdal_config_options: Some(vec![
1✔
3515
                        crate::api::model::operators::GdalConfigOption::from((
1✔
3516
                            "foo".to_string(),
1✔
3517
                            "bar".to_string(),
1✔
3518
                        )),
1✔
3519
                    ]),
1✔
3520
                    allow_alphaband_as_mask: false,
1✔
3521
                }],
1✔
3522
            )
1✔
3523
            .await;
6✔
3524

3525
            test_type(
1✔
3526
                &pool,
1✔
3527
                "TextGdalSourceTimePlaceholderKeyValue",
1✔
3528
                [crate::api::model::TextGdalSourceTimePlaceholderKeyValue {
1✔
3529
                    key: "foo".to_string(),
1✔
3530
                    value: GdalSourceTimePlaceholder {
1✔
3531
                        format: geoengine_datatypes::primitives::DateTimeParseFormat::unix().into(),
1✔
3532
                        reference: TimeReference::Start,
1✔
3533
                    },
1✔
3534
                }],
1✔
3535
            )
1✔
3536
            .await;
8✔
3537

3538
            test_type(
1✔
3539
                &pool,
1✔
3540
                "GdalMetaDataRegular",
1✔
3541
                [crate::api::model::operators::GdalMetaDataRegular {
1✔
3542
                    result_descriptor: RasterResultDescriptor {
1✔
3543
                        data_type: RasterDataType::U8,
1✔
3544
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3545
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3546
                            measurement: "Temperature".to_string(),
1✔
3547
                            unit: Some("°C".to_string()),
1✔
3548
                        })
1✔
3549
                        .into(),
1✔
3550
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3551
                        bbox: Some(
1✔
3552
                            crate::api::model::datatypes::SpatialPartition2D {
1✔
3553
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3554
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3555
                            }
1✔
3556
                            .into(),
1✔
3557
                        ),
1✔
3558
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3559
                    }
1✔
3560
                    .into(),
1✔
3561
                    params: crate::api::model::operators::GdalDatasetParameters {
1✔
3562
                        file_path: "text".into(),
1✔
3563
                        rasterband_channel: 1,
1✔
3564
                        geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3565
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3566
                            x_pixel_size: 1.0,
1✔
3567
                            y_pixel_size: 2.0,
1✔
3568
                        },
1✔
3569
                        width: 42,
1✔
3570
                        height: 23,
1✔
3571
                        file_not_found_handling:
1✔
3572
                            crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3573
                        no_data_value: Some(42.0),
1✔
3574
                        properties_mapping: Some(vec![
1✔
3575
                            crate::api::model::operators::GdalMetadataMapping {
1✔
3576
                                source_key: RasterPropertiesKey {
1✔
3577
                                    domain: None,
1✔
3578
                                    key: "foo".to_string(),
1✔
3579
                                },
1✔
3580
                                target_key: RasterPropertiesKey {
1✔
3581
                                    domain: Some("bar".to_string()),
1✔
3582
                                    key: "foo".to_string(),
1✔
3583
                                },
1✔
3584
                                target_type: RasterPropertiesEntryType::String,
1✔
3585
                            },
1✔
3586
                        ]),
1✔
3587
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3588
                        gdal_config_options: Some(vec![
1✔
3589
                            crate::api::model::operators::GdalConfigOption::from((
1✔
3590
                                "foo".to_string(),
1✔
3591
                                "bar".to_string(),
1✔
3592
                            )),
1✔
3593
                        ]),
1✔
3594
                        allow_alphaband_as_mask: false,
1✔
3595
                    },
1✔
3596
                    time_placeholders: [(
1✔
3597
                        "foo".to_string(),
1✔
3598
                        GdalSourceTimePlaceholder {
1✔
3599
                            format: geoengine_datatypes::primitives::DateTimeParseFormat::unix()
1✔
3600
                                .into(),
1✔
3601
                            reference: TimeReference::Start,
1✔
3602
                        },
1✔
3603
                    )]
1✔
3604
                    .into(),
1✔
3605
                    data_time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3606
                    step: TimeStep {
1✔
3607
                        granularity: TimeGranularity::Millis,
1✔
3608
                        step: 1,
1✔
3609
                    }
1✔
3610
                    .into(),
1✔
3611
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3612
                }],
1✔
3613
            )
1✔
3614
            .await;
6✔
3615

3616
            test_type(
1✔
3617
                &pool,
1✔
3618
                "GdalMetaDataStatic",
1✔
3619
                [crate::api::model::operators::GdalMetaDataStatic {
1✔
3620
                    time: Some(TimeInterval::new_unchecked(0, 1).into()),
1✔
3621
                    result_descriptor: RasterResultDescriptor {
1✔
3622
                        data_type: RasterDataType::U8,
1✔
3623
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3624
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3625
                            measurement: "Temperature".to_string(),
1✔
3626
                            unit: Some("°C".to_string()),
1✔
3627
                        })
1✔
3628
                        .into(),
1✔
3629
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3630
                        bbox: Some(
1✔
3631
                            crate::api::model::datatypes::SpatialPartition2D {
1✔
3632
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3633
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3634
                            }
1✔
3635
                            .into(),
1✔
3636
                        ),
1✔
3637
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3638
                    }
1✔
3639
                    .into(),
1✔
3640
                    params: crate::api::model::operators::GdalDatasetParameters {
1✔
3641
                        file_path: "text".into(),
1✔
3642
                        rasterband_channel: 1,
1✔
3643
                        geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3644
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3645
                            x_pixel_size: 1.0,
1✔
3646
                            y_pixel_size: 2.0,
1✔
3647
                        },
1✔
3648
                        width: 42,
1✔
3649
                        height: 23,
1✔
3650
                        file_not_found_handling:
1✔
3651
                            crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3652
                        no_data_value: Some(42.0),
1✔
3653
                        properties_mapping: Some(vec![
1✔
3654
                            crate::api::model::operators::GdalMetadataMapping {
1✔
3655
                                source_key: RasterPropertiesKey {
1✔
3656
                                    domain: None,
1✔
3657
                                    key: "foo".to_string(),
1✔
3658
                                },
1✔
3659
                                target_key: RasterPropertiesKey {
1✔
3660
                                    domain: Some("bar".to_string()),
1✔
3661
                                    key: "foo".to_string(),
1✔
3662
                                },
1✔
3663
                                target_type: RasterPropertiesEntryType::String,
1✔
3664
                            },
1✔
3665
                        ]),
1✔
3666
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3667
                        gdal_config_options: Some(vec![
1✔
3668
                            crate::api::model::operators::GdalConfigOption::from((
1✔
3669
                                "foo".to_string(),
1✔
3670
                                "bar".to_string(),
1✔
3671
                            )),
1✔
3672
                        ]),
1✔
3673
                        allow_alphaband_as_mask: false,
1✔
3674
                    },
1✔
3675
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3676
                }],
1✔
3677
            )
1✔
3678
            .await;
4✔
3679

3680
            test_type(
1✔
3681
                &pool,
1✔
3682
                "GdalMetadataNetCdfCf",
1✔
3683
                [crate::api::model::operators::GdalMetadataNetCdfCf {
1✔
3684
                    result_descriptor: RasterResultDescriptor {
1✔
3685
                        data_type: RasterDataType::U8,
1✔
3686
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3687
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3688
                            measurement: "Temperature".to_string(),
1✔
3689
                            unit: Some("°C".to_string()),
1✔
3690
                        })
1✔
3691
                        .into(),
1✔
3692
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3693
                        bbox: Some(
1✔
3694
                            crate::api::model::datatypes::SpatialPartition2D {
1✔
3695
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3696
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3697
                            }
1✔
3698
                            .into(),
1✔
3699
                        ),
1✔
3700
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3701
                    }
1✔
3702
                    .into(),
1✔
3703
                    params: crate::api::model::operators::GdalDatasetParameters {
1✔
3704
                        file_path: "text".into(),
1✔
3705
                        rasterband_channel: 1,
1✔
3706
                        geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3707
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3708
                            x_pixel_size: 1.0,
1✔
3709
                            y_pixel_size: 2.0,
1✔
3710
                        },
1✔
3711
                        width: 42,
1✔
3712
                        height: 23,
1✔
3713
                        file_not_found_handling:
1✔
3714
                            crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3715
                        no_data_value: Some(42.0),
1✔
3716
                        properties_mapping: Some(vec![
1✔
3717
                            crate::api::model::operators::GdalMetadataMapping {
1✔
3718
                                source_key: RasterPropertiesKey {
1✔
3719
                                    domain: None,
1✔
3720
                                    key: "foo".to_string(),
1✔
3721
                                },
1✔
3722
                                target_key: RasterPropertiesKey {
1✔
3723
                                    domain: Some("bar".to_string()),
1✔
3724
                                    key: "foo".to_string(),
1✔
3725
                                },
1✔
3726
                                target_type: RasterPropertiesEntryType::String,
1✔
3727
                            },
1✔
3728
                        ]),
1✔
3729
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3730
                        gdal_config_options: Some(vec![
1✔
3731
                            crate::api::model::operators::GdalConfigOption::from((
1✔
3732
                                "foo".to_string(),
1✔
3733
                                "bar".to_string(),
1✔
3734
                            )),
1✔
3735
                        ]),
1✔
3736
                        allow_alphaband_as_mask: false,
1✔
3737
                    },
1✔
3738
                    start: TimeInstance::from_millis(0).unwrap().into(),
1✔
3739
                    end: TimeInstance::from_millis(1000).unwrap().into(),
1✔
3740
                    cache_ttl: CacheTtlSeconds::max(),
1✔
3741
                    step: TimeStep {
1✔
3742
                        granularity: TimeGranularity::Millis,
1✔
3743
                        step: 1,
1✔
3744
                    }
1✔
3745
                    .into(),
1✔
3746
                    band_offset: 3,
1✔
3747
                }],
1✔
3748
            )
1✔
3749
            .await;
4✔
3750

3751
            test_type(
1✔
3752
                &pool,
1✔
3753
                "GdalMetaDataList",
1✔
3754
                [crate::api::model::operators::GdalMetaDataList {
1✔
3755
                    result_descriptor: RasterResultDescriptor {
1✔
3756
                        data_type: RasterDataType::U8,
1✔
3757
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3758
                        measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3759
                            measurement: "Temperature".to_string(),
1✔
3760
                            unit: Some("°C".to_string()),
1✔
3761
                        })
1✔
3762
                        .into(),
1✔
3763
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3764
                        bbox: Some(
1✔
3765
                            crate::api::model::datatypes::SpatialPartition2D {
1✔
3766
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3767
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3768
                            }
1✔
3769
                            .into(),
1✔
3770
                        ),
1✔
3771
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
3772
                    }
1✔
3773
                    .into(),
1✔
3774
                    params: vec![crate::api::model::operators::GdalLoadingInfoTemporalSlice {
1✔
3775
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3776
                        params: Some(crate::api::model::operators::GdalDatasetParameters {
1✔
3777
                            file_path: "text".into(),
1✔
3778
                            rasterband_channel: 1,
1✔
3779
                            geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3780
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3781
                                x_pixel_size: 1.0,
1✔
3782
                                y_pixel_size: 2.0,
1✔
3783
                            },
1✔
3784
                            width: 42,
1✔
3785
                            height: 23,
1✔
3786
                            file_not_found_handling:
1✔
3787
                                crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3788
                            no_data_value: Some(42.0),
1✔
3789
                            properties_mapping: Some(vec![
1✔
3790
                                crate::api::model::operators::GdalMetadataMapping {
1✔
3791
                                    source_key: RasterPropertiesKey {
1✔
3792
                                        domain: None,
1✔
3793
                                        key: "foo".to_string(),
1✔
3794
                                    },
1✔
3795
                                    target_key: RasterPropertiesKey {
1✔
3796
                                        domain: Some("bar".to_string()),
1✔
3797
                                        key: "foo".to_string(),
1✔
3798
                                    },
1✔
3799
                                    target_type: RasterPropertiesEntryType::String,
1✔
3800
                                },
1✔
3801
                            ]),
1✔
3802
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3803
                            gdal_config_options: Some(vec![
1✔
3804
                                crate::api::model::operators::GdalConfigOption::from((
1✔
3805
                                    "foo".to_string(),
1✔
3806
                                    "bar".to_string(),
1✔
3807
                                )),
1✔
3808
                            ]),
1✔
3809
                            allow_alphaband_as_mask: false,
1✔
3810
                        }),
1✔
3811
                        cache_ttl: CacheTtlSeconds::max(),
1✔
3812
                    }],
1✔
3813
                }],
1✔
3814
            )
1✔
3815
            .await;
7✔
3816

3817
            test_type(
1✔
3818
                &pool,
1✔
3819
                "MetaDataDefinition",
1✔
3820
                [
1✔
3821
                    crate::datasets::storage::MetaDataDefinition::MockMetaData(
1✔
3822
                        crate::api::model::operators::MockMetaData {
1✔
3823
                            loading_info:
1✔
3824
                                crate::api::model::operators::MockDatasetDataSourceLoadingInfo {
1✔
3825
                                    points: vec![
1✔
3826
                                        Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3827
                                        Coordinate2D::new(2., 1.0).into(),
1✔
3828
                                    ],
1✔
3829
                                },
1✔
3830
                            result_descriptor: VectorResultDescriptor {
1✔
3831
                                data_type: VectorDataType::MultiPoint,
1✔
3832
                                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3833
                                    SpatialReference::epsg_4326(),
1✔
3834
                                ),
1✔
3835
                                columns: [(
1✔
3836
                                    "foo".to_string(),
1✔
3837
                                    VectorColumnInfo {
1✔
3838
                                        data_type: FeatureDataType::Int,
1✔
3839
                                        measurement: Measurement::Unitless.into(),
1✔
3840
                                    },
1✔
3841
                                )]
1✔
3842
                                .into(),
1✔
3843
                                time: Some(TimeInterval::default()),
1✔
3844
                                bbox: Some(
1✔
3845
                                    BoundingBox2D::new(
1✔
3846
                                        Coordinate2D::new(0.0f64, 0.5),
1✔
3847
                                        Coordinate2D::new(2., 1.0),
1✔
3848
                                    )
1✔
3849
                                    .unwrap(),
1✔
3850
                                ),
1✔
3851
                            }
1✔
3852
                            .into(),
1✔
3853
                            phantom: PhantomData,
1✔
3854
                        }.into(),
1✔
3855
                    ),
1✔
3856
                    crate::api::model::services::MetaDataDefinition::OgrMetaData(crate::api::model::operators::OgrMetaData {
1✔
3857
                        loading_info: crate::api::model::operators::OgrSourceDataset {
1✔
3858
                            file_name: "test".into(),
1✔
3859
                            layer_name: "test".to_string(),
1✔
3860
                            data_type: Some(VectorDataType::MultiPoint.into()),
1✔
3861
                            time: crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3862
                                start_field: "start".to_string(),
1✔
3863
                                start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3864
                                duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3865
                            },
1✔
3866
                            default_geometry: Some(
1✔
3867
                                crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3868
                                    coordinates: vec![
1✔
3869
                                        Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3870
                                        Coordinate2D::new(2., 1.0).into(),
1✔
3871
                                    ],
1✔
3872
                                }),
1✔
3873
                            ),
1✔
3874
                            columns: Some(crate::api::model::operators::OgrSourceColumnSpec {
1✔
3875
                                format_specifics: Some(
1✔
3876
                                    crate::api::model::operators::FormatSpecifics::Csv {
1✔
3877
                                        header: CsvHeader::Auto.into(),
1✔
3878
                                    },
1✔
3879
                                ),
1✔
3880
                                x: "x".to_string(),
1✔
3881
                                y: Some("y".to_string()),
1✔
3882
                                int: vec!["int".to_string()],
1✔
3883
                                float: vec!["float".to_string()],
1✔
3884
                                text: vec!["text".to_string()],
1✔
3885
                                bool: vec!["bool".to_string()],
1✔
3886
                                datetime: vec!["datetime".to_string()],
1✔
3887
                                rename: Some(
1✔
3888
                                    [
1✔
3889
                                        ("xx".to_string(), "xx_renamed".to_string()),
1✔
3890
                                        ("yx".to_string(), "yy_renamed".to_string()),
1✔
3891
                                    ]
1✔
3892
                                    .into(),
1✔
3893
                                ),
1✔
3894
                            }),
1✔
3895
                            force_ogr_time_filter: false,
1✔
3896
                            force_ogr_spatial_filter: true,
1✔
3897
                            on_error: crate::api::model::operators::OgrSourceErrorSpec::Abort,
1✔
3898
                            sql_query: None,
1✔
3899
                            attribute_query: Some("foo = 'bar'".to_string()),
1✔
3900
                            cache_ttl: CacheTtlSeconds::new(5),
1✔
3901
                        },
1✔
3902
                        result_descriptor: VectorResultDescriptor {
1✔
3903
                            data_type: VectorDataType::MultiPoint,
1✔
3904
                            spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3905
                                SpatialReference::epsg_4326(),
1✔
3906
                            ),
1✔
3907
                            columns: [(
1✔
3908
                                "foo".to_string(),
1✔
3909
                                VectorColumnInfo {
1✔
3910
                                    data_type: FeatureDataType::Int,
1✔
3911
                                    measurement: Measurement::Unitless.into(),
1✔
3912
                                },
1✔
3913
                            )]
1✔
3914
                            .into(),
1✔
3915
                            time: Some(TimeInterval::default()),
1✔
3916
                            bbox: Some(
1✔
3917
                                BoundingBox2D::new(
1✔
3918
                                    Coordinate2D::new(0.0f64, 0.5),
1✔
3919
                                    Coordinate2D::new(2., 1.0),
1✔
3920
                                )
1✔
3921
                                .unwrap(),
1✔
3922
                            ),
1✔
3923
                        }
1✔
3924
                        .into(),
1✔
3925
                        phantom: PhantomData,
1✔
3926
                    }).into(),
1✔
3927
                    crate::api::model::services::MetaDataDefinition::GdalMetaDataRegular(crate::api::model::operators::GdalMetaDataRegular {
1✔
3928
                        result_descriptor: RasterResultDescriptor {
1✔
3929
                            data_type: RasterDataType::U8,
1✔
3930
                            spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3931
                            measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
3932
                                measurement: "Temperature".to_string(),
1✔
3933
                                unit: Some("°C".to_string()),
1✔
3934
                            })
1✔
3935
                            .into(),
1✔
3936
                            time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3937
                            bbox: Some(
1✔
3938
                                crate::api::model::datatypes::SpatialPartition2D {
1✔
3939
                                    upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3940
                                    lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3941
                                }
1✔
3942
                                .into(),
1✔
3943
                            ),
1✔
3944
                            resolution: Some(SpatialResolution::zero_point_one()),
1✔
3945
                        }
1✔
3946
                        .into(),
1✔
3947
                        params: crate::api::model::operators::GdalDatasetParameters {
1✔
3948
                            file_path: "text".into(),
1✔
3949
                            rasterband_channel: 1,
1✔
3950
                            geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3951
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3952
                                x_pixel_size: 1.0,
1✔
3953
                                y_pixel_size: 2.0,
1✔
3954
                            },
1✔
3955
                            width: 42,
1✔
3956
                            height: 23,
1✔
3957
                            file_not_found_handling:
1✔
3958
                                crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3959
                            no_data_value: Some(42.0),
1✔
3960
                            properties_mapping: Some(vec![
1✔
3961
                                crate::api::model::operators::GdalMetadataMapping {
1✔
3962
                                    source_key: RasterPropertiesKey {
1✔
3963
                                        domain: None,
1✔
3964
                                        key: "foo".to_string(),
1✔
3965
                                    },
1✔
3966
                                    target_key: RasterPropertiesKey {
1✔
3967
                                        domain: Some("bar".to_string()),
1✔
3968
                                        key: "foo".to_string(),
1✔
3969
                                    },
1✔
3970
                                    target_type: RasterPropertiesEntryType::String,
1✔
3971
                                },
1✔
3972
                            ]),
1✔
3973
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3974
                            gdal_config_options: Some(vec![
1✔
3975
                                crate::api::model::operators::GdalConfigOption::from((
1✔
3976
                                    "foo".to_string(),
1✔
3977
                                    "bar".to_string(),
1✔
3978
                                )),
1✔
3979
                            ]),
1✔
3980
                            allow_alphaband_as_mask: false,
1✔
3981
                        },
1✔
3982
                        time_placeholders: [(
1✔
3983
                            "foo".to_string(),
1✔
3984
                            GdalSourceTimePlaceholder {
1✔
3985
                                format: geoengine_datatypes::primitives::DateTimeParseFormat::unix()
1✔
3986
                                    .into(),
1✔
3987
                                reference: TimeReference::Start,
1✔
3988
                            },
1✔
3989
                        )]
1✔
3990
                        .into(),
1✔
3991
                        data_time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3992
                        step: TimeStep {
1✔
3993
                            granularity: TimeGranularity::Millis,
1✔
3994
                            step: 1,
1✔
3995
                        }
1✔
3996
                        .into(),
1✔
3997
                        cache_ttl: CacheTtlSeconds::max(),
1✔
3998
                    }).into(),
1✔
3999
                    crate::api::model::services::MetaDataDefinition::GdalStatic(crate::api::model::operators::GdalMetaDataStatic {
1✔
4000
                        time: Some(TimeInterval::new_unchecked(0, 1).into()),
1✔
4001
                        result_descriptor: RasterResultDescriptor {
1✔
4002
                            data_type: RasterDataType::U8,
1✔
4003
                            spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4004
                            measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
4005
                                measurement: "Temperature".to_string(),
1✔
4006
                                unit: Some("°C".to_string()),
1✔
4007
                            })
1✔
4008
                            .into(),
1✔
4009
                            time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4010
                            bbox: Some(
1✔
4011
                                crate::api::model::datatypes::SpatialPartition2D {
1✔
4012
                                    upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
4013
                                    lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
4014
                                }
1✔
4015
                                .into(),
1✔
4016
                            ),
1✔
4017
                            resolution: Some(SpatialResolution::zero_point_one()),
1✔
4018
                        }
1✔
4019
                        .into(),
1✔
4020
                        params: crate::api::model::operators::GdalDatasetParameters {
1✔
4021
                            file_path: "text".into(),
1✔
4022
                            rasterband_channel: 1,
1✔
4023
                            geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
4024
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
4025
                                x_pixel_size: 1.0,
1✔
4026
                                y_pixel_size: 2.0,
1✔
4027
                            },
1✔
4028
                            width: 42,
1✔
4029
                            height: 23,
1✔
4030
                            file_not_found_handling:
1✔
4031
                                crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
4032
                            no_data_value: Some(42.0),
1✔
4033
                            properties_mapping: Some(vec![
1✔
4034
                                crate::api::model::operators::GdalMetadataMapping {
1✔
4035
                                    source_key: RasterPropertiesKey {
1✔
4036
                                        domain: None,
1✔
4037
                                        key: "foo".to_string(),
1✔
4038
                                    },
1✔
4039
                                    target_key: RasterPropertiesKey {
1✔
4040
                                        domain: Some("bar".to_string()),
1✔
4041
                                        key: "foo".to_string(),
1✔
4042
                                    },
1✔
4043
                                    target_type: RasterPropertiesEntryType::String,
1✔
4044
                                },
1✔
4045
                            ]),
1✔
4046
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4047
                            gdal_config_options: Some(vec![
1✔
4048
                                crate::api::model::operators::GdalConfigOption::from((
1✔
4049
                                    "foo".to_string(),
1✔
4050
                                    "bar".to_string(),
1✔
4051
                                )),
1✔
4052
                            ]),
1✔
4053
                            allow_alphaband_as_mask: false,
1✔
4054
                        },
1✔
4055
                        cache_ttl: CacheTtlSeconds::max(),
1✔
4056
                    }).into(),
1✔
4057
                    crate::api::model::services::MetaDataDefinition::GdalMetadataNetCdfCf(crate::api::model::operators::GdalMetadataNetCdfCf {
1✔
4058
                        result_descriptor: RasterResultDescriptor {
1✔
4059
                            data_type: RasterDataType::U8,
1✔
4060
                            spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4061
                            measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
4062
                                measurement: "Temperature".to_string(),
1✔
4063
                                unit: Some("°C".to_string()),
1✔
4064
                            })
1✔
4065
                            .into(),
1✔
4066
                            time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4067
                            bbox: Some(
1✔
4068
                                crate::api::model::datatypes::SpatialPartition2D {
1✔
4069
                                    upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
4070
                                    lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
4071
                                }
1✔
4072
                                .into(),
1✔
4073
                            ),
1✔
4074
                            resolution: Some(SpatialResolution::zero_point_one()),
1✔
4075
                        }
1✔
4076
                        .into(),
1✔
4077
                        params: crate::api::model::operators::GdalDatasetParameters {
1✔
4078
                            file_path: "text".into(),
1✔
4079
                            rasterband_channel: 1,
1✔
4080
                            geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
4081
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
4082
                                x_pixel_size: 1.0,
1✔
4083
                                y_pixel_size: 2.0,
1✔
4084
                            },
1✔
4085
                            width: 42,
1✔
4086
                            height: 23,
1✔
4087
                            file_not_found_handling:
1✔
4088
                                crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
4089
                            no_data_value: Some(42.0),
1✔
4090
                            properties_mapping: Some(vec![
1✔
4091
                                crate::api::model::operators::GdalMetadataMapping {
1✔
4092
                                    source_key: RasterPropertiesKey {
1✔
4093
                                        domain: None,
1✔
4094
                                        key: "foo".to_string(),
1✔
4095
                                    },
1✔
4096
                                    target_key: RasterPropertiesKey {
1✔
4097
                                        domain: Some("bar".to_string()),
1✔
4098
                                        key: "foo".to_string(),
1✔
4099
                                    },
1✔
4100
                                    target_type: RasterPropertiesEntryType::String,
1✔
4101
                                },
1✔
4102
                            ]),
1✔
4103
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4104
                            gdal_config_options: Some(vec![
1✔
4105
                                crate::api::model::operators::GdalConfigOption::from((
1✔
4106
                                    "foo".to_string(),
1✔
4107
                                    "bar".to_string(),
1✔
4108
                                )),
1✔
4109
                            ]),
1✔
4110
                            allow_alphaband_as_mask: false,
1✔
4111
                        },
1✔
4112
                        start: TimeInstance::from_millis(0).unwrap().into(),
1✔
4113
                        end: TimeInstance::from_millis(1000).unwrap().into(),
1✔
4114
                        cache_ttl: CacheTtlSeconds::max(),
1✔
4115
                        step: TimeStep {
1✔
4116
                            granularity: TimeGranularity::Millis,
1✔
4117
                            step: 1,
1✔
4118
                        }
1✔
4119
                        .into(),
1✔
4120
                        band_offset: 3,
1✔
4121
                    }).into(),
1✔
4122
                    crate::api::model::services::MetaDataDefinition::GdalMetaDataList(
1✔
4123
                        crate::api::model::operators::GdalMetaDataList {
1✔
4124
                            result_descriptor: RasterResultDescriptor {
1✔
4125
                                data_type: RasterDataType::U8,
1✔
4126
                                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4127
                                measurement: Measurement::Continuous(ContinuousMeasurement {
1✔
4128
                                    measurement: "Temperature".to_string(),
1✔
4129
                                    unit: Some("°C".to_string()),
1✔
4130
                                })
1✔
4131
                                .into(),
1✔
4132
                                time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4133
                                bbox: Some(
1✔
4134
                                    crate::api::model::datatypes::SpatialPartition2D {
1✔
4135
                                        upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
4136
                                        lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
4137
                                    }
1✔
4138
                                    .into(),
1✔
4139
                                ),
1✔
4140
                                resolution: Some(SpatialResolution::zero_point_one()),
1✔
4141
                            }
1✔
4142
                            .into(),
1✔
4143
                            params: vec![crate::api::model::operators::GdalLoadingInfoTemporalSlice {
1✔
4144
                                time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4145
                                params: Some(crate::api::model::operators::GdalDatasetParameters {
1✔
4146
                                    file_path: "text".into(),
1✔
4147
                                    rasterband_channel: 1,
1✔
4148
                                    geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
4149
                                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
4150
                                        x_pixel_size: 1.0,
1✔
4151
                                        y_pixel_size: 2.0,
1✔
4152
                                    },
1✔
4153
                                    width: 42,
1✔
4154
                                    height: 23,
1✔
4155
                                    file_not_found_handling:
1✔
4156
                                        crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
4157
                                    no_data_value: Some(42.0),
1✔
4158
                                    properties_mapping: Some(vec![
1✔
4159
                                        crate::api::model::operators::GdalMetadataMapping {
1✔
4160
                                            source_key: RasterPropertiesKey {
1✔
4161
                                                domain: None,
1✔
4162
                                                key: "foo".to_string(),
1✔
4163
                                            },
1✔
4164
                                            target_key: RasterPropertiesKey {
1✔
4165
                                                domain: Some("bar".to_string()),
1✔
4166
                                                key: "foo".to_string(),
1✔
4167
                                            },
1✔
4168
                                            target_type: RasterPropertiesEntryType::String,
1✔
4169
                                        },
1✔
4170
                                    ]),
1✔
4171
                                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4172
                                    gdal_config_options: Some(vec![
1✔
4173
                                        crate::api::model::operators::GdalConfigOption::from((
1✔
4174
                                            "foo".to_string(),
1✔
4175
                                            "bar".to_string(),
1✔
4176
                                        )),
1✔
4177
                                    ]),
1✔
4178
                                    allow_alphaband_as_mask: false,
1✔
4179
                                }),
1✔
4180
                                cache_ttl: CacheTtlSeconds::max(),
1✔
4181
                            }],
1✔
4182
                        },
1✔
4183
                    ).into(),
1✔
4184
                ],
1✔
4185
            )
1✔
4186
            .await;
15✔
4187
        })
1✔
4188
        .await;
10✔
4189
    }
4190
}
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

© 2026 Coveralls, Inc