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

geo-engine / geoengine / 9957948370

16 Jul 2024 01:08PM UTC coverage: 90.659% (-0.03%) from 90.687%
9957948370

push

github

web-flow
Merge pull request #949 from geo-engine/suggest_raster_metadata

suggest raster metadata

197 of 268 new or added lines in 10 files covered. (73.51%)

12 existing lines in 10 files now uncovered.

133316 of 147052 relevant lines covered (90.66%)

52608.67 hits per line

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

97.6
/services/src/contexts/postgres.rs
1
use super::migrations::{all_migrations, CurrentSchemaMigration, MigrationResult};
2
use super::{initialize_database, ExecutionContextImpl, Session, SimpleApplicationContext};
3
use crate::api::cli::{add_datasets_from_directory, add_providers_from_directory};
4
use crate::api::model::services::Volume;
5
use crate::contexts::{ApplicationContext, QueryContextImpl, SessionId, SimpleSession};
6
use crate::contexts::{GeoEngineDb, SessionContext};
7
use crate::datasets::upload::Volumes;
8
use crate::datasets::DatasetName;
9
use crate::error::{self, Error, Result};
10
use crate::layers::add_from_directory::{
11
    add_layer_collections_from_directory, add_layers_from_directory,
12
};
13
use crate::projects::{ProjectId, STRectangle};
14
use crate::tasks::{SimpleTaskManager, SimpleTaskManagerBackend, SimpleTaskManagerContext};
15
use crate::util::config;
16
use crate::util::config::get_config_element;
17
use async_trait::async_trait;
18
use bb8_postgres::{
19
    bb8::Pool,
20
    bb8::PooledConnection,
21
    tokio_postgres::{error::SqlState, tls::MakeTlsConnect, tls::TlsConnect, Config, Socket},
22
    PostgresConnectionManager,
23
};
24
use geoengine_datatypes::raster::TilingSpecification;
25
use geoengine_operators::engine::ChunkByteSize;
26
use geoengine_operators::util::create_rayon_thread_pool;
27
use log::info;
28
use rayon::ThreadPool;
29
use snafu::ensure;
30
use std::path::PathBuf;
31
use std::sync::Arc;
32

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

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

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

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

74
        let pool = Pool::builder().build(pg_mgr).await?;
219✔
75
        let created_schema = Self::create_database(pool.get().await?).await?;
2,847✔
76

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

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

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

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

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

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

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

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

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

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

142
            add_providers_from_directory(&mut db, provider_defs_path).await;
×
143
        }
×
144

145
        Ok(app_ctx)
×
146
    }
×
147

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

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

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

176
    /// Clears the database if the Settings demand and the database properties allows it.
177
    pub(crate) async fn maybe_clear_database(
315✔
178
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
315✔
179
    ) -> Result<()> {
315✔
180
        let postgres_config = get_config_element::<crate::util::config::Postgres>()?;
315✔
181
        let database_status = Self::check_schema_status(conn).await?;
315✔
182
        let schema_name = postgres_config.schema;
315✔
183

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

200
        Ok(())
315✔
201
    }
315✔
202

203
    /// Creates the database schema. Returns true if the schema was created, false if it already existed.
204
    pub(crate) async fn create_database(
219✔
205
        mut conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
219✔
206
    ) -> Result<bool> {
219✔
207
        Self::maybe_clear_database(&conn).await?;
219✔
208

209
        let migration = initialize_database(
219✔
210
            &mut conn,
219✔
211
            Box::new(CurrentSchemaMigration),
219✔
212
            &all_migrations(),
219✔
213
        )
219✔
214
        .await?;
2,628✔
215

216
        Ok(migration == MigrationResult::CreatedDatabase)
219✔
217
    }
219✔
218

219
    async fn create_default_session(
219✔
220
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
219✔
221
        session_id: SessionId,
219✔
222
    ) -> Result<()> {
219✔
223
        let stmt = conn
219✔
224
            .prepare("INSERT INTO sessions (id, project_id, view) VALUES ($1, NULL ,NULL);")
219✔
225
            .await?;
219✔
226

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

229
        Ok(())
219✔
230
    }
219✔
231
    async fn load_default_session(
69✔
232
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
69✔
233
    ) -> Result<SimpleSession> {
69✔
234
        let stmt = conn
69✔
235
            .prepare("SELECT id, project_id, view FROM sessions LIMIT 1;")
69✔
236
            .await?;
418✔
237

238
        let row = conn.query_one(&stmt, &[]).await?;
69✔
239

240
        Ok(SimpleSession::new(row.get(0), row.get(1), row.get(2)))
69✔
241
    }
69✔
242
}
243

244
#[async_trait]
245
impl<Tls> SimpleApplicationContext for PostgresContext<Tls>
246
where
247
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
248
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
249
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
250
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
251
{
252
    async fn default_session_id(&self) -> SessionId {
84✔
253
        self.default_session_id
84✔
254
    }
168✔
255

256
    async fn default_session(&self) -> Result<SimpleSession> {
69✔
257
        Self::load_default_session(self.pool.get().await?).await
482✔
258
    }
207✔
259

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

263
        let stmt = conn
1✔
264
            .prepare("UPDATE sessions SET project_id = $1 WHERE id = $2;")
1✔
265
            .await?;
1✔
266

267
        conn.execute(&stmt, &[&project, &self.default_session_id])
1✔
268
            .await?;
1✔
269

270
        Ok(())
1✔
271
    }
3✔
272

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

276
        let stmt = conn
1✔
277
            .prepare("UPDATE sessions SET view = $1 WHERE id = $2;")
1✔
278
            .await?;
1✔
279

280
        conn.execute(&stmt, &[&view, &self.default_session_id])
1✔
281
            .await?;
1✔
282

283
        Ok(())
1✔
284
    }
3✔
285

286
    async fn default_session_context(&self) -> Result<Self::SessionContext> {
355✔
287
        Ok(self.session_context(self.session_by_id(self.default_session_id).await?))
4,108✔
288
    }
1,065✔
289
}
290

291
#[async_trait]
292
impl<Tls> ApplicationContext for PostgresContext<Tls>
293
where
294
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
295
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
296
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
297
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
298
{
299
    type SessionContext = PostgresSessionContext<Tls>;
300
    type Session = SimpleSession;
301

302
    fn session_context(&self, session: Self::Session) -> Self::SessionContext {
533✔
303
        PostgresSessionContext {
533✔
304
            session,
533✔
305
            context: self.clone(),
533✔
306
        }
533✔
307
    }
533✔
308

309
    async fn session_by_id(&self, session_id: SessionId) -> Result<Self::Session> {
468✔
310
        let mut conn = self.pool.get().await?;
468✔
311

312
        let tx = conn.build_transaction().start().await?;
465✔
313

314
        let stmt = tx
464✔
315
            .prepare(
464✔
316
                "
464✔
317
            SELECT           
464✔
318
                project_id,
464✔
319
                view
464✔
320
            FROM sessions
464✔
321
            WHERE id = $1;",
464✔
322
            )
464✔
323
            .await?;
3,276✔
324

325
        let row = tx
464✔
326
            .query_one(&stmt, &[&session_id])
464✔
327
            .await
410✔
328
            .map_err(|_error| error::Error::InvalidSession)?;
464✔
329

330
        Ok(SimpleSession::new(session_id, row.get(0), row.get(1)))
464✔
331
    }
1,400✔
332
}
333

334
#[derive(Clone)]
×
335
pub struct PostgresSessionContext<Tls>
336
where
337
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
338
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
339
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
340
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
341
{
342
    session: SimpleSession,
343
    context: PostgresContext<Tls>,
344
}
345

346
#[async_trait]
347
impl<Tls> SessionContext for PostgresSessionContext<Tls>
348
where
349
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
350
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
351
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
352
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
353
{
354
    type Session = SimpleSession;
355
    type GeoEngineDB = PostgresDb<Tls>;
356

357
    type TaskContext = SimpleTaskManagerContext;
358
    type TaskManager = SimpleTaskManager; // this does not persist across restarts
359
    type QueryContext = QueryContextImpl;
360
    type ExecutionContext = ExecutionContextImpl<Self::GeoEngineDB>;
361

362
    fn db(&self) -> Self::GeoEngineDB {
538✔
363
        PostgresDb::new(self.context.pool.clone())
538✔
364
    }
538✔
365

366
    fn tasks(&self) -> Self::TaskManager {
40✔
367
        SimpleTaskManager::new(self.context.task_manager.clone())
40✔
368
    }
40✔
369

370
    fn query_context(&self) -> Result<Self::QueryContext> {
27✔
371
        Ok(QueryContextImpl::new(
27✔
372
            self.context.query_ctx_chunk_size,
27✔
373
            self.context.thread_pool.clone(),
27✔
374
        ))
27✔
375
    }
27✔
376

377
    fn execution_context(&self) -> Result<Self::ExecutionContext> {
46✔
378
        Ok(ExecutionContextImpl::<PostgresDb<Tls>>::new(
46✔
379
            self.db(),
46✔
380
            self.context.thread_pool.clone(),
46✔
381
            self.context.exe_ctx_tiling_spec,
46✔
382
        ))
46✔
383
    }
46✔
384

385
    fn volumes(&self) -> Result<Vec<Volume>> {
×
NEW
386
        Ok(self
×
NEW
387
            .context
×
NEW
388
            .volumes
×
NEW
389
            .volumes
×
NEW
390
            .iter()
×
NEW
391
            .map(|v| Volume {
×
NEW
392
                name: v.name.0.clone(),
×
NEW
393
                path: Some(v.path.to_string_lossy().to_string()),
×
NEW
394
            })
×
NEW
395
            .collect())
×
UNCOV
396
    }
×
397

398
    fn session(&self) -> &Self::Session {
113✔
399
        &self.session
113✔
400
    }
113✔
401
}
402

403
#[derive(Debug)]
×
404
pub struct PostgresDb<Tls>
405
where
406
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
407
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
408
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
409
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
410
{
411
    pub(crate) conn_pool: Pool<PostgresConnectionManager<Tls>>,
412
}
413

414
impl<Tls> PostgresDb<Tls>
415
where
416
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
417
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
418
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
419
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
420
{
421
    pub fn new(conn_pool: Pool<PostgresConnectionManager<Tls>>) -> Self {
540✔
422
        Self { conn_pool }
540✔
423
    }
540✔
424

425
    /// Check whether the namespace of the given dataset is allowed for insertion
426
    pub(crate) fn check_namespace(id: &DatasetName) -> Result<()> {
77✔
427
        // due to a lack of users, etc., we only allow one namespace for now
77✔
428
        if id.namespace.is_none() {
77✔
429
            Ok(())
77✔
430
        } else {
431
            Err(Error::InvalidDatasetIdNamespace)
×
432
        }
433
    }
77✔
434
}
435

436
impl<Tls> GeoEngineDb for PostgresDb<Tls>
437
where
438
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
439
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
440
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
441
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
442
{
443
}
444

445
impl TryFrom<config::Postgres> for Config {
446
    type Error = Error;
447

448
    fn try_from(db_config: config::Postgres) -> Result<Self> {
25✔
449
        ensure!(
25✔
450
            db_config.schema != "public",
25✔
451
            crate::error::InvalidDatabaseSchema
×
452
        );
453

454
        let mut pg_config = Config::new();
25✔
455
        pg_config
25✔
456
            .user(&db_config.user)
25✔
457
            .password(&db_config.password)
25✔
458
            .host(&db_config.host)
25✔
459
            .dbname(&db_config.database)
25✔
460
            .port(db_config.port)
25✔
461
            // fix schema by providing `search_path` option
25✔
462
            .options(&format!("-c search_path={}", db_config.schema));
25✔
463
        Ok(pg_config)
25✔
464
    }
25✔
465
}
466

467
#[cfg(test)]
468
mod tests {
469
    use super::*;
470
    use crate::datasets::external::aruna::ArunaDataProviderDefinition;
471
    use crate::datasets::external::gbif::{GbifDataProvider, GbifDataProviderDefinition};
472
    use crate::datasets::external::gfbio_abcd::GfbioAbcdDataProviderDefinition;
473
    use crate::datasets::external::gfbio_collections::GfbioCollectionsDataProviderDefinition;
474
    use crate::datasets::external::netcdfcf::{
475
        EbvPortalDataProviderDefinition, NetCdfCfDataProviderDefinition,
476
    };
477
    use crate::datasets::external::pangaea::PangaeaDataProviderDefinition;
478
    use crate::datasets::listing::{DatasetListOptions, DatasetListing, ProvenanceOutput};
479
    use crate::datasets::listing::{DatasetProvider, Provenance};
480
    use crate::datasets::storage::{DatasetStore, MetaDataDefinition};
481
    use crate::datasets::upload::{FileId, UploadId};
482
    use crate::datasets::upload::{FileUpload, Upload, UploadDb};
483
    use crate::datasets::{AddDataset, DatasetIdAndName};
484
    use crate::ge_context;
485
    use crate::layers::add_from_directory::UNSORTED_COLLECTION_ID;
486
    use crate::layers::external::TypedDataProviderDefinition;
487
    use crate::layers::layer::{
488
        AddLayer, AddLayerCollection, CollectionItem, LayerCollection, LayerCollectionListOptions,
489
        LayerCollectionListing, LayerListing, Property, ProviderLayerCollectionId, ProviderLayerId,
490
    };
491
    use crate::layers::listing::{
492
        LayerCollectionId, LayerCollectionProvider, SearchParameters, SearchType,
493
    };
494
    use crate::layers::storage::{
495
        LayerDb, LayerProviderDb, LayerProviderListing, LayerProviderListingOptions,
496
        INTERNAL_PROVIDER_ID,
497
    };
498
    use crate::projects::{
499
        ColorParam, CreateProject, DerivedColor, DerivedNumber, LayerUpdate, LineSymbology,
500
        LoadVersion, NumberParam, OrderBy, Plot, PlotUpdate, PointSymbology, PolygonSymbology,
501
        ProjectDb, ProjectId, ProjectLayer, ProjectListOptions, ProjectListing, RasterSymbology,
502
        STRectangle, StrokeParam, Symbology, TextSymbology, UpdateProject,
503
    };
504
    use crate::util::encryption::U96;
505
    use crate::util::postgres::{assert_sql_type, DatabaseConnectionConfig};
506
    use crate::util::tests::register_ndvi_workflow_helper;
507
    use crate::workflows::registry::WorkflowRegistry;
508
    use crate::workflows::workflow::Workflow;
509
    use aes_gcm::aead::generic_array::arr;
510
    use bb8_postgres::tokio_postgres::NoTls;
511
    use futures::join;
512
    use geoengine_datatypes::collections::VectorDataType;
513
    use geoengine_datatypes::dataset::{DataProviderId, LayerId};
514
    use geoengine_datatypes::operations::image::{
515
        Breakpoint, Colorizer, RasterColorizer, RgbaColor,
516
    };
517
    use geoengine_datatypes::primitives::{
518
        BoundingBox2D, ClassificationMeasurement, ColumnSelection, ContinuousMeasurement,
519
        Coordinate2D, DateTimeParseFormat, FeatureDataType, MultiLineString, MultiPoint,
520
        MultiPolygon, NoGeometry, RasterQueryRectangle, SpatialPartition2D, SpatialResolution,
521
        TimeGranularity, TimeInstance, TimeInterval, TimeStep, TypedGeometry, VectorQueryRectangle,
522
    };
523
    use geoengine_datatypes::primitives::{CacheTtlSeconds, Measurement};
524
    use geoengine_datatypes::raster::{
525
        RasterDataType, RasterPropertiesEntryType, RasterPropertiesKey,
526
    };
527
    use geoengine_datatypes::spatial_reference::{SpatialReference, SpatialReferenceOption};
528
    use geoengine_datatypes::test_data;
529
    use geoengine_datatypes::util::{NotNanF64, StringPair};
530
    use geoengine_operators::engine::{
531
        MetaData, MetaDataProvider, MultipleRasterOrSingleVectorSource, PlotOperator,
532
        PlotResultDescriptor, RasterBandDescriptor, RasterBandDescriptors, RasterResultDescriptor,
533
        StaticMetaData, TypedOperator, TypedResultDescriptor, VectorColumnInfo, VectorOperator,
534
        VectorResultDescriptor,
535
    };
536
    use geoengine_operators::mock::{
537
        MockDatasetDataSourceLoadingInfo, MockPointSource, MockPointSourceParams,
538
    };
539
    use geoengine_operators::plot::{Statistics, StatisticsParams};
540
    use geoengine_operators::source::{
541
        CsvHeader, FileNotFoundHandling, FormatSpecifics, GdalDatasetGeoTransform,
542
        GdalDatasetParameters, GdalLoadingInfo, GdalLoadingInfoTemporalSlice, GdalMetaDataList,
543
        GdalMetaDataRegular, GdalMetaDataStatic, GdalMetadataMapping, GdalMetadataNetCdfCf,
544
        GdalRetryOptions, GdalSourceTimePlaceholder, OgrSourceColumnSpec, OgrSourceDataset,
545
        OgrSourceDatasetTimeType, OgrSourceDurationSpec, OgrSourceErrorSpec, OgrSourceTimeFormat,
546
        TimeReference, UnixTimeStampType,
547
    };
548
    use geoengine_operators::util::input::MultiRasterOrVectorOperator::Raster;
549
    use ordered_float::NotNan;
550
    use serde_json::json;
551
    use std::marker::PhantomData;
552
    use std::str::FromStr;
553
    use tokio_postgres::config::Host;
554

555
    #[ge_context::test]
3✔
556
    async fn test(app_ctx: PostgresContext<NoTls>) {
1✔
557
        let session = app_ctx.default_session().await.unwrap();
18✔
558

1✔
559
        create_projects(&app_ctx, &session).await;
74✔
560

561
        let projects = list_projects(&app_ctx, &session).await;
13✔
562

563
        let project_id = projects[0].id;
1✔
564

1✔
565
        update_projects(&app_ctx, &session, project_id).await;
169✔
566

567
        delete_project(&app_ctx, &session, project_id).await;
7✔
568
    }
1✔
569

570
    async fn delete_project(
1✔
571
        app_ctx: &PostgresContext<NoTls>,
1✔
572
        session: &SimpleSession,
1✔
573
        project_id: ProjectId,
1✔
574
    ) {
1✔
575
        let db = app_ctx.session_context(session.clone()).db();
1✔
576

1✔
577
        db.delete_project(project_id).await.unwrap();
3✔
578

1✔
579
        assert!(db.load_project(project_id).await.is_err());
4✔
580
    }
1✔
581

582
    #[allow(clippy::too_many_lines)]
583
    async fn update_projects(
1✔
584
        app_ctx: &PostgresContext<NoTls>,
1✔
585
        session: &SimpleSession,
1✔
586
        project_id: ProjectId,
1✔
587
    ) {
1✔
588
        let db = app_ctx.session_context(session.clone()).db();
1✔
589

590
        let project = db
1✔
591
            .load_project_version(project_id, LoadVersion::Latest)
1✔
592
            .await
41✔
593
            .unwrap();
1✔
594

595
        let layer_workflow_id = db
1✔
596
            .register_workflow(Workflow {
1✔
597
                operator: TypedOperator::Vector(
1✔
598
                    MockPointSource {
1✔
599
                        params: MockPointSourceParams {
1✔
600
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
601
                        },
1✔
602
                    }
1✔
603
                    .boxed(),
1✔
604
                ),
1✔
605
            })
1✔
606
            .await
3✔
607
            .unwrap();
1✔
608

1✔
609
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
3✔
610

611
        let plot_workflow_id = db
1✔
612
            .register_workflow(Workflow {
1✔
613
                operator: Statistics {
1✔
614
                    params: StatisticsParams {
1✔
615
                        column_names: vec![],
1✔
616
                        percentiles: vec![],
1✔
617
                    },
1✔
618
                    sources: MultipleRasterOrSingleVectorSource {
1✔
619
                        source: Raster(vec![]),
1✔
620
                    },
1✔
621
                }
1✔
622
                .boxed()
1✔
623
                .into(),
1✔
624
            })
1✔
625
            .await
3✔
626
            .unwrap();
1✔
627

1✔
628
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
3✔
629

630
        // add a plot
631
        let update = UpdateProject {
1✔
632
            id: project.id,
1✔
633
            name: Some("Test9 Updated".into()),
1✔
634
            description: None,
1✔
635
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
636
                workflow: layer_workflow_id,
1✔
637
                name: "TestLayer".into(),
1✔
638
                symbology: PointSymbology::default().into(),
1✔
639
                visibility: Default::default(),
1✔
640
            })]),
1✔
641
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
642
                workflow: plot_workflow_id,
1✔
643
                name: "Test Plot".into(),
1✔
644
            })]),
1✔
645
            bounds: None,
1✔
646
            time_step: None,
1✔
647
        };
1✔
648
        db.update_project(update).await.unwrap();
70✔
649

650
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
651
        assert_eq!(versions.len(), 2);
1✔
652

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

679
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
680
        assert_eq!(versions.len(), 3);
1✔
681

682
        // delete plots
683
        let update = UpdateProject {
1✔
684
            id: project.id,
1✔
685
            name: None,
1✔
686
            description: None,
1✔
687
            layers: None,
1✔
688
            plots: Some(vec![]),
1✔
689
            bounds: None,
1✔
690
            time_step: None,
1✔
691
        };
1✔
692
        db.update_project(update).await.unwrap();
17✔
693

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

698
    async fn list_projects(
1✔
699
        app_ctx: &PostgresContext<NoTls>,
1✔
700
        session: &SimpleSession,
1✔
701
    ) -> Vec<ProjectListing> {
1✔
702
        let options = ProjectListOptions {
1✔
703
            order: OrderBy::NameDesc,
1✔
704
            offset: 0,
1✔
705
            limit: 2,
1✔
706
        };
1✔
707

1✔
708
        let db = app_ctx.session_context(session.clone()).db();
1✔
709

710
        let projects = db.list_projects(options).await.unwrap();
13✔
711

1✔
712
        assert_eq!(projects.len(), 2);
1✔
713
        assert_eq!(projects[0].name, "Test9");
1✔
714
        assert_eq!(projects[1].name, "Test8");
1✔
715
        projects
1✔
716
    }
1✔
717

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

721
        for i in 0..10 {
11✔
722
            let create = CreateProject {
10✔
723
                name: format!("Test{i}"),
10✔
724
                description: format!("Test{}", 10 - i),
10✔
725
                bounds: STRectangle::new(
10✔
726
                    SpatialReferenceOption::Unreferenced,
10✔
727
                    0.,
10✔
728
                    0.,
10✔
729
                    1.,
10✔
730
                    1.,
10✔
731
                    0,
10✔
732
                    1,
10✔
733
                )
10✔
734
                .unwrap(),
10✔
735
                time_step: None,
10✔
736
            };
10✔
737
            db.create_project(create).await.unwrap();
74✔
738
        }
739
    }
1✔
740

741
    #[ge_context::test]
3✔
742
    async fn it_persists_workflows(app_ctx: PostgresContext<NoTls>) {
1✔
743
        let workflow = Workflow {
1✔
744
            operator: TypedOperator::Vector(
1✔
745
                MockPointSource {
1✔
746
                    params: MockPointSourceParams {
1✔
747
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
748
                    },
1✔
749
                }
1✔
750
                .boxed(),
1✔
751
            ),
1✔
752
        };
1✔
753

754
        let session = app_ctx.default_session().await.unwrap();
18✔
755
        let ctx = app_ctx.session_context(session);
1✔
756

1✔
757
        let db = ctx.db();
1✔
758
        let id = db.register_workflow(workflow).await.unwrap();
3✔
759

1✔
760
        drop(ctx);
1✔
761

762
        let workflow = db.load_workflow(&id).await.unwrap();
3✔
763

1✔
764
        let json = serde_json::to_string(&workflow).unwrap();
1✔
765
        assert_eq!(
1✔
766
            json,
1✔
767
            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✔
768
        );
1✔
769
    }
1✔
770

771
    #[allow(clippy::too_many_lines)]
772
    #[ge_context::test]
3✔
773
    async fn it_persists_datasets(app_ctx: PostgresContext<NoTls>) {
1✔
774
        let loading_info = OgrSourceDataset {
1✔
775
            file_name: PathBuf::from("test.csv"),
1✔
776
            layer_name: "test.csv".to_owned(),
1✔
777
            data_type: Some(VectorDataType::MultiPoint),
1✔
778
            time: OgrSourceDatasetTimeType::Start {
1✔
779
                start_field: "start".to_owned(),
1✔
780
                start_format: OgrSourceTimeFormat::Auto,
1✔
781
                duration: OgrSourceDurationSpec::Zero,
1✔
782
            },
1✔
783
            default_geometry: None,
1✔
784
            columns: Some(OgrSourceColumnSpec {
1✔
785
                format_specifics: Some(FormatSpecifics::Csv {
1✔
786
                    header: CsvHeader::Auto,
1✔
787
                }),
1✔
788
                x: "x".to_owned(),
1✔
789
                y: None,
1✔
790
                int: vec![],
1✔
791
                float: vec![],
1✔
792
                text: vec![],
1✔
793
                bool: vec![],
1✔
794
                datetime: vec![],
1✔
795
                rename: None,
1✔
796
            }),
1✔
797
            force_ogr_time_filter: false,
1✔
798
            force_ogr_spatial_filter: false,
1✔
799
            on_error: OgrSourceErrorSpec::Ignore,
1✔
800
            sql_query: None,
1✔
801
            attribute_query: None,
1✔
802
            cache_ttl: CacheTtlSeconds::default(),
1✔
803
        };
1✔
804

1✔
805
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
806
            OgrSourceDataset,
1✔
807
            VectorResultDescriptor,
1✔
808
            VectorQueryRectangle,
1✔
809
        > {
1✔
810
            loading_info: loading_info.clone(),
1✔
811
            result_descriptor: VectorResultDescriptor {
1✔
812
                data_type: VectorDataType::MultiPoint,
1✔
813
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
814
                columns: [(
1✔
815
                    "foo".to_owned(),
1✔
816
                    VectorColumnInfo {
1✔
817
                        data_type: FeatureDataType::Float,
1✔
818
                        measurement: Measurement::Unitless,
1✔
819
                    },
1✔
820
                )]
1✔
821
                .into_iter()
1✔
822
                .collect(),
1✔
823
                time: None,
1✔
824
                bbox: None,
1✔
825
            },
1✔
826
            phantom: Default::default(),
1✔
827
        });
1✔
828

829
        let session = app_ctx.default_session().await.unwrap();
18✔
830

1✔
831
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
832

1✔
833
        let db = app_ctx.session_context(session.clone()).db();
1✔
834
        let DatasetIdAndName {
835
            id: dataset_id,
1✔
836
            name: dataset_name,
1✔
837
        } = db
1✔
838
            .add_dataset(
1✔
839
                AddDataset {
1✔
840
                    name: Some(dataset_name.clone()),
1✔
841
                    display_name: "Ogr Test".to_owned(),
1✔
842
                    description: "desc".to_owned(),
1✔
843
                    source_operator: "OgrSource".to_owned(),
1✔
844
                    symbology: None,
1✔
845
                    provenance: Some(vec![Provenance {
1✔
846
                        citation: "citation".to_owned(),
1✔
847
                        license: "license".to_owned(),
1✔
848
                        uri: "uri".to_owned(),
1✔
849
                    }]),
1✔
850
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
851
                },
1✔
852
                meta_data,
1✔
853
            )
1✔
854
            .await
162✔
855
            .unwrap();
1✔
856

857
        let datasets = db
1✔
858
            .list_datasets(DatasetListOptions {
1✔
859
                filter: None,
1✔
860
                order: crate::datasets::listing::OrderBy::NameAsc,
1✔
861
                offset: 0,
1✔
862
                limit: 10,
1✔
863
                tags: None,
1✔
864
            })
1✔
865
            .await
3✔
866
            .unwrap();
1✔
867

1✔
868
        assert_eq!(datasets.len(), 1);
1✔
869

870
        assert_eq!(
1✔
871
            datasets[0],
1✔
872
            DatasetListing {
1✔
873
                id: dataset_id,
1✔
874
                name: dataset_name,
1✔
875
                display_name: "Ogr Test".to_owned(),
1✔
876
                description: "desc".to_owned(),
1✔
877
                source_operator: "OgrSource".to_owned(),
1✔
878
                symbology: None,
1✔
879
                tags: vec!["upload".to_owned(), "test".to_owned()],
1✔
880
                result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
881
                    data_type: VectorDataType::MultiPoint,
1✔
882
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
883
                    columns: [(
1✔
884
                        "foo".to_owned(),
1✔
885
                        VectorColumnInfo {
1✔
886
                            data_type: FeatureDataType::Float,
1✔
887
                            measurement: Measurement::Unitless
1✔
888
                        }
1✔
889
                    )]
1✔
890
                    .into_iter()
1✔
891
                    .collect(),
1✔
892
                    time: None,
1✔
893
                    bbox: None,
1✔
894
                })
1✔
895
            },
1✔
896
        );
1✔
897

898
        let provenance = db.load_provenance(&dataset_id).await.unwrap();
4✔
899

1✔
900
        assert_eq!(
1✔
901
            provenance,
1✔
902
            ProvenanceOutput {
1✔
903
                data: dataset_id.into(),
1✔
904
                provenance: Some(vec![Provenance {
1✔
905
                    citation: "citation".to_owned(),
1✔
906
                    license: "license".to_owned(),
1✔
907
                    uri: "uri".to_owned(),
1✔
908
                }])
1✔
909
            }
1✔
910
        );
1✔
911

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

1✔
915
        assert_eq!(
1✔
916
            meta_data
1✔
917
                .loading_info(VectorQueryRectangle {
1✔
918
                    spatial_bounds: BoundingBox2D::new_unchecked(
1✔
919
                        (-180., -90.).into(),
1✔
920
                        (180., 90.).into()
1✔
921
                    ),
1✔
922
                    time_interval: TimeInterval::default(),
1✔
923
                    spatial_resolution: SpatialResolution::zero_point_one(),
1✔
924
                    attributes: ColumnSelection::all()
1✔
925
                })
1✔
926
                .await
×
927
                .unwrap(),
1✔
928
            loading_info
929
        );
930
    }
1✔
931

932
    #[ge_context::test]
3✔
933
    async fn it_persists_uploads(app_ctx: PostgresContext<NoTls>) {
1✔
934
        let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
935
        let input = Upload {
1✔
936
            id,
1✔
937
            files: vec![FileUpload {
1✔
938
                id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
939
                name: "test.csv".to_owned(),
1✔
940
                byte_size: 1337,
1✔
941
            }],
1✔
942
        };
1✔
943

944
        let session = app_ctx.default_session().await.unwrap();
18✔
945

1✔
946
        let db = app_ctx.session_context(session.clone()).db();
1✔
947

1✔
948
        db.create_upload(input.clone()).await.unwrap();
6✔
949

950
        let upload = db.load_upload(id).await.unwrap();
3✔
951

1✔
952
        assert_eq!(upload, input);
1✔
953
    }
1✔
954

955
    #[allow(clippy::too_many_lines)]
956
    #[ge_context::test]
3✔
957
    async fn it_persists_layer_providers(app_ctx: PostgresContext<NoTls>) {
1✔
958
        let db = app_ctx.default_session_context().await.unwrap().db();
19✔
959

1✔
960
        let provider = NetCdfCfDataProviderDefinition {
1✔
961
            name: "netcdfcf".to_string(),
1✔
962
            description: "NetCdfCfProviderDefinition".to_string(),
1✔
963
            priority: Some(21),
1✔
964
            data: test_data!("netcdf4d/").into(),
1✔
965
            overviews: test_data!("netcdf4d/overviews/").into(),
1✔
966
            cache_ttl: CacheTtlSeconds::new(0),
1✔
967
        };
1✔
968

969
        let provider_id = db.add_layer_provider(provider.into()).await.unwrap();
33✔
970

971
        let providers = db
1✔
972
            .list_layer_providers(LayerProviderListingOptions {
1✔
973
                offset: 0,
1✔
974
                limit: 10,
1✔
975
            })
1✔
976
            .await
3✔
977
            .unwrap();
1✔
978

1✔
979
        assert_eq!(providers.len(), 1);
1✔
980

981
        assert_eq!(
1✔
982
            providers[0],
1✔
983
            LayerProviderListing {
1✔
984
                id: provider_id,
1✔
985
                name: "netcdfcf".to_owned(),
1✔
986
                priority: 21,
1✔
987
            }
1✔
988
        );
1✔
989

990
        let provider = db.load_layer_provider(provider_id).await.unwrap();
3✔
991

992
        let datasets = provider
1✔
993
            .load_layer_collection(
1✔
994
                &provider.get_root_layer_collection_id().await.unwrap(),
1✔
995
                LayerCollectionListOptions {
1✔
996
                    offset: 0,
1✔
997
                    limit: 10,
1✔
998
                },
1✔
999
            )
1000
            .await
5✔
1001
            .unwrap();
1✔
1002

1✔
1003
        assert_eq!(datasets.items.len(), 5, "{:?}", datasets.items);
1✔
1004
    }
1✔
1005

1006
    #[allow(clippy::too_many_lines)]
1007
    #[ge_context::test]
3✔
1008
    async fn it_loads_all_meta_data_types(app_ctx: PostgresContext<NoTls>) {
1✔
1009
        let session = app_ctx.default_session().await.unwrap();
18✔
1010

1✔
1011
        let db = app_ctx.session_context(session.clone()).db();
1✔
1012

1✔
1013
        let vector_descriptor = VectorResultDescriptor {
1✔
1014
            data_type: VectorDataType::Data,
1✔
1015
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1016
            columns: Default::default(),
1✔
1017
            time: None,
1✔
1018
            bbox: None,
1✔
1019
        };
1✔
1020

1✔
1021
        let raster_descriptor = RasterResultDescriptor {
1✔
1022
            data_type: RasterDataType::U8,
1✔
1023
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1024
            time: None,
1✔
1025
            bbox: None,
1✔
1026
            resolution: None,
1✔
1027
            bands: RasterBandDescriptors::new_single_band(),
1✔
1028
        };
1✔
1029

1✔
1030
        let vector_ds = AddDataset {
1✔
1031
            name: None,
1✔
1032
            display_name: "OgrDataset".to_string(),
1✔
1033
            description: "My Ogr dataset".to_string(),
1✔
1034
            source_operator: "OgrSource".to_string(),
1✔
1035
            symbology: None,
1✔
1036
            provenance: None,
1✔
1037
            tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
1038
        };
1✔
1039

1✔
1040
        let raster_ds = AddDataset {
1✔
1041
            name: None,
1✔
1042
            display_name: "GdalDataset".to_string(),
1✔
1043
            description: "My Gdal dataset".to_string(),
1✔
1044
            source_operator: "GdalSource".to_string(),
1✔
1045
            symbology: None,
1✔
1046
            provenance: None,
1✔
1047
            tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
1048
        };
1✔
1049

1✔
1050
        let gdal_params = GdalDatasetParameters {
1✔
1051
            file_path: Default::default(),
1✔
1052
            rasterband_channel: 0,
1✔
1053
            geo_transform: GdalDatasetGeoTransform {
1✔
1054
                origin_coordinate: Default::default(),
1✔
1055
                x_pixel_size: 0.0,
1✔
1056
                y_pixel_size: 0.0,
1✔
1057
            },
1✔
1058
            width: 0,
1✔
1059
            height: 0,
1✔
1060
            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1061
            no_data_value: None,
1✔
1062
            properties_mapping: None,
1✔
1063
            gdal_open_options: None,
1✔
1064
            gdal_config_options: None,
1✔
1065
            allow_alphaband_as_mask: false,
1✔
1066
            retry: None,
1✔
1067
        };
1✔
1068

1✔
1069
        let meta = StaticMetaData {
1✔
1070
            loading_info: OgrSourceDataset {
1✔
1071
                file_name: Default::default(),
1✔
1072
                layer_name: String::new(),
1✔
1073
                data_type: None,
1✔
1074
                time: Default::default(),
1✔
1075
                default_geometry: None,
1✔
1076
                columns: None,
1✔
1077
                force_ogr_time_filter: false,
1✔
1078
                force_ogr_spatial_filter: false,
1✔
1079
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1080
                sql_query: None,
1✔
1081
                attribute_query: None,
1✔
1082
                cache_ttl: CacheTtlSeconds::default(),
1✔
1083
            },
1✔
1084
            result_descriptor: vector_descriptor.clone(),
1✔
1085
            phantom: Default::default(),
1✔
1086
        };
1✔
1087

1088
        let id = db.add_dataset(vector_ds, meta.into()).await.unwrap().id;
159✔
1089

1090
        let meta: geoengine_operators::util::Result<
1✔
1091
            Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1092
        > = db.meta_data(&id.into()).await;
3✔
1093

1094
        assert!(meta.is_ok());
1✔
1095

1096
        let meta = GdalMetaDataRegular {
1✔
1097
            result_descriptor: raster_descriptor.clone(),
1✔
1098
            params: gdal_params.clone(),
1✔
1099
            time_placeholders: Default::default(),
1✔
1100
            data_time: Default::default(),
1✔
1101
            step: TimeStep {
1✔
1102
                granularity: TimeGranularity::Millis,
1✔
1103
                step: 0,
1✔
1104
            },
1✔
1105
            cache_ttl: CacheTtlSeconds::default(),
1✔
1106
        };
1✔
1107

1108
        let id = db
1✔
1109
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1110
            .await
5✔
1111
            .unwrap()
1✔
1112
            .id;
1113

1114
        let meta: geoengine_operators::util::Result<
1✔
1115
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1116
        > = db.meta_data(&id.into()).await;
3✔
1117

1118
        assert!(meta.is_ok());
1✔
1119

1120
        let meta = GdalMetaDataStatic {
1✔
1121
            time: None,
1✔
1122
            params: gdal_params.clone(),
1✔
1123
            result_descriptor: raster_descriptor.clone(),
1✔
1124
            cache_ttl: CacheTtlSeconds::default(),
1✔
1125
        };
1✔
1126

1127
        let id = db
1✔
1128
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1129
            .await
5✔
1130
            .unwrap()
1✔
1131
            .id;
1132

1133
        let meta: geoengine_operators::util::Result<
1✔
1134
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1135
        > = db.meta_data(&id.into()).await;
3✔
1136

1137
        assert!(meta.is_ok());
1✔
1138

1139
        let meta = GdalMetaDataList {
1✔
1140
            result_descriptor: raster_descriptor.clone(),
1✔
1141
            params: vec![],
1✔
1142
        };
1✔
1143

1144
        let id = db
1✔
1145
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1146
            .await
5✔
1147
            .unwrap()
1✔
1148
            .id;
1149

1150
        let meta: geoengine_operators::util::Result<
1✔
1151
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1152
        > = db.meta_data(&id.into()).await;
3✔
1153

1154
        assert!(meta.is_ok());
1✔
1155

1156
        let meta = GdalMetadataNetCdfCf {
1✔
1157
            result_descriptor: raster_descriptor.clone(),
1✔
1158
            params: gdal_params.clone(),
1✔
1159
            start: TimeInstance::MIN,
1✔
1160
            end: TimeInstance::MAX,
1✔
1161
            step: TimeStep {
1✔
1162
                granularity: TimeGranularity::Millis,
1✔
1163
                step: 0,
1✔
1164
            },
1✔
1165
            band_offset: 0,
1✔
1166
            cache_ttl: CacheTtlSeconds::default(),
1✔
1167
        };
1✔
1168

1169
        let id = db
1✔
1170
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1171
            .await
5✔
1172
            .unwrap()
1✔
1173
            .id;
1174

1175
        let meta: geoengine_operators::util::Result<
1✔
1176
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1177
        > = db.meta_data(&id.into()).await;
3✔
1178

1179
        assert!(meta.is_ok());
1✔
1180
    }
1✔
1181

1182
    #[allow(clippy::too_many_lines)]
1183
    #[ge_context::test]
3✔
1184
    async fn it_collects_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1185
        let session = app_ctx.default_session().await.unwrap();
18✔
1186

1✔
1187
        let layer_db = app_ctx.session_context(session).db();
1✔
1188

1✔
1189
        let workflow = Workflow {
1✔
1190
            operator: TypedOperator::Vector(
1✔
1191
                MockPointSource {
1✔
1192
                    params: MockPointSourceParams {
1✔
1193
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1194
                    },
1✔
1195
                }
1✔
1196
                .boxed(),
1✔
1197
            ),
1✔
1198
        };
1✔
1199

1200
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1201

1202
        let layer1 = layer_db
1✔
1203
            .add_layer(
1✔
1204
                AddLayer {
1✔
1205
                    name: "Layer1".to_string(),
1✔
1206
                    description: "Layer 1".to_string(),
1✔
1207
                    symbology: None,
1✔
1208
                    workflow: workflow.clone(),
1✔
1209
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1210
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1211
                },
1✔
1212
                &root_collection_id,
1✔
1213
            )
1✔
1214
            .await
45✔
1215
            .unwrap();
1✔
1216

1✔
1217
        assert_eq!(
1✔
1218
            layer_db.load_layer(&layer1).await.unwrap(),
3✔
1219
            crate::layers::layer::Layer {
1✔
1220
                id: ProviderLayerId {
1✔
1221
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1222
                    layer_id: layer1.clone(),
1✔
1223
                },
1✔
1224
                name: "Layer1".to_string(),
1✔
1225
                description: "Layer 1".to_string(),
1✔
1226
                symbology: None,
1✔
1227
                workflow: workflow.clone(),
1✔
1228
                metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1229
                properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1230
            }
1✔
1231
        );
1232

1233
        let collection1_id = layer_db
1✔
1234
            .add_layer_collection(
1✔
1235
                AddLayerCollection {
1✔
1236
                    name: "Collection1".to_string(),
1✔
1237
                    description: "Collection 1".to_string(),
1✔
1238
                    properties: Default::default(),
1✔
1239
                },
1✔
1240
                &root_collection_id,
1✔
1241
            )
1✔
1242
            .await
7✔
1243
            .unwrap();
1✔
1244

1245
        let layer2 = layer_db
1✔
1246
            .add_layer(
1✔
1247
                AddLayer {
1✔
1248
                    name: "Layer2".to_string(),
1✔
1249
                    description: "Layer 2".to_string(),
1✔
1250
                    symbology: None,
1✔
1251
                    workflow: workflow.clone(),
1✔
1252
                    metadata: Default::default(),
1✔
1253
                    properties: Default::default(),
1✔
1254
                },
1✔
1255
                &collection1_id,
1✔
1256
            )
1✔
1257
            .await
9✔
1258
            .unwrap();
1✔
1259

1260
        let collection2_id = layer_db
1✔
1261
            .add_layer_collection(
1✔
1262
                AddLayerCollection {
1✔
1263
                    name: "Collection2".to_string(),
1✔
1264
                    description: "Collection 2".to_string(),
1✔
1265
                    properties: Default::default(),
1✔
1266
                },
1✔
1267
                &collection1_id,
1✔
1268
            )
1✔
1269
            .await
7✔
1270
            .unwrap();
1✔
1271

1✔
1272
        layer_db
1✔
1273
            .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1274
            .await
3✔
1275
            .unwrap();
1✔
1276

1277
        let root_collection = layer_db
1✔
1278
            .load_layer_collection(
1✔
1279
                &root_collection_id,
1✔
1280
                LayerCollectionListOptions {
1✔
1281
                    offset: 0,
1✔
1282
                    limit: 20,
1✔
1283
                },
1✔
1284
            )
1✔
1285
            .await
5✔
1286
            .unwrap();
1✔
1287

1✔
1288
        assert_eq!(
1✔
1289
            root_collection,
1✔
1290
            LayerCollection {
1✔
1291
                id: ProviderLayerCollectionId {
1✔
1292
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1293
                    collection_id: root_collection_id,
1✔
1294
                },
1✔
1295
                name: "Layers".to_string(),
1✔
1296
                description: "All available Geo Engine layers".to_string(),
1✔
1297
                items: vec![
1✔
1298
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1299
                        id: ProviderLayerCollectionId {
1✔
1300
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1301
                            collection_id: collection1_id.clone(),
1✔
1302
                        },
1✔
1303
                        name: "Collection1".to_string(),
1✔
1304
                        description: "Collection 1".to_string(),
1✔
1305
                        properties: Default::default(),
1✔
1306
                    }),
1✔
1307
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1308
                        id: ProviderLayerCollectionId {
1✔
1309
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1310
                            collection_id: LayerCollectionId(UNSORTED_COLLECTION_ID.to_string()),
1✔
1311
                        },
1✔
1312
                        name: "Unsorted".to_string(),
1✔
1313
                        description: "Unsorted Layers".to_string(),
1✔
1314
                        properties: Default::default(),
1✔
1315
                    }),
1✔
1316
                    CollectionItem::Layer(LayerListing {
1✔
1317
                        id: ProviderLayerId {
1✔
1318
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1319
                            layer_id: layer1,
1✔
1320
                        },
1✔
1321
                        name: "Layer1".to_string(),
1✔
1322
                        description: "Layer 1".to_string(),
1✔
1323
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1324
                    })
1✔
1325
                ],
1✔
1326
                entry_label: None,
1✔
1327
                properties: vec![],
1✔
1328
            }
1✔
1329
        );
1✔
1330

1331
        let collection1 = layer_db
1✔
1332
            .load_layer_collection(
1✔
1333
                &collection1_id,
1✔
1334
                LayerCollectionListOptions {
1✔
1335
                    offset: 0,
1✔
1336
                    limit: 20,
1✔
1337
                },
1✔
1338
            )
1✔
1339
            .await
5✔
1340
            .unwrap();
1✔
1341

1✔
1342
        assert_eq!(
1✔
1343
            collection1,
1✔
1344
            LayerCollection {
1✔
1345
                id: ProviderLayerCollectionId {
1✔
1346
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1347
                    collection_id: collection1_id,
1✔
1348
                },
1✔
1349
                name: "Collection1".to_string(),
1✔
1350
                description: "Collection 1".to_string(),
1✔
1351
                items: vec![
1✔
1352
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1353
                        id: ProviderLayerCollectionId {
1✔
1354
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1355
                            collection_id: collection2_id,
1✔
1356
                        },
1✔
1357
                        name: "Collection2".to_string(),
1✔
1358
                        description: "Collection 2".to_string(),
1✔
1359
                        properties: Default::default(),
1✔
1360
                    }),
1✔
1361
                    CollectionItem::Layer(LayerListing {
1✔
1362
                        id: ProviderLayerId {
1✔
1363
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1364
                            layer_id: layer2,
1✔
1365
                        },
1✔
1366
                        name: "Layer2".to_string(),
1✔
1367
                        description: "Layer 2".to_string(),
1✔
1368
                        properties: vec![],
1✔
1369
                    })
1✔
1370
                ],
1✔
1371
                entry_label: None,
1✔
1372
                properties: vec![],
1✔
1373
            }
1✔
1374
        );
1✔
1375
    }
1✔
1376

1377
    #[allow(clippy::too_many_lines)]
1378
    #[ge_context::test]
3✔
1379
    async fn it_searches_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1380
        let session = app_ctx.default_session().await.unwrap();
18✔
1381

1✔
1382
        let layer_db = app_ctx.session_context(session).db();
1✔
1383

1✔
1384
        let workflow = Workflow {
1✔
1385
            operator: TypedOperator::Vector(
1✔
1386
                MockPointSource {
1✔
1387
                    params: MockPointSourceParams {
1✔
1388
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1389
                    },
1✔
1390
                }
1✔
1391
                .boxed(),
1✔
1392
            ),
1✔
1393
        };
1✔
1394

1395
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1396

1397
        let layer1 = layer_db
1✔
1398
            .add_layer(
1✔
1399
                AddLayer {
1✔
1400
                    name: "Layer1".to_string(),
1✔
1401
                    description: "Layer 1".to_string(),
1✔
1402
                    symbology: None,
1✔
1403
                    workflow: workflow.clone(),
1✔
1404
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1405
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1406
                },
1✔
1407
                &root_collection_id,
1✔
1408
            )
1✔
1409
            .await
45✔
1410
            .unwrap();
1✔
1411

1412
        let collection1_id = layer_db
1✔
1413
            .add_layer_collection(
1✔
1414
                AddLayerCollection {
1✔
1415
                    name: "Collection1".to_string(),
1✔
1416
                    description: "Collection 1".to_string(),
1✔
1417
                    properties: Default::default(),
1✔
1418
                },
1✔
1419
                &root_collection_id,
1✔
1420
            )
1✔
1421
            .await
7✔
1422
            .unwrap();
1✔
1423

1424
        let layer2 = layer_db
1✔
1425
            .add_layer(
1✔
1426
                AddLayer {
1✔
1427
                    name: "Layer2".to_string(),
1✔
1428
                    description: "Layer 2".to_string(),
1✔
1429
                    symbology: None,
1✔
1430
                    workflow: workflow.clone(),
1✔
1431
                    metadata: Default::default(),
1✔
1432
                    properties: Default::default(),
1✔
1433
                },
1✔
1434
                &collection1_id,
1✔
1435
            )
1✔
1436
            .await
9✔
1437
            .unwrap();
1✔
1438

1439
        let collection2_id = layer_db
1✔
1440
            .add_layer_collection(
1✔
1441
                AddLayerCollection {
1✔
1442
                    name: "Collection2".to_string(),
1✔
1443
                    description: "Collection 2".to_string(),
1✔
1444
                    properties: Default::default(),
1✔
1445
                },
1✔
1446
                &collection1_id,
1✔
1447
            )
1✔
1448
            .await
7✔
1449
            .unwrap();
1✔
1450

1451
        let root_collection_all = layer_db
1✔
1452
            .search(
1✔
1453
                &root_collection_id,
1✔
1454
                SearchParameters {
1✔
1455
                    search_type: SearchType::Fulltext,
1✔
1456
                    search_string: String::new(),
1✔
1457
                    limit: 10,
1✔
1458
                    offset: 0,
1✔
1459
                },
1✔
1460
            )
1✔
1461
            .await
5✔
1462
            .unwrap();
1✔
1463

1✔
1464
        assert_eq!(
1✔
1465
            root_collection_all,
1✔
1466
            LayerCollection {
1✔
1467
                id: ProviderLayerCollectionId {
1✔
1468
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1469
                    collection_id: root_collection_id.clone(),
1✔
1470
                },
1✔
1471
                name: "Layers".to_string(),
1✔
1472
                description: "All available Geo Engine layers".to_string(),
1✔
1473
                items: vec![
1✔
1474
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1475
                        id: ProviderLayerCollectionId {
1✔
1476
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1477
                            collection_id: collection1_id.clone(),
1✔
1478
                        },
1✔
1479
                        name: "Collection1".to_string(),
1✔
1480
                        description: "Collection 1".to_string(),
1✔
1481
                        properties: Default::default(),
1✔
1482
                    }),
1✔
1483
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1484
                        id: ProviderLayerCollectionId {
1✔
1485
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1486
                            collection_id: collection2_id.clone(),
1✔
1487
                        },
1✔
1488
                        name: "Collection2".to_string(),
1✔
1489
                        description: "Collection 2".to_string(),
1✔
1490
                        properties: Default::default(),
1✔
1491
                    }),
1✔
1492
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1493
                        id: ProviderLayerCollectionId {
1✔
1494
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1495
                            collection_id: LayerCollectionId(
1✔
1496
                                "ffb2dd9e-f5ad-427c-b7f1-c9a0c7a0ae3f".to_string()
1✔
1497
                            ),
1✔
1498
                        },
1✔
1499
                        name: "Unsorted".to_string(),
1✔
1500
                        description: "Unsorted Layers".to_string(),
1✔
1501
                        properties: Default::default(),
1✔
1502
                    }),
1✔
1503
                    CollectionItem::Layer(LayerListing {
1✔
1504
                        id: ProviderLayerId {
1✔
1505
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1506
                            layer_id: layer1.clone(),
1✔
1507
                        },
1✔
1508
                        name: "Layer1".to_string(),
1✔
1509
                        description: "Layer 1".to_string(),
1✔
1510
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1511
                    }),
1✔
1512
                    CollectionItem::Layer(LayerListing {
1✔
1513
                        id: ProviderLayerId {
1✔
1514
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1515
                            layer_id: layer2.clone(),
1✔
1516
                        },
1✔
1517
                        name: "Layer2".to_string(),
1✔
1518
                        description: "Layer 2".to_string(),
1✔
1519
                        properties: vec![],
1✔
1520
                    }),
1✔
1521
                ],
1✔
1522
                entry_label: None,
1✔
1523
                properties: vec![],
1✔
1524
            }
1✔
1525
        );
1✔
1526

1527
        let root_collection_filtered = layer_db
1✔
1528
            .search(
1✔
1529
                &root_collection_id,
1✔
1530
                SearchParameters {
1✔
1531
                    search_type: SearchType::Fulltext,
1✔
1532
                    search_string: "lection".to_string(),
1✔
1533
                    limit: 10,
1✔
1534
                    offset: 0,
1✔
1535
                },
1✔
1536
            )
1✔
1537
            .await
5✔
1538
            .unwrap();
1✔
1539

1✔
1540
        assert_eq!(
1✔
1541
            root_collection_filtered,
1✔
1542
            LayerCollection {
1✔
1543
                id: ProviderLayerCollectionId {
1✔
1544
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1545
                    collection_id: root_collection_id.clone(),
1✔
1546
                },
1✔
1547
                name: "Layers".to_string(),
1✔
1548
                description: "All available Geo Engine layers".to_string(),
1✔
1549
                items: vec![
1✔
1550
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1551
                        id: ProviderLayerCollectionId {
1✔
1552
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1553
                            collection_id: collection1_id.clone(),
1✔
1554
                        },
1✔
1555
                        name: "Collection1".to_string(),
1✔
1556
                        description: "Collection 1".to_string(),
1✔
1557
                        properties: Default::default(),
1✔
1558
                    }),
1✔
1559
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1560
                        id: ProviderLayerCollectionId {
1✔
1561
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1562
                            collection_id: collection2_id.clone(),
1✔
1563
                        },
1✔
1564
                        name: "Collection2".to_string(),
1✔
1565
                        description: "Collection 2".to_string(),
1✔
1566
                        properties: Default::default(),
1✔
1567
                    }),
1✔
1568
                ],
1✔
1569
                entry_label: None,
1✔
1570
                properties: vec![],
1✔
1571
            }
1✔
1572
        );
1✔
1573

1574
        let collection1_all = layer_db
1✔
1575
            .search(
1✔
1576
                &collection1_id,
1✔
1577
                SearchParameters {
1✔
1578
                    search_type: SearchType::Fulltext,
1✔
1579
                    search_string: String::new(),
1✔
1580
                    limit: 10,
1✔
1581
                    offset: 0,
1✔
1582
                },
1✔
1583
            )
1✔
1584
            .await
5✔
1585
            .unwrap();
1✔
1586

1✔
1587
        assert_eq!(
1✔
1588
            collection1_all,
1✔
1589
            LayerCollection {
1✔
1590
                id: ProviderLayerCollectionId {
1✔
1591
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1592
                    collection_id: collection1_id.clone(),
1✔
1593
                },
1✔
1594
                name: "Collection1".to_string(),
1✔
1595
                description: "Collection 1".to_string(),
1✔
1596
                items: vec![
1✔
1597
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1598
                        id: ProviderLayerCollectionId {
1✔
1599
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1600
                            collection_id: collection2_id.clone(),
1✔
1601
                        },
1✔
1602
                        name: "Collection2".to_string(),
1✔
1603
                        description: "Collection 2".to_string(),
1✔
1604
                        properties: Default::default(),
1✔
1605
                    }),
1✔
1606
                    CollectionItem::Layer(LayerListing {
1✔
1607
                        id: ProviderLayerId {
1✔
1608
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1609
                            layer_id: layer2.clone(),
1✔
1610
                        },
1✔
1611
                        name: "Layer2".to_string(),
1✔
1612
                        description: "Layer 2".to_string(),
1✔
1613
                        properties: vec![],
1✔
1614
                    }),
1✔
1615
                ],
1✔
1616
                entry_label: None,
1✔
1617
                properties: vec![],
1✔
1618
            }
1✔
1619
        );
1✔
1620

1621
        let collection1_filtered_fulltext = layer_db
1✔
1622
            .search(
1✔
1623
                &collection1_id,
1✔
1624
                SearchParameters {
1✔
1625
                    search_type: SearchType::Fulltext,
1✔
1626
                    search_string: "ay".to_string(),
1✔
1627
                    limit: 10,
1✔
1628
                    offset: 0,
1✔
1629
                },
1✔
1630
            )
1✔
1631
            .await
5✔
1632
            .unwrap();
1✔
1633

1✔
1634
        assert_eq!(
1✔
1635
            collection1_filtered_fulltext,
1✔
1636
            LayerCollection {
1✔
1637
                id: ProviderLayerCollectionId {
1✔
1638
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1639
                    collection_id: collection1_id.clone(),
1✔
1640
                },
1✔
1641
                name: "Collection1".to_string(),
1✔
1642
                description: "Collection 1".to_string(),
1✔
1643
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1644
                    id: ProviderLayerId {
1✔
1645
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1646
                        layer_id: layer2.clone(),
1✔
1647
                    },
1✔
1648
                    name: "Layer2".to_string(),
1✔
1649
                    description: "Layer 2".to_string(),
1✔
1650
                    properties: vec![],
1✔
1651
                }),],
1✔
1652
                entry_label: None,
1✔
1653
                properties: vec![],
1✔
1654
            }
1✔
1655
        );
1✔
1656

1657
        let collection1_filtered_prefix = layer_db
1✔
1658
            .search(
1✔
1659
                &collection1_id,
1✔
1660
                SearchParameters {
1✔
1661
                    search_type: SearchType::Prefix,
1✔
1662
                    search_string: "ay".to_string(),
1✔
1663
                    limit: 10,
1✔
1664
                    offset: 0,
1✔
1665
                },
1✔
1666
            )
1✔
1667
            .await
5✔
1668
            .unwrap();
1✔
1669

1✔
1670
        assert_eq!(
1✔
1671
            collection1_filtered_prefix,
1✔
1672
            LayerCollection {
1✔
1673
                id: ProviderLayerCollectionId {
1✔
1674
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1675
                    collection_id: collection1_id.clone(),
1✔
1676
                },
1✔
1677
                name: "Collection1".to_string(),
1✔
1678
                description: "Collection 1".to_string(),
1✔
1679
                items: vec![],
1✔
1680
                entry_label: None,
1✔
1681
                properties: vec![],
1✔
1682
            }
1✔
1683
        );
1✔
1684

1685
        let collection1_filtered_prefix2 = layer_db
1✔
1686
            .search(
1✔
1687
                &collection1_id,
1✔
1688
                SearchParameters {
1✔
1689
                    search_type: SearchType::Prefix,
1✔
1690
                    search_string: "Lay".to_string(),
1✔
1691
                    limit: 10,
1✔
1692
                    offset: 0,
1✔
1693
                },
1✔
1694
            )
1✔
1695
            .await
5✔
1696
            .unwrap();
1✔
1697

1✔
1698
        assert_eq!(
1✔
1699
            collection1_filtered_prefix2,
1✔
1700
            LayerCollection {
1✔
1701
                id: ProviderLayerCollectionId {
1✔
1702
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1703
                    collection_id: collection1_id.clone(),
1✔
1704
                },
1✔
1705
                name: "Collection1".to_string(),
1✔
1706
                description: "Collection 1".to_string(),
1✔
1707
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1708
                    id: ProviderLayerId {
1✔
1709
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1710
                        layer_id: layer2.clone(),
1✔
1711
                    },
1✔
1712
                    name: "Layer2".to_string(),
1✔
1713
                    description: "Layer 2".to_string(),
1✔
1714
                    properties: vec![],
1✔
1715
                }),],
1✔
1716
                entry_label: None,
1✔
1717
                properties: vec![],
1✔
1718
            }
1✔
1719
        );
1✔
1720
    }
1✔
1721

1722
    #[allow(clippy::too_many_lines)]
1723
    #[ge_context::test]
3✔
1724
    async fn it_autocompletes_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1725
        let session = app_ctx.default_session().await.unwrap();
18✔
1726

1✔
1727
        let layer_db = app_ctx.session_context(session).db();
1✔
1728

1✔
1729
        let workflow = Workflow {
1✔
1730
            operator: TypedOperator::Vector(
1✔
1731
                MockPointSource {
1✔
1732
                    params: MockPointSourceParams {
1✔
1733
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1734
                    },
1✔
1735
                }
1✔
1736
                .boxed(),
1✔
1737
            ),
1✔
1738
        };
1✔
1739

1740
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1741

1742
        let _layer1 = layer_db
1✔
1743
            .add_layer(
1✔
1744
                AddLayer {
1✔
1745
                    name: "Layer1".to_string(),
1✔
1746
                    description: "Layer 1".to_string(),
1✔
1747
                    symbology: None,
1✔
1748
                    workflow: workflow.clone(),
1✔
1749
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1750
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1751
                },
1✔
1752
                &root_collection_id,
1✔
1753
            )
1✔
1754
            .await
45✔
1755
            .unwrap();
1✔
1756

1757
        let collection1_id = layer_db
1✔
1758
            .add_layer_collection(
1✔
1759
                AddLayerCollection {
1✔
1760
                    name: "Collection1".to_string(),
1✔
1761
                    description: "Collection 1".to_string(),
1✔
1762
                    properties: Default::default(),
1✔
1763
                },
1✔
1764
                &root_collection_id,
1✔
1765
            )
1✔
1766
            .await
7✔
1767
            .unwrap();
1✔
1768

1769
        let _layer2 = layer_db
1✔
1770
            .add_layer(
1✔
1771
                AddLayer {
1✔
1772
                    name: "Layer2".to_string(),
1✔
1773
                    description: "Layer 2".to_string(),
1✔
1774
                    symbology: None,
1✔
1775
                    workflow: workflow.clone(),
1✔
1776
                    metadata: Default::default(),
1✔
1777
                    properties: Default::default(),
1✔
1778
                },
1✔
1779
                &collection1_id,
1✔
1780
            )
1✔
1781
            .await
9✔
1782
            .unwrap();
1✔
1783

1784
        let _collection2_id = layer_db
1✔
1785
            .add_layer_collection(
1✔
1786
                AddLayerCollection {
1✔
1787
                    name: "Collection2".to_string(),
1✔
1788
                    description: "Collection 2".to_string(),
1✔
1789
                    properties: Default::default(),
1✔
1790
                },
1✔
1791
                &collection1_id,
1✔
1792
            )
1✔
1793
            .await
7✔
1794
            .unwrap();
1✔
1795

1796
        let root_collection_all = layer_db
1✔
1797
            .autocomplete_search(
1✔
1798
                &root_collection_id,
1✔
1799
                SearchParameters {
1✔
1800
                    search_type: SearchType::Fulltext,
1✔
1801
                    search_string: String::new(),
1✔
1802
                    limit: 10,
1✔
1803
                    offset: 0,
1✔
1804
                },
1✔
1805
            )
1✔
1806
            .await
3✔
1807
            .unwrap();
1✔
1808

1✔
1809
        assert_eq!(
1✔
1810
            root_collection_all,
1✔
1811
            vec![
1✔
1812
                "Collection1".to_string(),
1✔
1813
                "Collection2".to_string(),
1✔
1814
                "Layer1".to_string(),
1✔
1815
                "Layer2".to_string(),
1✔
1816
                "Unsorted".to_string(),
1✔
1817
            ]
1✔
1818
        );
1✔
1819

1820
        let root_collection_filtered = layer_db
1✔
1821
            .autocomplete_search(
1✔
1822
                &root_collection_id,
1✔
1823
                SearchParameters {
1✔
1824
                    search_type: SearchType::Fulltext,
1✔
1825
                    search_string: "lection".to_string(),
1✔
1826
                    limit: 10,
1✔
1827
                    offset: 0,
1✔
1828
                },
1✔
1829
            )
1✔
1830
            .await
3✔
1831
            .unwrap();
1✔
1832

1✔
1833
        assert_eq!(
1✔
1834
            root_collection_filtered,
1✔
1835
            vec!["Collection1".to_string(), "Collection2".to_string(),]
1✔
1836
        );
1✔
1837

1838
        let collection1_all = layer_db
1✔
1839
            .autocomplete_search(
1✔
1840
                &collection1_id,
1✔
1841
                SearchParameters {
1✔
1842
                    search_type: SearchType::Fulltext,
1✔
1843
                    search_string: String::new(),
1✔
1844
                    limit: 10,
1✔
1845
                    offset: 0,
1✔
1846
                },
1✔
1847
            )
1✔
1848
            .await
3✔
1849
            .unwrap();
1✔
1850

1✔
1851
        assert_eq!(
1✔
1852
            collection1_all,
1✔
1853
            vec!["Collection2".to_string(), "Layer2".to_string(),]
1✔
1854
        );
1✔
1855

1856
        let collection1_filtered_fulltext = layer_db
1✔
1857
            .autocomplete_search(
1✔
1858
                &collection1_id,
1✔
1859
                SearchParameters {
1✔
1860
                    search_type: SearchType::Fulltext,
1✔
1861
                    search_string: "ay".to_string(),
1✔
1862
                    limit: 10,
1✔
1863
                    offset: 0,
1✔
1864
                },
1✔
1865
            )
1✔
1866
            .await
3✔
1867
            .unwrap();
1✔
1868

1✔
1869
        assert_eq!(collection1_filtered_fulltext, vec!["Layer2".to_string(),]);
1✔
1870

1871
        let collection1_filtered_prefix = layer_db
1✔
1872
            .autocomplete_search(
1✔
1873
                &collection1_id,
1✔
1874
                SearchParameters {
1✔
1875
                    search_type: SearchType::Prefix,
1✔
1876
                    search_string: "ay".to_string(),
1✔
1877
                    limit: 10,
1✔
1878
                    offset: 0,
1✔
1879
                },
1✔
1880
            )
1✔
1881
            .await
3✔
1882
            .unwrap();
1✔
1883

1✔
1884
        assert_eq!(collection1_filtered_prefix, Vec::<String>::new());
1✔
1885

1886
        let collection1_filtered_prefix2 = layer_db
1✔
1887
            .autocomplete_search(
1✔
1888
                &collection1_id,
1✔
1889
                SearchParameters {
1✔
1890
                    search_type: SearchType::Prefix,
1✔
1891
                    search_string: "Lay".to_string(),
1✔
1892
                    limit: 10,
1✔
1893
                    offset: 0,
1✔
1894
                },
1✔
1895
            )
1✔
1896
            .await
3✔
1897
            .unwrap();
1✔
1898

1✔
1899
        assert_eq!(collection1_filtered_prefix2, vec!["Layer2".to_string(),]);
1✔
1900
    }
1✔
1901

1902
    #[allow(clippy::too_many_lines)]
1903
    #[ge_context::test]
3✔
1904
    async fn it_reports_search_capabilities(app_ctx: PostgresContext<NoTls>) {
1✔
1905
        let session = app_ctx.default_session().await.unwrap();
18✔
1906

1✔
1907
        let layer_db = app_ctx.session_context(session).db();
1✔
1908

1✔
1909
        let capabilities = layer_db.capabilities().search;
1✔
1910

1911
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1912

1✔
1913
        if capabilities.search_types.fulltext {
1✔
1914
            assert!(layer_db
1✔
1915
                .search(
1✔
1916
                    &root_collection_id,
1✔
1917
                    SearchParameters {
1✔
1918
                        search_type: SearchType::Fulltext,
1✔
1919
                        search_string: String::new(),
1✔
1920
                        limit: 10,
1✔
1921
                        offset: 0,
1✔
1922
                    },
1✔
1923
                )
1✔
1924
                .await
8✔
1925
                .is_ok());
1✔
1926

1927
            if capabilities.autocomplete {
1✔
1928
                assert!(layer_db
1✔
1929
                    .autocomplete_search(
1✔
1930
                        &root_collection_id,
1✔
1931
                        SearchParameters {
1✔
1932
                            search_type: SearchType::Fulltext,
1✔
1933
                            search_string: String::new(),
1✔
1934
                            limit: 10,
1✔
1935
                            offset: 0,
1✔
1936
                        },
1✔
1937
                    )
1✔
1938
                    .await
3✔
1939
                    .is_ok());
1✔
1940
            } else {
1941
                assert!(layer_db
×
1942
                    .autocomplete_search(
×
1943
                        &root_collection_id,
×
1944
                        SearchParameters {
×
1945
                            search_type: SearchType::Fulltext,
×
1946
                            search_string: String::new(),
×
1947
                            limit: 10,
×
1948
                            offset: 0,
×
1949
                        },
×
1950
                    )
×
1951
                    .await
×
1952
                    .is_err());
×
1953
            }
1954
        }
×
1955
        if capabilities.search_types.prefix {
1✔
1956
            assert!(layer_db
1✔
1957
                .search(
1✔
1958
                    &root_collection_id,
1✔
1959
                    SearchParameters {
1✔
1960
                        search_type: SearchType::Prefix,
1✔
1961
                        search_string: String::new(),
1✔
1962
                        limit: 10,
1✔
1963
                        offset: 0,
1✔
1964
                    },
1✔
1965
                )
1✔
1966
                .await
5✔
1967
                .is_ok());
1✔
1968

1969
            if capabilities.autocomplete {
1✔
1970
                assert!(layer_db
1✔
1971
                    .autocomplete_search(
1✔
1972
                        &root_collection_id,
1✔
1973
                        SearchParameters {
1✔
1974
                            search_type: SearchType::Prefix,
1✔
1975
                            search_string: String::new(),
1✔
1976
                            limit: 10,
1✔
1977
                            offset: 0,
1✔
1978
                        },
1✔
1979
                    )
1✔
1980
                    .await
3✔
1981
                    .is_ok());
1✔
1982
            } else {
1983
                assert!(layer_db
×
1984
                    .autocomplete_search(
×
1985
                        &root_collection_id,
×
1986
                        SearchParameters {
×
1987
                            search_type: SearchType::Prefix,
×
1988
                            search_string: String::new(),
×
1989
                            limit: 10,
×
1990
                            offset: 0,
×
1991
                        },
×
1992
                    )
×
1993
                    .await
×
1994
                    .is_err());
×
1995
            }
1996
        }
×
1997
    }
1✔
1998

1999
    #[allow(clippy::too_many_lines)]
2000
    #[ge_context::test]
3✔
2001
    async fn it_removes_layer_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2002
        let session = app_ctx.default_session().await.unwrap();
18✔
2003

1✔
2004
        let layer_db = app_ctx.session_context(session).db();
1✔
2005

1✔
2006
        let layer = AddLayer {
1✔
2007
            name: "layer".to_string(),
1✔
2008
            description: "description".to_string(),
1✔
2009
            workflow: Workflow {
1✔
2010
                operator: TypedOperator::Vector(
1✔
2011
                    MockPointSource {
1✔
2012
                        params: MockPointSourceParams {
1✔
2013
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2014
                        },
1✔
2015
                    }
1✔
2016
                    .boxed(),
1✔
2017
                ),
1✔
2018
            },
1✔
2019
            symbology: None,
1✔
2020
            metadata: Default::default(),
1✔
2021
            properties: Default::default(),
1✔
2022
        };
1✔
2023

2024
        let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
2025

1✔
2026
        let collection = AddLayerCollection {
1✔
2027
            name: "top collection".to_string(),
1✔
2028
            description: "description".to_string(),
1✔
2029
            properties: Default::default(),
1✔
2030
        };
1✔
2031

2032
        let top_c_id = layer_db
1✔
2033
            .add_layer_collection(collection, root_collection)
1✔
2034
            .await
10✔
2035
            .unwrap();
1✔
2036

2037
        let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
43✔
2038

1✔
2039
        let collection = AddLayerCollection {
1✔
2040
            name: "empty collection".to_string(),
1✔
2041
            description: "description".to_string(),
1✔
2042
            properties: Default::default(),
1✔
2043
        };
1✔
2044

2045
        let empty_c_id = layer_db
1✔
2046
            .add_layer_collection(collection, &top_c_id)
1✔
2047
            .await
7✔
2048
            .unwrap();
1✔
2049

2050
        let items = layer_db
1✔
2051
            .load_layer_collection(
1✔
2052
                &top_c_id,
1✔
2053
                LayerCollectionListOptions {
1✔
2054
                    offset: 0,
1✔
2055
                    limit: 20,
1✔
2056
                },
1✔
2057
            )
1✔
2058
            .await
5✔
2059
            .unwrap();
1✔
2060

1✔
2061
        assert_eq!(
1✔
2062
            items,
1✔
2063
            LayerCollection {
1✔
2064
                id: ProviderLayerCollectionId {
1✔
2065
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2066
                    collection_id: top_c_id.clone(),
1✔
2067
                },
1✔
2068
                name: "top collection".to_string(),
1✔
2069
                description: "description".to_string(),
1✔
2070
                items: vec![
1✔
2071
                    CollectionItem::Collection(LayerCollectionListing {
1✔
2072
                        id: ProviderLayerCollectionId {
1✔
2073
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2074
                            collection_id: empty_c_id.clone(),
1✔
2075
                        },
1✔
2076
                        name: "empty collection".to_string(),
1✔
2077
                        description: "description".to_string(),
1✔
2078
                        properties: Default::default(),
1✔
2079
                    }),
1✔
2080
                    CollectionItem::Layer(LayerListing {
1✔
2081
                        id: ProviderLayerId {
1✔
2082
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2083
                            layer_id: l_id.clone(),
1✔
2084
                        },
1✔
2085
                        name: "layer".to_string(),
1✔
2086
                        description: "description".to_string(),
1✔
2087
                        properties: vec![],
1✔
2088
                    })
1✔
2089
                ],
1✔
2090
                entry_label: None,
1✔
2091
                properties: vec![],
1✔
2092
            }
1✔
2093
        );
1✔
2094

2095
        // remove empty collection
2096
        layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
9✔
2097

2098
        let items = layer_db
1✔
2099
            .load_layer_collection(
1✔
2100
                &top_c_id,
1✔
2101
                LayerCollectionListOptions {
1✔
2102
                    offset: 0,
1✔
2103
                    limit: 20,
1✔
2104
                },
1✔
2105
            )
1✔
2106
            .await
5✔
2107
            .unwrap();
1✔
2108

1✔
2109
        assert_eq!(
1✔
2110
            items,
1✔
2111
            LayerCollection {
1✔
2112
                id: ProviderLayerCollectionId {
1✔
2113
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2114
                    collection_id: top_c_id.clone(),
1✔
2115
                },
1✔
2116
                name: "top collection".to_string(),
1✔
2117
                description: "description".to_string(),
1✔
2118
                items: vec![CollectionItem::Layer(LayerListing {
1✔
2119
                    id: ProviderLayerId {
1✔
2120
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
2121
                        layer_id: l_id.clone(),
1✔
2122
                    },
1✔
2123
                    name: "layer".to_string(),
1✔
2124
                    description: "description".to_string(),
1✔
2125
                    properties: vec![],
1✔
2126
                })],
1✔
2127
                entry_label: None,
1✔
2128
                properties: vec![],
1✔
2129
            }
1✔
2130
        );
1✔
2131

2132
        // remove top (not root) collection
2133
        layer_db.remove_layer_collection(&top_c_id).await.unwrap();
9✔
2134

1✔
2135
        layer_db
1✔
2136
            .load_layer_collection(
1✔
2137
                &top_c_id,
1✔
2138
                LayerCollectionListOptions {
1✔
2139
                    offset: 0,
1✔
2140
                    limit: 20,
1✔
2141
                },
1✔
2142
            )
1✔
2143
            .await
3✔
2144
            .unwrap_err();
1✔
2145

1✔
2146
        // should be deleted automatically
1✔
2147
        layer_db.load_layer(&l_id).await.unwrap_err();
3✔
2148

1✔
2149
        // it is not allowed to remove the root collection
1✔
2150
        layer_db
1✔
2151
            .remove_layer_collection(root_collection)
1✔
2152
            .await
2✔
2153
            .unwrap_err();
1✔
2154
        layer_db
1✔
2155
            .load_layer_collection(
1✔
2156
                root_collection,
1✔
2157
                LayerCollectionListOptions {
1✔
2158
                    offset: 0,
1✔
2159
                    limit: 20,
1✔
2160
                },
1✔
2161
            )
1✔
2162
            .await
5✔
2163
            .unwrap();
1✔
2164
    }
1✔
2165

2166
    #[ge_context::test]
3✔
2167
    #[allow(clippy::too_many_lines)]
2168
    async fn it_removes_collections_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2169
        let session = app_ctx.default_session().await.unwrap();
18✔
2170

1✔
2171
        let db = app_ctx.session_context(session).db();
1✔
2172

2173
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2174

2175
        let mid_collection_id = db
1✔
2176
            .add_layer_collection(
1✔
2177
                AddLayerCollection {
1✔
2178
                    name: "mid collection".to_string(),
1✔
2179
                    description: "description".to_string(),
1✔
2180
                    properties: Default::default(),
1✔
2181
                },
1✔
2182
                root_collection_id,
1✔
2183
            )
1✔
2184
            .await
10✔
2185
            .unwrap();
1✔
2186

2187
        let bottom_collection_id = db
1✔
2188
            .add_layer_collection(
1✔
2189
                AddLayerCollection {
1✔
2190
                    name: "bottom collection".to_string(),
1✔
2191
                    description: "description".to_string(),
1✔
2192
                    properties: Default::default(),
1✔
2193
                },
1✔
2194
                &mid_collection_id,
1✔
2195
            )
1✔
2196
            .await
7✔
2197
            .unwrap();
1✔
2198

2199
        let layer_id = db
1✔
2200
            .add_layer(
1✔
2201
                AddLayer {
1✔
2202
                    name: "layer".to_string(),
1✔
2203
                    description: "description".to_string(),
1✔
2204
                    workflow: Workflow {
1✔
2205
                        operator: TypedOperator::Vector(
1✔
2206
                            MockPointSource {
1✔
2207
                                params: MockPointSourceParams {
1✔
2208
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2209
                                },
1✔
2210
                            }
1✔
2211
                            .boxed(),
1✔
2212
                        ),
1✔
2213
                    },
1✔
2214
                    symbology: None,
1✔
2215
                    metadata: Default::default(),
1✔
2216
                    properties: Default::default(),
1✔
2217
                },
1✔
2218
                &mid_collection_id,
1✔
2219
            )
1✔
2220
            .await
42✔
2221
            .unwrap();
1✔
2222

1✔
2223
        // removing the mid collection…
1✔
2224
        db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
2225
            .await
11✔
2226
            .unwrap();
1✔
2227

1✔
2228
        // …should remove itself
1✔
2229
        db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
2230
            .await
3✔
2231
            .unwrap_err();
1✔
2232

1✔
2233
        // …should remove the bottom collection
1✔
2234
        db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
2235
            .await
3✔
2236
            .unwrap_err();
1✔
2237

1✔
2238
        // … and should remove the layer of the bottom collection
1✔
2239
        db.load_layer(&layer_id).await.unwrap_err();
3✔
2240

1✔
2241
        // the root collection is still there
1✔
2242
        db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
2243
            .await
5✔
2244
            .unwrap();
1✔
2245
    }
1✔
2246

2247
    #[ge_context::test]
3✔
2248
    #[allow(clippy::too_many_lines)]
2249
    async fn it_removes_layers_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2250
        let session = app_ctx.default_session().await.unwrap();
18✔
2251

1✔
2252
        let db = app_ctx.session_context(session).db();
1✔
2253

2254
        let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
2255

2256
        let another_collection = db
1✔
2257
            .add_layer_collection(
1✔
2258
                AddLayerCollection {
1✔
2259
                    name: "top collection".to_string(),
1✔
2260
                    description: "description".to_string(),
1✔
2261
                    properties: Default::default(),
1✔
2262
                },
1✔
2263
                root_collection,
1✔
2264
            )
1✔
2265
            .await
10✔
2266
            .unwrap();
1✔
2267

2268
        let layer_in_one_collection = db
1✔
2269
            .add_layer(
1✔
2270
                AddLayer {
1✔
2271
                    name: "layer 1".to_string(),
1✔
2272
                    description: "description".to_string(),
1✔
2273
                    workflow: Workflow {
1✔
2274
                        operator: TypedOperator::Vector(
1✔
2275
                            MockPointSource {
1✔
2276
                                params: MockPointSourceParams {
1✔
2277
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2278
                                },
1✔
2279
                            }
1✔
2280
                            .boxed(),
1✔
2281
                        ),
1✔
2282
                    },
1✔
2283
                    symbology: None,
1✔
2284
                    metadata: Default::default(),
1✔
2285
                    properties: Default::default(),
1✔
2286
                },
1✔
2287
                &another_collection,
1✔
2288
            )
1✔
2289
            .await
42✔
2290
            .unwrap();
1✔
2291

2292
        let layer_in_two_collections = db
1✔
2293
            .add_layer(
1✔
2294
                AddLayer {
1✔
2295
                    name: "layer 2".to_string(),
1✔
2296
                    description: "description".to_string(),
1✔
2297
                    workflow: Workflow {
1✔
2298
                        operator: TypedOperator::Vector(
1✔
2299
                            MockPointSource {
1✔
2300
                                params: MockPointSourceParams {
1✔
2301
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2302
                                },
1✔
2303
                            }
1✔
2304
                            .boxed(),
1✔
2305
                        ),
1✔
2306
                    },
1✔
2307
                    symbology: None,
1✔
2308
                    metadata: Default::default(),
1✔
2309
                    properties: Default::default(),
1✔
2310
                },
1✔
2311
                &another_collection,
1✔
2312
            )
1✔
2313
            .await
9✔
2314
            .unwrap();
1✔
2315

1✔
2316
        db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
2317
            .await
3✔
2318
            .unwrap();
1✔
2319

1✔
2320
        // remove first layer --> should be deleted entirely
1✔
2321

1✔
2322
        db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
2323
            .await
7✔
2324
            .unwrap();
1✔
2325

2326
        let number_of_layer_in_collection = db
1✔
2327
            .load_layer_collection(
1✔
2328
                &another_collection,
1✔
2329
                LayerCollectionListOptions {
1✔
2330
                    offset: 0,
1✔
2331
                    limit: 20,
1✔
2332
                },
1✔
2333
            )
1✔
2334
            .await
5✔
2335
            .unwrap()
1✔
2336
            .items
1✔
2337
            .len();
1✔
2338
        assert_eq!(
1✔
2339
            number_of_layer_in_collection,
1✔
2340
            1 /* only the other collection should be here */
1✔
2341
        );
1✔
2342

2343
        db.load_layer(&layer_in_one_collection).await.unwrap_err();
3✔
2344

1✔
2345
        // remove second layer --> should only be gone in collection
1✔
2346

1✔
2347
        db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
2348
            .await
7✔
2349
            .unwrap();
1✔
2350

2351
        let number_of_layer_in_collection = db
1✔
2352
            .load_layer_collection(
1✔
2353
                &another_collection,
1✔
2354
                LayerCollectionListOptions {
1✔
2355
                    offset: 0,
1✔
2356
                    limit: 20,
1✔
2357
                },
1✔
2358
            )
1✔
2359
            .await
5✔
2360
            .unwrap()
1✔
2361
            .items
1✔
2362
            .len();
1✔
2363
        assert_eq!(
1✔
2364
            number_of_layer_in_collection,
1✔
2365
            0 /* both layers were deleted */
1✔
2366
        );
1✔
2367

2368
        db.load_layer(&layer_in_two_collections).await.unwrap();
3✔
2369
    }
1✔
2370

2371
    #[ge_context::test]
3✔
2372
    #[allow(clippy::too_many_lines)]
2373
    async fn it_deletes_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
2374
        let loading_info = OgrSourceDataset {
1✔
2375
            file_name: PathBuf::from("test.csv"),
1✔
2376
            layer_name: "test.csv".to_owned(),
1✔
2377
            data_type: Some(VectorDataType::MultiPoint),
1✔
2378
            time: OgrSourceDatasetTimeType::Start {
1✔
2379
                start_field: "start".to_owned(),
1✔
2380
                start_format: OgrSourceTimeFormat::Auto,
1✔
2381
                duration: OgrSourceDurationSpec::Zero,
1✔
2382
            },
1✔
2383
            default_geometry: None,
1✔
2384
            columns: Some(OgrSourceColumnSpec {
1✔
2385
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2386
                    header: CsvHeader::Auto,
1✔
2387
                }),
1✔
2388
                x: "x".to_owned(),
1✔
2389
                y: None,
1✔
2390
                int: vec![],
1✔
2391
                float: vec![],
1✔
2392
                text: vec![],
1✔
2393
                bool: vec![],
1✔
2394
                datetime: vec![],
1✔
2395
                rename: None,
1✔
2396
            }),
1✔
2397
            force_ogr_time_filter: false,
1✔
2398
            force_ogr_spatial_filter: false,
1✔
2399
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2400
            sql_query: None,
1✔
2401
            attribute_query: None,
1✔
2402
            cache_ttl: CacheTtlSeconds::default(),
1✔
2403
        };
1✔
2404

1✔
2405
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2406
            OgrSourceDataset,
1✔
2407
            VectorResultDescriptor,
1✔
2408
            VectorQueryRectangle,
1✔
2409
        > {
1✔
2410
            loading_info: loading_info.clone(),
1✔
2411
            result_descriptor: VectorResultDescriptor {
1✔
2412
                data_type: VectorDataType::MultiPoint,
1✔
2413
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2414
                columns: [(
1✔
2415
                    "foo".to_owned(),
1✔
2416
                    VectorColumnInfo {
1✔
2417
                        data_type: FeatureDataType::Float,
1✔
2418
                        measurement: Measurement::Unitless,
1✔
2419
                    },
1✔
2420
                )]
1✔
2421
                .into_iter()
1✔
2422
                .collect(),
1✔
2423
                time: None,
1✔
2424
                bbox: None,
1✔
2425
            },
1✔
2426
            phantom: Default::default(),
1✔
2427
        });
1✔
2428

2429
        let session = app_ctx.default_session().await.unwrap();
18✔
2430

1✔
2431
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2432

1✔
2433
        let db = app_ctx.session_context(session.clone()).db();
1✔
2434
        let dataset_id = db
1✔
2435
            .add_dataset(
1✔
2436
                AddDataset {
1✔
2437
                    name: Some(dataset_name),
1✔
2438
                    display_name: "Ogr Test".to_owned(),
1✔
2439
                    description: "desc".to_owned(),
1✔
2440
                    source_operator: "OgrSource".to_owned(),
1✔
2441
                    symbology: None,
1✔
2442
                    provenance: Some(vec![Provenance {
1✔
2443
                        citation: "citation".to_owned(),
1✔
2444
                        license: "license".to_owned(),
1✔
2445
                        uri: "uri".to_owned(),
1✔
2446
                    }]),
1✔
2447
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2448
                },
1✔
2449
                meta_data,
1✔
2450
            )
1✔
2451
            .await
160✔
2452
            .unwrap()
1✔
2453
            .id;
1✔
2454

1✔
2455
        assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
2456

2457
        db.delete_dataset(dataset_id).await.unwrap();
3✔
2458

1✔
2459
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2460
    }
1✔
2461

2462
    #[ge_context::test]
3✔
2463
    #[allow(clippy::too_many_lines)]
2464
    async fn it_deletes_admin_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
2465
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2466

1✔
2467
        let loading_info = OgrSourceDataset {
1✔
2468
            file_name: PathBuf::from("test.csv"),
1✔
2469
            layer_name: "test.csv".to_owned(),
1✔
2470
            data_type: Some(VectorDataType::MultiPoint),
1✔
2471
            time: OgrSourceDatasetTimeType::Start {
1✔
2472
                start_field: "start".to_owned(),
1✔
2473
                start_format: OgrSourceTimeFormat::Auto,
1✔
2474
                duration: OgrSourceDurationSpec::Zero,
1✔
2475
            },
1✔
2476
            default_geometry: None,
1✔
2477
            columns: Some(OgrSourceColumnSpec {
1✔
2478
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2479
                    header: CsvHeader::Auto,
1✔
2480
                }),
1✔
2481
                x: "x".to_owned(),
1✔
2482
                y: None,
1✔
2483
                int: vec![],
1✔
2484
                float: vec![],
1✔
2485
                text: vec![],
1✔
2486
                bool: vec![],
1✔
2487
                datetime: vec![],
1✔
2488
                rename: None,
1✔
2489
            }),
1✔
2490
            force_ogr_time_filter: false,
1✔
2491
            force_ogr_spatial_filter: false,
1✔
2492
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2493
            sql_query: None,
1✔
2494
            attribute_query: None,
1✔
2495
            cache_ttl: CacheTtlSeconds::default(),
1✔
2496
        };
1✔
2497

1✔
2498
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2499
            OgrSourceDataset,
1✔
2500
            VectorResultDescriptor,
1✔
2501
            VectorQueryRectangle,
1✔
2502
        > {
1✔
2503
            loading_info: loading_info.clone(),
1✔
2504
            result_descriptor: VectorResultDescriptor {
1✔
2505
                data_type: VectorDataType::MultiPoint,
1✔
2506
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2507
                columns: [(
1✔
2508
                    "foo".to_owned(),
1✔
2509
                    VectorColumnInfo {
1✔
2510
                        data_type: FeatureDataType::Float,
1✔
2511
                        measurement: Measurement::Unitless,
1✔
2512
                    },
1✔
2513
                )]
1✔
2514
                .into_iter()
1✔
2515
                .collect(),
1✔
2516
                time: None,
1✔
2517
                bbox: None,
1✔
2518
            },
1✔
2519
            phantom: Default::default(),
1✔
2520
        });
1✔
2521

2522
        let session = app_ctx.default_session().await.unwrap();
18✔
2523

1✔
2524
        let db = app_ctx.session_context(session).db();
1✔
2525
        let dataset_id = db
1✔
2526
            .add_dataset(
1✔
2527
                AddDataset {
1✔
2528
                    name: Some(dataset_name),
1✔
2529
                    display_name: "Ogr Test".to_owned(),
1✔
2530
                    description: "desc".to_owned(),
1✔
2531
                    source_operator: "OgrSource".to_owned(),
1✔
2532
                    symbology: None,
1✔
2533
                    provenance: Some(vec![Provenance {
1✔
2534
                        citation: "citation".to_owned(),
1✔
2535
                        license: "license".to_owned(),
1✔
2536
                        uri: "uri".to_owned(),
1✔
2537
                    }]),
1✔
2538
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2539
                },
1✔
2540
                meta_data,
1✔
2541
            )
1✔
2542
            .await
161✔
2543
            .unwrap()
1✔
2544
            .id;
1✔
2545

1✔
2546
        assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
2547

2548
        db.delete_dataset(dataset_id).await.unwrap();
3✔
2549

1✔
2550
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2551
    }
1✔
2552

2553
    #[ge_context::test]
3✔
2554
    async fn test_missing_layer_dataset_in_collection_listing(app_ctx: PostgresContext<NoTls>) {
1✔
2555
        let session = app_ctx.default_session().await.unwrap();
18✔
2556
        let db = app_ctx.session_context(session).db();
1✔
2557

2558
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2559

2560
        let top_collection_id = db
1✔
2561
            .add_layer_collection(
1✔
2562
                AddLayerCollection {
1✔
2563
                    name: "top collection".to_string(),
1✔
2564
                    description: "description".to_string(),
1✔
2565
                    properties: Default::default(),
1✔
2566
                },
1✔
2567
                root_collection_id,
1✔
2568
            )
1✔
2569
            .await
10✔
2570
            .unwrap();
1✔
2571

1✔
2572
        let faux_layer = LayerId("faux".to_string());
1✔
2573

1✔
2574
        // this should fail
1✔
2575
        db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
2576
            .await
×
2577
            .unwrap_err();
1✔
2578

2579
        let root_collection_layers = db
1✔
2580
            .load_layer_collection(
1✔
2581
                &top_collection_id,
1✔
2582
                LayerCollectionListOptions {
1✔
2583
                    offset: 0,
1✔
2584
                    limit: 20,
1✔
2585
                },
1✔
2586
            )
1✔
2587
            .await
5✔
2588
            .unwrap();
1✔
2589

1✔
2590
        assert_eq!(
1✔
2591
            root_collection_layers,
1✔
2592
            LayerCollection {
1✔
2593
                id: ProviderLayerCollectionId {
1✔
2594
                    provider_id: DataProviderId(
1✔
2595
                        "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
2596
                    ),
1✔
2597
                    collection_id: top_collection_id.clone(),
1✔
2598
                },
1✔
2599
                name: "top collection".to_string(),
1✔
2600
                description: "description".to_string(),
1✔
2601
                items: vec![],
1✔
2602
                entry_label: None,
1✔
2603
                properties: vec![],
1✔
2604
            }
1✔
2605
        );
1✔
2606
    }
1✔
2607

2608
    #[allow(clippy::too_many_lines)]
2609
    #[ge_context::test]
3✔
2610
    async fn it_updates_project_layer_symbology(app_ctx: PostgresContext<NoTls>) {
1✔
2611
        let session = app_ctx.default_session().await.unwrap();
18✔
2612

2613
        let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
171✔
2614

2615
        let db = app_ctx.session_context(session.clone()).db();
1✔
2616

1✔
2617
        let create_project: CreateProject = serde_json::from_value(json!({
1✔
2618
            "name": "Default",
1✔
2619
            "description": "Default project",
1✔
2620
            "bounds": {
1✔
2621
                "boundingBox": {
1✔
2622
                    "lowerLeftCoordinate": {
1✔
2623
                        "x": -180,
1✔
2624
                        "y": -90
1✔
2625
                    },
1✔
2626
                    "upperRightCoordinate": {
1✔
2627
                        "x": 180,
1✔
2628
                        "y": 90
1✔
2629
                    }
1✔
2630
                },
1✔
2631
                "spatialReference": "EPSG:4326",
1✔
2632
                "timeInterval": {
1✔
2633
                    "start": 1_396_353_600_000i64,
1✔
2634
                    "end": 1_396_353_600_000i64
1✔
2635
                }
1✔
2636
            },
1✔
2637
            "timeStep": {
1✔
2638
                "step": 1,
1✔
2639
                "granularity": "months"
1✔
2640
            }
1✔
2641
        }))
1✔
2642
        .unwrap();
1✔
2643

2644
        let project_id = db.create_project(create_project).await.unwrap();
7✔
2645

1✔
2646
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2647
            "id": project_id.to_string(),
1✔
2648
            "layers": [{
1✔
2649
                "name": "NDVI",
1✔
2650
                "workflow": workflow_id.to_string(),
1✔
2651
                "visibility": {
1✔
2652
                    "data": true,
1✔
2653
                    "legend": false
1✔
2654
                },
1✔
2655
                "symbology": {
1✔
2656
                    "type": "raster",
1✔
2657
                    "opacity": 1,
1✔
2658
                    "rasterColorizer": {
1✔
2659
                        "type": "singleBand",
1✔
2660
                        "band": 0,
1✔
2661
                        "bandColorizer": {
1✔
2662
                            "type": "linearGradient",
1✔
2663
                            "breakpoints": [{
1✔
2664
                                "value": 1,
1✔
2665
                                "color": [0, 0, 0, 255]
1✔
2666
                            }, {
1✔
2667
                                "value": 255,
1✔
2668
                                "color": [255, 255, 255, 255]
1✔
2669
                            }],
1✔
2670
                            "noDataColor": [0, 0, 0, 0],
1✔
2671
                            "overColor": [255, 255, 255, 127],
1✔
2672
                            "underColor": [255, 255, 255, 127]
1✔
2673
                        }
1✔
2674
                    }
1✔
2675
                }
1✔
2676
            }]
1✔
2677
        }))
1✔
2678
        .unwrap();
1✔
2679

1✔
2680
        db.update_project(update).await.unwrap();
70✔
2681

1✔
2682
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2683
            "id": project_id.to_string(),
1✔
2684
            "layers": [{
1✔
2685
                "name": "NDVI",
1✔
2686
                "workflow": workflow_id.to_string(),
1✔
2687
                "visibility": {
1✔
2688
                    "data": true,
1✔
2689
                    "legend": false
1✔
2690
                },
1✔
2691
                "symbology": {
1✔
2692
                    "type": "raster",
1✔
2693
                    "opacity": 1,
1✔
2694
                    "rasterColorizer": {
1✔
2695
                        "type": "singleBand",
1✔
2696
                        "band": 0,
1✔
2697
                        "bandColorizer": {
1✔
2698
                            "type": "linearGradient",
1✔
2699
                            "breakpoints": [{
1✔
2700
                                "value": 1,
1✔
2701
                                "color": [0, 0, 4, 255]
1✔
2702
                            }, {
1✔
2703
                                "value": 17.866_666_666_666_667,
1✔
2704
                                "color": [11, 9, 36, 255]
1✔
2705
                            }, {
1✔
2706
                                "value": 34.733_333_333_333_334,
1✔
2707
                                "color": [32, 17, 75, 255]
1✔
2708
                            }, {
1✔
2709
                                "value": 51.6,
1✔
2710
                                "color": [59, 15, 112, 255]
1✔
2711
                            }, {
1✔
2712
                                "value": 68.466_666_666_666_67,
1✔
2713
                                "color": [87, 21, 126, 255]
1✔
2714
                            }, {
1✔
2715
                                "value": 85.333_333_333_333_33,
1✔
2716
                                "color": [114, 31, 129, 255]
1✔
2717
                            }, {
1✔
2718
                                "value": 102.199_999_999_999_99,
1✔
2719
                                "color": [140, 41, 129, 255]
1✔
2720
                            }, {
1✔
2721
                                "value": 119.066_666_666_666_65,
1✔
2722
                                "color": [168, 50, 125, 255]
1✔
2723
                            }, {
1✔
2724
                                "value": 135.933_333_333_333_34,
1✔
2725
                                "color": [196, 60, 117, 255]
1✔
2726
                            }, {
1✔
2727
                                "value": 152.799_999_999_999_98,
1✔
2728
                                "color": [222, 73, 104, 255]
1✔
2729
                            }, {
1✔
2730
                                "value": 169.666_666_666_666_66,
1✔
2731
                                "color": [241, 96, 93, 255]
1✔
2732
                            }, {
1✔
2733
                                "value": 186.533_333_333_333_33,
1✔
2734
                                "color": [250, 127, 94, 255]
1✔
2735
                            }, {
1✔
2736
                                "value": 203.399_999_999_999_98,
1✔
2737
                                "color": [254, 159, 109, 255]
1✔
2738
                            }, {
1✔
2739
                                "value": 220.266_666_666_666_65,
1✔
2740
                                "color": [254, 191, 132, 255]
1✔
2741
                            }, {
1✔
2742
                                "value": 237.133_333_333_333_3,
1✔
2743
                                "color": [253, 222, 160, 255]
1✔
2744
                            }, {
1✔
2745
                                "value": 254,
1✔
2746
                                "color": [252, 253, 191, 255]
1✔
2747
                            }],
1✔
2748
                            "noDataColor": [0, 0, 0, 0],
1✔
2749
                            "overColor": [255, 255, 255, 127],
1✔
2750
                            "underColor": [255, 255, 255, 127]
1✔
2751
                        }
1✔
2752
                    }
1✔
2753
                }
1✔
2754
            }]
1✔
2755
        }))
1✔
2756
        .unwrap();
1✔
2757

1✔
2758
        db.update_project(update).await.unwrap();
68✔
2759

1✔
2760
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2761
            "id": project_id.to_string(),
1✔
2762
            "layers": [{
1✔
2763
                "name": "NDVI",
1✔
2764
                "workflow": workflow_id.to_string(),
1✔
2765
                "visibility": {
1✔
2766
                    "data": true,
1✔
2767
                    "legend": false
1✔
2768
                },
1✔
2769
                "symbology": {
1✔
2770
                    "type": "raster",
1✔
2771
                    "opacity": 1,
1✔
2772
                    "rasterColorizer": {
1✔
2773
                        "type": "singleBand",
1✔
2774
                        "band": 0,
1✔
2775
                        "bandColorizer": {
1✔
2776
                            "type": "linearGradient",
1✔
2777
                            "breakpoints": [{
1✔
2778
                                "value": 1,
1✔
2779
                                "color": [0, 0, 4, 255]
1✔
2780
                            }, {
1✔
2781
                                "value": 17.866_666_666_666_667,
1✔
2782
                                "color": [11, 9, 36, 255]
1✔
2783
                            }, {
1✔
2784
                                "value": 34.733_333_333_333_334,
1✔
2785
                                "color": [32, 17, 75, 255]
1✔
2786
                            }, {
1✔
2787
                                "value": 51.6,
1✔
2788
                                "color": [59, 15, 112, 255]
1✔
2789
                            }, {
1✔
2790
                                "value": 68.466_666_666_666_67,
1✔
2791
                                "color": [87, 21, 126, 255]
1✔
2792
                            }, {
1✔
2793
                                "value": 85.333_333_333_333_33,
1✔
2794
                                "color": [114, 31, 129, 255]
1✔
2795
                            }, {
1✔
2796
                                "value": 102.199_999_999_999_99,
1✔
2797
                                "color": [140, 41, 129, 255]
1✔
2798
                            }, {
1✔
2799
                                "value": 119.066_666_666_666_65,
1✔
2800
                                "color": [168, 50, 125, 255]
1✔
2801
                            }, {
1✔
2802
                                "value": 135.933_333_333_333_34,
1✔
2803
                                "color": [196, 60, 117, 255]
1✔
2804
                            }, {
1✔
2805
                                "value": 152.799_999_999_999_98,
1✔
2806
                                "color": [222, 73, 104, 255]
1✔
2807
                            }, {
1✔
2808
                                "value": 169.666_666_666_666_66,
1✔
2809
                                "color": [241, 96, 93, 255]
1✔
2810
                            }, {
1✔
2811
                                "value": 186.533_333_333_333_33,
1✔
2812
                                "color": [250, 127, 94, 255]
1✔
2813
                            }, {
1✔
2814
                                "value": 203.399_999_999_999_98,
1✔
2815
                                "color": [254, 159, 109, 255]
1✔
2816
                            }, {
1✔
2817
                                "value": 220.266_666_666_666_65,
1✔
2818
                                "color": [254, 191, 132, 255]
1✔
2819
                            }, {
1✔
2820
                                "value": 237.133_333_333_333_3,
1✔
2821
                                "color": [253, 222, 160, 255]
1✔
2822
                            }, {
1✔
2823
                                "value": 254,
1✔
2824
                                "color": [252, 253, 191, 255]
1✔
2825
                            }],
1✔
2826
                            "noDataColor": [0, 0, 0, 0],
1✔
2827
                            "overColor": [255, 255, 255, 127],
1✔
2828
                            "underColor": [255, 255, 255, 127]
1✔
2829
                        }
1✔
2830
                    }
1✔
2831
                }
1✔
2832
            }]
1✔
2833
        }))
1✔
2834
        .unwrap();
1✔
2835

1✔
2836
        db.update_project(update).await.unwrap();
16✔
2837

1✔
2838
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2839
            "id": project_id.to_string(),
1✔
2840
            "layers": [{
1✔
2841
                "name": "NDVI",
1✔
2842
                "workflow": workflow_id.to_string(),
1✔
2843
                "visibility": {
1✔
2844
                    "data": true,
1✔
2845
                    "legend": false
1✔
2846
                },
1✔
2847
                "symbology": {
1✔
2848
                    "type": "raster",
1✔
2849
                    "opacity": 1,
1✔
2850
                    "rasterColorizer": {
1✔
2851
                        "type": "singleBand",
1✔
2852
                        "band": 0,
1✔
2853
                        "bandColorizer": {
1✔
2854
                            "type": "linearGradient",
1✔
2855
                            "breakpoints": [{
1✔
2856
                                "value": 1,
1✔
2857
                                "color": [0, 0, 4, 255]
1✔
2858
                            }, {
1✔
2859
                                "value": 17.933_333_333_333_334,
1✔
2860
                                "color": [11, 9, 36, 255]
1✔
2861
                            }, {
1✔
2862
                                "value": 34.866_666_666_666_67,
1✔
2863
                                "color": [32, 17, 75, 255]
1✔
2864
                            }, {
1✔
2865
                                "value": 51.800_000_000_000_004,
1✔
2866
                                "color": [59, 15, 112, 255]
1✔
2867
                            }, {
1✔
2868
                                "value": 68.733_333_333_333_33,
1✔
2869
                                "color": [87, 21, 126, 255]
1✔
2870
                            }, {
1✔
2871
                                "value": 85.666_666_666_666_66,
1✔
2872
                                "color": [114, 31, 129, 255]
1✔
2873
                            }, {
1✔
2874
                                "value": 102.6,
1✔
2875
                                "color": [140, 41, 129, 255]
1✔
2876
                            }, {
1✔
2877
                                "value": 119.533_333_333_333_32,
1✔
2878
                                "color": [168, 50, 125, 255]
1✔
2879
                            }, {
1✔
2880
                                "value": 136.466_666_666_666_67,
1✔
2881
                                "color": [196, 60, 117, 255]
1✔
2882
                            }, {
1✔
2883
                                "value": 153.4,
1✔
2884
                                "color": [222, 73, 104, 255]
1✔
2885
                            }, {
1✔
2886
                                "value": 170.333_333_333_333_31,
1✔
2887
                                "color": [241, 96, 93, 255]
1✔
2888
                            }, {
1✔
2889
                                "value": 187.266_666_666_666_65,
1✔
2890
                                "color": [250, 127, 94, 255]
1✔
2891
                            }, {
1✔
2892
                                "value": 204.2,
1✔
2893
                                "color": [254, 159, 109, 255]
1✔
2894
                            }, {
1✔
2895
                                "value": 221.133_333_333_333_33,
1✔
2896
                                "color": [254, 191, 132, 255]
1✔
2897
                            }, {
1✔
2898
                                "value": 238.066_666_666_666_63,
1✔
2899
                                "color": [253, 222, 160, 255]
1✔
2900
                            }, {
1✔
2901
                                "value": 255,
1✔
2902
                                "color": [252, 253, 191, 255]
1✔
2903
                            }],
1✔
2904
                            "noDataColor": [0, 0, 0, 0],
1✔
2905
                            "overColor": [255, 255, 255, 127],
1✔
2906
                            "underColor": [255, 255, 255, 127]
1✔
2907
                        }
1✔
2908
                    }
1✔
2909
                }
1✔
2910
            }]
1✔
2911
        }))
1✔
2912
        .unwrap();
1✔
2913

2914
        // run two updates concurrently
2915
        let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
84✔
2916

2917
        assert!(r0.is_ok());
1✔
2918
        assert!(r1.is_ok());
1✔
2919
    }
1✔
2920

2921
    #[ge_context::test]
3✔
2922
    #[allow(clippy::too_many_lines)]
2923
    async fn it_resolves_dataset_names_to_ids(app_ctx: PostgresContext<NoTls>) {
1✔
2924
        let session = app_ctx.default_session().await.unwrap();
18✔
2925
        let db = app_ctx.session_context(session.clone()).db();
1✔
2926

1✔
2927
        let loading_info = OgrSourceDataset {
1✔
2928
            file_name: PathBuf::from("test.csv"),
1✔
2929
            layer_name: "test.csv".to_owned(),
1✔
2930
            data_type: Some(VectorDataType::MultiPoint),
1✔
2931
            time: OgrSourceDatasetTimeType::Start {
1✔
2932
                start_field: "start".to_owned(),
1✔
2933
                start_format: OgrSourceTimeFormat::Auto,
1✔
2934
                duration: OgrSourceDurationSpec::Zero,
1✔
2935
            },
1✔
2936
            default_geometry: None,
1✔
2937
            columns: Some(OgrSourceColumnSpec {
1✔
2938
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2939
                    header: CsvHeader::Auto,
1✔
2940
                }),
1✔
2941
                x: "x".to_owned(),
1✔
2942
                y: None,
1✔
2943
                int: vec![],
1✔
2944
                float: vec![],
1✔
2945
                text: vec![],
1✔
2946
                bool: vec![],
1✔
2947
                datetime: vec![],
1✔
2948
                rename: None,
1✔
2949
            }),
1✔
2950
            force_ogr_time_filter: false,
1✔
2951
            force_ogr_spatial_filter: false,
1✔
2952
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2953
            sql_query: None,
1✔
2954
            attribute_query: None,
1✔
2955
            cache_ttl: CacheTtlSeconds::default(),
1✔
2956
        };
1✔
2957

1✔
2958
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2959
            OgrSourceDataset,
1✔
2960
            VectorResultDescriptor,
1✔
2961
            VectorQueryRectangle,
1✔
2962
        > {
1✔
2963
            loading_info: loading_info.clone(),
1✔
2964
            result_descriptor: VectorResultDescriptor {
1✔
2965
                data_type: VectorDataType::MultiPoint,
1✔
2966
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2967
                columns: [(
1✔
2968
                    "foo".to_owned(),
1✔
2969
                    VectorColumnInfo {
1✔
2970
                        data_type: FeatureDataType::Float,
1✔
2971
                        measurement: Measurement::Unitless,
1✔
2972
                    },
1✔
2973
                )]
1✔
2974
                .into_iter()
1✔
2975
                .collect(),
1✔
2976
                time: None,
1✔
2977
                bbox: None,
1✔
2978
            },
1✔
2979
            phantom: Default::default(),
1✔
2980
        });
1✔
2981

2982
        let DatasetIdAndName {
2983
            id: dataset_id1,
1✔
2984
            name: dataset_name1,
1✔
2985
        } = db
1✔
2986
            .add_dataset(
1✔
2987
                AddDataset {
1✔
2988
                    name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2989
                    display_name: "Ogr Test".to_owned(),
1✔
2990
                    description: "desc".to_owned(),
1✔
2991
                    source_operator: "OgrSource".to_owned(),
1✔
2992
                    symbology: None,
1✔
2993
                    provenance: Some(vec![Provenance {
1✔
2994
                        citation: "citation".to_owned(),
1✔
2995
                        license: "license".to_owned(),
1✔
2996
                        uri: "uri".to_owned(),
1✔
2997
                    }]),
1✔
2998
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2999
                },
1✔
3000
                meta_data.clone(),
1✔
3001
            )
1✔
3002
            .await
162✔
3003
            .unwrap();
1✔
3004

1✔
3005
        assert_eq!(
1✔
3006
            db.resolve_dataset_name_to_id(&dataset_name1)
1✔
3007
                .await
3✔
3008
                .unwrap()
1✔
3009
                .unwrap(),
1✔
3010
            dataset_id1
3011
        );
3012
    }
1✔
3013

3014
    #[ge_context::test]
3✔
3015
    #[allow(clippy::too_many_lines)]
3016
    async fn test_postgres_type_serialization(app_ctx: PostgresContext<NoTls>) {
1✔
3017
        let pool = app_ctx.pool.get().await.unwrap();
1✔
3018

1✔
3019
        assert_sql_type(&pool, "RgbaColor", [RgbaColor::new(0, 1, 2, 3)]).await;
4✔
3020

3021
        assert_sql_type(
1✔
3022
            &pool,
1✔
3023
            "double precision",
1✔
3024
            [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
3025
        )
1✔
3026
        .await;
2✔
3027

3028
        assert_sql_type(
1✔
3029
            &pool,
1✔
3030
            "Breakpoint",
1✔
3031
            [Breakpoint {
1✔
3032
                value: NotNan::<f64>::new(1.0).unwrap(),
1✔
3033
                color: RgbaColor::new(0, 0, 0, 0),
1✔
3034
            }],
1✔
3035
        )
1✔
3036
        .await;
5✔
3037

3038
        assert_sql_type(
1✔
3039
            &pool,
1✔
3040
            "Colorizer",
1✔
3041
            [
1✔
3042
                Colorizer::LinearGradient {
1✔
3043
                    breakpoints: vec![
1✔
3044
                        Breakpoint {
1✔
3045
                            value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
3046
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
3047
                        },
1✔
3048
                        Breakpoint {
1✔
3049
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
3050
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
3051
                        },
1✔
3052
                    ],
1✔
3053
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3054
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3055
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3056
                },
1✔
3057
                Colorizer::LogarithmicGradient {
1✔
3058
                    breakpoints: vec![
1✔
3059
                        Breakpoint {
1✔
3060
                            value: NotNan::<f64>::new(1.0).unwrap(),
1✔
3061
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
3062
                        },
1✔
3063
                        Breakpoint {
1✔
3064
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
3065
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
3066
                        },
1✔
3067
                    ],
1✔
3068
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3069
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3070
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3071
                },
1✔
3072
                Colorizer::palette(
1✔
3073
                    [
1✔
3074
                        (NotNan::<f64>::new(1.0).unwrap(), RgbaColor::new(0, 0, 0, 0)),
1✔
3075
                        (
1✔
3076
                            NotNan::<f64>::new(2.0).unwrap(),
1✔
3077
                            RgbaColor::new(255, 0, 0, 255),
1✔
3078
                        ),
1✔
3079
                        (
1✔
3080
                            NotNan::<f64>::new(3.0).unwrap(),
1✔
3081
                            RgbaColor::new(0, 10, 20, 30),
1✔
3082
                        ),
1✔
3083
                    ]
1✔
3084
                    .into(),
1✔
3085
                    RgbaColor::new(1, 2, 3, 4),
1✔
3086
                    RgbaColor::new(5, 6, 7, 8),
1✔
3087
                )
1✔
3088
                .unwrap(),
1✔
3089
                Colorizer::Rgba,
1✔
3090
            ],
1✔
3091
        )
1✔
3092
        .await;
14✔
3093

3094
        assert_sql_type(
1✔
3095
            &pool,
1✔
3096
            "ColorParam",
1✔
3097
            [
1✔
3098
                ColorParam::Static {
1✔
3099
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3100
                },
1✔
3101
                ColorParam::Derived(DerivedColor {
1✔
3102
                    attribute: "foobar".to_string(),
1✔
3103
                    colorizer: Colorizer::Rgba,
1✔
3104
                }),
1✔
3105
            ],
1✔
3106
        )
1✔
3107
        .await;
6✔
3108

3109
        assert_sql_type(
1✔
3110
            &pool,
1✔
3111
            "NumberParam",
1✔
3112
            [
1✔
3113
                NumberParam::Static { value: 42 },
1✔
3114
                NumberParam::Derived(DerivedNumber {
1✔
3115
                    attribute: "foobar".to_string(),
1✔
3116
                    factor: 1.0,
1✔
3117
                    default_value: 42.,
1✔
3118
                }),
1✔
3119
            ],
1✔
3120
        )
1✔
3121
        .await;
6✔
3122

3123
        assert_sql_type(
1✔
3124
            &pool,
1✔
3125
            "StrokeParam",
1✔
3126
            [StrokeParam {
1✔
3127
                width: NumberParam::Static { value: 42 },
1✔
3128
                color: ColorParam::Static {
1✔
3129
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3130
                },
1✔
3131
            }],
1✔
3132
        )
1✔
3133
        .await;
4✔
3134

3135
        assert_sql_type(
1✔
3136
            &pool,
1✔
3137
            "TextSymbology",
1✔
3138
            [TextSymbology {
1✔
3139
                attribute: "attribute".to_string(),
1✔
3140
                fill_color: ColorParam::Static {
1✔
3141
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3142
                },
1✔
3143
                stroke: StrokeParam {
1✔
3144
                    width: NumberParam::Static { value: 42 },
1✔
3145
                    color: ColorParam::Static {
1✔
3146
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
3147
                    },
1✔
3148
                },
1✔
3149
            }],
1✔
3150
        )
1✔
3151
        .await;
4✔
3152

3153
        assert_sql_type(
1✔
3154
            &pool,
1✔
3155
            "Symbology",
1✔
3156
            [
1✔
3157
                Symbology::Point(PointSymbology {
1✔
3158
                    fill_color: ColorParam::Static {
1✔
3159
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
3160
                    },
1✔
3161
                    stroke: StrokeParam {
1✔
3162
                        width: NumberParam::Static { value: 42 },
1✔
3163
                        color: ColorParam::Static {
1✔
3164
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3165
                        },
1✔
3166
                    },
1✔
3167
                    radius: NumberParam::Static { value: 42 },
1✔
3168
                    text: Some(TextSymbology {
1✔
3169
                        attribute: "attribute".to_string(),
1✔
3170
                        fill_color: ColorParam::Static {
1✔
3171
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3172
                        },
1✔
3173
                        stroke: StrokeParam {
1✔
3174
                            width: NumberParam::Static { value: 42 },
1✔
3175
                            color: ColorParam::Static {
1✔
3176
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
3177
                            },
1✔
3178
                        },
1✔
3179
                    }),
1✔
3180
                }),
1✔
3181
                Symbology::Line(LineSymbology {
1✔
3182
                    stroke: StrokeParam {
1✔
3183
                        width: NumberParam::Static { value: 42 },
1✔
3184
                        color: ColorParam::Static {
1✔
3185
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3186
                        },
1✔
3187
                    },
1✔
3188
                    text: Some(TextSymbology {
1✔
3189
                        attribute: "attribute".to_string(),
1✔
3190
                        fill_color: ColorParam::Static {
1✔
3191
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3192
                        },
1✔
3193
                        stroke: StrokeParam {
1✔
3194
                            width: NumberParam::Static { value: 42 },
1✔
3195
                            color: ColorParam::Static {
1✔
3196
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
3197
                            },
1✔
3198
                        },
1✔
3199
                    }),
1✔
3200
                    auto_simplified: true,
1✔
3201
                }),
1✔
3202
                Symbology::Polygon(PolygonSymbology {
1✔
3203
                    fill_color: ColorParam::Static {
1✔
3204
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
3205
                    },
1✔
3206
                    stroke: StrokeParam {
1✔
3207
                        width: NumberParam::Static { value: 42 },
1✔
3208
                        color: ColorParam::Static {
1✔
3209
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3210
                        },
1✔
3211
                    },
1✔
3212
                    text: Some(TextSymbology {
1✔
3213
                        attribute: "attribute".to_string(),
1✔
3214
                        fill_color: ColorParam::Static {
1✔
3215
                            color: RgbaColor::new(0, 10, 20, 30),
1✔
3216
                        },
1✔
3217
                        stroke: StrokeParam {
1✔
3218
                            width: NumberParam::Static { value: 42 },
1✔
3219
                            color: ColorParam::Static {
1✔
3220
                                color: RgbaColor::new(0, 10, 20, 30),
1✔
3221
                            },
1✔
3222
                        },
1✔
3223
                    }),
1✔
3224
                    auto_simplified: true,
1✔
3225
                }),
1✔
3226
                Symbology::Raster(RasterSymbology {
1✔
3227
                    opacity: 1.0,
1✔
3228
                    raster_colorizer: RasterColorizer::SingleBand {
1✔
3229
                        band: 0,
1✔
3230
                        band_colorizer: Colorizer::LinearGradient {
1✔
3231
                            breakpoints: vec![
1✔
3232
                                Breakpoint {
1✔
3233
                                    value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
3234
                                    color: RgbaColor::new(0, 0, 0, 0),
1✔
3235
                                },
1✔
3236
                                Breakpoint {
1✔
3237
                                    value: NotNan::<f64>::new(2.0).unwrap(),
1✔
3238
                                    color: RgbaColor::new(255, 0, 0, 255),
1✔
3239
                                },
1✔
3240
                            ],
1✔
3241
                            no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3242
                            over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3243
                            under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3244
                        },
1✔
3245
                    },
1✔
3246
                }),
1✔
3247
            ],
1✔
3248
        )
1✔
3249
        .await;
22✔
3250

3251
        assert_sql_type(
1✔
3252
            &pool,
1✔
3253
            "RasterDataType",
1✔
3254
            [
1✔
3255
                RasterDataType::U8,
1✔
3256
                RasterDataType::U16,
1✔
3257
                RasterDataType::U32,
1✔
3258
                RasterDataType::U64,
1✔
3259
                RasterDataType::I8,
1✔
3260
                RasterDataType::I16,
1✔
3261
                RasterDataType::I32,
1✔
3262
                RasterDataType::I64,
1✔
3263
                RasterDataType::F32,
1✔
3264
                RasterDataType::F64,
1✔
3265
            ],
1✔
3266
        )
1✔
3267
        .await;
22✔
3268

3269
        assert_sql_type(
1✔
3270
            &pool,
1✔
3271
            "Measurement",
1✔
3272
            [
1✔
3273
                Measurement::Unitless,
1✔
3274
                Measurement::Continuous(ContinuousMeasurement {
1✔
3275
                    measurement: "Temperature".to_string(),
1✔
3276
                    unit: Some("°C".to_string()),
1✔
3277
                }),
1✔
3278
                Measurement::Classification(ClassificationMeasurement {
1✔
3279
                    measurement: "Color".to_string(),
1✔
3280
                    classes: [(1, "Grayscale".to_string()), (2, "Colorful".to_string())].into(),
1✔
3281
                }),
1✔
3282
            ],
1✔
3283
        )
1✔
3284
        .await;
15✔
3285

3286
        assert_sql_type(&pool, "Coordinate2D", [Coordinate2D::new(0.0f64, 1.)]).await;
4✔
3287

3288
        assert_sql_type(
1✔
3289
            &pool,
1✔
3290
            "SpatialPartition2D",
1✔
3291
            [
1✔
3292
                SpatialPartition2D::new(Coordinate2D::new(0.0f64, 1.), Coordinate2D::new(2., 0.5))
1✔
3293
                    .unwrap(),
1✔
3294
            ],
1✔
3295
        )
1✔
3296
        .await;
5✔
3297

3298
        assert_sql_type(
1✔
3299
            &pool,
1✔
3300
            "BoundingBox2D",
1✔
3301
            [
1✔
3302
                BoundingBox2D::new(Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0))
1✔
3303
                    .unwrap(),
1✔
3304
            ],
1✔
3305
        )
1✔
3306
        .await;
4✔
3307

3308
        assert_sql_type(
1✔
3309
            &pool,
1✔
3310
            "SpatialResolution",
1✔
3311
            [SpatialResolution { x: 1.2, y: 2.3 }],
1✔
3312
        )
1✔
3313
        .await;
4✔
3314

3315
        assert_sql_type(
1✔
3316
            &pool,
1✔
3317
            "VectorDataType",
1✔
3318
            [
1✔
3319
                VectorDataType::Data,
1✔
3320
                VectorDataType::MultiPoint,
1✔
3321
                VectorDataType::MultiLineString,
1✔
3322
                VectorDataType::MultiPolygon,
1✔
3323
            ],
1✔
3324
        )
1✔
3325
        .await;
10✔
3326

3327
        assert_sql_type(
1✔
3328
            &pool,
1✔
3329
            "FeatureDataType",
1✔
3330
            [
1✔
3331
                FeatureDataType::Category,
1✔
3332
                FeatureDataType::Int,
1✔
3333
                FeatureDataType::Float,
1✔
3334
                FeatureDataType::Text,
1✔
3335
                FeatureDataType::Bool,
1✔
3336
                FeatureDataType::DateTime,
1✔
3337
            ],
1✔
3338
        )
1✔
3339
        .await;
14✔
3340

3341
        assert_sql_type(&pool, "TimeInterval", [TimeInterval::default()]).await;
4✔
3342

3343
        assert_sql_type(
1✔
3344
            &pool,
1✔
3345
            "SpatialReference",
1✔
3346
            [
1✔
3347
                SpatialReferenceOption::Unreferenced,
1✔
3348
                SpatialReferenceOption::SpatialReference(SpatialReference::epsg_4326()),
1✔
3349
            ],
1✔
3350
        )
1✔
3351
        .await;
8✔
3352

3353
        assert_sql_type(
1✔
3354
            &pool,
1✔
3355
            "PlotResultDescriptor",
1✔
3356
            [PlotResultDescriptor {
1✔
3357
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
3358
                time: None,
1✔
3359
                bbox: None,
1✔
3360
            }],
1✔
3361
        )
1✔
3362
        .await;
4✔
3363

3364
        assert_sql_type(
1✔
3365
            &pool,
1✔
3366
            "VectorResultDescriptor",
1✔
3367
            [VectorResultDescriptor {
1✔
3368
                data_type: VectorDataType::MultiPoint,
1✔
3369
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3370
                    SpatialReference::epsg_4326(),
1✔
3371
                ),
1✔
3372
                columns: [(
1✔
3373
                    "foo".to_string(),
1✔
3374
                    VectorColumnInfo {
1✔
3375
                        data_type: FeatureDataType::Int,
1✔
3376
                        measurement: Measurement::Unitless,
1✔
3377
                    },
1✔
3378
                )]
1✔
3379
                .into(),
1✔
3380
                time: Some(TimeInterval::default()),
1✔
3381
                bbox: Some(
1✔
3382
                    BoundingBox2D::new(Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0))
1✔
3383
                        .unwrap(),
1✔
3384
                ),
1✔
3385
            }],
1✔
3386
        )
1✔
3387
        .await;
7✔
3388

3389
        assert_sql_type(
1✔
3390
            &pool,
1✔
3391
            "RasterResultDescriptor",
1✔
3392
            [RasterResultDescriptor {
1✔
3393
                data_type: RasterDataType::U8,
1✔
3394
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3395
                    SpatialReference::epsg_4326(),
1✔
3396
                ),
1✔
3397
                time: Some(TimeInterval::default()),
1✔
3398
                bbox: Some(
1✔
3399
                    SpatialPartition2D::new(
1✔
3400
                        Coordinate2D::new(0.0f64, 1.),
1✔
3401
                        Coordinate2D::new(2., 0.5),
1✔
3402
                    )
1✔
3403
                    .unwrap(),
1✔
3404
                ),
1✔
3405
                resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }),
1✔
3406
                bands: RasterBandDescriptors::new_single_band(),
1✔
3407
            }],
1✔
3408
        )
1✔
3409
        .await;
7✔
3410

3411
        assert_sql_type(
1✔
3412
            &pool,
1✔
3413
            "ResultDescriptor",
1✔
3414
            [
1✔
3415
                TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
3416
                    data_type: VectorDataType::MultiPoint,
1✔
3417
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3418
                        SpatialReference::epsg_4326(),
1✔
3419
                    ),
1✔
3420
                    columns: [(
1✔
3421
                        "foo".to_string(),
1✔
3422
                        VectorColumnInfo {
1✔
3423
                            data_type: FeatureDataType::Int,
1✔
3424
                            measurement: Measurement::Unitless,
1✔
3425
                        },
1✔
3426
                    )]
1✔
3427
                    .into(),
1✔
3428
                    time: Some(TimeInterval::default()),
1✔
3429
                    bbox: Some(
1✔
3430
                        BoundingBox2D::new(
1✔
3431
                            Coordinate2D::new(0.0f64, 0.5),
1✔
3432
                            Coordinate2D::new(2., 1.0),
1✔
3433
                        )
1✔
3434
                        .unwrap(),
1✔
3435
                    ),
1✔
3436
                }),
1✔
3437
                TypedResultDescriptor::Raster(RasterResultDescriptor {
1✔
3438
                    data_type: RasterDataType::U8,
1✔
3439
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3440
                        SpatialReference::epsg_4326(),
1✔
3441
                    ),
1✔
3442
                    time: Some(TimeInterval::default()),
1✔
3443
                    bbox: Some(
1✔
3444
                        SpatialPartition2D::new(
1✔
3445
                            Coordinate2D::new(0.0f64, 1.),
1✔
3446
                            Coordinate2D::new(2., 0.5),
1✔
3447
                        )
1✔
3448
                        .unwrap(),
1✔
3449
                    ),
1✔
3450
                    resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }),
1✔
3451
                    bands: RasterBandDescriptors::new_single_band(),
1✔
3452
                }),
1✔
3453
                TypedResultDescriptor::Plot(PlotResultDescriptor {
1✔
3454
                    spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
3455
                    time: None,
1✔
3456
                    bbox: None,
1✔
3457
                }),
1✔
3458
            ],
1✔
3459
        )
1✔
3460
        .await;
8✔
3461

3462
        assert_sql_type(
1✔
3463
            &pool,
1✔
3464
            "MockDatasetDataSourceLoadingInfo",
1✔
3465
            [MockDatasetDataSourceLoadingInfo {
1✔
3466
                points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3467
            }],
1✔
3468
        )
1✔
3469
        .await;
5✔
3470

3471
        assert_sql_type(
1✔
3472
            &pool,
1✔
3473
            "OgrSourceTimeFormat",
1✔
3474
            [
1✔
3475
                OgrSourceTimeFormat::Auto,
1✔
3476
                OgrSourceTimeFormat::Custom {
1✔
3477
                    custom_format: geoengine_datatypes::primitives::DateTimeParseFormat::custom(
1✔
3478
                        "%Y-%m-%dT%H:%M:%S%.3fZ".to_string(),
1✔
3479
                    ),
1✔
3480
                },
1✔
3481
                OgrSourceTimeFormat::UnixTimeStamp {
1✔
3482
                    timestamp_type: UnixTimeStampType::EpochSeconds,
1✔
3483
                    fmt: geoengine_datatypes::primitives::DateTimeParseFormat::unix(),
1✔
3484
                },
1✔
3485
            ],
1✔
3486
        )
1✔
3487
        .await;
17✔
3488

3489
        assert_sql_type(
1✔
3490
            &pool,
1✔
3491
            "OgrSourceDurationSpec",
1✔
3492
            [
1✔
3493
                OgrSourceDurationSpec::Infinite,
1✔
3494
                OgrSourceDurationSpec::Zero,
1✔
3495
                OgrSourceDurationSpec::Value(TimeStep {
1✔
3496
                    granularity: TimeGranularity::Millis,
1✔
3497
                    step: 1000,
1✔
3498
                }),
1✔
3499
            ],
1✔
3500
        )
1✔
3501
        .await;
12✔
3502

3503
        assert_sql_type(
1✔
3504
            &pool,
1✔
3505
            "OgrSourceDatasetTimeType",
1✔
3506
            [
1✔
3507
                OgrSourceDatasetTimeType::None,
1✔
3508
                OgrSourceDatasetTimeType::Start {
1✔
3509
                    start_field: "start".to_string(),
1✔
3510
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3511
                    duration: OgrSourceDurationSpec::Zero,
1✔
3512
                },
1✔
3513
                OgrSourceDatasetTimeType::StartEnd {
1✔
3514
                    start_field: "start".to_string(),
1✔
3515
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3516
                    end_field: "end".to_string(),
1✔
3517
                    end_format: OgrSourceTimeFormat::Auto,
1✔
3518
                },
1✔
3519
                OgrSourceDatasetTimeType::StartDuration {
1✔
3520
                    start_field: "start".to_string(),
1✔
3521
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3522
                    duration_field: "duration".to_string(),
1✔
3523
                },
1✔
3524
            ],
1✔
3525
        )
1✔
3526
        .await;
16✔
3527

3528
        assert_sql_type(
1✔
3529
            &pool,
1✔
3530
            "FormatSpecifics",
1✔
3531
            [FormatSpecifics::Csv {
1✔
3532
                header: CsvHeader::Yes,
1✔
3533
            }],
1✔
3534
        )
1✔
3535
        .await;
8✔
3536

3537
        assert_sql_type(
1✔
3538
            &pool,
1✔
3539
            "OgrSourceColumnSpec",
1✔
3540
            [OgrSourceColumnSpec {
1✔
3541
                format_specifics: Some(FormatSpecifics::Csv {
1✔
3542
                    header: CsvHeader::Auto,
1✔
3543
                }),
1✔
3544
                x: "x".to_string(),
1✔
3545
                y: Some("y".to_string()),
1✔
3546
                int: vec!["int".to_string()],
1✔
3547
                float: vec!["float".to_string()],
1✔
3548
                text: vec!["text".to_string()],
1✔
3549
                bool: vec!["bool".to_string()],
1✔
3550
                datetime: vec!["datetime".to_string()],
1✔
3551
                rename: Some(
1✔
3552
                    [
1✔
3553
                        ("xx".to_string(), "xx_renamed".to_string()),
1✔
3554
                        ("yx".to_string(), "yy_renamed".to_string()),
1✔
3555
                    ]
1✔
3556
                    .into(),
1✔
3557
                ),
1✔
3558
            }],
1✔
3559
        )
1✔
3560
        .await;
7✔
3561

3562
        assert_sql_type(
1✔
3563
            &pool,
1✔
3564
            "point[]",
1✔
3565
            [MultiPoint::new(vec![
1✔
3566
                Coordinate2D::new(0.0f64, 0.5),
1✔
3567
                Coordinate2D::new(2., 1.0),
1✔
3568
            ])
1✔
3569
            .unwrap()],
1✔
3570
        )
1✔
3571
        .await;
2✔
3572

3573
        assert_sql_type(
1✔
3574
            &pool,
1✔
3575
            "path[]",
1✔
3576
            [MultiLineString::new(vec![
1✔
3577
                vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3578
                vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3579
            ])
1✔
3580
            .unwrap()],
1✔
3581
        )
1✔
3582
        .await;
2✔
3583

3584
        assert_sql_type(
1✔
3585
            &pool,
1✔
3586
            "\"Polygon\"[]",
1✔
3587
            [MultiPolygon::new(vec![
1✔
3588
                vec![
1✔
3589
                    vec![
1✔
3590
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3591
                        Coordinate2D::new(2., 1.0),
1✔
3592
                        Coordinate2D::new(2., 1.0),
1✔
3593
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3594
                    ],
1✔
3595
                    vec![
1✔
3596
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3597
                        Coordinate2D::new(2., 1.0),
1✔
3598
                        Coordinate2D::new(2., 1.0),
1✔
3599
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3600
                    ],
1✔
3601
                ],
1✔
3602
                vec![
1✔
3603
                    vec![
1✔
3604
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3605
                        Coordinate2D::new(2., 1.0),
1✔
3606
                        Coordinate2D::new(2., 1.0),
1✔
3607
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3608
                    ],
1✔
3609
                    vec![
1✔
3610
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3611
                        Coordinate2D::new(2., 1.0),
1✔
3612
                        Coordinate2D::new(2., 1.0),
1✔
3613
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3614
                    ],
1✔
3615
                ],
1✔
3616
            ])
1✔
3617
            .unwrap()],
1✔
3618
        )
1✔
3619
        .await;
4✔
3620

3621
        assert_sql_type(
1✔
3622
            &pool,
1✔
3623
            "TypedGeometry",
1✔
3624
            [
1✔
3625
                TypedGeometry::Data(NoGeometry),
1✔
3626
                TypedGeometry::MultiPoint(
1✔
3627
                    MultiPoint::new(vec![
1✔
3628
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3629
                        Coordinate2D::new(2., 1.0),
1✔
3630
                    ])
1✔
3631
                    .unwrap(),
1✔
3632
                ),
1✔
3633
                TypedGeometry::MultiLineString(
1✔
3634
                    MultiLineString::new(vec![
1✔
3635
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3636
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3637
                    ])
1✔
3638
                    .unwrap(),
1✔
3639
                ),
1✔
3640
                TypedGeometry::MultiPolygon(
1✔
3641
                    MultiPolygon::new(vec![
1✔
3642
                        vec![
1✔
3643
                            vec![
1✔
3644
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3645
                                Coordinate2D::new(2., 1.0),
1✔
3646
                                Coordinate2D::new(2., 1.0),
1✔
3647
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3648
                            ],
1✔
3649
                            vec![
1✔
3650
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3651
                                Coordinate2D::new(2., 1.0),
1✔
3652
                                Coordinate2D::new(2., 1.0),
1✔
3653
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3654
                            ],
1✔
3655
                        ],
1✔
3656
                        vec![
1✔
3657
                            vec![
1✔
3658
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3659
                                Coordinate2D::new(2., 1.0),
1✔
3660
                                Coordinate2D::new(2., 1.0),
1✔
3661
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3662
                            ],
1✔
3663
                            vec![
1✔
3664
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3665
                                Coordinate2D::new(2., 1.0),
1✔
3666
                                Coordinate2D::new(2., 1.0),
1✔
3667
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3668
                            ],
1✔
3669
                        ],
1✔
3670
                    ])
1✔
3671
                    .unwrap(),
1✔
3672
                ),
1✔
3673
            ],
1✔
3674
        )
1✔
3675
        .await;
11✔
3676

3677
        assert_sql_type(&pool, "int", [CacheTtlSeconds::new(100)]).await;
2✔
3678

3679
        assert_sql_type(
1✔
3680
            &pool,
1✔
3681
            "OgrSourceDataset",
1✔
3682
            [OgrSourceDataset {
1✔
3683
                file_name: "test".into(),
1✔
3684
                layer_name: "test".to_string(),
1✔
3685
                data_type: Some(VectorDataType::MultiPoint),
1✔
3686
                time: OgrSourceDatasetTimeType::Start {
1✔
3687
                    start_field: "start".to_string(),
1✔
3688
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3689
                    duration: OgrSourceDurationSpec::Zero,
1✔
3690
                },
1✔
3691
                default_geometry: Some(TypedGeometry::MultiPoint(
1✔
3692
                    MultiPoint::new(vec![
1✔
3693
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3694
                        Coordinate2D::new(2., 1.0),
1✔
3695
                    ])
1✔
3696
                    .unwrap(),
1✔
3697
                )),
1✔
3698
                columns: Some(OgrSourceColumnSpec {
1✔
3699
                    format_specifics: Some(FormatSpecifics::Csv {
1✔
3700
                        header: CsvHeader::Auto,
1✔
3701
                    }),
1✔
3702
                    x: "x".to_string(),
1✔
3703
                    y: Some("y".to_string()),
1✔
3704
                    int: vec!["int".to_string()],
1✔
3705
                    float: vec!["float".to_string()],
1✔
3706
                    text: vec!["text".to_string()],
1✔
3707
                    bool: vec!["bool".to_string()],
1✔
3708
                    datetime: vec!["datetime".to_string()],
1✔
3709
                    rename: Some(
1✔
3710
                        [
1✔
3711
                            ("xx".to_string(), "xx_renamed".to_string()),
1✔
3712
                            ("yx".to_string(), "yy_renamed".to_string()),
1✔
3713
                        ]
1✔
3714
                        .into(),
1✔
3715
                    ),
1✔
3716
                }),
1✔
3717
                force_ogr_time_filter: false,
1✔
3718
                force_ogr_spatial_filter: true,
1✔
3719
                on_error: OgrSourceErrorSpec::Abort,
1✔
3720
                sql_query: None,
1✔
3721
                attribute_query: Some("foo = 'bar'".to_string()),
1✔
3722
                cache_ttl: CacheTtlSeconds::new(5),
1✔
3723
            }],
1✔
3724
        )
1✔
3725
        .await;
6✔
3726

3727
        assert_sql_type(
1✔
3728
            &pool,
1✔
3729
            "MockMetaData",
1✔
3730
            [StaticMetaData::<
1✔
3731
                MockDatasetDataSourceLoadingInfo,
1✔
3732
                VectorResultDescriptor,
1✔
3733
                VectorQueryRectangle,
1✔
3734
            > {
1✔
3735
                loading_info: MockDatasetDataSourceLoadingInfo {
1✔
3736
                    points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3737
                },
1✔
3738
                result_descriptor: VectorResultDescriptor {
1✔
3739
                    data_type: VectorDataType::MultiPoint,
1✔
3740
                    spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3741
                        SpatialReference::epsg_4326(),
1✔
3742
                    ),
1✔
3743
                    columns: [(
1✔
3744
                        "foo".to_string(),
1✔
3745
                        VectorColumnInfo {
1✔
3746
                            data_type: FeatureDataType::Int,
1✔
3747
                            measurement: Measurement::Unitless,
1✔
3748
                        },
1✔
3749
                    )]
1✔
3750
                    .into(),
1✔
3751
                    time: Some(TimeInterval::default()),
1✔
3752
                    bbox: Some(
1✔
3753
                        BoundingBox2D::new(
1✔
3754
                            Coordinate2D::new(0.0f64, 0.5),
1✔
3755
                            Coordinate2D::new(2., 1.0),
1✔
3756
                        )
1✔
3757
                        .unwrap(),
1✔
3758
                    ),
1✔
3759
                },
1✔
3760
                phantom: PhantomData,
1✔
3761
            }],
1✔
3762
        )
1✔
3763
        .await;
4✔
3764

3765
        assert_sql_type(
1✔
3766
            &pool,
1✔
3767
            "OgrMetaData",
1✔
3768
            [
1✔
3769
                StaticMetaData::<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle> {
1✔
3770
                    loading_info: OgrSourceDataset {
1✔
3771
                        file_name: "test".into(),
1✔
3772
                        layer_name: "test".to_string(),
1✔
3773
                        data_type: Some(VectorDataType::MultiPoint),
1✔
3774
                        time: OgrSourceDatasetTimeType::Start {
1✔
3775
                            start_field: "start".to_string(),
1✔
3776
                            start_format: OgrSourceTimeFormat::Auto,
1✔
3777
                            duration: OgrSourceDurationSpec::Zero,
1✔
3778
                        },
1✔
3779
                        default_geometry: Some(TypedGeometry::MultiPoint(
1✔
3780
                            MultiPoint::new(vec![
1✔
3781
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3782
                                Coordinate2D::new(2., 1.0),
1✔
3783
                            ])
1✔
3784
                            .unwrap(),
1✔
3785
                        )),
1✔
3786
                        columns: Some(OgrSourceColumnSpec {
1✔
3787
                            format_specifics: Some(FormatSpecifics::Csv {
1✔
3788
                                header: CsvHeader::Auto,
1✔
3789
                            }),
1✔
3790
                            x: "x".to_string(),
1✔
3791
                            y: Some("y".to_string()),
1✔
3792
                            int: vec!["int".to_string()],
1✔
3793
                            float: vec!["float".to_string()],
1✔
3794
                            text: vec!["text".to_string()],
1✔
3795
                            bool: vec!["bool".to_string()],
1✔
3796
                            datetime: vec!["datetime".to_string()],
1✔
3797
                            rename: Some(
1✔
3798
                                [
1✔
3799
                                    ("xx".to_string(), "xx_renamed".to_string()),
1✔
3800
                                    ("yx".to_string(), "yy_renamed".to_string()),
1✔
3801
                                ]
1✔
3802
                                .into(),
1✔
3803
                            ),
1✔
3804
                        }),
1✔
3805
                        force_ogr_time_filter: false,
1✔
3806
                        force_ogr_spatial_filter: true,
1✔
3807
                        on_error: OgrSourceErrorSpec::Abort,
1✔
3808
                        sql_query: None,
1✔
3809
                        attribute_query: Some("foo = 'bar'".to_string()),
1✔
3810
                        cache_ttl: CacheTtlSeconds::new(5),
1✔
3811
                    },
1✔
3812
                    result_descriptor: VectorResultDescriptor {
1✔
3813
                        data_type: VectorDataType::MultiPoint,
1✔
3814
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3815
                            SpatialReference::epsg_4326(),
1✔
3816
                        ),
1✔
3817
                        columns: [(
1✔
3818
                            "foo".to_string(),
1✔
3819
                            VectorColumnInfo {
1✔
3820
                                data_type: FeatureDataType::Int,
1✔
3821
                                measurement: Measurement::Unitless,
1✔
3822
                            },
1✔
3823
                        )]
1✔
3824
                        .into(),
1✔
3825
                        time: Some(TimeInterval::default()),
1✔
3826
                        bbox: Some(
1✔
3827
                            BoundingBox2D::new(
1✔
3828
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3829
                                Coordinate2D::new(2., 1.0),
1✔
3830
                            )
1✔
3831
                            .unwrap(),
1✔
3832
                        ),
1✔
3833
                    },
1✔
3834
                    phantom: PhantomData,
1✔
3835
                },
1✔
3836
            ],
1✔
3837
        )
1✔
3838
        .await;
4✔
3839

3840
        assert_sql_type(
1✔
3841
            &pool,
1✔
3842
            "GdalDatasetGeoTransform",
1✔
3843
            [GdalDatasetGeoTransform {
1✔
3844
                origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3845
                x_pixel_size: 1.0,
1✔
3846
                y_pixel_size: 2.0,
1✔
3847
            }],
1✔
3848
        )
1✔
3849
        .await;
4✔
3850

3851
        assert_sql_type(
1✔
3852
            &pool,
1✔
3853
            "FileNotFoundHandling",
1✔
3854
            [FileNotFoundHandling::NoData, FileNotFoundHandling::Error],
1✔
3855
        )
1✔
3856
        .await;
6✔
3857

3858
        assert_sql_type(
1✔
3859
            &pool,
1✔
3860
            "GdalMetadataMapping",
1✔
3861
            [GdalMetadataMapping {
1✔
3862
                source_key: RasterPropertiesKey {
1✔
3863
                    domain: None,
1✔
3864
                    key: "foo".to_string(),
1✔
3865
                },
1✔
3866
                target_key: RasterPropertiesKey {
1✔
3867
                    domain: Some("bar".to_string()),
1✔
3868
                    key: "foo".to_string(),
1✔
3869
                },
1✔
3870
                target_type: RasterPropertiesEntryType::String,
1✔
3871
            }],
1✔
3872
        )
1✔
3873
        .await;
8✔
3874

3875
        assert_sql_type(
1✔
3876
            &pool,
1✔
3877
            "StringPair",
1✔
3878
            [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3879
        )
1✔
3880
        .await;
3✔
3881

3882
        assert_sql_type(
1✔
3883
            &pool,
1✔
3884
            "GdalDatasetParameters",
1✔
3885
            [GdalDatasetParameters {
1✔
3886
                file_path: "text".into(),
1✔
3887
                rasterband_channel: 1,
1✔
3888
                geo_transform: GdalDatasetGeoTransform {
1✔
3889
                    origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3890
                    x_pixel_size: 1.0,
1✔
3891
                    y_pixel_size: 2.0,
1✔
3892
                },
1✔
3893
                width: 42,
1✔
3894
                height: 23,
1✔
3895
                file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3896
                no_data_value: Some(42.0),
1✔
3897
                properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3898
                    source_key: RasterPropertiesKey {
1✔
3899
                        domain: None,
1✔
3900
                        key: "foo".to_string(),
1✔
3901
                    },
1✔
3902
                    target_key: RasterPropertiesKey {
1✔
3903
                        domain: Some("bar".to_string()),
1✔
3904
                        key: "foo".to_string(),
1✔
3905
                    },
1✔
3906
                    target_type: RasterPropertiesEntryType::String,
1✔
3907
                }]),
1✔
3908
                gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3909
                gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3910
                allow_alphaband_as_mask: false,
1✔
3911
                retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3912
            }],
1✔
3913
        )
1✔
3914
        .await;
8✔
3915

3916
        assert_sql_type(
1✔
3917
            &pool,
1✔
3918
            "GdalMetaDataRegular",
1✔
3919
            [GdalMetaDataRegular {
1✔
3920
                result_descriptor: RasterResultDescriptor {
1✔
3921
                    data_type: RasterDataType::U8,
1✔
3922
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3923
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3924
                    bbox: Some(
1✔
3925
                        SpatialPartition2D::new(
1✔
3926
                            Coordinate2D::new(0.0f64, 1.),
1✔
3927
                            Coordinate2D::new(2., 0.5),
1✔
3928
                        )
1✔
3929
                        .unwrap(),
1✔
3930
                    ),
1✔
3931
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
3932
                    bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
3933
                        "band".into(),
1✔
3934
                        Measurement::Continuous(ContinuousMeasurement {
1✔
3935
                            measurement: "Temperature".to_string(),
1✔
3936
                            unit: Some("°C".to_string()),
1✔
3937
                        }),
1✔
3938
                    )])
1✔
3939
                    .unwrap(),
1✔
3940
                },
1✔
3941
                params: GdalDatasetParameters {
1✔
3942
                    file_path: "text".into(),
1✔
3943
                    rasterband_channel: 1,
1✔
3944
                    geo_transform: GdalDatasetGeoTransform {
1✔
3945
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3946
                        x_pixel_size: 1.0,
1✔
3947
                        y_pixel_size: 2.0,
1✔
3948
                    },
1✔
3949
                    width: 42,
1✔
3950
                    height: 23,
1✔
3951
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
3952
                    no_data_value: Some(42.0),
1✔
3953
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
3954
                        source_key: RasterPropertiesKey {
1✔
3955
                            domain: None,
1✔
3956
                            key: "foo".to_string(),
1✔
3957
                        },
1✔
3958
                        target_key: RasterPropertiesKey {
1✔
3959
                            domain: Some("bar".to_string()),
1✔
3960
                            key: "foo".to_string(),
1✔
3961
                        },
1✔
3962
                        target_type: RasterPropertiesEntryType::String,
1✔
3963
                    }]),
1✔
3964
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
3965
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
3966
                    allow_alphaband_as_mask: false,
1✔
3967
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
3968
                },
1✔
3969
                time_placeholders: [(
1✔
3970
                    "foo".to_string(),
1✔
3971
                    GdalSourceTimePlaceholder {
1✔
3972
                        format: geoengine_datatypes::primitives::DateTimeParseFormat::unix(),
1✔
3973
                        reference: TimeReference::Start,
1✔
3974
                    },
1✔
3975
                )]
1✔
3976
                .into(),
1✔
3977
                data_time: TimeInterval::new_unchecked(0, 1),
1✔
3978
                step: TimeStep {
1✔
3979
                    granularity: TimeGranularity::Millis,
1✔
3980
                    step: 1,
1✔
3981
                },
1✔
3982
                cache_ttl: CacheTtlSeconds::max(),
1✔
3983
            }],
1✔
3984
        )
1✔
3985
        .await;
12✔
3986

3987
        assert_sql_type(
1✔
3988
            &pool,
1✔
3989
            "GdalMetaDataStatic",
1✔
3990
            [GdalMetaDataStatic {
1✔
3991
                time: Some(TimeInterval::new_unchecked(0, 1)),
1✔
3992
                result_descriptor: RasterResultDescriptor {
1✔
3993
                    data_type: RasterDataType::U8,
1✔
3994
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
3995
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
3996
                    bbox: Some(
1✔
3997
                        SpatialPartition2D::new(
1✔
3998
                            Coordinate2D::new(0.0f64, 1.),
1✔
3999
                            Coordinate2D::new(2., 0.5),
1✔
4000
                        )
1✔
4001
                        .unwrap(),
1✔
4002
                    ),
1✔
4003
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
4004
                    bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4005
                        "band".into(),
1✔
4006
                        Measurement::Continuous(ContinuousMeasurement {
1✔
4007
                            measurement: "Temperature".to_string(),
1✔
4008
                            unit: Some("°C".to_string()),
1✔
4009
                        }),
1✔
4010
                    )])
1✔
4011
                    .unwrap(),
1✔
4012
                },
1✔
4013
                params: GdalDatasetParameters {
1✔
4014
                    file_path: "text".into(),
1✔
4015
                    rasterband_channel: 1,
1✔
4016
                    geo_transform: GdalDatasetGeoTransform {
1✔
4017
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4018
                        x_pixel_size: 1.0,
1✔
4019
                        y_pixel_size: 2.0,
1✔
4020
                    },
1✔
4021
                    width: 42,
1✔
4022
                    height: 23,
1✔
4023
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4024
                    no_data_value: Some(42.0),
1✔
4025
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4026
                        source_key: RasterPropertiesKey {
1✔
4027
                            domain: None,
1✔
4028
                            key: "foo".to_string(),
1✔
4029
                        },
1✔
4030
                        target_key: RasterPropertiesKey {
1✔
4031
                            domain: Some("bar".to_string()),
1✔
4032
                            key: "foo".to_string(),
1✔
4033
                        },
1✔
4034
                        target_type: RasterPropertiesEntryType::String,
1✔
4035
                    }]),
1✔
4036
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4037
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4038
                    allow_alphaband_as_mask: false,
1✔
4039
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4040
                },
1✔
4041
                cache_ttl: CacheTtlSeconds::max(),
1✔
4042
            }],
1✔
4043
        )
1✔
4044
        .await;
4✔
4045

4046
        assert_sql_type(
1✔
4047
            &pool,
1✔
4048
            "GdalMetadataNetCdfCf",
1✔
4049
            [GdalMetadataNetCdfCf {
1✔
4050
                result_descriptor: RasterResultDescriptor {
1✔
4051
                    data_type: RasterDataType::U8,
1✔
4052
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4053
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4054
                    bbox: Some(
1✔
4055
                        SpatialPartition2D::new(
1✔
4056
                            Coordinate2D::new(0.0f64, 1.),
1✔
4057
                            Coordinate2D::new(2., 0.5),
1✔
4058
                        )
1✔
4059
                        .unwrap(),
1✔
4060
                    ),
1✔
4061
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
4062
                    bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4063
                        "band".into(),
1✔
4064
                        Measurement::Continuous(ContinuousMeasurement {
1✔
4065
                            measurement: "Temperature".to_string(),
1✔
4066
                            unit: Some("°C".to_string()),
1✔
4067
                        }),
1✔
4068
                    )])
1✔
4069
                    .unwrap(),
1✔
4070
                },
1✔
4071
                params: GdalDatasetParameters {
1✔
4072
                    file_path: "text".into(),
1✔
4073
                    rasterband_channel: 1,
1✔
4074
                    geo_transform: GdalDatasetGeoTransform {
1✔
4075
                        origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4076
                        x_pixel_size: 1.0,
1✔
4077
                        y_pixel_size: 2.0,
1✔
4078
                    },
1✔
4079
                    width: 42,
1✔
4080
                    height: 23,
1✔
4081
                    file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4082
                    no_data_value: Some(42.0),
1✔
4083
                    properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4084
                        source_key: RasterPropertiesKey {
1✔
4085
                            domain: None,
1✔
4086
                            key: "foo".to_string(),
1✔
4087
                        },
1✔
4088
                        target_key: RasterPropertiesKey {
1✔
4089
                            domain: Some("bar".to_string()),
1✔
4090
                            key: "foo".to_string(),
1✔
4091
                        },
1✔
4092
                        target_type: RasterPropertiesEntryType::String,
1✔
4093
                    }]),
1✔
4094
                    gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4095
                    gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4096
                    allow_alphaband_as_mask: false,
1✔
4097
                    retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4098
                },
1✔
4099
                start: TimeInstance::from_millis(0).unwrap(),
1✔
4100
                end: TimeInstance::from_millis(1000).unwrap(),
1✔
4101
                cache_ttl: CacheTtlSeconds::max(),
1✔
4102
                step: TimeStep {
1✔
4103
                    granularity: TimeGranularity::Millis,
1✔
4104
                    step: 1,
1✔
4105
                },
1✔
4106
                band_offset: 3,
1✔
4107
            }],
1✔
4108
        )
1✔
4109
        .await;
4✔
4110

4111
        assert_sql_type(
1✔
4112
            &pool,
1✔
4113
            "GdalMetaDataList",
1✔
4114
            [GdalMetaDataList {
1✔
4115
                result_descriptor: RasterResultDescriptor {
1✔
4116
                    data_type: RasterDataType::U8,
1✔
4117
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4118
                    time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4119
                    bbox: Some(
1✔
4120
                        SpatialPartition2D::new(
1✔
4121
                            Coordinate2D::new(0.0f64, 1.),
1✔
4122
                            Coordinate2D::new(2., 0.5),
1✔
4123
                        )
1✔
4124
                        .unwrap(),
1✔
4125
                    ),
1✔
4126
                    resolution: Some(SpatialResolution::zero_point_one()),
1✔
4127
                    bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4128
                        "band".into(),
1✔
4129
                        Measurement::Continuous(ContinuousMeasurement {
1✔
4130
                            measurement: "Temperature".to_string(),
1✔
4131
                            unit: Some("°C".to_string()),
1✔
4132
                        }),
1✔
4133
                    )])
1✔
4134
                    .unwrap(),
1✔
4135
                },
1✔
4136
                params: vec![GdalLoadingInfoTemporalSlice {
1✔
4137
                    time: TimeInterval::new_unchecked(0, 1),
1✔
4138
                    params: Some(GdalDatasetParameters {
1✔
4139
                        file_path: "text".into(),
1✔
4140
                        rasterband_channel: 1,
1✔
4141
                        geo_transform: GdalDatasetGeoTransform {
1✔
4142
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4143
                            x_pixel_size: 1.0,
1✔
4144
                            y_pixel_size: 2.0,
1✔
4145
                        },
1✔
4146
                        width: 42,
1✔
4147
                        height: 23,
1✔
4148
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4149
                        no_data_value: Some(42.0),
1✔
4150
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4151
                            source_key: RasterPropertiesKey {
1✔
4152
                                domain: None,
1✔
4153
                                key: "foo".to_string(),
1✔
4154
                            },
1✔
4155
                            target_key: RasterPropertiesKey {
1✔
4156
                                domain: Some("bar".to_string()),
1✔
4157
                                key: "foo".to_string(),
1✔
4158
                            },
1✔
4159
                            target_type: RasterPropertiesEntryType::String,
1✔
4160
                        }]),
1✔
4161
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4162
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4163
                        allow_alphaband_as_mask: false,
1✔
4164
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4165
                    }),
1✔
4166
                    cache_ttl: CacheTtlSeconds::max(),
1✔
4167
                }],
1✔
4168
            }],
1✔
4169
        )
1✔
4170
        .await;
7✔
4171

4172
        assert_sql_type(
1✔
4173
            &pool,
1✔
4174
            "MetaDataDefinition",
1✔
4175
            [
1✔
4176
                MetaDataDefinition::MockMetaData(StaticMetaData::<
1✔
4177
                    MockDatasetDataSourceLoadingInfo,
1✔
4178
                    VectorResultDescriptor,
1✔
4179
                    VectorQueryRectangle,
1✔
4180
                > {
1✔
4181
                    loading_info: MockDatasetDataSourceLoadingInfo {
1✔
4182
                        points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
4183
                    },
1✔
4184
                    result_descriptor: VectorResultDescriptor {
1✔
4185
                        data_type: VectorDataType::MultiPoint,
1✔
4186
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
4187
                            SpatialReference::epsg_4326(),
1✔
4188
                        ),
1✔
4189
                        columns: [(
1✔
4190
                            "foo".to_string(),
1✔
4191
                            VectorColumnInfo {
1✔
4192
                                data_type: FeatureDataType::Int,
1✔
4193
                                measurement: Measurement::Unitless,
1✔
4194
                            },
1✔
4195
                        )]
1✔
4196
                        .into(),
1✔
4197
                        time: Some(TimeInterval::default()),
1✔
4198
                        bbox: Some(
1✔
4199
                            BoundingBox2D::new(
1✔
4200
                                Coordinate2D::new(0.0f64, 0.5),
1✔
4201
                                Coordinate2D::new(2., 1.0),
1✔
4202
                            )
1✔
4203
                            .unwrap(),
1✔
4204
                        ),
1✔
4205
                    },
1✔
4206
                    phantom: PhantomData,
1✔
4207
                }),
1✔
4208
                MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
4209
                    OgrSourceDataset,
1✔
4210
                    VectorResultDescriptor,
1✔
4211
                    VectorQueryRectangle,
1✔
4212
                > {
1✔
4213
                    loading_info: OgrSourceDataset {
1✔
4214
                        file_name: "test".into(),
1✔
4215
                        layer_name: "test".to_string(),
1✔
4216
                        data_type: Some(VectorDataType::MultiPoint),
1✔
4217
                        time: OgrSourceDatasetTimeType::Start {
1✔
4218
                            start_field: "start".to_string(),
1✔
4219
                            start_format: OgrSourceTimeFormat::Auto,
1✔
4220
                            duration: OgrSourceDurationSpec::Zero,
1✔
4221
                        },
1✔
4222
                        default_geometry: Some(TypedGeometry::MultiPoint(
1✔
4223
                            MultiPoint::new(vec![
1✔
4224
                                Coordinate2D::new(0.0f64, 0.5),
1✔
4225
                                Coordinate2D::new(2., 1.0),
1✔
4226
                            ])
1✔
4227
                            .unwrap(),
1✔
4228
                        )),
1✔
4229
                        columns: Some(OgrSourceColumnSpec {
1✔
4230
                            format_specifics: Some(FormatSpecifics::Csv {
1✔
4231
                                header: CsvHeader::Auto,
1✔
4232
                            }),
1✔
4233
                            x: "x".to_string(),
1✔
4234
                            y: Some("y".to_string()),
1✔
4235
                            int: vec!["int".to_string()],
1✔
4236
                            float: vec!["float".to_string()],
1✔
4237
                            text: vec!["text".to_string()],
1✔
4238
                            bool: vec!["bool".to_string()],
1✔
4239
                            datetime: vec!["datetime".to_string()],
1✔
4240
                            rename: Some(
1✔
4241
                                [
1✔
4242
                                    ("xx".to_string(), "xx_renamed".to_string()),
1✔
4243
                                    ("yx".to_string(), "yy_renamed".to_string()),
1✔
4244
                                ]
1✔
4245
                                .into(),
1✔
4246
                            ),
1✔
4247
                        }),
1✔
4248
                        force_ogr_time_filter: false,
1✔
4249
                        force_ogr_spatial_filter: true,
1✔
4250
                        on_error: OgrSourceErrorSpec::Abort,
1✔
4251
                        sql_query: None,
1✔
4252
                        attribute_query: Some("foo = 'bar'".to_string()),
1✔
4253
                        cache_ttl: CacheTtlSeconds::new(5),
1✔
4254
                    },
1✔
4255
                    result_descriptor: VectorResultDescriptor {
1✔
4256
                        data_type: VectorDataType::MultiPoint,
1✔
4257
                        spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
4258
                            SpatialReference::epsg_4326(),
1✔
4259
                        ),
1✔
4260
                        columns: [(
1✔
4261
                            "foo".to_string(),
1✔
4262
                            VectorColumnInfo {
1✔
4263
                                data_type: FeatureDataType::Int,
1✔
4264
                                measurement: Measurement::Unitless,
1✔
4265
                            },
1✔
4266
                        )]
1✔
4267
                        .into(),
1✔
4268
                        time: Some(TimeInterval::default()),
1✔
4269
                        bbox: Some(
1✔
4270
                            BoundingBox2D::new(
1✔
4271
                                Coordinate2D::new(0.0f64, 0.5),
1✔
4272
                                Coordinate2D::new(2., 1.0),
1✔
4273
                            )
1✔
4274
                            .unwrap(),
1✔
4275
                        ),
1✔
4276
                    },
1✔
4277
                    phantom: PhantomData,
1✔
4278
                }),
1✔
4279
                MetaDataDefinition::GdalMetaDataRegular(GdalMetaDataRegular {
1✔
4280
                    result_descriptor: RasterResultDescriptor {
1✔
4281
                        data_type: RasterDataType::U8,
1✔
4282
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4283
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4284
                        bbox: Some(
1✔
4285
                            SpatialPartition2D::new(
1✔
4286
                                Coordinate2D::new(0.0f64, 1.),
1✔
4287
                                Coordinate2D::new(2., 0.5),
1✔
4288
                            )
1✔
4289
                            .unwrap(),
1✔
4290
                        ),
1✔
4291
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
4292
                        bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4293
                            "band".into(),
1✔
4294
                            Measurement::Continuous(ContinuousMeasurement {
1✔
4295
                                measurement: "Temperature".to_string(),
1✔
4296
                                unit: Some("°C".to_string()),
1✔
4297
                            }),
1✔
4298
                        )])
1✔
4299
                        .unwrap(),
1✔
4300
                    },
1✔
4301
                    params: GdalDatasetParameters {
1✔
4302
                        file_path: "text".into(),
1✔
4303
                        rasterband_channel: 1,
1✔
4304
                        geo_transform: GdalDatasetGeoTransform {
1✔
4305
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4306
                            x_pixel_size: 1.0,
1✔
4307
                            y_pixel_size: 2.0,
1✔
4308
                        },
1✔
4309
                        width: 42,
1✔
4310
                        height: 23,
1✔
4311
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4312
                        no_data_value: Some(42.0),
1✔
4313
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4314
                            source_key: RasterPropertiesKey {
1✔
4315
                                domain: None,
1✔
4316
                                key: "foo".to_string(),
1✔
4317
                            },
1✔
4318
                            target_key: RasterPropertiesKey {
1✔
4319
                                domain: Some("bar".to_string()),
1✔
4320
                                key: "foo".to_string(),
1✔
4321
                            },
1✔
4322
                            target_type: RasterPropertiesEntryType::String,
1✔
4323
                        }]),
1✔
4324
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4325
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4326
                        allow_alphaband_as_mask: false,
1✔
4327
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4328
                    },
1✔
4329
                    time_placeholders: [(
1✔
4330
                        "foo".to_string(),
1✔
4331
                        GdalSourceTimePlaceholder {
1✔
4332
                            format: DateTimeParseFormat::unix(),
1✔
4333
                            reference: TimeReference::Start,
1✔
4334
                        },
1✔
4335
                    )]
1✔
4336
                    .into(),
1✔
4337
                    data_time: TimeInterval::new_unchecked(0, 1),
1✔
4338
                    step: TimeStep {
1✔
4339
                        granularity: TimeGranularity::Millis,
1✔
4340
                        step: 1,
1✔
4341
                    },
1✔
4342
                    cache_ttl: CacheTtlSeconds::max(),
1✔
4343
                }),
1✔
4344
                MetaDataDefinition::GdalStatic(GdalMetaDataStatic {
1✔
4345
                    time: Some(TimeInterval::new_unchecked(0, 1)),
1✔
4346
                    result_descriptor: RasterResultDescriptor {
1✔
4347
                        data_type: RasterDataType::U8,
1✔
4348
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4349
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4350
                        bbox: Some(
1✔
4351
                            SpatialPartition2D::new(
1✔
4352
                                Coordinate2D::new(0.0f64, 1.),
1✔
4353
                                Coordinate2D::new(2., 0.5),
1✔
4354
                            )
1✔
4355
                            .unwrap(),
1✔
4356
                        ),
1✔
4357
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
4358
                        bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4359
                            "band".into(),
1✔
4360
                            Measurement::Continuous(ContinuousMeasurement {
1✔
4361
                                measurement: "Temperature".to_string(),
1✔
4362
                                unit: Some("°C".to_string()),
1✔
4363
                            }),
1✔
4364
                        )])
1✔
4365
                        .unwrap(),
1✔
4366
                    },
1✔
4367
                    params: GdalDatasetParameters {
1✔
4368
                        file_path: "text".into(),
1✔
4369
                        rasterband_channel: 1,
1✔
4370
                        geo_transform: GdalDatasetGeoTransform {
1✔
4371
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4372
                            x_pixel_size: 1.0,
1✔
4373
                            y_pixel_size: 2.0,
1✔
4374
                        },
1✔
4375
                        width: 42,
1✔
4376
                        height: 23,
1✔
4377
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4378
                        no_data_value: Some(42.0),
1✔
4379
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4380
                            source_key: RasterPropertiesKey {
1✔
4381
                                domain: None,
1✔
4382
                                key: "foo".to_string(),
1✔
4383
                            },
1✔
4384
                            target_key: RasterPropertiesKey {
1✔
4385
                                domain: Some("bar".to_string()),
1✔
4386
                                key: "foo".to_string(),
1✔
4387
                            },
1✔
4388
                            target_type: RasterPropertiesEntryType::String,
1✔
4389
                        }]),
1✔
4390
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4391
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4392
                        allow_alphaband_as_mask: false,
1✔
4393
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4394
                    },
1✔
4395
                    cache_ttl: CacheTtlSeconds::max(),
1✔
4396
                }),
1✔
4397
                MetaDataDefinition::GdalMetadataNetCdfCf(GdalMetadataNetCdfCf {
1✔
4398
                    result_descriptor: RasterResultDescriptor {
1✔
4399
                        data_type: RasterDataType::U8,
1✔
4400
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4401
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4402
                        bbox: Some(
1✔
4403
                            SpatialPartition2D::new(
1✔
4404
                                Coordinate2D::new(0.0f64, 1.),
1✔
4405
                                Coordinate2D::new(2., 0.5),
1✔
4406
                            )
1✔
4407
                            .unwrap(),
1✔
4408
                        ),
1✔
4409
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
4410
                        bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4411
                            "band".into(),
1✔
4412
                            Measurement::Continuous(ContinuousMeasurement {
1✔
4413
                                measurement: "Temperature".to_string(),
1✔
4414
                                unit: Some("°C".to_string()),
1✔
4415
                            }),
1✔
4416
                        )])
1✔
4417
                        .unwrap(),
1✔
4418
                    },
1✔
4419
                    params: GdalDatasetParameters {
1✔
4420
                        file_path: "text".into(),
1✔
4421
                        rasterband_channel: 1,
1✔
4422
                        geo_transform: GdalDatasetGeoTransform {
1✔
4423
                            origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4424
                            x_pixel_size: 1.0,
1✔
4425
                            y_pixel_size: 2.0,
1✔
4426
                        },
1✔
4427
                        width: 42,
1✔
4428
                        height: 23,
1✔
4429
                        file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4430
                        no_data_value: Some(42.0),
1✔
4431
                        properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4432
                            source_key: RasterPropertiesKey {
1✔
4433
                                domain: None,
1✔
4434
                                key: "foo".to_string(),
1✔
4435
                            },
1✔
4436
                            target_key: RasterPropertiesKey {
1✔
4437
                                domain: Some("bar".to_string()),
1✔
4438
                                key: "foo".to_string(),
1✔
4439
                            },
1✔
4440
                            target_type: RasterPropertiesEntryType::String,
1✔
4441
                        }]),
1✔
4442
                        gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4443
                        gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4444
                        allow_alphaband_as_mask: false,
1✔
4445
                        retry: Some(GdalRetryOptions { max_retries: 3 }),
1✔
4446
                    },
1✔
4447
                    start: TimeInstance::from_millis(0).unwrap(),
1✔
4448
                    end: TimeInstance::from_millis(1000).unwrap(),
1✔
4449
                    cache_ttl: CacheTtlSeconds::max(),
1✔
4450
                    step: TimeStep {
1✔
4451
                        granularity: TimeGranularity::Millis,
1✔
4452
                        step: 1,
1✔
4453
                    },
1✔
4454
                    band_offset: 3,
1✔
4455
                }),
1✔
4456
                MetaDataDefinition::GdalMetaDataList(GdalMetaDataList {
1✔
4457
                    result_descriptor: RasterResultDescriptor {
1✔
4458
                        data_type: RasterDataType::U8,
1✔
4459
                        spatial_reference: SpatialReference::epsg_4326().into(),
1✔
4460
                        time: TimeInterval::new_unchecked(0, 1).into(),
1✔
4461
                        bbox: Some(
1✔
4462
                            SpatialPartition2D::new(
1✔
4463
                                Coordinate2D::new(0.0f64, 1.),
1✔
4464
                                Coordinate2D::new(2., 0.5),
1✔
4465
                            )
1✔
4466
                            .unwrap(),
1✔
4467
                        ),
1✔
4468
                        resolution: Some(SpatialResolution::zero_point_one()),
1✔
4469
                        bands: RasterBandDescriptors::new(vec![RasterBandDescriptor::new(
1✔
4470
                            "band".into(),
1✔
4471
                            Measurement::Continuous(ContinuousMeasurement {
1✔
4472
                                measurement: "Temperature".to_string(),
1✔
4473
                                unit: Some("°C".to_string()),
1✔
4474
                            }),
1✔
4475
                        )])
1✔
4476
                        .unwrap(),
1✔
4477
                    },
1✔
4478
                    params: vec![GdalLoadingInfoTemporalSlice {
1✔
4479
                        time: TimeInterval::new_unchecked(0, 1),
1✔
4480
                        params: Some(GdalDatasetParameters {
1✔
4481
                            file_path: "text".into(),
1✔
4482
                            rasterband_channel: 1,
1✔
4483
                            geo_transform: GdalDatasetGeoTransform {
1✔
4484
                                origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
4485
                                x_pixel_size: 1.0,
1✔
4486
                                y_pixel_size: 2.0,
1✔
4487
                            },
1✔
4488
                            width: 42,
1✔
4489
                            height: 23,
1✔
4490
                            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
4491
                            no_data_value: Some(42.0),
1✔
4492
                            properties_mapping: Some(vec![GdalMetadataMapping {
1✔
4493
                                source_key: RasterPropertiesKey {
1✔
4494
                                    domain: None,
1✔
4495
                                    key: "foo".to_string(),
1✔
4496
                                },
1✔
4497
                                target_key: RasterPropertiesKey {
1✔
4498
                                    domain: Some("bar".to_string()),
1✔
4499
                                    key: "foo".to_string(),
1✔
4500
                                },
1✔
4501
                                target_type: RasterPropertiesEntryType::String,
1✔
4502
                            }]),
1✔
4503
                            gdal_open_options: Some(vec!["foo".to_string(), "bar".to_string()]),
1✔
4504
                            gdal_config_options: Some(vec![("foo".to_string(), "bar".to_string())]),
1✔
4505
                            allow_alphaband_as_mask: false,
1✔
4506
                            retry: None,
1✔
4507
                        }),
1✔
4508
                        cache_ttl: CacheTtlSeconds::max(),
1✔
4509
                    }],
1✔
4510
                }),
1✔
4511
            ],
1✔
4512
        )
1✔
4513
        .await;
15✔
4514

4515
        assert_sql_type(
1✔
4516
            &pool,
1✔
4517
            "bytea",
1✔
4518
            [U96::from(
1✔
4519
                arr![u8; 13, 227, 191, 247, 123, 193, 214, 165, 185, 37, 101, 24],
1✔
4520
            )],
1✔
4521
        )
1✔
4522
        .await;
2✔
4523

4524
        test_data_provider_definition_types(&pool).await;
63✔
4525
    }
1✔
4526

4527
    #[test]
1✔
4528
    fn test_postgres_config_translation() {
1✔
4529
        let host = "localhost";
1✔
4530
        let port = 8095;
1✔
4531
        let ge_default = "geoengine";
1✔
4532
        let schema = "geoengine";
1✔
4533

1✔
4534
        let db_config = config::Postgres {
1✔
4535
            host: host.to_string(),
1✔
4536
            port,
1✔
4537
            database: ge_default.to_string(),
1✔
4538
            schema: schema.to_string(),
1✔
4539
            user: ge_default.to_string(),
1✔
4540
            password: ge_default.to_string(),
1✔
4541
            clear_database_on_start: false,
1✔
4542
        };
1✔
4543

1✔
4544
        let pg_config = Config::try_from(db_config).unwrap();
1✔
4545

1✔
4546
        assert_eq!(ge_default, pg_config.get_user().unwrap());
1✔
4547
        assert_eq!(
1✔
4548
            <str as AsRef<[u8]>>::as_ref(ge_default).to_vec(),
1✔
4549
            pg_config.get_password().unwrap()
1✔
4550
        );
1✔
4551
        assert_eq!(ge_default, pg_config.get_dbname().unwrap());
1✔
4552
        assert_eq!(
1✔
4553
            &format!("-c search_path={schema}"),
1✔
4554
            pg_config.get_options().unwrap()
1✔
4555
        );
1✔
4556
        assert_eq!(vec![Host::Tcp(host.to_string())], pg_config.get_hosts());
1✔
4557
        assert_eq!(vec![port], pg_config.get_ports());
1✔
4558
    }
1✔
4559

4560
    #[allow(clippy::too_many_lines)]
4561
    async fn test_data_provider_definition_types(
1✔
4562
        pool: &PooledConnection<'_, PostgresConnectionManager<tokio_postgres::NoTls>>,
1✔
4563
    ) {
1✔
4564
        assert_sql_type(
1✔
4565
            pool,
1✔
4566
            "ArunaDataProviderDefinition",
1✔
4567
            [ArunaDataProviderDefinition {
1✔
4568
                id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0").unwrap(),
1✔
4569
                name: "NFDI".to_string(),
1✔
4570
                description: "NFDI".to_string(),
1✔
4571
                priority: Some(33),
1✔
4572
                api_url: "http://test".to_string(),
1✔
4573
                project_id: "project".to_string(),
1✔
4574
                api_token: "api_token".to_string(),
1✔
4575
                filter_label: "filter".to_string(),
1✔
4576
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4577
            }],
1✔
4578
        )
1✔
4579
        .await;
4✔
4580

4581
        assert_sql_type(
1✔
4582
            pool,
1✔
4583
            "GbifDataProviderDefinition",
1✔
4584
            [GbifDataProviderDefinition {
1✔
4585
                name: "GBIF".to_string(),
1✔
4586
                description: "GFBio".to_string(),
1✔
4587
                priority: None,
1✔
4588
                db_config: DatabaseConnectionConfig {
1✔
4589
                    host: "testhost".to_string(),
1✔
4590
                    port: 1234,
1✔
4591
                    database: "testdb".to_string(),
1✔
4592
                    schema: "testschema".to_string(),
1✔
4593
                    user: "testuser".to_string(),
1✔
4594
                    password: "testpass".to_string(),
1✔
4595
                },
1✔
4596
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4597
                autocomplete_timeout: 3,
1✔
4598
                columns: GbifDataProvider::all_columns(),
1✔
4599
            }],
1✔
4600
        )
1✔
4601
        .await;
6✔
4602

4603
        assert_sql_type(
1✔
4604
            pool,
1✔
4605
            "GfbioAbcdDataProviderDefinition",
1✔
4606
            [GfbioAbcdDataProviderDefinition {
1✔
4607
                name: "GFbio".to_string(),
1✔
4608
                description: "GFBio".to_string(),
1✔
4609
                priority: None,
1✔
4610
                db_config: DatabaseConnectionConfig {
1✔
4611
                    host: "testhost".to_string(),
1✔
4612
                    port: 1234,
1✔
4613
                    database: "testdb".to_string(),
1✔
4614
                    schema: "testschema".to_string(),
1✔
4615
                    user: "testuser".to_string(),
1✔
4616
                    password: "testpass".to_string(),
1✔
4617
                },
1✔
4618
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4619
            }],
1✔
4620
        )
1✔
4621
        .await;
4✔
4622

4623
        assert_sql_type(
1✔
4624
            pool,
1✔
4625
            "GfbioCollectionsDataProviderDefinition",
1✔
4626
            [GfbioCollectionsDataProviderDefinition {
1✔
4627
                name: "GFbio".to_string(),
1✔
4628
                description: "GFBio".to_string(),
1✔
4629
                priority: None,
1✔
4630
                collection_api_url: "http://testhost".try_into().unwrap(),
1✔
4631
                collection_api_auth_token: "token".to_string(),
1✔
4632
                abcd_db_config: DatabaseConnectionConfig {
1✔
4633
                    host: "testhost".to_string(),
1✔
4634
                    port: 1234,
1✔
4635
                    database: "testdb".to_string(),
1✔
4636
                    schema: "testschema".to_string(),
1✔
4637
                    user: "testuser".to_string(),
1✔
4638
                    password: "testpass".to_string(),
1✔
4639
                },
1✔
4640
                pangaea_url: "http://panaea".try_into().unwrap(),
1✔
4641
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4642
            }],
1✔
4643
        )
1✔
4644
        .await;
4✔
4645

4646
        assert_sql_type(pool, "\"PropertyType\"[]", [Vec::<Property>::new()]).await;
5✔
4647

4648
        assert_sql_type(
1✔
4649
            pool,
1✔
4650
            "EbvPortalDataProviderDefinition",
1✔
4651
            [EbvPortalDataProviderDefinition {
1✔
4652
                name: "ebv".to_string(),
1✔
4653
                description: "EBV".to_string(),
1✔
4654
                priority: None,
1✔
4655
                data: "a_path".into(),
1✔
4656
                base_url: "http://base".try_into().unwrap(),
1✔
4657
                overviews: "another_path".into(),
1✔
4658
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4659
            }],
1✔
4660
        )
1✔
4661
        .await;
4✔
4662

4663
        assert_sql_type(
1✔
4664
            pool,
1✔
4665
            "NetCdfCfDataProviderDefinition",
1✔
4666
            [NetCdfCfDataProviderDefinition {
1✔
4667
                name: "netcdfcf".to_string(),
1✔
4668
                description: "netcdfcf".to_string(),
1✔
4669
                priority: Some(33),
1✔
4670
                data: "a_path".into(),
1✔
4671
                overviews: "another_path".into(),
1✔
4672
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4673
            }],
1✔
4674
        )
1✔
4675
        .await;
4✔
4676

4677
        assert_sql_type(
1✔
4678
            pool,
1✔
4679
            "PangaeaDataProviderDefinition",
1✔
4680
            [PangaeaDataProviderDefinition {
1✔
4681
                name: "pangaea".to_string(),
1✔
4682
                description: "pangaea".to_string(),
1✔
4683
                priority: None,
1✔
4684
                base_url: "http://base".try_into().unwrap(),
1✔
4685
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4686
            }],
1✔
4687
        )
1✔
4688
        .await;
4✔
4689

4690
        assert_sql_type(
1✔
4691
            pool,
1✔
4692
            "DataProviderDefinition",
1✔
4693
            [
1✔
4694
                TypedDataProviderDefinition::ArunaDataProviderDefinition(
1✔
4695
                    ArunaDataProviderDefinition {
1✔
4696
                        id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0")
1✔
4697
                            .unwrap(),
1✔
4698
                        name: "NFDI".to_string(),
1✔
4699
                        description: "NFDI".to_string(),
1✔
4700
                        priority: Some(33),
1✔
4701
                        api_url: "http://test".to_string(),
1✔
4702
                        project_id: "project".to_string(),
1✔
4703
                        api_token: "api_token".to_string(),
1✔
4704
                        filter_label: "filter".to_string(),
1✔
4705
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4706
                    },
1✔
4707
                ),
1✔
4708
                TypedDataProviderDefinition::GbifDataProviderDefinition(
1✔
4709
                    GbifDataProviderDefinition {
1✔
4710
                        name: "GBIF".to_string(),
1✔
4711
                        description: "GFBio".to_string(),
1✔
4712
                        priority: None,
1✔
4713
                        db_config: DatabaseConnectionConfig {
1✔
4714
                            host: "testhost".to_string(),
1✔
4715
                            port: 1234,
1✔
4716
                            database: "testdb".to_string(),
1✔
4717
                            schema: "testschema".to_string(),
1✔
4718
                            user: "testuser".to_string(),
1✔
4719
                            password: "testpass".to_string(),
1✔
4720
                        },
1✔
4721
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4722
                        autocomplete_timeout: 3,
1✔
4723
                        columns: GbifDataProvider::all_columns(),
1✔
4724
                    },
1✔
4725
                ),
1✔
4726
                TypedDataProviderDefinition::GfbioAbcdDataProviderDefinition(
1✔
4727
                    GfbioAbcdDataProviderDefinition {
1✔
4728
                        name: "GFbio".to_string(),
1✔
4729
                        description: "GFBio".to_string(),
1✔
4730
                        priority: None,
1✔
4731
                        db_config: DatabaseConnectionConfig {
1✔
4732
                            host: "testhost".to_string(),
1✔
4733
                            port: 1234,
1✔
4734
                            database: "testdb".to_string(),
1✔
4735
                            schema: "testschema".to_string(),
1✔
4736
                            user: "testuser".to_string(),
1✔
4737
                            password: "testpass".to_string(),
1✔
4738
                        },
1✔
4739
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4740
                    },
1✔
4741
                ),
1✔
4742
                TypedDataProviderDefinition::GfbioCollectionsDataProviderDefinition(
1✔
4743
                    GfbioCollectionsDataProviderDefinition {
1✔
4744
                        name: "GFbio".to_string(),
1✔
4745
                        description: "GFBio".to_string(),
1✔
4746
                        priority: None,
1✔
4747
                        collection_api_url: "http://testhost".try_into().unwrap(),
1✔
4748
                        collection_api_auth_token: "token".to_string(),
1✔
4749
                        abcd_db_config: DatabaseConnectionConfig {
1✔
4750
                            host: "testhost".to_string(),
1✔
4751
                            port: 1234,
1✔
4752
                            database: "testdb".to_string(),
1✔
4753
                            schema: "testschema".to_string(),
1✔
4754
                            user: "testuser".to_string(),
1✔
4755
                            password: "testpass".to_string(),
1✔
4756
                        },
1✔
4757
                        pangaea_url: "http://panaea".try_into().unwrap(),
1✔
4758
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4759
                    },
1✔
4760
                ),
1✔
4761
                TypedDataProviderDefinition::EbvPortalDataProviderDefinition(
1✔
4762
                    EbvPortalDataProviderDefinition {
1✔
4763
                        name: "ebv".to_string(),
1✔
4764
                        description: "ebv".to_string(),
1✔
4765
                        priority: Some(33),
1✔
4766
                        data: "a_path".into(),
1✔
4767
                        base_url: "http://base".try_into().unwrap(),
1✔
4768
                        overviews: "another_path".into(),
1✔
4769
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4770
                    },
1✔
4771
                ),
1✔
4772
                TypedDataProviderDefinition::NetCdfCfDataProviderDefinition(
1✔
4773
                    NetCdfCfDataProviderDefinition {
1✔
4774
                        name: "netcdfcf".to_string(),
1✔
4775
                        description: "netcdfcf".to_string(),
1✔
4776
                        priority: Some(33),
1✔
4777
                        data: "a_path".into(),
1✔
4778
                        overviews: "another_path".into(),
1✔
4779
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4780
                    },
1✔
4781
                ),
1✔
4782
                TypedDataProviderDefinition::PangaeaDataProviderDefinition(
1✔
4783
                    PangaeaDataProviderDefinition {
1✔
4784
                        name: "pangaea".to_string(),
1✔
4785
                        description: "pangaea".to_string(),
1✔
4786
                        priority: None,
1✔
4787
                        base_url: "http://base".try_into().unwrap(),
1✔
4788
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4789
                    },
1✔
4790
                ),
1✔
4791
            ],
1✔
4792
        )
1✔
4793
        .await;
28✔
4794
    }
1✔
4795
}
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