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

geo-engine / geoengine / 6022749615

30 Aug 2023 08:57AM UTC coverage: 89.84% (+0.009%) from 89.831%
6022749615

push

github

web-flow
Merge pull request #867 from glombiewski/postgres-port-fix

Use postgres port on startup

45 of 45 new or added lines in 2 files covered. (100.0%)

105833 of 117801 relevant lines covered (89.84%)

61463.62 hits per line

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

98.07
/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;
17
use crate::util::config::get_config_element;
18
use async_trait::async_trait;
19
use bb8_postgres::{
20
    bb8::Pool,
21
    bb8::PooledConnection,
22
    tokio_postgres::{error::SqlState, tls::MakeTlsConnect, tls::TlsConnect, Config, Socket},
23
    PostgresConnectionManager,
24
};
25
use geoengine_datatypes::raster::TilingSpecification;
26
use geoengine_operators::engine::ChunkByteSize;
27
use geoengine_operators::util::create_rayon_thread_pool;
28
use log::{debug, info};
29
use rayon::ThreadPool;
30
use std::path::PathBuf;
31
use std::sync::Arc;
32

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

147
        Ok(app_ctx)
×
148
    }
×
149

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

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

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

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

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

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

205
        let tx = conn.build_transaction().start().await?;
320✔
206

207
        tx.batch_execute(include_str!("schema.sql")).await?;
320✔
208

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

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

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

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

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

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

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

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

274
        tx.commit().await?;
320✔
275

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

278
        Ok(true)
320✔
279
    }
320✔
280

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

498
impl From<config::Postgres> for Config {
499
    fn from(db_config: config::Postgres) -> Self {
1✔
500
        let mut pg_config = Config::new();
1✔
501
        pg_config
1✔
502
            .user(&db_config.user)
1✔
503
            .password(&db_config.password)
1✔
504
            .host(&db_config.host)
1✔
505
            .dbname(&db_config.database)
1✔
506
            .port(db_config.port)
1✔
507
            // fix schema by providing `search_path` option
1✔
508
            .options(&format!("-c search_path={}", db_config.schema));
1✔
509
        pg_config
1✔
510
    }
1✔
511
}
512

513
#[cfg(test)]
514
mod tests {
515
    use std::collections::HashMap;
516
    use std::marker::PhantomData;
517
    use std::str::FromStr;
518

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

585
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
586
    async fn test() {
1✔
587
        with_temp_context(|app_ctx, _| async move {
1✔
588
            let session = app_ctx.default_session().await.unwrap();
18✔
589

1✔
590
            create_projects(&app_ctx, &session).await;
74✔
591

592
            let projects = list_projects(&app_ctx, &session).await;
11✔
593

594
            let project_id = projects[0].id;
1✔
595

1✔
596
            update_projects(&app_ctx, &session, project_id).await;
155✔
597

598
            delete_project(&app_ctx, &session, project_id).await;
6✔
599
        })
1✔
600
        .await;
9✔
601
    }
602

603
    async fn delete_project(
1✔
604
        app_ctx: &PostgresContext<NoTls>,
1✔
605
        session: &SimpleSession,
1✔
606
        project_id: ProjectId,
1✔
607
    ) {
1✔
608
        let db = app_ctx.session_context(session.clone()).db();
1✔
609

1✔
610
        db.delete_project(project_id).await.unwrap();
3✔
611

1✔
612
        assert!(db.load_project(project_id).await.is_err());
3✔
613
    }
1✔
614

615
    #[allow(clippy::too_many_lines)]
616
    async fn update_projects(
1✔
617
        app_ctx: &PostgresContext<NoTls>,
1✔
618
        session: &SimpleSession,
1✔
619
        project_id: ProjectId,
1✔
620
    ) {
1✔
621
        let db = app_ctx.session_context(session.clone()).db();
1✔
622

623
        let project = db
1✔
624
            .load_project_version(project_id, LoadVersion::Latest)
1✔
625
            .await
37✔
626
            .unwrap();
1✔
627

628
        let layer_workflow_id = db
1✔
629
            .register_workflow(Workflow {
1✔
630
                operator: TypedOperator::Vector(
1✔
631
                    MockPointSource {
1✔
632
                        params: MockPointSourceParams {
1✔
633
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
634
                        },
1✔
635
                    }
1✔
636
                    .boxed(),
1✔
637
                ),
1✔
638
            })
1✔
639
            .await
3✔
640
            .unwrap();
1✔
641

1✔
642
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
3✔
643

644
        let plot_workflow_id = db
1✔
645
            .register_workflow(Workflow {
1✔
646
                operator: Statistics {
1✔
647
                    params: StatisticsParams {
1✔
648
                        column_names: vec![],
1✔
649
                    },
1✔
650
                    sources: MultipleRasterOrSingleVectorSource {
1✔
651
                        source: Raster(vec![]),
1✔
652
                    },
1✔
653
                }
1✔
654
                .boxed()
1✔
655
                .into(),
1✔
656
            })
1✔
657
            .await
3✔
658
            .unwrap();
1✔
659

1✔
660
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
3✔
661

662
        // add a plot
663
        let update = UpdateProject {
1✔
664
            id: project.id,
1✔
665
            name: Some("Test9 Updated".into()),
1✔
666
            description: None,
1✔
667
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
668
                workflow: layer_workflow_id,
1✔
669
                name: "TestLayer".into(),
1✔
670
                symbology: PointSymbology::default().into(),
1✔
671
                visibility: Default::default(),
1✔
672
            })]),
1✔
673
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
674
                workflow: plot_workflow_id,
1✔
675
                name: "Test Plot".into(),
1✔
676
            })]),
1✔
677
            bounds: None,
1✔
678
            time_step: None,
1✔
679
        };
1✔
680
        db.update_project(update).await.unwrap();
65✔
681

682
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
683
        assert_eq!(versions.len(), 2);
1✔
684

685
        // add second plot
686
        let update = UpdateProject {
1✔
687
            id: project.id,
1✔
688
            name: Some("Test9 Updated".into()),
1✔
689
            description: None,
1✔
690
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
691
                workflow: layer_workflow_id,
1✔
692
                name: "TestLayer".into(),
1✔
693
                symbology: PointSymbology::default().into(),
1✔
694
                visibility: Default::default(),
1✔
695
            })]),
1✔
696
            plots: Some(vec![
1✔
697
                PlotUpdate::UpdateOrInsert(Plot {
1✔
698
                    workflow: plot_workflow_id,
1✔
699
                    name: "Test Plot".into(),
1✔
700
                }),
1✔
701
                PlotUpdate::UpdateOrInsert(Plot {
1✔
702
                    workflow: plot_workflow_id,
1✔
703
                    name: "Test Plot".into(),
1✔
704
                }),
1✔
705
            ]),
1✔
706
            bounds: None,
1✔
707
            time_step: None,
1✔
708
        };
1✔
709
        db.update_project(update).await.unwrap();
18✔
710

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

714
        // delete plots
715
        let update = UpdateProject {
1✔
716
            id: project.id,
1✔
717
            name: None,
1✔
718
            description: None,
1✔
719
            layers: None,
1✔
720
            plots: Some(vec![]),
1✔
721
            bounds: None,
1✔
722
            time_step: None,
1✔
723
        };
1✔
724
        db.update_project(update).await.unwrap();
14✔
725

726
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
727
        assert_eq!(versions.len(), 4);
1✔
728
    }
1✔
729

730
    async fn list_projects(
1✔
731
        app_ctx: &PostgresContext<NoTls>,
1✔
732
        session: &SimpleSession,
1✔
733
    ) -> Vec<ProjectListing> {
1✔
734
        let options = ProjectListOptions {
1✔
735
            filter: ProjectFilter::None,
1✔
736
            order: OrderBy::NameDesc,
1✔
737
            offset: 0,
1✔
738
            limit: 2,
1✔
739
        };
1✔
740

1✔
741
        let db = app_ctx.session_context(session.clone()).db();
1✔
742

743
        let projects = db.list_projects(options).await.unwrap();
11✔
744

1✔
745
        assert_eq!(projects.len(), 2);
1✔
746
        assert_eq!(projects[0].name, "Test9");
1✔
747
        assert_eq!(projects[1].name, "Test8");
1✔
748
        projects
1✔
749
    }
1✔
750

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

754
        for i in 0..10 {
11✔
755
            let create = CreateProject {
10✔
756
                name: format!("Test{i}"),
10✔
757
                description: format!("Test{}", 10 - i),
10✔
758
                bounds: STRectangle::new(
10✔
759
                    SpatialReferenceOption::Unreferenced,
10✔
760
                    0.,
10✔
761
                    0.,
10✔
762
                    1.,
10✔
763
                    1.,
10✔
764
                    0,
10✔
765
                    1,
10✔
766
                )
10✔
767
                .unwrap(),
10✔
768
                time_step: None,
10✔
769
            };
10✔
770
            db.create_project(create).await.unwrap();
74✔
771
        }
772
    }
1✔
773

774
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
775
    async fn it_persists_workflows() {
1✔
776
        with_temp_context(|app_ctx, _pg_config| async move {
1✔
777
            let workflow = Workflow {
1✔
778
                operator: TypedOperator::Vector(
1✔
779
                    MockPointSource {
1✔
780
                        params: MockPointSourceParams {
1✔
781
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
782
                        },
1✔
783
                    }
1✔
784
                    .boxed(),
1✔
785
                ),
1✔
786
            };
1✔
787

788
            let session = app_ctx.default_session().await.unwrap();
18✔
789
        let ctx = app_ctx.session_context(session);
1✔
790

1✔
791
            let db = ctx
1✔
792
                .db();
1✔
793
            let id = db
1✔
794
                .register_workflow(workflow)
1✔
795
                .await
3✔
796
                .unwrap();
1✔
797

1✔
798
            drop(ctx);
1✔
799

800
            let workflow = db.load_workflow(&id).await.unwrap();
3✔
801

1✔
802
            let json = serde_json::to_string(&workflow).unwrap();
1✔
803
            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✔
804
        })
1✔
805
        .await;
11✔
806
    }
807

808
    #[allow(clippy::too_many_lines)]
809
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
810
    async fn it_persists_datasets() {
1✔
811
        with_temp_context(|app_ctx, _| async move {
1✔
812
            let loading_info = OgrSourceDataset {
1✔
813
                file_name: PathBuf::from("test.csv"),
1✔
814
                layer_name: "test.csv".to_owned(),
1✔
815
                data_type: Some(VectorDataType::MultiPoint),
1✔
816
                time: OgrSourceDatasetTimeType::Start {
1✔
817
                    start_field: "start".to_owned(),
1✔
818
                    start_format: OgrSourceTimeFormat::Auto,
1✔
819
                    duration: OgrSourceDurationSpec::Zero,
1✔
820
                },
1✔
821
                default_geometry: None,
1✔
822
                columns: Some(OgrSourceColumnSpec {
1✔
823
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
824
                        header: CsvHeader::Auto,
1✔
825
                    }),
1✔
826
                    x: "x".to_owned(),
1✔
827
                    y: None,
1✔
828
                    int: vec![],
1✔
829
                    float: vec![],
1✔
830
                    text: vec![],
1✔
831
                    bool: vec![],
1✔
832
                    datetime: vec![],
1✔
833
                    rename: None,
1✔
834
                }),
1✔
835
                force_ogr_time_filter: false,
1✔
836
                force_ogr_spatial_filter: false,
1✔
837
                on_error: OgrSourceErrorSpec::Ignore,
1✔
838
                sql_query: None,
1✔
839
                attribute_query: None,
1✔
840
                cache_ttl: CacheTtlSeconds::default(),
1✔
841
            };
1✔
842

1✔
843
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
844
                OgrSourceDataset,
1✔
845
                VectorResultDescriptor,
1✔
846
                VectorQueryRectangle,
1✔
847
            > {
1✔
848
                loading_info: loading_info.clone(),
1✔
849
                result_descriptor: VectorResultDescriptor {
1✔
850
                    data_type: VectorDataType::MultiPoint,
1✔
851
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
852
                    columns: [(
1✔
853
                        "foo".to_owned(),
1✔
854
                        VectorColumnInfo {
1✔
855
                            data_type: FeatureDataType::Float,
1✔
856
                            measurement: Measurement::Unitless.into(),
1✔
857
                        },
1✔
858
                    )]
1✔
859
                    .into_iter()
1✔
860
                    .collect(),
1✔
861
                    time: None,
1✔
862
                    bbox: None,
1✔
863
                },
1✔
864
                phantom: Default::default(),
1✔
865
            });
1✔
866

867
            let session = app_ctx.default_session().await.unwrap();
18✔
868

1✔
869
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
870

1✔
871
            let db = app_ctx.session_context(session.clone()).db();
1✔
872
            let wrap = db.wrap_meta_data(meta_data);
1✔
873
            let DatasetIdAndName {
874
                id: dataset_id,
1✔
875
                name: dataset_name,
1✔
876
            } = db
1✔
877
                .add_dataset(
1✔
878
                    AddDataset {
1✔
879
                        name: Some(dataset_name.clone()),
1✔
880
                        display_name: "Ogr Test".to_owned(),
1✔
881
                        description: "desc".to_owned(),
1✔
882
                        source_operator: "OgrSource".to_owned(),
1✔
883
                        symbology: None,
1✔
884
                        provenance: Some(vec![Provenance {
1✔
885
                            citation: "citation".to_owned(),
1✔
886
                            license: "license".to_owned(),
1✔
887
                            uri: "uri".to_owned(),
1✔
888
                        }]),
1✔
889
                    },
1✔
890
                    wrap,
1✔
891
                )
1✔
892
                .await
151✔
893
                .unwrap();
1✔
894

895
            let datasets = db
1✔
896
                .list_datasets(DatasetListOptions {
1✔
897
                    filter: None,
1✔
898
                    order: crate::datasets::listing::OrderBy::NameAsc,
1✔
899
                    offset: 0,
1✔
900
                    limit: 10,
1✔
901
                })
1✔
902
                .await
3✔
903
                .unwrap();
1✔
904

1✔
905
            assert_eq!(datasets.len(), 1);
1✔
906

907
            assert_eq!(
1✔
908
                datasets[0],
1✔
909
                DatasetListing {
1✔
910
                    id: dataset_id,
1✔
911
                    name: dataset_name,
1✔
912
                    display_name: "Ogr Test".to_owned(),
1✔
913
                    description: "desc".to_owned(),
1✔
914
                    source_operator: "OgrSource".to_owned(),
1✔
915
                    symbology: None,
1✔
916
                    tags: vec![],
1✔
917
                    result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
918
                        data_type: VectorDataType::MultiPoint,
1✔
919
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
920
                        columns: [(
1✔
921
                            "foo".to_owned(),
1✔
922
                            VectorColumnInfo {
1✔
923
                                data_type: FeatureDataType::Float,
1✔
924
                                measurement: Measurement::Unitless.into()
1✔
925
                            }
1✔
926
                        )]
1✔
927
                        .into_iter()
1✔
928
                        .collect(),
1✔
929
                        time: None,
1✔
930
                        bbox: None,
1✔
931
                    })
1✔
932
                    .into(),
1✔
933
                },
1✔
934
            );
1✔
935

936
            let provenance = db.load_provenance(&dataset_id).await.unwrap();
3✔
937

1✔
938
            assert_eq!(
1✔
939
                provenance,
1✔
940
                ProvenanceOutput {
1✔
941
                    data: dataset_id.into(),
1✔
942
                    provenance: Some(vec![Provenance {
1✔
943
                        citation: "citation".to_owned(),
1✔
944
                        license: "license".to_owned(),
1✔
945
                        uri: "uri".to_owned(),
1✔
946
                    }])
1✔
947
                }
1✔
948
            );
1✔
949

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

953
            assert_eq!(
1✔
954
                meta_data
1✔
955
                    .loading_info(VectorQueryRectangle {
1✔
956
                        spatial_bounds: BoundingBox2D::new_unchecked(
1✔
957
                            (-180., -90.).into(),
1✔
958
                            (180., 90.).into()
1✔
959
                        ),
1✔
960
                        time_interval: TimeInterval::default(),
1✔
961
                        spatial_resolution: SpatialResolution::zero_point_one(),
1✔
962
                    })
1✔
963
                    .await
×
964
                    .unwrap(),
1✔
965
                loading_info
966
            );
967
        })
1✔
968
        .await;
12✔
969
    }
970

971
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
972
    async fn it_persists_uploads() {
1✔
973
        with_temp_context(|app_ctx, _| async move {
1✔
974
            let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
975
            let input = Upload {
1✔
976
                id,
1✔
977
                files: vec![FileUpload {
1✔
978
                    id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
979
                    name: "test.csv".to_owned(),
1✔
980
                    byte_size: 1337,
1✔
981
                }],
1✔
982
            };
1✔
983

984
            let session = app_ctx.default_session().await.unwrap();
18✔
985

1✔
986
            let db = app_ctx.session_context(session.clone()).db();
1✔
987

1✔
988
            db.create_upload(input.clone()).await.unwrap();
6✔
989

990
            let upload = db.load_upload(id).await.unwrap();
3✔
991

1✔
992
            assert_eq!(upload, input);
1✔
993
        })
1✔
994
        .await;
8✔
995
    }
996

997
    #[allow(clippy::too_many_lines)]
998
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
999
    async fn it_persists_layer_providers() {
1✔
1000
        with_temp_context(|app_ctx, _| async move {
1✔
1001
            let db = app_ctx.default_session_context().await.unwrap().db();
19✔
1002

1✔
1003
            let provider_id =
1✔
1004
                DataProviderId::from_str("7b20c8d7-d754-4f8f-ad44-dddd25df22d2").unwrap();
1✔
1005

1✔
1006
            let loading_info = OgrSourceDataset {
1✔
1007
                file_name: PathBuf::from("test.csv"),
1✔
1008
                layer_name: "test.csv".to_owned(),
1✔
1009
                data_type: Some(VectorDataType::MultiPoint),
1✔
1010
                time: OgrSourceDatasetTimeType::Start {
1✔
1011
                    start_field: "start".to_owned(),
1✔
1012
                    start_format: OgrSourceTimeFormat::Auto,
1✔
1013
                    duration: OgrSourceDurationSpec::Zero,
1✔
1014
                },
1✔
1015
                default_geometry: None,
1✔
1016
                columns: Some(OgrSourceColumnSpec {
1✔
1017
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1018
                        header: CsvHeader::Auto,
1✔
1019
                    }),
1✔
1020
                    x: "x".to_owned(),
1✔
1021
                    y: None,
1✔
1022
                    int: vec![],
1✔
1023
                    float: vec![],
1✔
1024
                    text: vec![],
1✔
1025
                    bool: vec![],
1✔
1026
                    datetime: vec![],
1✔
1027
                    rename: None,
1✔
1028
                }),
1✔
1029
                force_ogr_time_filter: false,
1✔
1030
                force_ogr_spatial_filter: false,
1✔
1031
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1032
                sql_query: None,
1✔
1033
                attribute_query: None,
1✔
1034
                cache_ttl: CacheTtlSeconds::default(),
1✔
1035
            };
1✔
1036

1✔
1037
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1038
                OgrSourceDataset,
1✔
1039
                VectorResultDescriptor,
1✔
1040
                VectorQueryRectangle,
1✔
1041
            > {
1✔
1042
                loading_info: loading_info.clone(),
1✔
1043
                result_descriptor: VectorResultDescriptor {
1✔
1044
                    data_type: VectorDataType::MultiPoint,
1✔
1045
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1046
                    columns: [(
1✔
1047
                        "foo".to_owned(),
1✔
1048
                        VectorColumnInfo {
1✔
1049
                            data_type: FeatureDataType::Float,
1✔
1050
                            measurement: Measurement::Unitless.into(),
1✔
1051
                        },
1✔
1052
                    )]
1✔
1053
                    .into_iter()
1✔
1054
                    .collect(),
1✔
1055
                    time: None,
1✔
1056
                    bbox: None,
1✔
1057
                },
1✔
1058
                phantom: Default::default(),
1✔
1059
            });
1✔
1060

1✔
1061
            let provider = MockExternalLayerProviderDefinition {
1✔
1062
                id: provider_id,
1✔
1063
                root_collection: MockCollection {
1✔
1064
                    id: LayerCollectionId("b5f82c7c-9133-4ac1-b4ae-8faac3b9a6df".to_owned()),
1✔
1065
                    name: "Mock Collection A".to_owned(),
1✔
1066
                    description: "Some description".to_owned(),
1✔
1067
                    collections: vec![MockCollection {
1✔
1068
                        id: LayerCollectionId("21466897-37a1-4666-913a-50b5244699ad".to_owned()),
1✔
1069
                        name: "Mock Collection B".to_owned(),
1✔
1070
                        description: "Some description".to_owned(),
1✔
1071
                        collections: vec![],
1✔
1072
                        layers: vec![],
1✔
1073
                    }],
1✔
1074
                    layers: vec![],
1✔
1075
                },
1✔
1076
                data: [("myData".to_owned(), meta_data)].into_iter().collect(),
1✔
1077
            };
1✔
1078

1✔
1079
            db.add_layer_provider(Box::new(provider)).await.unwrap();
3✔
1080

1081
            let providers = db
1✔
1082
                .list_layer_providers(LayerProviderListingOptions {
1✔
1083
                    offset: 0,
1✔
1084
                    limit: 10,
1✔
1085
                })
1✔
1086
                .await
3✔
1087
                .unwrap();
1✔
1088

1✔
1089
            assert_eq!(providers.len(), 1);
1✔
1090

1091
            assert_eq!(
1✔
1092
                providers[0],
1✔
1093
                LayerProviderListing {
1✔
1094
                    id: provider_id,
1✔
1095
                    name: "MockName".to_owned(),
1✔
1096
                    description: "MockType".to_owned(),
1✔
1097
                }
1✔
1098
            );
1✔
1099

1100
            let provider = db.load_layer_provider(provider_id).await.unwrap();
3✔
1101

1102
            let datasets = provider
1✔
1103
                .load_layer_collection(
1104
                    &provider.get_root_layer_collection_id().await.unwrap(),
1✔
1105
                    LayerCollectionListOptions {
1✔
1106
                        offset: 0,
1✔
1107
                        limit: 10,
1✔
1108
                    },
1✔
1109
                )
1110
                .await
×
1111
                .unwrap();
1✔
1112

1✔
1113
            assert_eq!(datasets.items.len(), 1);
1✔
1114
        })
1✔
1115
        .await;
9✔
1116
    }
1117

1118
    #[allow(clippy::too_many_lines)]
1119
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1120
    async fn it_loads_all_meta_data_types() {
1✔
1121
        with_temp_context(|app_ctx, _| async move {
1✔
1122
            let session = app_ctx.default_session().await.unwrap();
18✔
1123

1✔
1124
            let db = app_ctx.session_context(session.clone()).db();
1✔
1125

1✔
1126
            let vector_descriptor = VectorResultDescriptor {
1✔
1127
                data_type: VectorDataType::Data,
1✔
1128
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1129
                columns: Default::default(),
1✔
1130
                time: None,
1✔
1131
                bbox: None,
1✔
1132
            };
1✔
1133

1✔
1134
            let raster_descriptor = RasterResultDescriptor {
1✔
1135
                data_type: RasterDataType::U8,
1✔
1136
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1137
                measurement: Default::default(),
1✔
1138
                time: None,
1✔
1139
                bbox: None,
1✔
1140
                resolution: None,
1✔
1141
            };
1✔
1142

1✔
1143
            let vector_ds = AddDataset {
1✔
1144
                name: None,
1✔
1145
                display_name: "OgrDataset".to_string(),
1✔
1146
                description: "My Ogr dataset".to_string(),
1✔
1147
                source_operator: "OgrSource".to_string(),
1✔
1148
                symbology: None,
1✔
1149
                provenance: None,
1✔
1150
            };
1✔
1151

1✔
1152
            let raster_ds = AddDataset {
1✔
1153
                name: None,
1✔
1154
                display_name: "GdalDataset".to_string(),
1✔
1155
                description: "My Gdal dataset".to_string(),
1✔
1156
                source_operator: "GdalSource".to_string(),
1✔
1157
                symbology: None,
1✔
1158
                provenance: None,
1✔
1159
            };
1✔
1160

1✔
1161
            let gdal_params = GdalDatasetParameters {
1✔
1162
                file_path: Default::default(),
1✔
1163
                rasterband_channel: 0,
1✔
1164
                geo_transform: GdalDatasetGeoTransform {
1✔
1165
                    origin_coordinate: Default::default(),
1✔
1166
                    x_pixel_size: 0.0,
1✔
1167
                    y_pixel_size: 0.0,
1✔
1168
                },
1✔
1169
                width: 0,
1✔
1170
                height: 0,
1✔
1171
                file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1172
                no_data_value: None,
1✔
1173
                properties_mapping: None,
1✔
1174
                gdal_open_options: None,
1✔
1175
                gdal_config_options: None,
1✔
1176
                allow_alphaband_as_mask: false,
1✔
1177
                retry: None,
1✔
1178
            };
1✔
1179

1✔
1180
            let meta = StaticMetaData {
1✔
1181
                loading_info: OgrSourceDataset {
1✔
1182
                    file_name: Default::default(),
1✔
1183
                    layer_name: String::new(),
1✔
1184
                    data_type: None,
1✔
1185
                    time: Default::default(),
1✔
1186
                    default_geometry: None,
1✔
1187
                    columns: None,
1✔
1188
                    force_ogr_time_filter: false,
1✔
1189
                    force_ogr_spatial_filter: false,
1✔
1190
                    on_error: OgrSourceErrorSpec::Ignore,
1✔
1191
                    sql_query: None,
1✔
1192
                    attribute_query: None,
1✔
1193
                    cache_ttl: CacheTtlSeconds::default(),
1✔
1194
                },
1✔
1195
                result_descriptor: vector_descriptor.clone(),
1✔
1196
                phantom: Default::default(),
1✔
1197
            };
1✔
1198

1✔
1199
            let meta = db.wrap_meta_data(MetaDataDefinition::OgrMetaData(meta));
1✔
1200

1201
            let id = db.add_dataset(vector_ds, meta).await.unwrap().id;
153✔
1202

1203
            let meta: geoengine_operators::util::Result<
1✔
1204
                Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1205
            > = db.meta_data(&id.into()).await;
3✔
1206

1207
            assert!(meta.is_ok());
1✔
1208

1209
            let meta = GdalMetaDataRegular {
1✔
1210
                result_descriptor: raster_descriptor.clone(),
1✔
1211
                params: gdal_params.clone(),
1✔
1212
                time_placeholders: Default::default(),
1✔
1213
                data_time: Default::default(),
1✔
1214
                step: TimeStep {
1✔
1215
                    granularity: TimeGranularity::Millis,
1✔
1216
                    step: 0,
1✔
1217
                },
1✔
1218
                cache_ttl: CacheTtlSeconds::default(),
1✔
1219
            };
1✔
1220

1✔
1221
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataRegular(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 = GdalMetaDataStatic {
1✔
1232
                time: None,
1✔
1233
                params: gdal_params.clone(),
1✔
1234
                result_descriptor: raster_descriptor.clone(),
1✔
1235
                cache_ttl: CacheTtlSeconds::default(),
1✔
1236
            };
1✔
1237

1✔
1238
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalStatic(meta));
1✔
1239

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

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

1246
            assert!(meta.is_ok());
1✔
1247

1248
            let meta = GdalMetaDataList {
1✔
1249
                result_descriptor: raster_descriptor.clone(),
1✔
1250
                params: vec![],
1✔
1251
            };
1✔
1252

1✔
1253
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetaDataList(meta));
1✔
1254

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

1257
            let meta: geoengine_operators::util::Result<
1✔
1258
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1259
            > = db.meta_data(&id.into()).await;
4✔
1260

1261
            assert!(meta.is_ok());
1✔
1262

1263
            let meta = GdalMetadataNetCdfCf {
1✔
1264
                result_descriptor: raster_descriptor.clone(),
1✔
1265
                params: gdal_params.clone(),
1✔
1266
                start: TimeInstance::MIN,
1✔
1267
                end: TimeInstance::MAX,
1✔
1268
                step: TimeStep {
1✔
1269
                    granularity: TimeGranularity::Millis,
1✔
1270
                    step: 0,
1✔
1271
                },
1✔
1272
                band_offset: 0,
1✔
1273
                cache_ttl: CacheTtlSeconds::default(),
1✔
1274
            };
1✔
1275

1✔
1276
            let meta = db.wrap_meta_data(MetaDataDefinition::GdalMetadataNetCdfCf(meta));
1✔
1277

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

1280
            let meta: geoengine_operators::util::Result<
1✔
1281
                Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1282
            > = db.meta_data(&id.into()).await;
3✔
1283

1284
            assert!(meta.is_ok());
1✔
1285
        })
1✔
1286
        .await;
11✔
1287
    }
1288

1289
    #[allow(clippy::too_many_lines)]
1290
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1291
    async fn it_collects_layers() {
1✔
1292
        with_temp_context(|app_ctx, _| async move {
1✔
1293
            let session = app_ctx.default_session().await.unwrap();
18✔
1294

1✔
1295
            let layer_db = app_ctx.session_context(session).db();
1✔
1296

1✔
1297
            let workflow = Workflow {
1✔
1298
                operator: TypedOperator::Vector(
1✔
1299
                    MockPointSource {
1✔
1300
                        params: MockPointSourceParams {
1✔
1301
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1302
                        },
1✔
1303
                    }
1✔
1304
                    .boxed(),
1✔
1305
                ),
1✔
1306
            };
1✔
1307

1308
            let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1309

1310
            let layer1 = layer_db
1✔
1311
                .add_layer(
1✔
1312
                    AddLayer {
1✔
1313
                        name: "Layer1".to_string(),
1✔
1314
                        description: "Layer 1".to_string(),
1✔
1315
                        symbology: None,
1✔
1316
                        workflow: workflow.clone(),
1✔
1317
                        metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1318
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1319
                    },
1✔
1320
                    &root_collection_id,
1✔
1321
                )
1✔
1322
                .await
44✔
1323
                .unwrap();
1✔
1324

1325
            assert_eq!(
1✔
1326
                layer_db.load_layer(&layer1).await.unwrap(),
3✔
1327
                crate::layers::layer::Layer {
1✔
1328
                    id: ProviderLayerId {
1✔
1329
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1330
                        layer_id: layer1.clone(),
1✔
1331
                    },
1✔
1332
                    name: "Layer1".to_string(),
1✔
1333
                    description: "Layer 1".to_string(),
1✔
1334
                    symbology: None,
1✔
1335
                    workflow: workflow.clone(),
1✔
1336
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1337
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1338
                }
1✔
1339
            );
1340

1341
            let collection1_id = layer_db
1✔
1342
                .add_layer_collection(
1✔
1343
                    AddLayerCollection {
1✔
1344
                        name: "Collection1".to_string(),
1✔
1345
                        description: "Collection 1".to_string(),
1✔
1346
                        properties: Default::default(),
1✔
1347
                    },
1✔
1348
                    &root_collection_id,
1✔
1349
                )
1✔
1350
                .await
7✔
1351
                .unwrap();
1✔
1352

1353
            let layer2 = layer_db
1✔
1354
                .add_layer(
1✔
1355
                    AddLayer {
1✔
1356
                        name: "Layer2".to_string(),
1✔
1357
                        description: "Layer 2".to_string(),
1✔
1358
                        symbology: None,
1✔
1359
                        workflow: workflow.clone(),
1✔
1360
                        metadata: Default::default(),
1✔
1361
                        properties: Default::default(),
1✔
1362
                    },
1✔
1363
                    &collection1_id,
1✔
1364
                )
1✔
1365
                .await
9✔
1366
                .unwrap();
1✔
1367

1368
            let collection2_id = layer_db
1✔
1369
                .add_layer_collection(
1✔
1370
                    AddLayerCollection {
1✔
1371
                        name: "Collection2".to_string(),
1✔
1372
                        description: "Collection 2".to_string(),
1✔
1373
                        properties: Default::default(),
1✔
1374
                    },
1✔
1375
                    &collection1_id,
1✔
1376
                )
1✔
1377
                .await
7✔
1378
                .unwrap();
1✔
1379

1✔
1380
            layer_db
1✔
1381
                .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1382
                .await
3✔
1383
                .unwrap();
1✔
1384

1385
            let root_collection = layer_db
1✔
1386
                .load_layer_collection(
1✔
1387
                    &root_collection_id,
1✔
1388
                    LayerCollectionListOptions {
1✔
1389
                        offset: 0,
1✔
1390
                        limit: 20,
1✔
1391
                    },
1✔
1392
                )
1✔
1393
                .await
5✔
1394
                .unwrap();
1✔
1395

1✔
1396
            assert_eq!(
1✔
1397
                root_collection,
1✔
1398
                LayerCollection {
1✔
1399
                    id: ProviderLayerCollectionId {
1✔
1400
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1401
                        collection_id: root_collection_id,
1✔
1402
                    },
1✔
1403
                    name: "Layers".to_string(),
1✔
1404
                    description: "All available Geo Engine layers".to_string(),
1✔
1405
                    items: vec![
1✔
1406
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1407
                            id: ProviderLayerCollectionId {
1✔
1408
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1409
                                collection_id: collection1_id.clone(),
1✔
1410
                            },
1✔
1411
                            name: "Collection1".to_string(),
1✔
1412
                            description: "Collection 1".to_string(),
1✔
1413
                            properties: Default::default(),
1✔
1414
                        }),
1✔
1415
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1416
                            id: ProviderLayerCollectionId {
1✔
1417
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1418
                                collection_id: LayerCollectionId(
1✔
1419
                                    UNSORTED_COLLECTION_ID.to_string()
1✔
1420
                                ),
1✔
1421
                            },
1✔
1422
                            name: "Unsorted".to_string(),
1✔
1423
                            description: "Unsorted Layers".to_string(),
1✔
1424
                            properties: Default::default(),
1✔
1425
                        }),
1✔
1426
                        CollectionItem::Layer(LayerListing {
1✔
1427
                            id: ProviderLayerId {
1✔
1428
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1429
                                layer_id: layer1,
1✔
1430
                            },
1✔
1431
                            name: "Layer1".to_string(),
1✔
1432
                            description: "Layer 1".to_string(),
1✔
1433
                            properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1434
                        })
1✔
1435
                    ],
1✔
1436
                    entry_label: None,
1✔
1437
                    properties: vec![],
1✔
1438
                }
1✔
1439
            );
1✔
1440

1441
            let collection1 = layer_db
1✔
1442
                .load_layer_collection(
1✔
1443
                    &collection1_id,
1✔
1444
                    LayerCollectionListOptions {
1✔
1445
                        offset: 0,
1✔
1446
                        limit: 20,
1✔
1447
                    },
1✔
1448
                )
1✔
1449
                .await
5✔
1450
                .unwrap();
1✔
1451

1✔
1452
            assert_eq!(
1✔
1453
                collection1,
1✔
1454
                LayerCollection {
1✔
1455
                    id: ProviderLayerCollectionId {
1✔
1456
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1457
                        collection_id: collection1_id,
1✔
1458
                    },
1✔
1459
                    name: "Collection1".to_string(),
1✔
1460
                    description: "Collection 1".to_string(),
1✔
1461
                    items: vec![
1✔
1462
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1463
                            id: ProviderLayerCollectionId {
1✔
1464
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1465
                                collection_id: collection2_id,
1✔
1466
                            },
1✔
1467
                            name: "Collection2".to_string(),
1✔
1468
                            description: "Collection 2".to_string(),
1✔
1469
                            properties: Default::default(),
1✔
1470
                        }),
1✔
1471
                        CollectionItem::Layer(LayerListing {
1✔
1472
                            id: ProviderLayerId {
1✔
1473
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1474
                                layer_id: layer2,
1✔
1475
                            },
1✔
1476
                            name: "Layer2".to_string(),
1✔
1477
                            description: "Layer 2".to_string(),
1✔
1478
                            properties: vec![],
1✔
1479
                        })
1✔
1480
                    ],
1✔
1481
                    entry_label: None,
1✔
1482
                    properties: vec![],
1✔
1483
                }
1✔
1484
            );
1✔
1485
        })
1✔
1486
        .await;
9✔
1487
    }
1488

1489
    #[allow(clippy::too_many_lines)]
1490
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1491
    async fn it_removes_layer_collections() {
1✔
1492
        with_temp_context(|app_ctx, _| async move {
1✔
1493
            let session = app_ctx.default_session().await.unwrap();
18✔
1494

1✔
1495
            let layer_db = app_ctx.session_context(session).db();
1✔
1496

1✔
1497
            let layer = AddLayer {
1✔
1498
                name: "layer".to_string(),
1✔
1499
                description: "description".to_string(),
1✔
1500
                workflow: Workflow {
1✔
1501
                    operator: TypedOperator::Vector(
1✔
1502
                        MockPointSource {
1✔
1503
                            params: MockPointSourceParams {
1✔
1504
                                points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1505
                            },
1✔
1506
                        }
1✔
1507
                        .boxed(),
1✔
1508
                    ),
1✔
1509
                },
1✔
1510
                symbology: None,
1✔
1511
                metadata: Default::default(),
1✔
1512
                properties: Default::default(),
1✔
1513
            };
1✔
1514

1515
            let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1516

1✔
1517
            let collection = AddLayerCollection {
1✔
1518
                name: "top collection".to_string(),
1✔
1519
                description: "description".to_string(),
1✔
1520
                properties: Default::default(),
1✔
1521
            };
1✔
1522

1523
            let top_c_id = layer_db
1✔
1524
                .add_layer_collection(collection, root_collection)
1✔
1525
                .await
10✔
1526
                .unwrap();
1✔
1527

1528
            let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
41✔
1529

1✔
1530
            let collection = AddLayerCollection {
1✔
1531
                name: "empty collection".to_string(),
1✔
1532
                description: "description".to_string(),
1✔
1533
                properties: Default::default(),
1✔
1534
            };
1✔
1535

1536
            let empty_c_id = layer_db
1✔
1537
                .add_layer_collection(collection, &top_c_id)
1✔
1538
                .await
7✔
1539
                .unwrap();
1✔
1540

1541
            let items = layer_db
1✔
1542
                .load_layer_collection(
1✔
1543
                    &top_c_id,
1✔
1544
                    LayerCollectionListOptions {
1✔
1545
                        offset: 0,
1✔
1546
                        limit: 20,
1✔
1547
                    },
1✔
1548
                )
1✔
1549
                .await
5✔
1550
                .unwrap();
1✔
1551

1✔
1552
            assert_eq!(
1✔
1553
                items,
1✔
1554
                LayerCollection {
1✔
1555
                    id: ProviderLayerCollectionId {
1✔
1556
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1557
                        collection_id: top_c_id.clone(),
1✔
1558
                    },
1✔
1559
                    name: "top collection".to_string(),
1✔
1560
                    description: "description".to_string(),
1✔
1561
                    items: vec![
1✔
1562
                        CollectionItem::Collection(LayerCollectionListing {
1✔
1563
                            id: ProviderLayerCollectionId {
1✔
1564
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1565
                                collection_id: empty_c_id.clone(),
1✔
1566
                            },
1✔
1567
                            name: "empty collection".to_string(),
1✔
1568
                            description: "description".to_string(),
1✔
1569
                            properties: Default::default(),
1✔
1570
                        }),
1✔
1571
                        CollectionItem::Layer(LayerListing {
1✔
1572
                            id: ProviderLayerId {
1✔
1573
                                provider_id: INTERNAL_PROVIDER_ID,
1✔
1574
                                layer_id: l_id.clone(),
1✔
1575
                            },
1✔
1576
                            name: "layer".to_string(),
1✔
1577
                            description: "description".to_string(),
1✔
1578
                            properties: vec![],
1✔
1579
                        })
1✔
1580
                    ],
1✔
1581
                    entry_label: None,
1✔
1582
                    properties: vec![],
1✔
1583
                }
1✔
1584
            );
1✔
1585

1586
            // remove empty collection
1587
            layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
9✔
1588

1589
            let items = layer_db
1✔
1590
                .load_layer_collection(
1✔
1591
                    &top_c_id,
1✔
1592
                    LayerCollectionListOptions {
1✔
1593
                        offset: 0,
1✔
1594
                        limit: 20,
1✔
1595
                    },
1✔
1596
                )
1✔
1597
                .await
5✔
1598
                .unwrap();
1✔
1599

1✔
1600
            assert_eq!(
1✔
1601
                items,
1✔
1602
                LayerCollection {
1✔
1603
                    id: ProviderLayerCollectionId {
1✔
1604
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1605
                        collection_id: top_c_id.clone(),
1✔
1606
                    },
1✔
1607
                    name: "top collection".to_string(),
1✔
1608
                    description: "description".to_string(),
1✔
1609
                    items: vec![CollectionItem::Layer(LayerListing {
1✔
1610
                        id: ProviderLayerId {
1✔
1611
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1612
                            layer_id: l_id.clone(),
1✔
1613
                        },
1✔
1614
                        name: "layer".to_string(),
1✔
1615
                        description: "description".to_string(),
1✔
1616
                        properties: vec![],
1✔
1617
                    })],
1✔
1618
                    entry_label: None,
1✔
1619
                    properties: vec![],
1✔
1620
                }
1✔
1621
            );
1✔
1622

1623
            // remove top (not root) collection
1624
            layer_db.remove_layer_collection(&top_c_id).await.unwrap();
9✔
1625

1✔
1626
            layer_db
1✔
1627
                .load_layer_collection(
1✔
1628
                    &top_c_id,
1✔
1629
                    LayerCollectionListOptions {
1✔
1630
                        offset: 0,
1✔
1631
                        limit: 20,
1✔
1632
                    },
1✔
1633
                )
1✔
1634
                .await
3✔
1635
                .unwrap_err();
1✔
1636

1✔
1637
            // should be deleted automatically
1✔
1638
            layer_db.load_layer(&l_id).await.unwrap_err();
3✔
1639

1✔
1640
            // it is not allowed to remove the root collection
1✔
1641
            layer_db
1✔
1642
                .remove_layer_collection(root_collection)
1✔
1643
                .await
×
1644
                .unwrap_err();
1✔
1645
            layer_db
1✔
1646
                .load_layer_collection(
1✔
1647
                    root_collection,
1✔
1648
                    LayerCollectionListOptions {
1✔
1649
                        offset: 0,
1✔
1650
                        limit: 20,
1✔
1651
                    },
1✔
1652
                )
1✔
1653
                .await
5✔
1654
                .unwrap();
1✔
1655
        })
1✔
1656
        .await;
12✔
1657
    }
1658

1659
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1660
    #[allow(clippy::too_many_lines)]
1661
    async fn it_removes_collections_from_collections() {
1✔
1662
        with_temp_context(|app_ctx, _| async move {
1✔
1663
            let session = app_ctx.default_session().await.unwrap();
18✔
1664

1✔
1665
            let db = app_ctx.session_context(session).db();
1✔
1666

1667
            let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
1668

1669
            let mid_collection_id = db
1✔
1670
                .add_layer_collection(
1✔
1671
                    AddLayerCollection {
1✔
1672
                        name: "mid collection".to_string(),
1✔
1673
                        description: "description".to_string(),
1✔
1674
                        properties: Default::default(),
1✔
1675
                    },
1✔
1676
                    root_collection_id,
1✔
1677
                )
1✔
1678
                .await
10✔
1679
                .unwrap();
1✔
1680

1681
            let bottom_collection_id = db
1✔
1682
                .add_layer_collection(
1✔
1683
                    AddLayerCollection {
1✔
1684
                        name: "bottom collection".to_string(),
1✔
1685
                        description: "description".to_string(),
1✔
1686
                        properties: Default::default(),
1✔
1687
                    },
1✔
1688
                    &mid_collection_id,
1✔
1689
                )
1✔
1690
                .await
7✔
1691
                .unwrap();
1✔
1692

1693
            let layer_id = db
1✔
1694
                .add_layer(
1✔
1695
                    AddLayer {
1✔
1696
                        name: "layer".to_string(),
1✔
1697
                        description: "description".to_string(),
1✔
1698
                        workflow: Workflow {
1✔
1699
                            operator: TypedOperator::Vector(
1✔
1700
                                MockPointSource {
1✔
1701
                                    params: MockPointSourceParams {
1✔
1702
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1703
                                    },
1✔
1704
                                }
1✔
1705
                                .boxed(),
1✔
1706
                            ),
1✔
1707
                        },
1✔
1708
                        symbology: None,
1✔
1709
                        metadata: Default::default(),
1✔
1710
                        properties: Default::default(),
1✔
1711
                    },
1✔
1712
                    &mid_collection_id,
1✔
1713
                )
1✔
1714
                .await
41✔
1715
                .unwrap();
1✔
1716

1✔
1717
            // removing the mid collection…
1✔
1718
            db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
1719
                .await
11✔
1720
                .unwrap();
1✔
1721

1✔
1722
            // …should remove itself
1✔
1723
            db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
1724
                .await
3✔
1725
                .unwrap_err();
1✔
1726

1✔
1727
            // …should remove the bottom collection
1✔
1728
            db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
1729
                .await
3✔
1730
                .unwrap_err();
1✔
1731

1✔
1732
            // … and should remove the layer of the bottom collection
1✔
1733
            db.load_layer(&layer_id).await.unwrap_err();
3✔
1734

1✔
1735
            // the root collection is still there
1✔
1736
            db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
1737
                .await
5✔
1738
                .unwrap();
1✔
1739
        })
1✔
1740
        .await;
11✔
1741
    }
1742

1743
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1744
    #[allow(clippy::too_many_lines)]
1745
    async fn it_removes_layers_from_collections() {
1✔
1746
        with_temp_context(|app_ctx, _| async move {
1✔
1747
            let session = app_ctx.default_session().await.unwrap();
18✔
1748

1✔
1749
            let db = app_ctx.session_context(session).db();
1✔
1750

1751
            let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
1752

1753
            let another_collection = db
1✔
1754
                .add_layer_collection(
1✔
1755
                    AddLayerCollection {
1✔
1756
                        name: "top collection".to_string(),
1✔
1757
                        description: "description".to_string(),
1✔
1758
                        properties: Default::default(),
1✔
1759
                    },
1✔
1760
                    root_collection,
1✔
1761
                )
1✔
1762
                .await
10✔
1763
                .unwrap();
1✔
1764

1765
            let layer_in_one_collection = db
1✔
1766
                .add_layer(
1✔
1767
                    AddLayer {
1✔
1768
                        name: "layer 1".to_string(),
1✔
1769
                        description: "description".to_string(),
1✔
1770
                        workflow: Workflow {
1✔
1771
                            operator: TypedOperator::Vector(
1✔
1772
                                MockPointSource {
1✔
1773
                                    params: MockPointSourceParams {
1✔
1774
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1775
                                    },
1✔
1776
                                }
1✔
1777
                                .boxed(),
1✔
1778
                            ),
1✔
1779
                        },
1✔
1780
                        symbology: None,
1✔
1781
                        metadata: Default::default(),
1✔
1782
                        properties: Default::default(),
1✔
1783
                    },
1✔
1784
                    &another_collection,
1✔
1785
                )
1✔
1786
                .await
40✔
1787
                .unwrap();
1✔
1788

1789
            let layer_in_two_collections = db
1✔
1790
                .add_layer(
1✔
1791
                    AddLayer {
1✔
1792
                        name: "layer 2".to_string(),
1✔
1793
                        description: "description".to_string(),
1✔
1794
                        workflow: Workflow {
1✔
1795
                            operator: TypedOperator::Vector(
1✔
1796
                                MockPointSource {
1✔
1797
                                    params: MockPointSourceParams {
1✔
1798
                                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1799
                                    },
1✔
1800
                                }
1✔
1801
                                .boxed(),
1✔
1802
                            ),
1✔
1803
                        },
1✔
1804
                        symbology: None,
1✔
1805
                        metadata: Default::default(),
1✔
1806
                        properties: Default::default(),
1✔
1807
                    },
1✔
1808
                    &another_collection,
1✔
1809
                )
1✔
1810
                .await
9✔
1811
                .unwrap();
1✔
1812

1✔
1813
            db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
1814
                .await
3✔
1815
                .unwrap();
1✔
1816

1✔
1817
            // remove first layer --> should be deleted entirely
1✔
1818

1✔
1819
            db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
1820
                .await
7✔
1821
                .unwrap();
1✔
1822

1823
            let number_of_layer_in_collection = db
1✔
1824
                .load_layer_collection(
1✔
1825
                    &another_collection,
1✔
1826
                    LayerCollectionListOptions {
1✔
1827
                        offset: 0,
1✔
1828
                        limit: 20,
1✔
1829
                    },
1✔
1830
                )
1✔
1831
                .await
5✔
1832
                .unwrap()
1✔
1833
                .items
1✔
1834
                .len();
1✔
1835
            assert_eq!(
1✔
1836
                number_of_layer_in_collection,
1✔
1837
                1 /* only the other collection should be here */
1✔
1838
            );
1✔
1839

1840
            db.load_layer(&layer_in_one_collection).await.unwrap_err();
3✔
1841

1✔
1842
            // remove second layer --> should only be gone in collection
1✔
1843

1✔
1844
            db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
1845
                .await
7✔
1846
                .unwrap();
1✔
1847

1848
            let number_of_layer_in_collection = db
1✔
1849
                .load_layer_collection(
1✔
1850
                    &another_collection,
1✔
1851
                    LayerCollectionListOptions {
1✔
1852
                        offset: 0,
1✔
1853
                        limit: 20,
1✔
1854
                    },
1✔
1855
                )
1✔
1856
                .await
5✔
1857
                .unwrap()
1✔
1858
                .items
1✔
1859
                .len();
1✔
1860
            assert_eq!(
1✔
1861
                number_of_layer_in_collection,
1✔
1862
                0 /* both layers were deleted */
1✔
1863
            );
1✔
1864

1865
            db.load_layer(&layer_in_two_collections).await.unwrap();
3✔
1866
        })
1✔
1867
        .await;
11✔
1868
    }
1869

1870
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1871
    #[allow(clippy::too_many_lines)]
1872
    async fn it_deletes_dataset() {
1✔
1873
        with_temp_context(|app_ctx, _| async move {
1✔
1874
            let loading_info = OgrSourceDataset {
1✔
1875
                file_name: PathBuf::from("test.csv"),
1✔
1876
                layer_name: "test.csv".to_owned(),
1✔
1877
                data_type: Some(VectorDataType::MultiPoint),
1✔
1878
                time: OgrSourceDatasetTimeType::Start {
1✔
1879
                    start_field: "start".to_owned(),
1✔
1880
                    start_format: OgrSourceTimeFormat::Auto,
1✔
1881
                    duration: OgrSourceDurationSpec::Zero,
1✔
1882
                },
1✔
1883
                default_geometry: None,
1✔
1884
                columns: Some(OgrSourceColumnSpec {
1✔
1885
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1886
                        header: CsvHeader::Auto,
1✔
1887
                    }),
1✔
1888
                    x: "x".to_owned(),
1✔
1889
                    y: None,
1✔
1890
                    int: vec![],
1✔
1891
                    float: vec![],
1✔
1892
                    text: vec![],
1✔
1893
                    bool: vec![],
1✔
1894
                    datetime: vec![],
1✔
1895
                    rename: None,
1✔
1896
                }),
1✔
1897
                force_ogr_time_filter: false,
1✔
1898
                force_ogr_spatial_filter: false,
1✔
1899
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1900
                sql_query: None,
1✔
1901
                attribute_query: None,
1✔
1902
                cache_ttl: CacheTtlSeconds::default(),
1✔
1903
            };
1✔
1904

1✔
1905
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
1906
                OgrSourceDataset,
1✔
1907
                VectorResultDescriptor,
1✔
1908
                VectorQueryRectangle,
1✔
1909
            > {
1✔
1910
                loading_info: loading_info.clone(),
1✔
1911
                result_descriptor: VectorResultDescriptor {
1✔
1912
                    data_type: VectorDataType::MultiPoint,
1✔
1913
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
1914
                    columns: [(
1✔
1915
                        "foo".to_owned(),
1✔
1916
                        VectorColumnInfo {
1✔
1917
                            data_type: FeatureDataType::Float,
1✔
1918
                            measurement: Measurement::Unitless.into(),
1✔
1919
                        },
1✔
1920
                    )]
1✔
1921
                    .into_iter()
1✔
1922
                    .collect(),
1✔
1923
                    time: None,
1✔
1924
                    bbox: None,
1✔
1925
                },
1✔
1926
                phantom: Default::default(),
1✔
1927
            });
1✔
1928

1929
            let session = app_ctx.default_session().await.unwrap();
18✔
1930

1✔
1931
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1932

1✔
1933
            let db = app_ctx.session_context(session.clone()).db();
1✔
1934
            let wrap = db.wrap_meta_data(meta_data);
1✔
1935
            let dataset_id = db
1✔
1936
                .add_dataset(
1✔
1937
                    AddDataset {
1✔
1938
                        name: Some(dataset_name),
1✔
1939
                        display_name: "Ogr Test".to_owned(),
1✔
1940
                        description: "desc".to_owned(),
1✔
1941
                        source_operator: "OgrSource".to_owned(),
1✔
1942
                        symbology: None,
1✔
1943
                        provenance: Some(vec![Provenance {
1✔
1944
                            citation: "citation".to_owned(),
1✔
1945
                            license: "license".to_owned(),
1✔
1946
                            uri: "uri".to_owned(),
1✔
1947
                        }]),
1✔
1948
                    },
1✔
1949
                    wrap,
1✔
1950
                )
1✔
1951
                .await
153✔
1952
                .unwrap()
1✔
1953
                .id;
1954

1955
            assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
1956

1957
            db.delete_dataset(dataset_id).await.unwrap();
3✔
1958

1959
            assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
1960
        })
1✔
1961
        .await;
11✔
1962
    }
1963

1964
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
1965
    #[allow(clippy::too_many_lines)]
1966
    async fn it_deletes_admin_dataset() {
1✔
1967
        with_temp_context(|app_ctx, _| async move {
1✔
1968
            let dataset_name = DatasetName::new(None, "my_dataset");
1✔
1969

1✔
1970
            let loading_info = OgrSourceDataset {
1✔
1971
                file_name: PathBuf::from("test.csv"),
1✔
1972
                layer_name: "test.csv".to_owned(),
1✔
1973
                data_type: Some(VectorDataType::MultiPoint),
1✔
1974
                time: OgrSourceDatasetTimeType::Start {
1✔
1975
                    start_field: "start".to_owned(),
1✔
1976
                    start_format: OgrSourceTimeFormat::Auto,
1✔
1977
                    duration: OgrSourceDurationSpec::Zero,
1✔
1978
                },
1✔
1979
                default_geometry: None,
1✔
1980
                columns: Some(OgrSourceColumnSpec {
1✔
1981
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
1982
                        header: CsvHeader::Auto,
1✔
1983
                    }),
1✔
1984
                    x: "x".to_owned(),
1✔
1985
                    y: None,
1✔
1986
                    int: vec![],
1✔
1987
                    float: vec![],
1✔
1988
                    text: vec![],
1✔
1989
                    bool: vec![],
1✔
1990
                    datetime: vec![],
1✔
1991
                    rename: None,
1✔
1992
                }),
1✔
1993
                force_ogr_time_filter: false,
1✔
1994
                force_ogr_spatial_filter: false,
1✔
1995
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1996
                sql_query: None,
1✔
1997
                attribute_query: None,
1✔
1998
                cache_ttl: CacheTtlSeconds::default(),
1✔
1999
            };
1✔
2000

1✔
2001
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2002
                OgrSourceDataset,
1✔
2003
                VectorResultDescriptor,
1✔
2004
                VectorQueryRectangle,
1✔
2005
            > {
1✔
2006
                loading_info: loading_info.clone(),
1✔
2007
                result_descriptor: VectorResultDescriptor {
1✔
2008
                    data_type: VectorDataType::MultiPoint,
1✔
2009
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2010
                    columns: [(
1✔
2011
                        "foo".to_owned(),
1✔
2012
                        VectorColumnInfo {
1✔
2013
                            data_type: FeatureDataType::Float,
1✔
2014
                            measurement: Measurement::Unitless.into(),
1✔
2015
                        },
1✔
2016
                    )]
1✔
2017
                    .into_iter()
1✔
2018
                    .collect(),
1✔
2019
                    time: None,
1✔
2020
                    bbox: None,
1✔
2021
                },
1✔
2022
                phantom: Default::default(),
1✔
2023
            });
1✔
2024

2025
            let session = app_ctx.default_session().await.unwrap();
18✔
2026

1✔
2027
            let db = app_ctx.session_context(session).db();
1✔
2028
            let wrap = db.wrap_meta_data(meta_data);
1✔
2029
            let dataset_id = db
1✔
2030
                .add_dataset(
1✔
2031
                    AddDataset {
1✔
2032
                        name: Some(dataset_name),
1✔
2033
                        display_name: "Ogr Test".to_owned(),
1✔
2034
                        description: "desc".to_owned(),
1✔
2035
                        source_operator: "OgrSource".to_owned(),
1✔
2036
                        symbology: None,
1✔
2037
                        provenance: Some(vec![Provenance {
1✔
2038
                            citation: "citation".to_owned(),
1✔
2039
                            license: "license".to_owned(),
1✔
2040
                            uri: "uri".to_owned(),
1✔
2041
                        }]),
1✔
2042
                    },
1✔
2043
                    wrap,
1✔
2044
                )
1✔
2045
                .await
153✔
2046
                .unwrap()
1✔
2047
                .id;
2048

2049
            assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
2050

2051
            db.delete_dataset(dataset_id).await.unwrap();
3✔
2052

2053
            assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2054
        })
1✔
2055
        .await;
12✔
2056
    }
2057

2058
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2059
    async fn test_missing_layer_dataset_in_collection_listing() {
1✔
2060
        with_temp_context(|app_ctx, _| async move {
1✔
2061
            let session = app_ctx.default_session().await.unwrap();
18✔
2062
            let db = app_ctx.session_context(session).db();
1✔
2063

2064
            let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2065

2066
            let top_collection_id = db
1✔
2067
                .add_layer_collection(
1✔
2068
                    AddLayerCollection {
1✔
2069
                        name: "top collection".to_string(),
1✔
2070
                        description: "description".to_string(),
1✔
2071
                        properties: Default::default(),
1✔
2072
                    },
1✔
2073
                    root_collection_id,
1✔
2074
                )
1✔
2075
                .await
10✔
2076
                .unwrap();
1✔
2077

1✔
2078
            let faux_layer = LayerId("faux".to_string());
1✔
2079

1✔
2080
            // this should fail
1✔
2081
            db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
2082
                .await
×
2083
                .unwrap_err();
1✔
2084

2085
            let root_collection_layers = db
1✔
2086
                .load_layer_collection(
1✔
2087
                    &top_collection_id,
1✔
2088
                    LayerCollectionListOptions {
1✔
2089
                        offset: 0,
1✔
2090
                        limit: 20,
1✔
2091
                    },
1✔
2092
                )
1✔
2093
                .await
5✔
2094
                .unwrap();
1✔
2095

1✔
2096
            assert_eq!(
1✔
2097
                root_collection_layers,
1✔
2098
                LayerCollection {
1✔
2099
                    id: ProviderLayerCollectionId {
1✔
2100
                        provider_id: DataProviderId(
1✔
2101
                            "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
2102
                        ),
1✔
2103
                        collection_id: top_collection_id.clone(),
1✔
2104
                    },
1✔
2105
                    name: "top collection".to_string(),
1✔
2106
                    description: "description".to_string(),
1✔
2107
                    items: vec![],
1✔
2108
                    entry_label: None,
1✔
2109
                    properties: vec![],
1✔
2110
                }
1✔
2111
            );
1✔
2112
        })
1✔
2113
        .await;
11✔
2114
    }
2115

2116
    #[allow(clippy::too_many_lines)]
2117
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2118
    async fn it_updates_project_layer_symbology() {
1✔
2119
        with_temp_context(|app_ctx, _| async move {
1✔
2120
            let session = app_ctx.default_session().await.unwrap();
18✔
2121

2122
            let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
162✔
2123

2124
            let db = app_ctx.session_context(session.clone()).db();
1✔
2125

1✔
2126
            let create_project: CreateProject = serde_json::from_value(json!({
1✔
2127
                "name": "Default",
1✔
2128
                "description": "Default project",
1✔
2129
                "bounds": {
1✔
2130
                    "boundingBox": {
1✔
2131
                        "lowerLeftCoordinate": {
1✔
2132
                            "x": -180,
1✔
2133
                            "y": -90
1✔
2134
                        },
1✔
2135
                        "upperRightCoordinate": {
1✔
2136
                            "x": 180,
1✔
2137
                            "y": 90
1✔
2138
                        }
1✔
2139
                    },
1✔
2140
                    "spatialReference": "EPSG:4326",
1✔
2141
                    "timeInterval": {
1✔
2142
                        "start": 1_396_353_600_000i64,
1✔
2143
                        "end": 1_396_353_600_000i64
1✔
2144
                    }
1✔
2145
                },
1✔
2146
                "timeStep": {
1✔
2147
                    "step": 1,
1✔
2148
                    "granularity": "months"
1✔
2149
                }
1✔
2150
            }))
1✔
2151
            .unwrap();
1✔
2152

2153
            let project_id = db.create_project(create_project).await.unwrap();
7✔
2154

1✔
2155
            let update: UpdateProject = serde_json::from_value(json!({
1✔
2156
                "id": project_id.to_string(),
1✔
2157
                "layers": [{
1✔
2158
                    "name": "NDVI",
1✔
2159
                    "workflow": workflow_id.to_string(),
1✔
2160
                    "visibility": {
1✔
2161
                        "data": true,
1✔
2162
                        "legend": false
1✔
2163
                    },
1✔
2164
                    "symbology": {
1✔
2165
                        "type": "raster",
1✔
2166
                        "opacity": 1,
1✔
2167
                        "colorizer": {
1✔
2168
                            "type": "linearGradient",
1✔
2169
                            "breakpoints": [{
1✔
2170
                                "value": 1,
1✔
2171
                                "color": [0, 0, 0, 255]
1✔
2172
                            }, {
1✔
2173
                                "value": 255,
1✔
2174
                                "color": [255, 255, 255, 255]
1✔
2175
                            }],
1✔
2176
                            "noDataColor": [0, 0, 0, 0],
1✔
2177
                            "overColor": [255, 255, 255, 127],
1✔
2178
                            "underColor": [255, 255, 255, 127]
1✔
2179
                        }
1✔
2180
                    }
1✔
2181
                }]
1✔
2182
            }))
1✔
2183
            .unwrap();
1✔
2184

1✔
2185
            db.update_project(update).await.unwrap();
65✔
2186

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

1✔
2259
            db.update_project(update).await.unwrap();
14✔
2260

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

1✔
2333
            db.update_project(update).await.unwrap();
14✔
2334

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

1✔
2407
            let update = update;
1✔
2408

2409
            // run two updates concurrently
2410
            let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
1✔
2411

2412
            assert!(r0.is_ok());
1✔
2413
            assert!(r1.is_ok());
1✔
2414
        })
1✔
2415
        .await;
11✔
2416
    }
2417

2418
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2419
    #[allow(clippy::too_many_lines)]
2420
    async fn it_resolves_dataset_names_to_ids() {
1✔
2421
        with_temp_context(|app_ctx, _| async move {
1✔
2422
            let session = app_ctx.default_session().await.unwrap();
18✔
2423
            let db = app_ctx.session_context(session.clone()).db();
1✔
2424

1✔
2425
            let loading_info = OgrSourceDataset {
1✔
2426
                file_name: PathBuf::from("test.csv"),
1✔
2427
                layer_name: "test.csv".to_owned(),
1✔
2428
                data_type: Some(VectorDataType::MultiPoint),
1✔
2429
                time: OgrSourceDatasetTimeType::Start {
1✔
2430
                    start_field: "start".to_owned(),
1✔
2431
                    start_format: OgrSourceTimeFormat::Auto,
1✔
2432
                    duration: OgrSourceDurationSpec::Zero,
1✔
2433
                },
1✔
2434
                default_geometry: None,
1✔
2435
                columns: Some(OgrSourceColumnSpec {
1✔
2436
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
2437
                        header: CsvHeader::Auto,
1✔
2438
                    }),
1✔
2439
                    x: "x".to_owned(),
1✔
2440
                    y: None,
1✔
2441
                    int: vec![],
1✔
2442
                    float: vec![],
1✔
2443
                    text: vec![],
1✔
2444
                    bool: vec![],
1✔
2445
                    datetime: vec![],
1✔
2446
                    rename: None,
1✔
2447
                }),
1✔
2448
                force_ogr_time_filter: false,
1✔
2449
                force_ogr_spatial_filter: false,
1✔
2450
                on_error: OgrSourceErrorSpec::Ignore,
1✔
2451
                sql_query: None,
1✔
2452
                attribute_query: None,
1✔
2453
                cache_ttl: CacheTtlSeconds::default(),
1✔
2454
            };
1✔
2455

1✔
2456
            let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2457
                OgrSourceDataset,
1✔
2458
                VectorResultDescriptor,
1✔
2459
                VectorQueryRectangle,
1✔
2460
            > {
1✔
2461
                loading_info: loading_info.clone(),
1✔
2462
                result_descriptor: VectorResultDescriptor {
1✔
2463
                    data_type: VectorDataType::MultiPoint,
1✔
2464
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2465
                    columns: [(
1✔
2466
                        "foo".to_owned(),
1✔
2467
                        VectorColumnInfo {
1✔
2468
                            data_type: FeatureDataType::Float,
1✔
2469
                            measurement: Measurement::Unitless.into(),
1✔
2470
                        },
1✔
2471
                    )]
1✔
2472
                    .into_iter()
1✔
2473
                    .collect(),
1✔
2474
                    time: None,
1✔
2475
                    bbox: None,
1✔
2476
                },
1✔
2477
                phantom: Default::default(),
1✔
2478
            });
1✔
2479

2480
            let DatasetIdAndName {
2481
                id: dataset_id1,
1✔
2482
                name: dataset_name1,
1✔
2483
            } = db
1✔
2484
                .add_dataset(
1✔
2485
                    AddDataset {
1✔
2486
                        name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2487
                        display_name: "Ogr Test".to_owned(),
1✔
2488
                        description: "desc".to_owned(),
1✔
2489
                        source_operator: "OgrSource".to_owned(),
1✔
2490
                        symbology: None,
1✔
2491
                        provenance: Some(vec![Provenance {
1✔
2492
                            citation: "citation".to_owned(),
1✔
2493
                            license: "license".to_owned(),
1✔
2494
                            uri: "uri".to_owned(),
1✔
2495
                        }]),
1✔
2496
                    },
1✔
2497
                    db.wrap_meta_data(meta_data.clone()),
1✔
2498
                )
1✔
2499
                .await
153✔
2500
                .unwrap();
1✔
2501

2502
            assert_eq!(
1✔
2503
                db.resolve_dataset_name_to_id(&dataset_name1).await.unwrap(),
3✔
2504
                dataset_id1
2505
            );
2506
        })
1✔
2507
        .await;
12✔
2508
    }
2509

2510
    #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1✔
2511
    #[allow(clippy::too_many_lines)]
2512
    async fn test_postgres_type_serialization() {
1✔
2513
        pub async fn test_type<T>(
51✔
2514
            conn: &PooledConnection<'_, PostgresConnectionManager<tokio_postgres::NoTls>>,
51✔
2515
            sql_type: &str,
51✔
2516
            checks: impl IntoIterator<Item = T>,
51✔
2517
        ) where
51✔
2518
            T: PartialEq + postgres_types::FromSqlOwned + postgres_types::ToSql + Sync,
51✔
2519
        {
51✔
2520
            const UNQUOTED: [&str; 3] = ["double precision", "int", "point[]"];
1✔
2521

1✔
2522
            // don't quote built-in types
1✔
2523
            let quote = if UNQUOTED.contains(&sql_type) || sql_type.contains('[') {
51✔
2524
                ""
6✔
2525
            } else {
1✔
2526
                "\""
45✔
2527
            };
1✔
2528

1✔
2529
            for value in checks {
152✔
2530
                let stmt = conn
101✔
2531
                    .prepare(&format!("SELECT $1::{quote}{sql_type}{quote}"))
101✔
2532
                    .await
259✔
2533
                    .unwrap();
101✔
2534
                let result: T = conn.query_one(&stmt, &[&value]).await.unwrap().get(0);
103✔
2535

101✔
2536
                assert_eq!(value, result);
101✔
2537
            }
1✔
2538
        }
51✔
2539

1✔
2540
        with_temp_context(|app_ctx, _| async move {
1✔
2541
            let pool = app_ctx.pool.get().await.unwrap();
1✔
2542

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

2545
            test_type(
1✔
2546
                &pool,
1✔
2547
                "double precision",
1✔
2548
                [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
2549
            )
1✔
2550
            .await;
2✔
2551

2552
            test_type(
1✔
2553
                &pool,
1✔
2554
                "Breakpoint",
1✔
2555
                [Breakpoint {
1✔
2556
                    value: NotNan::<f64>::new(1.0).unwrap().into(),
1✔
2557
                    color: RgbaColor([0, 0, 0, 0]),
1✔
2558
                }],
1✔
2559
            )
1✔
2560
            .await;
5✔
2561

2562
            test_type(
1✔
2563
                &pool,
1✔
2564
                "DefaultColors",
1✔
2565
                [
1✔
2566
                    DefaultColors::DefaultColor {
1✔
2567
                        default_color: RgbaColor([0, 10, 20, 30]),
1✔
2568
                    },
1✔
2569
                    DefaultColors::OverUnder(OverUnderColors {
1✔
2570
                        over_color: RgbaColor([1, 2, 3, 4]),
1✔
2571
                        under_color: RgbaColor([5, 6, 7, 8]),
1✔
2572
                    }),
1✔
2573
                ],
1✔
2574
            )
1✔
2575
            .await;
6✔
2576

2577
            test_type(
1✔
2578
                &pool,
1✔
2579
                "ColorizerType",
1✔
2580
                [
1✔
2581
                    ColorizerTypeDbType::LinearGradient,
1✔
2582
                    ColorizerTypeDbType::LogarithmicGradient,
1✔
2583
                    ColorizerTypeDbType::Palette,
1✔
2584
                    ColorizerTypeDbType::Rgba,
1✔
2585
                ],
1✔
2586
            )
1✔
2587
            .await;
11✔
2588

2589
            test_type(
1✔
2590
                &pool,
1✔
2591
                "Colorizer",
1✔
2592
                [
1✔
2593
                    Colorizer::LinearGradient(LinearGradient {
1✔
2594
                        breakpoints: vec![
1✔
2595
                            Breakpoint {
1✔
2596
                                value: NotNan::<f64>::new(-10.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::LogarithmicGradient(LogarithmicGradient {
1✔
2611
                        breakpoints: vec![
1✔
2612
                            Breakpoint {
1✔
2613
                                value: NotNan::<f64>::new(1.0).unwrap().into(),
1✔
2614
                                color: RgbaColor([0, 0, 0, 0]),
1✔
2615
                            },
1✔
2616
                            Breakpoint {
1✔
2617
                                value: NotNan::<f64>::new(2.0).unwrap().into(),
1✔
2618
                                color: RgbaColor([255, 0, 0, 255]),
1✔
2619
                            },
1✔
2620
                        ],
1✔
2621
                        no_data_color: RgbaColor([0, 10, 20, 30]),
1✔
2622
                        color_fields: DefaultColors::OverUnder(OverUnderColors {
1✔
2623
                            over_color: RgbaColor([1, 2, 3, 4]),
1✔
2624
                            under_color: RgbaColor([5, 6, 7, 8]),
1✔
2625
                        }),
1✔
2626
                    }),
1✔
2627
                    Colorizer::Palette {
1✔
2628
                        colors: Palette(
1✔
2629
                            [
1✔
2630
                                (NotNan::<f64>::new(1.0).unwrap(), RgbaColor([0, 0, 0, 0])),
1✔
2631
                                (
1✔
2632
                                    NotNan::<f64>::new(2.0).unwrap(),
1✔
2633
                                    RgbaColor([255, 0, 0, 255]),
1✔
2634
                                ),
1✔
2635
                                (NotNan::<f64>::new(3.0).unwrap(), RgbaColor([0, 10, 20, 30])),
1✔
2636
                            ]
1✔
2637
                            .into(),
1✔
2638
                        ),
1✔
2639
                        no_data_color: RgbaColor([1, 2, 3, 4]),
1✔
2640
                        default_color: RgbaColor([5, 6, 7, 8]),
1✔
2641
                    },
1✔
2642
                    Colorizer::Rgba,
1✔
2643
                ],
1✔
2644
            )
1✔
2645
            .await;
11✔
2646

2647
            test_type(
1✔
2648
                &pool,
1✔
2649
                "ColorParam",
1✔
2650
                [
1✔
2651
                    ColorParam::Static {
1✔
2652
                        color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2653
                    },
1✔
2654
                    ColorParam::Derived(DerivedColor {
1✔
2655
                        attribute: "foobar".to_string(),
1✔
2656
                        colorizer: Colorizer::Rgba,
1✔
2657
                    }),
1✔
2658
                ],
1✔
2659
            )
1✔
2660
            .await;
6✔
2661

2662
            test_type(
1✔
2663
                &pool,
1✔
2664
                "NumberParam",
1✔
2665
                [
1✔
2666
                    NumberParam::Static { value: 42 },
1✔
2667
                    NumberParam::Derived(DerivedNumber {
1✔
2668
                        attribute: "foobar".to_string(),
1✔
2669
                        factor: 1.0,
1✔
2670
                        default_value: 42.,
1✔
2671
                    }),
1✔
2672
                ],
1✔
2673
            )
1✔
2674
            .await;
6✔
2675

2676
            test_type(
1✔
2677
                &pool,
1✔
2678
                "StrokeParam",
1✔
2679
                [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
            .await;
4✔
2687

2688
            test_type(
1✔
2689
                &pool,
1✔
2690
                "TextSymbology",
1✔
2691
                [TextSymbology {
1✔
2692
                    attribute: "attribute".to_string(),
1✔
2693
                    fill_color: ColorParam::Static {
1✔
2694
                        color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2695
                    },
1✔
2696
                    stroke: StrokeParam {
1✔
2697
                        width: NumberParam::Static { value: 42 },
1✔
2698
                        color: ColorParam::Static {
1✔
2699
                            color: RgbaColor([0, 10, 20, 30]).into(),
1✔
2700
                        },
1✔
2701
                    },
1✔
2702
                }],
1✔
2703
            )
1✔
2704
            .await;
4✔
2705

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

2803
            test_type(
1✔
2804
                &pool,
1✔
2805
                "RasterDataType",
1✔
2806
                [
1✔
2807
                    crate::api::model::datatypes::RasterDataType::U8,
1✔
2808
                    crate::api::model::datatypes::RasterDataType::U16,
1✔
2809
                    crate::api::model::datatypes::RasterDataType::U32,
1✔
2810
                    crate::api::model::datatypes::RasterDataType::U64,
1✔
2811
                    crate::api::model::datatypes::RasterDataType::I8,
1✔
2812
                    crate::api::model::datatypes::RasterDataType::I16,
1✔
2813
                    crate::api::model::datatypes::RasterDataType::I32,
1✔
2814
                    crate::api::model::datatypes::RasterDataType::I64,
1✔
2815
                    crate::api::model::datatypes::RasterDataType::F32,
1✔
2816
                    crate::api::model::datatypes::RasterDataType::F64,
1✔
2817
                ],
1✔
2818
            )
1✔
2819
            .await;
22✔
2820

2821
            test_type(
1✔
2822
                &pool,
1✔
2823
                "Measurement",
1✔
2824
                [
1✔
2825
                    Measurement::Unitless,
1✔
2826
                    Measurement::Continuous(ContinuousMeasurement {
1✔
2827
                        measurement: "Temperature".to_string(),
1✔
2828
                        unit: Some("°C".to_string()),
1✔
2829
                    }),
1✔
2830
                    Measurement::Classification(ClassificationMeasurement {
1✔
2831
                        measurement: "Color".to_string(),
1✔
2832
                        classes: [(1, "Grayscale".to_string()), (2, "Colorful".to_string())].into(),
1✔
2833
                    }),
1✔
2834
                ],
1✔
2835
            )
1✔
2836
            .await;
15✔
2837

2838
            test_type(
1✔
2839
                &pool,
1✔
2840
                "Coordinate2D",
1✔
2841
                [crate::api::model::datatypes::Coordinate2D::from(
1✔
2842
                    Coordinate2D::new(0.0f64, 1.),
1✔
2843
                )],
1✔
2844
            )
1✔
2845
            .await;
4✔
2846

2847
            test_type(
1✔
2848
                &pool,
1✔
2849
                "SpatialPartition2D",
1✔
2850
                [crate::api::model::datatypes::SpatialPartition2D {
1✔
2851
                    upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
2852
                    lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
2853
                }],
1✔
2854
            )
1✔
2855
            .await;
5✔
2856

2857
            test_type(
1✔
2858
                &pool,
1✔
2859
                "BoundingBox2D",
1✔
2860
                [crate::api::model::datatypes::BoundingBox2D {
1✔
2861
                    lower_left_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
2862
                    upper_right_coordinate: Coordinate2D::new(2., 1.0).into(),
1✔
2863
                }],
1✔
2864
            )
1✔
2865
            .await;
4✔
2866

2867
            test_type(
1✔
2868
                &pool,
1✔
2869
                "SpatialResolution",
1✔
2870
                [crate::api::model::datatypes::SpatialResolution { x: 1.2, y: 2.3 }],
1✔
2871
            )
1✔
2872
            .await;
4✔
2873

2874
            test_type(
1✔
2875
                &pool,
1✔
2876
                "VectorDataType",
1✔
2877
                [
1✔
2878
                    crate::api::model::datatypes::VectorDataType::Data,
1✔
2879
                    crate::api::model::datatypes::VectorDataType::MultiPoint,
1✔
2880
                    crate::api::model::datatypes::VectorDataType::MultiLineString,
1✔
2881
                    crate::api::model::datatypes::VectorDataType::MultiPolygon,
1✔
2882
                ],
1✔
2883
            )
1✔
2884
            .await;
10✔
2885

2886
            test_type(
1✔
2887
                &pool,
1✔
2888
                "FeatureDataType",
1✔
2889
                [
1✔
2890
                    crate::api::model::datatypes::FeatureDataType::Category,
1✔
2891
                    crate::api::model::datatypes::FeatureDataType::Int,
1✔
2892
                    crate::api::model::datatypes::FeatureDataType::Float,
1✔
2893
                    crate::api::model::datatypes::FeatureDataType::Text,
1✔
2894
                    crate::api::model::datatypes::FeatureDataType::Bool,
1✔
2895
                    crate::api::model::datatypes::FeatureDataType::DateTime,
1✔
2896
                ],
1✔
2897
            )
1✔
2898
            .await;
14✔
2899

2900
            test_type(
1✔
2901
                &pool,
1✔
2902
                "TimeInterval",
1✔
2903
                [crate::api::model::datatypes::TimeInterval::from(
1✔
2904
                    TimeInterval::default(),
1✔
2905
                )],
1✔
2906
            )
1✔
2907
            .await;
4✔
2908

2909
            test_type(
1✔
2910
                &pool,
1✔
2911
                "SpatialReference",
1✔
2912
                [
1✔
2913
                    crate::api::model::datatypes::SpatialReferenceOption::Unreferenced,
1✔
2914
                    crate::api::model::datatypes::SpatialReferenceOption::SpatialReference(
1✔
2915
                        SpatialReference::epsg_4326().into(),
1✔
2916
                    ),
1✔
2917
                ],
1✔
2918
            )
1✔
2919
            .await;
8✔
2920

2921
            test_type(
1✔
2922
                &pool,
1✔
2923
                "PlotResultDescriptor",
1✔
2924
                [PlotResultDescriptor {
1✔
2925
                    spatial_reference: SpatialReferenceOption::Unreferenced.into(),
1✔
2926
                    time: None,
1✔
2927
                    bbox: None,
1✔
2928
                }],
1✔
2929
            )
1✔
2930
            .await;
4✔
2931

2932
            test_type(
1✔
2933
                &pool,
1✔
2934
                "VectorResultDescriptor",
1✔
2935
                [crate::api::model::operators::VectorResultDescriptor {
1✔
2936
                    data_type: VectorDataType::MultiPoint.into(),
1✔
2937
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2938
                        SpatialReference::epsg_4326(),
1✔
2939
                    )
1✔
2940
                    .into(),
1✔
2941
                    columns: [(
1✔
2942
                        "foo".to_string(),
1✔
2943
                        VectorColumnInfo {
1✔
2944
                            data_type: FeatureDataType::Int,
1✔
2945
                            measurement: Measurement::Unitless.into(),
1✔
2946
                        }
1✔
2947
                        .into(),
1✔
2948
                    )]
1✔
2949
                    .into(),
1✔
2950
                    time: Some(TimeInterval::default().into()),
1✔
2951
                    bbox: Some(
1✔
2952
                        BoundingBox2D::new(
1✔
2953
                            Coordinate2D::new(0.0f64, 0.5),
1✔
2954
                            Coordinate2D::new(2., 1.0),
1✔
2955
                        )
1✔
2956
                        .unwrap()
1✔
2957
                        .into(),
1✔
2958
                    ),
1✔
2959
                }],
1✔
2960
            )
1✔
2961
            .await;
7✔
2962

2963
            test_type(
1✔
2964
                &pool,
1✔
2965
                "RasterResultDescriptor",
1✔
2966
                [crate::api::model::operators::RasterResultDescriptor {
1✔
2967
                    data_type: RasterDataType::U8.into(),
1✔
2968
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2969
                        SpatialReference::epsg_4326(),
1✔
2970
                    )
1✔
2971
                    .into(),
1✔
2972
                    measurement: Measurement::Unitless,
1✔
2973
                    time: Some(TimeInterval::default().into()),
1✔
2974
                    bbox: Some(SpatialPartition2D {
1✔
2975
                        upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
2976
                        lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
2977
                    }),
1✔
2978
                    resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }.into()),
1✔
2979
                }],
1✔
2980
            )
1✔
2981
            .await;
4✔
2982

2983
            test_type(
1✔
2984
                &pool,
1✔
2985
                "ResultDescriptor",
1✔
2986
                [
1✔
2987
                    crate::api::model::operators::TypedResultDescriptor::Vector(
1✔
2988
                        VectorResultDescriptor {
1✔
2989
                            data_type: VectorDataType::MultiPoint,
1✔
2990
                            spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
2991
                                SpatialReference::epsg_4326(),
1✔
2992
                            ),
1✔
2993
                            columns: [(
1✔
2994
                                "foo".to_string(),
1✔
2995
                                VectorColumnInfo {
1✔
2996
                                    data_type: FeatureDataType::Int,
1✔
2997
                                    measurement: Measurement::Unitless.into(),
1✔
2998
                                },
1✔
2999
                            )]
1✔
3000
                            .into(),
1✔
3001
                            time: Some(TimeInterval::default()),
1✔
3002
                            bbox: Some(
1✔
3003
                                BoundingBox2D::new(
1✔
3004
                                    Coordinate2D::new(0.0f64, 0.5),
1✔
3005
                                    Coordinate2D::new(2., 1.0),
1✔
3006
                                )
1✔
3007
                                .unwrap(),
1✔
3008
                            ),
1✔
3009
                        }
1✔
3010
                        .into(),
1✔
3011
                    ),
1✔
3012
                    crate::api::model::operators::TypedResultDescriptor::Raster(
1✔
3013
                        crate::api::model::operators::RasterResultDescriptor {
1✔
3014
                            data_type: RasterDataType::U8.into(),
1✔
3015
                            spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3016
                                SpatialReference::epsg_4326(),
1✔
3017
                            )
1✔
3018
                            .into(),
1✔
3019
                            measurement: Measurement::Unitless,
1✔
3020
                            time: Some(TimeInterval::default().into()),
1✔
3021
                            bbox: Some(SpatialPartition2D {
1✔
3022
                                upper_left_coordinate: Coordinate2D::new(0.0f64, 1.).into(),
1✔
3023
                                lower_right_coordinate: Coordinate2D::new(2., 0.5).into(),
1✔
3024
                            }),
1✔
3025
                            resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }.into()),
1✔
3026
                        },
1✔
3027
                    ),
1✔
3028
                    crate::api::model::operators::TypedResultDescriptor::Plot(
1✔
3029
                        PlotResultDescriptor {
1✔
3030
                            spatial_reference: SpatialReferenceOption::Unreferenced.into(),
1✔
3031
                            time: None,
1✔
3032
                            bbox: None,
1✔
3033
                        },
1✔
3034
                    ),
1✔
3035
                ],
1✔
3036
            )
1✔
3037
            .await;
8✔
3038

3039
            test_type(
1✔
3040
                &pool,
1✔
3041
                "\"TextTextKeyValue\"[]",
1✔
3042
                [HashMapTextTextDbType::from(
1✔
3043
                    &HashMap::<String, String>::from([
1✔
3044
                        ("foo".to_string(), "bar".to_string()),
1✔
3045
                        ("baz".to_string(), "fuu".to_string()),
1✔
3046
                    ]),
1✔
3047
                )],
1✔
3048
            )
1✔
3049
            .await;
5✔
3050

3051
            test_type(
1✔
3052
                &pool,
1✔
3053
                "MockDatasetDataSourceLoadingInfo",
1✔
3054
                [
1✔
3055
                    crate::api::model::operators::MockDatasetDataSourceLoadingInfo {
1✔
3056
                        points: vec![
1✔
3057
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3058
                            Coordinate2D::new(2., 1.0).into(),
1✔
3059
                        ],
1✔
3060
                    },
1✔
3061
                ],
1✔
3062
            )
1✔
3063
            .await;
6✔
3064

3065
            test_type(
1✔
3066
                &pool,
1✔
3067
                "OgrSourceTimeFormat",
1✔
3068
                [
1✔
3069
                    crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3070
                    crate::api::model::operators::OgrSourceTimeFormat::Custom {
1✔
3071
                        custom_format:
1✔
3072
                            geoengine_datatypes::primitives::DateTimeParseFormat::custom(
1✔
3073
                                "%Y-%m-%dT%H:%M:%S%.3fZ".to_string(),
1✔
3074
                            )
1✔
3075
                            .into(),
1✔
3076
                    },
1✔
3077
                    crate::api::model::operators::OgrSourceTimeFormat::UnixTimeStamp {
1✔
3078
                        timestamp_type: UnixTimeStampType::EpochSeconds,
1✔
3079
                        fmt: geoengine_datatypes::primitives::DateTimeParseFormat::unix().into(),
1✔
3080
                    },
1✔
3081
                ],
1✔
3082
            )
1✔
3083
            .await;
16✔
3084

3085
            test_type(
1✔
3086
                &pool,
1✔
3087
                "OgrSourceDurationSpec",
1✔
3088
                [
1✔
3089
                    crate::api::model::operators::OgrSourceDurationSpec::Infinite,
1✔
3090
                    crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3091
                    crate::api::model::operators::OgrSourceDurationSpec::Value(
1✔
3092
                        TimeStep {
1✔
3093
                            granularity: TimeGranularity::Millis,
1✔
3094
                            step: 1000,
1✔
3095
                        }
1✔
3096
                        .into(),
1✔
3097
                    ),
1✔
3098
                ],
1✔
3099
            )
1✔
3100
            .await;
12✔
3101

3102
            test_type(
1✔
3103
                &pool,
1✔
3104
                "OgrSourceDatasetTimeType",
1✔
3105
                [
1✔
3106
                    crate::api::model::operators::OgrSourceDatasetTimeType::None,
1✔
3107
                    crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3108
                        start_field: "start".to_string(),
1✔
3109
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3110
                        duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3111
                    },
1✔
3112
                    crate::api::model::operators::OgrSourceDatasetTimeType::StartEnd {
1✔
3113
                        start_field: "start".to_string(),
1✔
3114
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3115
                        end_field: "end".to_string(),
1✔
3116
                        end_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3117
                    },
1✔
3118
                    crate::api::model::operators::OgrSourceDatasetTimeType::StartDuration {
1✔
3119
                        start_field: "start".to_string(),
1✔
3120
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3121
                        duration_field: "duration".to_string(),
1✔
3122
                    },
1✔
3123
                ],
1✔
3124
            )
1✔
3125
            .await;
16✔
3126

3127
            test_type(
1✔
3128
                &pool,
1✔
3129
                "FormatSpecifics",
1✔
3130
                [crate::api::model::operators::FormatSpecifics::Csv {
1✔
3131
                    header: CsvHeader::Yes.into(),
1✔
3132
                }],
1✔
3133
            )
1✔
3134
            .await;
8✔
3135

3136
            test_type(
1✔
3137
                &pool,
1✔
3138
                "OgrSourceColumnSpec",
1✔
3139
                [crate::api::model::operators::OgrSourceColumnSpec {
1✔
3140
                    format_specifics: Some(crate::api::model::operators::FormatSpecifics::Csv {
1✔
3141
                        header: CsvHeader::Auto.into(),
1✔
3142
                    }),
1✔
3143
                    x: "x".to_string(),
1✔
3144
                    y: Some("y".to_string()),
1✔
3145
                    int: vec!["int".to_string()],
1✔
3146
                    float: vec!["float".to_string()],
1✔
3147
                    text: vec!["text".to_string()],
1✔
3148
                    bool: vec!["bool".to_string()],
1✔
3149
                    datetime: vec!["datetime".to_string()],
1✔
3150
                    rename: Some(
1✔
3151
                        [
1✔
3152
                            ("xx".to_string(), "xx_renamed".to_string()),
1✔
3153
                            ("yx".to_string(), "yy_renamed".to_string()),
1✔
3154
                        ]
1✔
3155
                        .into(),
1✔
3156
                    ),
1✔
3157
                }],
1✔
3158
            )
1✔
3159
            .await;
4✔
3160

3161
            test_type(
1✔
3162
                &pool,
1✔
3163
                "point[]",
1✔
3164
                [MultiPoint {
1✔
3165
                    coordinates: 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
            .await;
2✔
3172

3173
            test_type(
1✔
3174
                &pool,
1✔
3175
                "path[]",
1✔
3176
                [MultiLineString {
1✔
3177
                    coordinates: vec![
1✔
3178
                        vec![
1✔
3179
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3180
                            Coordinate2D::new(2., 1.0).into(),
1✔
3181
                        ],
1✔
3182
                        vec![
1✔
3183
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3184
                            Coordinate2D::new(2., 1.0).into(),
1✔
3185
                        ],
1✔
3186
                    ],
1✔
3187
                }],
1✔
3188
            )
1✔
3189
            .await;
2✔
3190

3191
            test_type(
1✔
3192
                &pool,
1✔
3193
                "\"Polygon\"[]",
1✔
3194
                [MultiPolygon {
1✔
3195
                    polygons: vec![
1✔
3196
                        vec![
1✔
3197
                            vec![
1✔
3198
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3199
                                Coordinate2D::new(2., 1.0).into(),
1✔
3200
                                Coordinate2D::new(2., 1.0).into(),
1✔
3201
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3202
                            ],
1✔
3203
                            vec![
1✔
3204
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3205
                                Coordinate2D::new(2., 1.0).into(),
1✔
3206
                                Coordinate2D::new(2., 1.0).into(),
1✔
3207
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3208
                            ],
1✔
3209
                        ],
1✔
3210
                        vec![
1✔
3211
                            vec![
1✔
3212
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3213
                                Coordinate2D::new(2., 1.0).into(),
1✔
3214
                                Coordinate2D::new(2., 1.0).into(),
1✔
3215
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3216
                            ],
1✔
3217
                            vec![
1✔
3218
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3219
                                Coordinate2D::new(2., 1.0).into(),
1✔
3220
                                Coordinate2D::new(2., 1.0).into(),
1✔
3221
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3222
                            ],
1✔
3223
                        ],
1✔
3224
                    ],
1✔
3225
                }],
1✔
3226
            )
1✔
3227
            .await;
4✔
3228

3229
            test_type(
1✔
3230
                &pool,
1✔
3231
                "TypedGeometry",
1✔
3232
                [
1✔
3233
                    crate::api::model::operators::TypedGeometry::Data(NoGeometry),
1✔
3234
                    crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3235
                        coordinates: vec![
1✔
3236
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3237
                            Coordinate2D::new(2., 1.0).into(),
1✔
3238
                        ],
1✔
3239
                    }),
1✔
3240
                    crate::api::model::operators::TypedGeometry::MultiLineString(MultiLineString {
1✔
3241
                        coordinates: vec![
1✔
3242
                            vec![
1✔
3243
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3244
                                Coordinate2D::new(2., 1.0).into(),
1✔
3245
                            ],
1✔
3246
                            vec![
1✔
3247
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3248
                                Coordinate2D::new(2., 1.0).into(),
1✔
3249
                            ],
1✔
3250
                        ],
1✔
3251
                    }),
1✔
3252
                    crate::api::model::operators::TypedGeometry::MultiPolygon(MultiPolygon {
1✔
3253
                        polygons: vec![
1✔
3254
                            vec![
1✔
3255
                                vec![
1✔
3256
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3257
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3258
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3259
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3260
                                ],
1✔
3261
                                vec![
1✔
3262
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3263
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3264
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3265
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3266
                                ],
1✔
3267
                            ],
1✔
3268
                            vec![
1✔
3269
                                vec![
1✔
3270
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3271
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3272
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3273
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3274
                                ],
1✔
3275
                                vec![
1✔
3276
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3277
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3278
                                    Coordinate2D::new(2., 1.0).into(),
1✔
3279
                                    Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3280
                                ],
1✔
3281
                            ],
1✔
3282
                        ],
1✔
3283
                    }),
1✔
3284
                ],
1✔
3285
            )
1✔
3286
            .await;
11✔
3287

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

3290
            test_type(
1✔
3291
                &pool,
1✔
3292
                "OgrSourceDataset",
1✔
3293
                [crate::api::model::operators::OgrSourceDataset {
1✔
3294
                    file_name: "test".into(),
1✔
3295
                    layer_name: "test".to_string(),
1✔
3296
                    data_type: Some(VectorDataType::MultiPoint.into()),
1✔
3297
                    time: crate::api::model::operators::OgrSourceDatasetTimeType::Start {
1✔
3298
                        start_field: "start".to_string(),
1✔
3299
                        start_format: crate::api::model::operators::OgrSourceTimeFormat::Auto,
1✔
3300
                        duration: crate::api::model::operators::OgrSourceDurationSpec::Zero,
1✔
3301
                    },
1✔
3302
                    default_geometry: Some(
1✔
3303
                        crate::api::model::operators::TypedGeometry::MultiPoint(MultiPoint {
1✔
3304
                            coordinates: vec![
1✔
3305
                                Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3306
                                Coordinate2D::new(2., 1.0).into(),
1✔
3307
                            ],
1✔
3308
                        }),
1✔
3309
                    ),
1✔
3310
                    columns: Some(crate::api::model::operators::OgrSourceColumnSpec {
1✔
3311
                        format_specifics: Some(
1✔
3312
                            crate::api::model::operators::FormatSpecifics::Csv {
1✔
3313
                                header: CsvHeader::Auto.into(),
1✔
3314
                            },
1✔
3315
                        ),
1✔
3316
                        x: "x".to_string(),
1✔
3317
                        y: Some("y".to_string()),
1✔
3318
                        int: vec!["int".to_string()],
1✔
3319
                        float: vec!["float".to_string()],
1✔
3320
                        text: vec!["text".to_string()],
1✔
3321
                        bool: vec!["bool".to_string()],
1✔
3322
                        datetime: vec!["datetime".to_string()],
1✔
3323
                        rename: Some(
1✔
3324
                            [
1✔
3325
                                ("xx".to_string(), "xx_renamed".to_string()),
1✔
3326
                                ("yx".to_string(), "yy_renamed".to_string()),
1✔
3327
                            ]
1✔
3328
                            .into(),
1✔
3329
                        ),
1✔
3330
                    }),
1✔
3331
                    force_ogr_time_filter: false,
1✔
3332
                    force_ogr_spatial_filter: true,
1✔
3333
                    on_error: crate::api::model::operators::OgrSourceErrorSpec::Abort,
1✔
3334
                    sql_query: None,
1✔
3335
                    attribute_query: Some("foo = 'bar'".to_string()),
1✔
3336
                    cache_ttl: CacheTtlSeconds::new(5),
1✔
3337
                }],
1✔
3338
            )
1✔
3339
            .await;
6✔
3340

3341
            test_type(
1✔
3342
                &pool,
1✔
3343
                "MockMetaData",
1✔
3344
                [crate::api::model::operators::MockMetaData {
1✔
3345
                    loading_info: crate::api::model::operators::MockDatasetDataSourceLoadingInfo {
1✔
3346
                        points: vec![
1✔
3347
                            Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3348
                            Coordinate2D::new(2., 1.0).into(),
1✔
3349
                        ],
1✔
3350
                    },
1✔
3351
                    result_descriptor: VectorResultDescriptor {
1✔
3352
                        data_type: VectorDataType::MultiPoint,
1✔
3353
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3354
                            SpatialReference::epsg_4326(),
1✔
3355
                        ),
1✔
3356
                        columns: [(
1✔
3357
                            "foo".to_string(),
1✔
3358
                            VectorColumnInfo {
1✔
3359
                                data_type: FeatureDataType::Int,
1✔
3360
                                measurement: Measurement::Unitless.into(),
1✔
3361
                            },
1✔
3362
                        )]
1✔
3363
                        .into(),
1✔
3364
                        time: Some(TimeInterval::default()),
1✔
3365
                        bbox: Some(
1✔
3366
                            BoundingBox2D::new(
1✔
3367
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3368
                                Coordinate2D::new(2., 1.0),
1✔
3369
                            )
1✔
3370
                            .unwrap(),
1✔
3371
                        ),
1✔
3372
                    }
1✔
3373
                    .into(),
1✔
3374
                    phantom: PhantomData,
1✔
3375
                }],
1✔
3376
            )
1✔
3377
            .await;
4✔
3378

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

3456
            test_type(
1✔
3457
                &pool,
1✔
3458
                "GdalDatasetGeoTransform",
1✔
3459
                [crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3460
                    origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3461
                    x_pixel_size: 1.0,
1✔
3462
                    y_pixel_size: 2.0,
1✔
3463
                }],
1✔
3464
            )
1✔
3465
            .await;
4✔
3466

3467
            test_type(
1✔
3468
                &pool,
1✔
3469
                "FileNotFoundHandling",
1✔
3470
                [
1✔
3471
                    crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3472
                    crate::api::model::operators::FileNotFoundHandling::Error,
1✔
3473
                ],
1✔
3474
            )
1✔
3475
            .await;
6✔
3476

3477
            test_type(
1✔
3478
                &pool,
1✔
3479
                "GdalMetadataMapping",
1✔
3480
                [crate::api::model::operators::GdalMetadataMapping {
1✔
3481
                    source_key: RasterPropertiesKey {
1✔
3482
                        domain: None,
1✔
3483
                        key: "foo".to_string(),
1✔
3484
                    },
1✔
3485
                    target_key: RasterPropertiesKey {
1✔
3486
                        domain: Some("bar".to_string()),
1✔
3487
                        key: "foo".to_string(),
1✔
3488
                    },
1✔
3489
                    target_type: RasterPropertiesEntryType::String,
1✔
3490
                }],
1✔
3491
            )
1✔
3492
            .await;
8✔
3493

3494
            test_type(
1✔
3495
                &pool,
1✔
3496
                "StringPair",
1✔
3497
                [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3498
            )
1✔
3499
            .await;
3✔
3500

3501
            test_type(
1✔
3502
                &pool,
1✔
3503
                "GdalDatasetParameters",
1✔
3504
                [crate::api::model::operators::GdalDatasetParameters {
1✔
3505
                    file_path: "text".into(),
1✔
3506
                    rasterband_channel: 1,
1✔
3507
                    geo_transform: crate::api::model::operators::GdalDatasetGeoTransform {
1✔
3508
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5).into(),
1✔
3509
                        x_pixel_size: 1.0,
1✔
3510
                        y_pixel_size: 2.0,
1✔
3511
                    },
1✔
3512
                    width: 42,
1✔
3513
                    height: 23,
1✔
3514
                    file_not_found_handling:
1✔
3515
                        crate::api::model::operators::FileNotFoundHandling::NoData,
1✔
3516
                    no_data_value: Some(42.0),
1✔
3517
                    properties_mapping: Some(vec![
1✔
3518
                        crate::api::model::operators::GdalMetadataMapping {
1✔
3519
                            source_key: RasterPropertiesKey {
1✔
3520
                                domain: None,
1✔
3521
                                key: "foo".to_string(),
1✔
3522
                            },
1✔
3523
                            target_key: RasterPropertiesKey {
1✔
3524
                                domain: Some("bar".to_string()),
1✔
3525
                                key: "foo".to_string(),
1✔
3526
                            },
1✔
3527
                            target_type: RasterPropertiesEntryType::String,
1✔
3528
                        },
1✔
3529
                    ]),
1✔
3530
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3531
                    gdal_config_options: Some(vec![
1✔
3532
                        crate::api::model::operators::GdalConfigOption::from((
1✔
3533
                            "foo".to_string(),
1✔
3534
                            "bar".to_string(),
1✔
3535
                        )),
1✔
3536
                    ]),
1✔
3537
                    allow_alphaband_as_mask: false,
1✔
3538
                }],
1✔
3539
            )
1✔
3540
            .await;
6✔
3541

3542
            test_type(
1✔
3543
                &pool,
1✔
3544
                "TextGdalSourceTimePlaceholderKeyValue",
1✔
3545
                [crate::api::model::TextGdalSourceTimePlaceholderKeyValue {
1✔
3546
                    key: "foo".to_string(),
1✔
3547
                    value: GdalSourceTimePlaceholder {
1✔
3548
                        format: geoengine_datatypes::primitives::DateTimeParseFormat::unix().into(),
1✔
3549
                        reference: TimeReference::Start,
1✔
3550
                    },
1✔
3551
                }],
1✔
3552
            )
1✔
3553
            .await;
8✔
3554

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

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

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

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

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

4208
    #[test]
1✔
4209
    fn test_postgres_config_translation() {
1✔
4210
        let host = "localhost";
1✔
4211
        let port = 8095;
1✔
4212
        let ge_default = "geoengine";
1✔
4213
        let schema = "public";
1✔
4214

1✔
4215
        let db_config = config::Postgres {
1✔
4216
            host: host.to_string(),
1✔
4217
            port,
1✔
4218
            database: ge_default.to_string(),
1✔
4219
            schema: schema.to_string(),
1✔
4220
            user: ge_default.to_string(),
1✔
4221
            password: ge_default.to_string(),
1✔
4222
            clear_database_on_start: false,
1✔
4223
        };
1✔
4224

1✔
4225
        let pg_config = Config::from(db_config);
1✔
4226

1✔
4227
        assert_eq!(ge_default, pg_config.get_user().unwrap());
1✔
4228
        assert_eq!(
1✔
4229
            <str as AsRef<[u8]>>::as_ref(ge_default).to_vec(),
1✔
4230
            pg_config.get_password().unwrap()
1✔
4231
        );
1✔
4232
        assert_eq!(ge_default, pg_config.get_dbname().unwrap());
1✔
4233
        assert_eq!(
1✔
4234
            &format!("-c search_path={schema}"),
1✔
4235
            pg_config.get_options().unwrap()
1✔
4236
        );
1✔
4237
        assert_eq!(vec![Host::Tcp(host.to_string())], pg_config.get_hosts());
1✔
4238
        assert_eq!(vec![port], pg_config.get_ports());
1✔
4239
    }
1✔
4240
}
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