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

geo-engine / geoengine / 9778355898

03 Jul 2024 01:01PM UTC coverage: 90.738% (+0.05%) from 90.687%
9778355898

Pull #970

github

web-flow
Merge 40c130305 into 9a33a5b13
Pull Request #970: FAIR dataset deletion

1374 of 1429 new or added lines in 10 files covered. (96.15%)

28 existing lines in 16 files now uncovered.

134479 of 148206 relevant lines covered (90.74%)

52200.61 hits per line

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

97.76
/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::contexts::{ApplicationContext, QueryContextImpl, SessionId, SimpleSession};
5
use crate::contexts::{GeoEngineDb, SessionContext};
6
use crate::datasets::upload::{Volume, Volumes};
7
use crate::datasets::DatasetName;
8
use crate::error::{self, Error, Result};
9
use crate::layers::add_from_directory::{
10
    add_layer_collections_from_directory, add_layers_from_directory,
11
};
12
use crate::projects::{ProjectId, STRectangle};
13
use crate::tasks::{SimpleTaskManager, SimpleTaskManagerBackend, SimpleTaskManagerContext};
14
use crate::util::config;
15
use crate::util::config::get_config_element;
16
use async_trait::async_trait;
17
use bb8_postgres::{
18
    bb8::Pool,
19
    bb8::PooledConnection,
20
    tokio_postgres::{error::SqlState, tls::MakeTlsConnect, tls::TlsConnect, Config, Socket},
21
    PostgresConnectionManager,
22
};
23
use geoengine_datatypes::raster::TilingSpecification;
24
use geoengine_operators::engine::ChunkByteSize;
25
use geoengine_operators::util::create_rayon_thread_pool;
26
use log::info;
27
use rayon::ThreadPool;
28
use snafu::ensure;
29
use std::path::PathBuf;
30
use std::sync::Arc;
31

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

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

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

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

73
        let pool = Pool::builder().build(pg_mgr).await?;
218✔
74
        let created_schema = Self::create_database(pool.get().await?).await?;
2,834✔
75

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

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

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

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

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

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

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

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

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

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

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

144
        Ok(app_ctx)
×
145
    }
×
146

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

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

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

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

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

199
        Ok(())
320✔
200
    }
320✔
201

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

285
    async fn default_session_context(&self) -> Result<Self::SessionContext> {
354✔
286
        Ok(self.session_context(self.session_by_id(self.default_session_id).await?))
4,057✔
287
    }
1,062✔
288
}
289

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

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

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

311
        let tx = conn.build_transaction().start().await?;
460✔
312

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

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

329
        Ok(SimpleSession::new(session_id, row.get(0), row.get(1)))
460✔
330
    }
1,392✔
331
}
332

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

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

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

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

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

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

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

384
    fn volumes(&self) -> Result<Vec<Volume>> {
×
385
        Ok(self.context.volumes.volumes.clone())
×
386
    }
×
387

388
    fn session(&self) -> &Self::Session {
112✔
389
        &self.session
112✔
390
    }
112✔
391
}
392

393
#[derive(Debug)]
×
394
pub struct PostgresDb<Tls>
395
where
396
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
397
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
398
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
399
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
400
{
401
    pub(crate) conn_pool: Pool<PostgresConnectionManager<Tls>>,
402
}
403

404
impl<Tls> 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 fn new(conn_pool: Pool<PostgresConnectionManager<Tls>>) -> Self {
538✔
412
        Self { conn_pool }
538✔
413
    }
538✔
414

415
    /// Check whether the namespace of the given dataset is allowed for insertion
416
    pub(crate) fn check_namespace(id: &DatasetName) -> Result<()> {
76✔
417
        // due to a lack of users, etc., we only allow one namespace for now
76✔
418
        if id.namespace.is_none() {
76✔
419
            Ok(())
76✔
420
        } else {
421
            Err(Error::InvalidDatasetIdNamespace)
×
422
        }
423
    }
76✔
424
}
425

426
impl<Tls> GeoEngineDb for PostgresDb<Tls>
427
where
428
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
429
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
430
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
431
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
432
{
433
}
434

435
impl TryFrom<config::Postgres> for Config {
436
    type Error = Error;
437

438
    fn try_from(db_config: config::Postgres) -> Result<Self> {
25✔
439
        ensure!(
25✔
440
            db_config.schema != "public",
25✔
441
            crate::error::InvalidDatabaseSchema
×
442
        );
443

444
        let mut pg_config = Config::new();
25✔
445
        pg_config
25✔
446
            .user(&db_config.user)
25✔
447
            .password(&db_config.password)
25✔
448
            .host(&db_config.host)
25✔
449
            .dbname(&db_config.database)
25✔
450
            .port(db_config.port)
25✔
451
            // fix schema by providing `search_path` option
25✔
452
            .options(&format!("-c search_path={}", db_config.schema));
25✔
453
        Ok(pg_config)
25✔
454
    }
25✔
455
}
456

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

545
    #[ge_context::test]
3✔
546
    async fn test(app_ctx: PostgresContext<NoTls>) {
1✔
547
        let session = app_ctx.default_session().await.unwrap();
18✔
548

1✔
549
        create_projects(&app_ctx, &session).await;
74✔
550

551
        let projects = list_projects(&app_ctx, &session).await;
13✔
552

553
        let project_id = projects[0].id;
1✔
554

1✔
555
        update_projects(&app_ctx, &session, project_id).await;
168✔
556

557
        delete_project(&app_ctx, &session, project_id).await;
7✔
558
    }
1✔
559

560
    async fn delete_project(
1✔
561
        app_ctx: &PostgresContext<NoTls>,
1✔
562
        session: &SimpleSession,
1✔
563
        project_id: ProjectId,
1✔
564
    ) {
1✔
565
        let db = app_ctx.session_context(session.clone()).db();
1✔
566

1✔
567
        db.delete_project(project_id).await.unwrap();
3✔
568

1✔
569
        assert!(db.load_project(project_id).await.is_err());
4✔
570
    }
1✔
571

572
    #[allow(clippy::too_many_lines)]
573
    async fn update_projects(
1✔
574
        app_ctx: &PostgresContext<NoTls>,
1✔
575
        session: &SimpleSession,
1✔
576
        project_id: ProjectId,
1✔
577
    ) {
1✔
578
        let db = app_ctx.session_context(session.clone()).db();
1✔
579

580
        let project = db
1✔
581
            .load_project_version(project_id, LoadVersion::Latest)
1✔
582
            .await
41✔
583
            .unwrap();
1✔
584

585
        let layer_workflow_id = db
1✔
586
            .register_workflow(Workflow {
1✔
587
                operator: TypedOperator::Vector(
1✔
588
                    MockPointSource {
1✔
589
                        params: MockPointSourceParams {
1✔
590
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
591
                        },
1✔
592
                    }
1✔
593
                    .boxed(),
1✔
594
                ),
1✔
595
            })
1✔
596
            .await
3✔
597
            .unwrap();
1✔
598

1✔
599
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
3✔
600

601
        let plot_workflow_id = db
1✔
602
            .register_workflow(Workflow {
1✔
603
                operator: Statistics {
1✔
604
                    params: StatisticsParams {
1✔
605
                        column_names: vec![],
1✔
606
                        percentiles: vec![],
1✔
607
                    },
1✔
608
                    sources: MultipleRasterOrSingleVectorSource {
1✔
609
                        source: Raster(vec![]),
1✔
610
                    },
1✔
611
                }
1✔
612
                .boxed()
1✔
613
                .into(),
1✔
614
            })
1✔
615
            .await
3✔
616
            .unwrap();
1✔
617

1✔
618
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
3✔
619

620
        // add a plot
621
        let update = UpdateProject {
1✔
622
            id: project.id,
1✔
623
            name: Some("Test9 Updated".into()),
1✔
624
            description: None,
1✔
625
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
626
                workflow: layer_workflow_id,
1✔
627
                name: "TestLayer".into(),
1✔
628
                symbology: PointSymbology::default().into(),
1✔
629
                visibility: Default::default(),
1✔
630
            })]),
1✔
631
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
632
                workflow: plot_workflow_id,
1✔
633
                name: "Test Plot".into(),
1✔
634
            })]),
1✔
635
            bounds: None,
1✔
636
            time_step: None,
1✔
637
        };
1✔
638
        db.update_project(update).await.unwrap();
70✔
639

640
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
641
        assert_eq!(versions.len(), 2);
1✔
642

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

669
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
670
        assert_eq!(versions.len(), 3);
1✔
671

672
        // delete plots
673
        let update = UpdateProject {
1✔
674
            id: project.id,
1✔
675
            name: None,
1✔
676
            description: None,
1✔
677
            layers: None,
1✔
678
            plots: Some(vec![]),
1✔
679
            bounds: None,
1✔
680
            time_step: None,
1✔
681
        };
1✔
682
        db.update_project(update).await.unwrap();
16✔
683

684
        let versions = db.list_project_versions(project_id).await.unwrap();
3✔
685
        assert_eq!(versions.len(), 4);
1✔
686
    }
1✔
687

688
    async fn list_projects(
1✔
689
        app_ctx: &PostgresContext<NoTls>,
1✔
690
        session: &SimpleSession,
1✔
691
    ) -> Vec<ProjectListing> {
1✔
692
        let options = ProjectListOptions {
1✔
693
            order: OrderBy::NameDesc,
1✔
694
            offset: 0,
1✔
695
            limit: 2,
1✔
696
        };
1✔
697

1✔
698
        let db = app_ctx.session_context(session.clone()).db();
1✔
699

700
        let projects = db.list_projects(options).await.unwrap();
13✔
701

1✔
702
        assert_eq!(projects.len(), 2);
1✔
703
        assert_eq!(projects[0].name, "Test9");
1✔
704
        assert_eq!(projects[1].name, "Test8");
1✔
705
        projects
1✔
706
    }
1✔
707

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

711
        for i in 0..10 {
11✔
712
            let create = CreateProject {
10✔
713
                name: format!("Test{i}"),
10✔
714
                description: format!("Test{}", 10 - i),
10✔
715
                bounds: STRectangle::new(
10✔
716
                    SpatialReferenceOption::Unreferenced,
10✔
717
                    0.,
10✔
718
                    0.,
10✔
719
                    1.,
10✔
720
                    1.,
10✔
721
                    0,
10✔
722
                    1,
10✔
723
                )
10✔
724
                .unwrap(),
10✔
725
                time_step: None,
10✔
726
            };
10✔
727
            db.create_project(create).await.unwrap();
74✔
728
        }
729
    }
1✔
730

731
    #[ge_context::test]
3✔
732
    async fn it_persists_workflows(app_ctx: PostgresContext<NoTls>) {
1✔
733
        let workflow = Workflow {
1✔
734
            operator: TypedOperator::Vector(
1✔
735
                MockPointSource {
1✔
736
                    params: MockPointSourceParams {
1✔
737
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
738
                    },
1✔
739
                }
1✔
740
                .boxed(),
1✔
741
            ),
1✔
742
        };
1✔
743

744
        let session = app_ctx.default_session().await.unwrap();
18✔
745
        let ctx = app_ctx.session_context(session);
1✔
746

1✔
747
        let db = ctx.db();
1✔
748
        let id = db.register_workflow(workflow).await.unwrap();
3✔
749

1✔
750
        drop(ctx);
1✔
751

752
        let workflow = db.load_workflow(&id).await.unwrap();
3✔
753

1✔
754
        let json = serde_json::to_string(&workflow).unwrap();
1✔
755
        assert_eq!(
1✔
756
            json,
1✔
757
            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✔
758
        );
1✔
759
    }
1✔
760

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

1✔
795
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
796
            OgrSourceDataset,
1✔
797
            VectorResultDescriptor,
1✔
798
            VectorQueryRectangle,
1✔
799
        > {
1✔
800
            loading_info: loading_info.clone(),
1✔
801
            result_descriptor: VectorResultDescriptor {
1✔
802
                data_type: VectorDataType::MultiPoint,
1✔
803
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
804
                columns: [(
1✔
805
                    "foo".to_owned(),
1✔
806
                    VectorColumnInfo {
1✔
807
                        data_type: FeatureDataType::Float,
1✔
808
                        measurement: Measurement::Unitless,
1✔
809
                    },
1✔
810
                )]
1✔
811
                .into_iter()
1✔
812
                .collect(),
1✔
813
                time: None,
1✔
814
                bbox: None,
1✔
815
            },
1✔
816
            phantom: Default::default(),
1✔
817
        });
1✔
818

819
        let session = app_ctx.default_session().await.unwrap();
18✔
820

1✔
821
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
822

1✔
823
        let db = app_ctx.session_context(session.clone()).db();
1✔
824
        let DatasetIdAndName {
825
            id: dataset_id,
1✔
826
            name: dataset_name,
1✔
827
        } = db
1✔
828
            .add_dataset(
1✔
829
                AddDataset {
1✔
830
                    name: Some(dataset_name.clone()),
1✔
831
                    display_name: "Ogr Test".to_owned(),
1✔
832
                    description: "desc".to_owned(),
1✔
833
                    source_operator: "OgrSource".to_owned(),
1✔
834
                    symbology: None,
1✔
835
                    provenance: Some(vec![Provenance {
1✔
836
                        citation: "citation".to_owned(),
1✔
837
                        license: "license".to_owned(),
1✔
838
                        uri: "uri".to_owned(),
1✔
839
                    }]),
1✔
840
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
841
                },
1✔
842
                meta_data,
1✔
843
            )
1✔
844
            .await
161✔
845
            .unwrap();
1✔
846

847
        let datasets = db
1✔
848
            .list_datasets(DatasetListOptions {
1✔
849
                filter: None,
1✔
850
                order: crate::datasets::listing::OrderBy::NameAsc,
1✔
851
                offset: 0,
1✔
852
                limit: 10,
1✔
853
                tags: None,
1✔
854
            })
1✔
855
            .await
3✔
856
            .unwrap();
1✔
857

1✔
858
        assert_eq!(datasets.len(), 1);
1✔
859

860
        assert_eq!(
1✔
861
            datasets[0],
1✔
862
            DatasetListing {
1✔
863
                id: dataset_id,
1✔
864
                name: dataset_name,
1✔
865
                display_name: "Ogr Test".to_owned(),
1✔
866
                description: "desc".to_owned(),
1✔
867
                source_operator: "OgrSource".to_owned(),
1✔
868
                symbology: None,
1✔
869
                tags: vec!["upload".to_owned(), "test".to_owned()],
1✔
870
                result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
871
                    data_type: VectorDataType::MultiPoint,
1✔
872
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
873
                    columns: [(
1✔
874
                        "foo".to_owned(),
1✔
875
                        VectorColumnInfo {
1✔
876
                            data_type: FeatureDataType::Float,
1✔
877
                            measurement: Measurement::Unitless
1✔
878
                        }
1✔
879
                    )]
1✔
880
                    .into_iter()
1✔
881
                    .collect(),
1✔
882
                    time: None,
1✔
883
                    bbox: None,
1✔
884
                })
1✔
885
            },
1✔
886
        );
1✔
887

888
        let provenance = db.load_provenance(&dataset_id).await.unwrap();
4✔
889

1✔
890
        assert_eq!(
1✔
891
            provenance,
1✔
892
            ProvenanceOutput {
1✔
893
                data: dataset_id.into(),
1✔
894
                provenance: Some(vec![Provenance {
1✔
895
                    citation: "citation".to_owned(),
1✔
896
                    license: "license".to_owned(),
1✔
897
                    uri: "uri".to_owned(),
1✔
898
                }])
1✔
899
            }
1✔
900
        );
1✔
901

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

1✔
905
        assert_eq!(
1✔
906
            meta_data
1✔
907
                .loading_info(VectorQueryRectangle {
1✔
908
                    spatial_bounds: BoundingBox2D::new_unchecked(
1✔
909
                        (-180., -90.).into(),
1✔
910
                        (180., 90.).into()
1✔
911
                    ),
1✔
912
                    time_interval: TimeInterval::default(),
1✔
913
                    spatial_resolution: SpatialResolution::zero_point_one(),
1✔
914
                    attributes: ColumnSelection::all()
1✔
915
                })
1✔
916
                .await
×
917
                .unwrap(),
1✔
918
            loading_info
919
        );
920
    }
1✔
921

922
    #[ge_context::test]
3✔
923
    async fn it_persists_uploads(app_ctx: PostgresContext<NoTls>) {
1✔
924
        let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
925
        let input = Upload {
1✔
926
            id,
1✔
927
            files: vec![FileUpload {
1✔
928
                id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
929
                name: "test.csv".to_owned(),
1✔
930
                byte_size: 1337,
1✔
931
            }],
1✔
932
        };
1✔
933

934
        let session = app_ctx.default_session().await.unwrap();
18✔
935

1✔
936
        let db = app_ctx.session_context(session.clone()).db();
1✔
937

1✔
938
        db.create_upload(input.clone()).await.unwrap();
6✔
939

940
        let upload = db.load_upload(id).await.unwrap();
3✔
941

1✔
942
        assert_eq!(upload, input);
1✔
943
    }
1✔
944

945
    #[allow(clippy::too_many_lines)]
946
    #[ge_context::test]
3✔
947
    async fn it_persists_layer_providers(app_ctx: PostgresContext<NoTls>) {
1✔
948
        let db = app_ctx.default_session_context().await.unwrap().db();
19✔
949

1✔
950
        let provider = NetCdfCfDataProviderDefinition {
1✔
951
            name: "netcdfcf".to_string(),
1✔
952
            description: "NetCdfCfProviderDefinition".to_string(),
1✔
953
            priority: Some(21),
1✔
954
            data: test_data!("netcdf4d/").into(),
1✔
955
            overviews: test_data!("netcdf4d/overviews/").into(),
1✔
956
            cache_ttl: CacheTtlSeconds::new(0),
1✔
957
        };
1✔
958

959
        let provider_id = db.add_layer_provider(provider.into()).await.unwrap();
33✔
960

961
        let providers = db
1✔
962
            .list_layer_providers(LayerProviderListingOptions {
1✔
963
                offset: 0,
1✔
964
                limit: 10,
1✔
965
            })
1✔
966
            .await
3✔
967
            .unwrap();
1✔
968

1✔
969
        assert_eq!(providers.len(), 1);
1✔
970

971
        assert_eq!(
1✔
972
            providers[0],
1✔
973
            LayerProviderListing {
1✔
974
                id: provider_id,
1✔
975
                name: "netcdfcf".to_owned(),
1✔
976
                priority: 21,
1✔
977
            }
1✔
978
        );
1✔
979

980
        let provider = db.load_layer_provider(provider_id).await.unwrap();
3✔
981

982
        let datasets = provider
1✔
983
            .load_layer_collection(
1✔
984
                &provider.get_root_layer_collection_id().await.unwrap(),
1✔
985
                LayerCollectionListOptions {
1✔
986
                    offset: 0,
1✔
987
                    limit: 10,
1✔
988
                },
1✔
989
            )
990
            .await
5✔
991
            .unwrap();
1✔
992

1✔
993
        assert_eq!(datasets.items.len(), 5, "{:?}", datasets.items);
1✔
994
    }
1✔
995

996
    #[allow(clippy::too_many_lines)]
997
    #[ge_context::test]
3✔
998
    async fn it_loads_all_meta_data_types(app_ctx: PostgresContext<NoTls>) {
1✔
999
        let session = app_ctx.default_session().await.unwrap();
18✔
1000

1✔
1001
        let db = app_ctx.session_context(session.clone()).db();
1✔
1002

1✔
1003
        let vector_descriptor = VectorResultDescriptor {
1✔
1004
            data_type: VectorDataType::Data,
1✔
1005
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1006
            columns: Default::default(),
1✔
1007
            time: None,
1✔
1008
            bbox: None,
1✔
1009
        };
1✔
1010

1✔
1011
        let raster_descriptor = RasterResultDescriptor {
1✔
1012
            data_type: RasterDataType::U8,
1✔
1013
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
1014
            time: None,
1✔
1015
            bbox: None,
1✔
1016
            resolution: None,
1✔
1017
            bands: RasterBandDescriptors::new_single_band(),
1✔
1018
        };
1✔
1019

1✔
1020
        let vector_ds = AddDataset {
1✔
1021
            name: None,
1✔
1022
            display_name: "OgrDataset".to_string(),
1✔
1023
            description: "My Ogr dataset".to_string(),
1✔
1024
            source_operator: "OgrSource".to_string(),
1✔
1025
            symbology: None,
1✔
1026
            provenance: None,
1✔
1027
            tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
1028
        };
1✔
1029

1✔
1030
        let raster_ds = AddDataset {
1✔
1031
            name: None,
1✔
1032
            display_name: "GdalDataset".to_string(),
1✔
1033
            description: "My Gdal dataset".to_string(),
1✔
1034
            source_operator: "GdalSource".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 gdal_params = GdalDatasetParameters {
1✔
1041
            file_path: Default::default(),
1✔
1042
            rasterband_channel: 0,
1✔
1043
            geo_transform: GdalDatasetGeoTransform {
1✔
1044
                origin_coordinate: Default::default(),
1✔
1045
                x_pixel_size: 0.0,
1✔
1046
                y_pixel_size: 0.0,
1✔
1047
            },
1✔
1048
            width: 0,
1✔
1049
            height: 0,
1✔
1050
            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1051
            no_data_value: None,
1✔
1052
            properties_mapping: None,
1✔
1053
            gdal_open_options: None,
1✔
1054
            gdal_config_options: None,
1✔
1055
            allow_alphaband_as_mask: false,
1✔
1056
            retry: None,
1✔
1057
        };
1✔
1058

1✔
1059
        let meta = StaticMetaData {
1✔
1060
            loading_info: OgrSourceDataset {
1✔
1061
                file_name: Default::default(),
1✔
1062
                layer_name: String::new(),
1✔
1063
                data_type: None,
1✔
1064
                time: Default::default(),
1✔
1065
                default_geometry: None,
1✔
1066
                columns: None,
1✔
1067
                force_ogr_time_filter: false,
1✔
1068
                force_ogr_spatial_filter: false,
1✔
1069
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1070
                sql_query: None,
1✔
1071
                attribute_query: None,
1✔
1072
                cache_ttl: CacheTtlSeconds::default(),
1✔
1073
            },
1✔
1074
            result_descriptor: vector_descriptor.clone(),
1✔
1075
            phantom: Default::default(),
1✔
1076
        };
1✔
1077

1078
        let id = db.add_dataset(vector_ds, meta.into()).await.unwrap().id;
161✔
1079

1080
        let meta: geoengine_operators::util::Result<
1✔
1081
            Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1082
        > = db.meta_data(&id.into()).await;
3✔
1083

1084
        assert!(meta.is_ok());
1✔
1085

1086
        let meta = GdalMetaDataRegular {
1✔
1087
            result_descriptor: raster_descriptor.clone(),
1✔
1088
            params: gdal_params.clone(),
1✔
1089
            time_placeholders: Default::default(),
1✔
1090
            data_time: Default::default(),
1✔
1091
            step: TimeStep {
1✔
1092
                granularity: TimeGranularity::Millis,
1✔
1093
                step: 0,
1✔
1094
            },
1✔
1095
            cache_ttl: CacheTtlSeconds::default(),
1✔
1096
        };
1✔
1097

1098
        let id = db
1✔
1099
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1100
            .await
5✔
1101
            .unwrap()
1✔
1102
            .id;
1103

1104
        let meta: geoengine_operators::util::Result<
1✔
1105
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1106
        > = db.meta_data(&id.into()).await;
4✔
1107

1108
        assert!(meta.is_ok());
1✔
1109

1110
        let meta = GdalMetaDataStatic {
1✔
1111
            time: None,
1✔
1112
            params: gdal_params.clone(),
1✔
1113
            result_descriptor: raster_descriptor.clone(),
1✔
1114
            cache_ttl: CacheTtlSeconds::default(),
1✔
1115
        };
1✔
1116

1117
        let id = db
1✔
1118
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1119
            .await
5✔
1120
            .unwrap()
1✔
1121
            .id;
1122

1123
        let meta: geoengine_operators::util::Result<
1✔
1124
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1125
        > = db.meta_data(&id.into()).await;
3✔
1126

1127
        assert!(meta.is_ok());
1✔
1128

1129
        let meta = GdalMetaDataList {
1✔
1130
            result_descriptor: raster_descriptor.clone(),
1✔
1131
            params: vec![],
1✔
1132
        };
1✔
1133

1134
        let id = db
1✔
1135
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1136
            .await
5✔
1137
            .unwrap()
1✔
1138
            .id;
1139

1140
        let meta: geoengine_operators::util::Result<
1✔
1141
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1142
        > = db.meta_data(&id.into()).await;
3✔
1143

1144
        assert!(meta.is_ok());
1✔
1145

1146
        let meta = GdalMetadataNetCdfCf {
1✔
1147
            result_descriptor: raster_descriptor.clone(),
1✔
1148
            params: gdal_params.clone(),
1✔
1149
            start: TimeInstance::MIN,
1✔
1150
            end: TimeInstance::MAX,
1✔
1151
            step: TimeStep {
1✔
1152
                granularity: TimeGranularity::Millis,
1✔
1153
                step: 0,
1✔
1154
            },
1✔
1155
            band_offset: 0,
1✔
1156
            cache_ttl: CacheTtlSeconds::default(),
1✔
1157
        };
1✔
1158

1159
        let id = db
1✔
1160
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1161
            .await
5✔
1162
            .unwrap()
1✔
1163
            .id;
1164

1165
        let meta: geoengine_operators::util::Result<
1✔
1166
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1167
        > = db.meta_data(&id.into()).await;
3✔
1168

1169
        assert!(meta.is_ok());
1✔
1170
    }
1✔
1171

1172
    #[allow(clippy::too_many_lines)]
1173
    #[ge_context::test]
3✔
1174
    async fn it_collects_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1175
        let session = app_ctx.default_session().await.unwrap();
18✔
1176

1✔
1177
        let layer_db = app_ctx.session_context(session).db();
1✔
1178

1✔
1179
        let workflow = Workflow {
1✔
1180
            operator: TypedOperator::Vector(
1✔
1181
                MockPointSource {
1✔
1182
                    params: MockPointSourceParams {
1✔
1183
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1184
                    },
1✔
1185
                }
1✔
1186
                .boxed(),
1✔
1187
            ),
1✔
1188
        };
1✔
1189

1190
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1191

1192
        let layer1 = layer_db
1✔
1193
            .add_layer(
1✔
1194
                AddLayer {
1✔
1195
                    name: "Layer1".to_string(),
1✔
1196
                    description: "Layer 1".to_string(),
1✔
1197
                    symbology: None,
1✔
1198
                    workflow: workflow.clone(),
1✔
1199
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1200
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1201
                },
1✔
1202
                &root_collection_id,
1✔
1203
            )
1✔
1204
            .await
45✔
1205
            .unwrap();
1✔
1206

1✔
1207
        assert_eq!(
1✔
1208
            layer_db.load_layer(&layer1).await.unwrap(),
3✔
1209
            crate::layers::layer::Layer {
1✔
1210
                id: ProviderLayerId {
1✔
1211
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1212
                    layer_id: layer1.clone(),
1✔
1213
                },
1✔
1214
                name: "Layer1".to_string(),
1✔
1215
                description: "Layer 1".to_string(),
1✔
1216
                symbology: None,
1✔
1217
                workflow: workflow.clone(),
1✔
1218
                metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1219
                properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1220
            }
1✔
1221
        );
1222

1223
        let collection1_id = layer_db
1✔
1224
            .add_layer_collection(
1✔
1225
                AddLayerCollection {
1✔
1226
                    name: "Collection1".to_string(),
1✔
1227
                    description: "Collection 1".to_string(),
1✔
1228
                    properties: Default::default(),
1✔
1229
                },
1✔
1230
                &root_collection_id,
1✔
1231
            )
1✔
1232
            .await
7✔
1233
            .unwrap();
1✔
1234

1235
        let layer2 = layer_db
1✔
1236
            .add_layer(
1✔
1237
                AddLayer {
1✔
1238
                    name: "Layer2".to_string(),
1✔
1239
                    description: "Layer 2".to_string(),
1✔
1240
                    symbology: None,
1✔
1241
                    workflow: workflow.clone(),
1✔
1242
                    metadata: Default::default(),
1✔
1243
                    properties: Default::default(),
1✔
1244
                },
1✔
1245
                &collection1_id,
1✔
1246
            )
1✔
1247
            .await
9✔
1248
            .unwrap();
1✔
1249

1250
        let collection2_id = layer_db
1✔
1251
            .add_layer_collection(
1✔
1252
                AddLayerCollection {
1✔
1253
                    name: "Collection2".to_string(),
1✔
1254
                    description: "Collection 2".to_string(),
1✔
1255
                    properties: Default::default(),
1✔
1256
                },
1✔
1257
                &collection1_id,
1✔
1258
            )
1✔
1259
            .await
7✔
1260
            .unwrap();
1✔
1261

1✔
1262
        layer_db
1✔
1263
            .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1264
            .await
3✔
1265
            .unwrap();
1✔
1266

1267
        let root_collection = layer_db
1✔
1268
            .load_layer_collection(
1✔
1269
                &root_collection_id,
1✔
1270
                LayerCollectionListOptions {
1✔
1271
                    offset: 0,
1✔
1272
                    limit: 20,
1✔
1273
                },
1✔
1274
            )
1✔
1275
            .await
5✔
1276
            .unwrap();
1✔
1277

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

1321
        let collection1 = layer_db
1✔
1322
            .load_layer_collection(
1✔
1323
                &collection1_id,
1✔
1324
                LayerCollectionListOptions {
1✔
1325
                    offset: 0,
1✔
1326
                    limit: 20,
1✔
1327
                },
1✔
1328
            )
1✔
1329
            .await
5✔
1330
            .unwrap();
1✔
1331

1✔
1332
        assert_eq!(
1✔
1333
            collection1,
1✔
1334
            LayerCollection {
1✔
1335
                id: ProviderLayerCollectionId {
1✔
1336
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1337
                    collection_id: collection1_id,
1✔
1338
                },
1✔
1339
                name: "Collection1".to_string(),
1✔
1340
                description: "Collection 1".to_string(),
1✔
1341
                items: vec![
1✔
1342
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1343
                        id: ProviderLayerCollectionId {
1✔
1344
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1345
                            collection_id: collection2_id,
1✔
1346
                        },
1✔
1347
                        name: "Collection2".to_string(),
1✔
1348
                        description: "Collection 2".to_string(),
1✔
1349
                        properties: Default::default(),
1✔
1350
                    }),
1✔
1351
                    CollectionItem::Layer(LayerListing {
1✔
1352
                        id: ProviderLayerId {
1✔
1353
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1354
                            layer_id: layer2,
1✔
1355
                        },
1✔
1356
                        name: "Layer2".to_string(),
1✔
1357
                        description: "Layer 2".to_string(),
1✔
1358
                        properties: vec![],
1✔
1359
                    })
1✔
1360
                ],
1✔
1361
                entry_label: None,
1✔
1362
                properties: vec![],
1✔
1363
            }
1✔
1364
        );
1✔
1365
    }
1✔
1366

1367
    #[allow(clippy::too_many_lines)]
1368
    #[ge_context::test]
3✔
1369
    async fn it_searches_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1370
        let session = app_ctx.default_session().await.unwrap();
18✔
1371

1✔
1372
        let layer_db = app_ctx.session_context(session).db();
1✔
1373

1✔
1374
        let workflow = Workflow {
1✔
1375
            operator: TypedOperator::Vector(
1✔
1376
                MockPointSource {
1✔
1377
                    params: MockPointSourceParams {
1✔
1378
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1379
                    },
1✔
1380
                }
1✔
1381
                .boxed(),
1✔
1382
            ),
1✔
1383
        };
1✔
1384

1385
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1386

1387
        let layer1 = layer_db
1✔
1388
            .add_layer(
1✔
1389
                AddLayer {
1✔
1390
                    name: "Layer1".to_string(),
1✔
1391
                    description: "Layer 1".to_string(),
1✔
1392
                    symbology: None,
1✔
1393
                    workflow: workflow.clone(),
1✔
1394
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1395
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1396
                },
1✔
1397
                &root_collection_id,
1✔
1398
            )
1✔
1399
            .await
46✔
1400
            .unwrap();
1✔
1401

1402
        let collection1_id = layer_db
1✔
1403
            .add_layer_collection(
1✔
1404
                AddLayerCollection {
1✔
1405
                    name: "Collection1".to_string(),
1✔
1406
                    description: "Collection 1".to_string(),
1✔
1407
                    properties: Default::default(),
1✔
1408
                },
1✔
1409
                &root_collection_id,
1✔
1410
            )
1✔
1411
            .await
7✔
1412
            .unwrap();
1✔
1413

1414
        let layer2 = layer_db
1✔
1415
            .add_layer(
1✔
1416
                AddLayer {
1✔
1417
                    name: "Layer2".to_string(),
1✔
1418
                    description: "Layer 2".to_string(),
1✔
1419
                    symbology: None,
1✔
1420
                    workflow: workflow.clone(),
1✔
1421
                    metadata: Default::default(),
1✔
1422
                    properties: Default::default(),
1✔
1423
                },
1✔
1424
                &collection1_id,
1✔
1425
            )
1✔
1426
            .await
9✔
1427
            .unwrap();
1✔
1428

1429
        let collection2_id = layer_db
1✔
1430
            .add_layer_collection(
1✔
1431
                AddLayerCollection {
1✔
1432
                    name: "Collection2".to_string(),
1✔
1433
                    description: "Collection 2".to_string(),
1✔
1434
                    properties: Default::default(),
1✔
1435
                },
1✔
1436
                &collection1_id,
1✔
1437
            )
1✔
1438
            .await
7✔
1439
            .unwrap();
1✔
1440

1441
        let root_collection_all = layer_db
1✔
1442
            .search(
1✔
1443
                &root_collection_id,
1✔
1444
                SearchParameters {
1✔
1445
                    search_type: SearchType::Fulltext,
1✔
1446
                    search_string: String::new(),
1✔
1447
                    limit: 10,
1✔
1448
                    offset: 0,
1✔
1449
                },
1✔
1450
            )
1✔
1451
            .await
5✔
1452
            .unwrap();
1✔
1453

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

1517
        let root_collection_filtered = layer_db
1✔
1518
            .search(
1✔
1519
                &root_collection_id,
1✔
1520
                SearchParameters {
1✔
1521
                    search_type: SearchType::Fulltext,
1✔
1522
                    search_string: "lection".to_string(),
1✔
1523
                    limit: 10,
1✔
1524
                    offset: 0,
1✔
1525
                },
1✔
1526
            )
1✔
1527
            .await
5✔
1528
            .unwrap();
1✔
1529

1✔
1530
        assert_eq!(
1✔
1531
            root_collection_filtered,
1✔
1532
            LayerCollection {
1✔
1533
                id: ProviderLayerCollectionId {
1✔
1534
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1535
                    collection_id: root_collection_id.clone(),
1✔
1536
                },
1✔
1537
                name: "Layers".to_string(),
1✔
1538
                description: "All available Geo Engine layers".to_string(),
1✔
1539
                items: vec![
1✔
1540
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1541
                        id: ProviderLayerCollectionId {
1✔
1542
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1543
                            collection_id: collection1_id.clone(),
1✔
1544
                        },
1✔
1545
                        name: "Collection1".to_string(),
1✔
1546
                        description: "Collection 1".to_string(),
1✔
1547
                        properties: Default::default(),
1✔
1548
                    }),
1✔
1549
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1550
                        id: ProviderLayerCollectionId {
1✔
1551
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1552
                            collection_id: collection2_id.clone(),
1✔
1553
                        },
1✔
1554
                        name: "Collection2".to_string(),
1✔
1555
                        description: "Collection 2".to_string(),
1✔
1556
                        properties: Default::default(),
1✔
1557
                    }),
1✔
1558
                ],
1✔
1559
                entry_label: None,
1✔
1560
                properties: vec![],
1✔
1561
            }
1✔
1562
        );
1✔
1563

1564
        let collection1_all = layer_db
1✔
1565
            .search(
1✔
1566
                &collection1_id,
1✔
1567
                SearchParameters {
1✔
1568
                    search_type: SearchType::Fulltext,
1✔
1569
                    search_string: String::new(),
1✔
1570
                    limit: 10,
1✔
1571
                    offset: 0,
1✔
1572
                },
1✔
1573
            )
1✔
1574
            .await
5✔
1575
            .unwrap();
1✔
1576

1✔
1577
        assert_eq!(
1✔
1578
            collection1_all,
1✔
1579
            LayerCollection {
1✔
1580
                id: ProviderLayerCollectionId {
1✔
1581
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1582
                    collection_id: collection1_id.clone(),
1✔
1583
                },
1✔
1584
                name: "Collection1".to_string(),
1✔
1585
                description: "Collection 1".to_string(),
1✔
1586
                items: vec![
1✔
1587
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1588
                        id: ProviderLayerCollectionId {
1✔
1589
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1590
                            collection_id: collection2_id.clone(),
1✔
1591
                        },
1✔
1592
                        name: "Collection2".to_string(),
1✔
1593
                        description: "Collection 2".to_string(),
1✔
1594
                        properties: Default::default(),
1✔
1595
                    }),
1✔
1596
                    CollectionItem::Layer(LayerListing {
1✔
1597
                        id: ProviderLayerId {
1✔
1598
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1599
                            layer_id: layer2.clone(),
1✔
1600
                        },
1✔
1601
                        name: "Layer2".to_string(),
1✔
1602
                        description: "Layer 2".to_string(),
1✔
1603
                        properties: vec![],
1✔
1604
                    }),
1✔
1605
                ],
1✔
1606
                entry_label: None,
1✔
1607
                properties: vec![],
1✔
1608
            }
1✔
1609
        );
1✔
1610

1611
        let collection1_filtered_fulltext = layer_db
1✔
1612
            .search(
1✔
1613
                &collection1_id,
1✔
1614
                SearchParameters {
1✔
1615
                    search_type: SearchType::Fulltext,
1✔
1616
                    search_string: "ay".to_string(),
1✔
1617
                    limit: 10,
1✔
1618
                    offset: 0,
1✔
1619
                },
1✔
1620
            )
1✔
1621
            .await
5✔
1622
            .unwrap();
1✔
1623

1✔
1624
        assert_eq!(
1✔
1625
            collection1_filtered_fulltext,
1✔
1626
            LayerCollection {
1✔
1627
                id: ProviderLayerCollectionId {
1✔
1628
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1629
                    collection_id: collection1_id.clone(),
1✔
1630
                },
1✔
1631
                name: "Collection1".to_string(),
1✔
1632
                description: "Collection 1".to_string(),
1✔
1633
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1634
                    id: ProviderLayerId {
1✔
1635
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1636
                        layer_id: layer2.clone(),
1✔
1637
                    },
1✔
1638
                    name: "Layer2".to_string(),
1✔
1639
                    description: "Layer 2".to_string(),
1✔
1640
                    properties: vec![],
1✔
1641
                }),],
1✔
1642
                entry_label: None,
1✔
1643
                properties: vec![],
1✔
1644
            }
1✔
1645
        );
1✔
1646

1647
        let collection1_filtered_prefix = layer_db
1✔
1648
            .search(
1✔
1649
                &collection1_id,
1✔
1650
                SearchParameters {
1✔
1651
                    search_type: SearchType::Prefix,
1✔
1652
                    search_string: "ay".to_string(),
1✔
1653
                    limit: 10,
1✔
1654
                    offset: 0,
1✔
1655
                },
1✔
1656
            )
1✔
1657
            .await
5✔
1658
            .unwrap();
1✔
1659

1✔
1660
        assert_eq!(
1✔
1661
            collection1_filtered_prefix,
1✔
1662
            LayerCollection {
1✔
1663
                id: ProviderLayerCollectionId {
1✔
1664
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1665
                    collection_id: collection1_id.clone(),
1✔
1666
                },
1✔
1667
                name: "Collection1".to_string(),
1✔
1668
                description: "Collection 1".to_string(),
1✔
1669
                items: vec![],
1✔
1670
                entry_label: None,
1✔
1671
                properties: vec![],
1✔
1672
            }
1✔
1673
        );
1✔
1674

1675
        let collection1_filtered_prefix2 = layer_db
1✔
1676
            .search(
1✔
1677
                &collection1_id,
1✔
1678
                SearchParameters {
1✔
1679
                    search_type: SearchType::Prefix,
1✔
1680
                    search_string: "Lay".to_string(),
1✔
1681
                    limit: 10,
1✔
1682
                    offset: 0,
1✔
1683
                },
1✔
1684
            )
1✔
1685
            .await
5✔
1686
            .unwrap();
1✔
1687

1✔
1688
        assert_eq!(
1✔
1689
            collection1_filtered_prefix2,
1✔
1690
            LayerCollection {
1✔
1691
                id: ProviderLayerCollectionId {
1✔
1692
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1693
                    collection_id: collection1_id.clone(),
1✔
1694
                },
1✔
1695
                name: "Collection1".to_string(),
1✔
1696
                description: "Collection 1".to_string(),
1✔
1697
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1698
                    id: ProviderLayerId {
1✔
1699
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1700
                        layer_id: layer2.clone(),
1✔
1701
                    },
1✔
1702
                    name: "Layer2".to_string(),
1✔
1703
                    description: "Layer 2".to_string(),
1✔
1704
                    properties: vec![],
1✔
1705
                }),],
1✔
1706
                entry_label: None,
1✔
1707
                properties: vec![],
1✔
1708
            }
1✔
1709
        );
1✔
1710
    }
1✔
1711

1712
    #[allow(clippy::too_many_lines)]
1713
    #[ge_context::test]
3✔
1714
    async fn it_autocompletes_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1715
        let session = app_ctx.default_session().await.unwrap();
18✔
1716

1✔
1717
        let layer_db = app_ctx.session_context(session).db();
1✔
1718

1✔
1719
        let workflow = Workflow {
1✔
1720
            operator: TypedOperator::Vector(
1✔
1721
                MockPointSource {
1✔
1722
                    params: MockPointSourceParams {
1✔
1723
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1724
                    },
1✔
1725
                }
1✔
1726
                .boxed(),
1✔
1727
            ),
1✔
1728
        };
1✔
1729

1730
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1731

1732
        let _layer1 = layer_db
1✔
1733
            .add_layer(
1✔
1734
                AddLayer {
1✔
1735
                    name: "Layer1".to_string(),
1✔
1736
                    description: "Layer 1".to_string(),
1✔
1737
                    symbology: None,
1✔
1738
                    workflow: workflow.clone(),
1✔
1739
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1740
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1741
                },
1✔
1742
                &root_collection_id,
1✔
1743
            )
1✔
1744
            .await
45✔
1745
            .unwrap();
1✔
1746

1747
        let collection1_id = layer_db
1✔
1748
            .add_layer_collection(
1✔
1749
                AddLayerCollection {
1✔
1750
                    name: "Collection1".to_string(),
1✔
1751
                    description: "Collection 1".to_string(),
1✔
1752
                    properties: Default::default(),
1✔
1753
                },
1✔
1754
                &root_collection_id,
1✔
1755
            )
1✔
1756
            .await
7✔
1757
            .unwrap();
1✔
1758

1759
        let _layer2 = layer_db
1✔
1760
            .add_layer(
1✔
1761
                AddLayer {
1✔
1762
                    name: "Layer2".to_string(),
1✔
1763
                    description: "Layer 2".to_string(),
1✔
1764
                    symbology: None,
1✔
1765
                    workflow: workflow.clone(),
1✔
1766
                    metadata: Default::default(),
1✔
1767
                    properties: Default::default(),
1✔
1768
                },
1✔
1769
                &collection1_id,
1✔
1770
            )
1✔
1771
            .await
9✔
1772
            .unwrap();
1✔
1773

1774
        let _collection2_id = layer_db
1✔
1775
            .add_layer_collection(
1✔
1776
                AddLayerCollection {
1✔
1777
                    name: "Collection2".to_string(),
1✔
1778
                    description: "Collection 2".to_string(),
1✔
1779
                    properties: Default::default(),
1✔
1780
                },
1✔
1781
                &collection1_id,
1✔
1782
            )
1✔
1783
            .await
7✔
1784
            .unwrap();
1✔
1785

1786
        let root_collection_all = layer_db
1✔
1787
            .autocomplete_search(
1✔
1788
                &root_collection_id,
1✔
1789
                SearchParameters {
1✔
1790
                    search_type: SearchType::Fulltext,
1✔
1791
                    search_string: String::new(),
1✔
1792
                    limit: 10,
1✔
1793
                    offset: 0,
1✔
1794
                },
1✔
1795
            )
1✔
1796
            .await
3✔
1797
            .unwrap();
1✔
1798

1✔
1799
        assert_eq!(
1✔
1800
            root_collection_all,
1✔
1801
            vec![
1✔
1802
                "Collection1".to_string(),
1✔
1803
                "Collection2".to_string(),
1✔
1804
                "Layer1".to_string(),
1✔
1805
                "Layer2".to_string(),
1✔
1806
                "Unsorted".to_string(),
1✔
1807
            ]
1✔
1808
        );
1✔
1809

1810
        let root_collection_filtered = layer_db
1✔
1811
            .autocomplete_search(
1✔
1812
                &root_collection_id,
1✔
1813
                SearchParameters {
1✔
1814
                    search_type: SearchType::Fulltext,
1✔
1815
                    search_string: "lection".to_string(),
1✔
1816
                    limit: 10,
1✔
1817
                    offset: 0,
1✔
1818
                },
1✔
1819
            )
1✔
1820
            .await
3✔
1821
            .unwrap();
1✔
1822

1✔
1823
        assert_eq!(
1✔
1824
            root_collection_filtered,
1✔
1825
            vec!["Collection1".to_string(), "Collection2".to_string(),]
1✔
1826
        );
1✔
1827

1828
        let collection1_all = layer_db
1✔
1829
            .autocomplete_search(
1✔
1830
                &collection1_id,
1✔
1831
                SearchParameters {
1✔
1832
                    search_type: SearchType::Fulltext,
1✔
1833
                    search_string: String::new(),
1✔
1834
                    limit: 10,
1✔
1835
                    offset: 0,
1✔
1836
                },
1✔
1837
            )
1✔
1838
            .await
3✔
1839
            .unwrap();
1✔
1840

1✔
1841
        assert_eq!(
1✔
1842
            collection1_all,
1✔
1843
            vec!["Collection2".to_string(), "Layer2".to_string(),]
1✔
1844
        );
1✔
1845

1846
        let collection1_filtered_fulltext = layer_db
1✔
1847
            .autocomplete_search(
1✔
1848
                &collection1_id,
1✔
1849
                SearchParameters {
1✔
1850
                    search_type: SearchType::Fulltext,
1✔
1851
                    search_string: "ay".to_string(),
1✔
1852
                    limit: 10,
1✔
1853
                    offset: 0,
1✔
1854
                },
1✔
1855
            )
1✔
1856
            .await
3✔
1857
            .unwrap();
1✔
1858

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

1861
        let collection1_filtered_prefix = layer_db
1✔
1862
            .autocomplete_search(
1✔
1863
                &collection1_id,
1✔
1864
                SearchParameters {
1✔
1865
                    search_type: SearchType::Prefix,
1✔
1866
                    search_string: "ay".to_string(),
1✔
1867
                    limit: 10,
1✔
1868
                    offset: 0,
1✔
1869
                },
1✔
1870
            )
1✔
1871
            .await
3✔
1872
            .unwrap();
1✔
1873

1✔
1874
        assert_eq!(collection1_filtered_prefix, Vec::<String>::new());
1✔
1875

1876
        let collection1_filtered_prefix2 = layer_db
1✔
1877
            .autocomplete_search(
1✔
1878
                &collection1_id,
1✔
1879
                SearchParameters {
1✔
1880
                    search_type: SearchType::Prefix,
1✔
1881
                    search_string: "Lay".to_string(),
1✔
1882
                    limit: 10,
1✔
1883
                    offset: 0,
1✔
1884
                },
1✔
1885
            )
1✔
1886
            .await
3✔
1887
            .unwrap();
1✔
1888

1✔
1889
        assert_eq!(collection1_filtered_prefix2, vec!["Layer2".to_string(),]);
1✔
1890
    }
1✔
1891

1892
    #[allow(clippy::too_many_lines)]
1893
    #[ge_context::test]
3✔
1894
    async fn it_reports_search_capabilities(app_ctx: PostgresContext<NoTls>) {
1✔
1895
        let session = app_ctx.default_session().await.unwrap();
18✔
1896

1✔
1897
        let layer_db = app_ctx.session_context(session).db();
1✔
1898

1✔
1899
        let capabilities = layer_db.capabilities().search;
1✔
1900

1901
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1902

1✔
1903
        if capabilities.search_types.fulltext {
1✔
1904
            assert!(layer_db
1✔
1905
                .search(
1✔
1906
                    &root_collection_id,
1✔
1907
                    SearchParameters {
1✔
1908
                        search_type: SearchType::Fulltext,
1✔
1909
                        search_string: String::new(),
1✔
1910
                        limit: 10,
1✔
1911
                        offset: 0,
1✔
1912
                    },
1✔
1913
                )
1✔
1914
                .await
8✔
1915
                .is_ok());
1✔
1916

1917
            if capabilities.autocomplete {
1✔
1918
                assert!(layer_db
1✔
1919
                    .autocomplete_search(
1✔
1920
                        &root_collection_id,
1✔
1921
                        SearchParameters {
1✔
1922
                            search_type: SearchType::Fulltext,
1✔
1923
                            search_string: String::new(),
1✔
1924
                            limit: 10,
1✔
1925
                            offset: 0,
1✔
1926
                        },
1✔
1927
                    )
1✔
1928
                    .await
3✔
1929
                    .is_ok());
1✔
1930
            } else {
1931
                assert!(layer_db
×
1932
                    .autocomplete_search(
×
1933
                        &root_collection_id,
×
1934
                        SearchParameters {
×
1935
                            search_type: SearchType::Fulltext,
×
1936
                            search_string: String::new(),
×
1937
                            limit: 10,
×
1938
                            offset: 0,
×
1939
                        },
×
1940
                    )
×
1941
                    .await
×
1942
                    .is_err());
×
1943
            }
1944
        }
×
1945
        if capabilities.search_types.prefix {
1✔
1946
            assert!(layer_db
1✔
1947
                .search(
1✔
1948
                    &root_collection_id,
1✔
1949
                    SearchParameters {
1✔
1950
                        search_type: SearchType::Prefix,
1✔
1951
                        search_string: String::new(),
1✔
1952
                        limit: 10,
1✔
1953
                        offset: 0,
1✔
1954
                    },
1✔
1955
                )
1✔
1956
                .await
5✔
1957
                .is_ok());
1✔
1958

1959
            if capabilities.autocomplete {
1✔
1960
                assert!(layer_db
1✔
1961
                    .autocomplete_search(
1✔
1962
                        &root_collection_id,
1✔
1963
                        SearchParameters {
1✔
1964
                            search_type: SearchType::Prefix,
1✔
1965
                            search_string: String::new(),
1✔
1966
                            limit: 10,
1✔
1967
                            offset: 0,
1✔
1968
                        },
1✔
1969
                    )
1✔
1970
                    .await
3✔
1971
                    .is_ok());
1✔
1972
            } else {
1973
                assert!(layer_db
×
1974
                    .autocomplete_search(
×
1975
                        &root_collection_id,
×
1976
                        SearchParameters {
×
1977
                            search_type: SearchType::Prefix,
×
1978
                            search_string: String::new(),
×
1979
                            limit: 10,
×
1980
                            offset: 0,
×
1981
                        },
×
1982
                    )
×
1983
                    .await
×
1984
                    .is_err());
×
1985
            }
1986
        }
×
1987
    }
1✔
1988

1989
    #[allow(clippy::too_many_lines)]
1990
    #[ge_context::test]
3✔
1991
    async fn it_removes_layer_collections(app_ctx: PostgresContext<NoTls>) {
1✔
1992
        let session = app_ctx.default_session().await.unwrap();
18✔
1993

1✔
1994
        let layer_db = app_ctx.session_context(session).db();
1✔
1995

1✔
1996
        let layer = AddLayer {
1✔
1997
            name: "layer".to_string(),
1✔
1998
            description: "description".to_string(),
1✔
1999
            workflow: Workflow {
1✔
2000
                operator: TypedOperator::Vector(
1✔
2001
                    MockPointSource {
1✔
2002
                        params: MockPointSourceParams {
1✔
2003
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2004
                        },
1✔
2005
                    }
1✔
2006
                    .boxed(),
1✔
2007
                ),
1✔
2008
            },
1✔
2009
            symbology: None,
1✔
2010
            metadata: Default::default(),
1✔
2011
            properties: Default::default(),
1✔
2012
        };
1✔
2013

2014
        let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
2015

1✔
2016
        let collection = AddLayerCollection {
1✔
2017
            name: "top collection".to_string(),
1✔
2018
            description: "description".to_string(),
1✔
2019
            properties: Default::default(),
1✔
2020
        };
1✔
2021

2022
        let top_c_id = layer_db
1✔
2023
            .add_layer_collection(collection, root_collection)
1✔
2024
            .await
10✔
2025
            .unwrap();
1✔
2026

2027
        let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
42✔
2028

1✔
2029
        let collection = AddLayerCollection {
1✔
2030
            name: "empty collection".to_string(),
1✔
2031
            description: "description".to_string(),
1✔
2032
            properties: Default::default(),
1✔
2033
        };
1✔
2034

2035
        let empty_c_id = layer_db
1✔
2036
            .add_layer_collection(collection, &top_c_id)
1✔
2037
            .await
7✔
2038
            .unwrap();
1✔
2039

2040
        let items = layer_db
1✔
2041
            .load_layer_collection(
1✔
2042
                &top_c_id,
1✔
2043
                LayerCollectionListOptions {
1✔
2044
                    offset: 0,
1✔
2045
                    limit: 20,
1✔
2046
                },
1✔
2047
            )
1✔
2048
            .await
5✔
2049
            .unwrap();
1✔
2050

1✔
2051
        assert_eq!(
1✔
2052
            items,
1✔
2053
            LayerCollection {
1✔
2054
                id: ProviderLayerCollectionId {
1✔
2055
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2056
                    collection_id: top_c_id.clone(),
1✔
2057
                },
1✔
2058
                name: "top collection".to_string(),
1✔
2059
                description: "description".to_string(),
1✔
2060
                items: vec![
1✔
2061
                    CollectionItem::Collection(LayerCollectionListing {
1✔
2062
                        id: ProviderLayerCollectionId {
1✔
2063
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2064
                            collection_id: empty_c_id.clone(),
1✔
2065
                        },
1✔
2066
                        name: "empty collection".to_string(),
1✔
2067
                        description: "description".to_string(),
1✔
2068
                        properties: Default::default(),
1✔
2069
                    }),
1✔
2070
                    CollectionItem::Layer(LayerListing {
1✔
2071
                        id: ProviderLayerId {
1✔
2072
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2073
                            layer_id: l_id.clone(),
1✔
2074
                        },
1✔
2075
                        name: "layer".to_string(),
1✔
2076
                        description: "description".to_string(),
1✔
2077
                        properties: vec![],
1✔
2078
                    })
1✔
2079
                ],
1✔
2080
                entry_label: None,
1✔
2081
                properties: vec![],
1✔
2082
            }
1✔
2083
        );
1✔
2084

2085
        // remove empty collection
2086
        layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
9✔
2087

2088
        let items = layer_db
1✔
2089
            .load_layer_collection(
1✔
2090
                &top_c_id,
1✔
2091
                LayerCollectionListOptions {
1✔
2092
                    offset: 0,
1✔
2093
                    limit: 20,
1✔
2094
                },
1✔
2095
            )
1✔
2096
            .await
5✔
2097
            .unwrap();
1✔
2098

1✔
2099
        assert_eq!(
1✔
2100
            items,
1✔
2101
            LayerCollection {
1✔
2102
                id: ProviderLayerCollectionId {
1✔
2103
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2104
                    collection_id: top_c_id.clone(),
1✔
2105
                },
1✔
2106
                name: "top collection".to_string(),
1✔
2107
                description: "description".to_string(),
1✔
2108
                items: vec![CollectionItem::Layer(LayerListing {
1✔
2109
                    id: ProviderLayerId {
1✔
2110
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
2111
                        layer_id: l_id.clone(),
1✔
2112
                    },
1✔
2113
                    name: "layer".to_string(),
1✔
2114
                    description: "description".to_string(),
1✔
2115
                    properties: vec![],
1✔
2116
                })],
1✔
2117
                entry_label: None,
1✔
2118
                properties: vec![],
1✔
2119
            }
1✔
2120
        );
1✔
2121

2122
        // remove top (not root) collection
2123
        layer_db.remove_layer_collection(&top_c_id).await.unwrap();
9✔
2124

1✔
2125
        layer_db
1✔
2126
            .load_layer_collection(
1✔
2127
                &top_c_id,
1✔
2128
                LayerCollectionListOptions {
1✔
2129
                    offset: 0,
1✔
2130
                    limit: 20,
1✔
2131
                },
1✔
2132
            )
1✔
2133
            .await
3✔
2134
            .unwrap_err();
1✔
2135

1✔
2136
        // should be deleted automatically
1✔
2137
        layer_db.load_layer(&l_id).await.unwrap_err();
3✔
2138

1✔
2139
        // it is not allowed to remove the root collection
1✔
2140
        layer_db
1✔
2141
            .remove_layer_collection(root_collection)
1✔
2142
            .await
2✔
2143
            .unwrap_err();
1✔
2144
        layer_db
1✔
2145
            .load_layer_collection(
1✔
2146
                root_collection,
1✔
2147
                LayerCollectionListOptions {
1✔
2148
                    offset: 0,
1✔
2149
                    limit: 20,
1✔
2150
                },
1✔
2151
            )
1✔
2152
            .await
5✔
2153
            .unwrap();
1✔
2154
    }
1✔
2155

2156
    #[ge_context::test]
3✔
2157
    #[allow(clippy::too_many_lines)]
2158
    async fn it_removes_collections_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2159
        let session = app_ctx.default_session().await.unwrap();
18✔
2160

1✔
2161
        let db = app_ctx.session_context(session).db();
1✔
2162

2163
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2164

2165
        let mid_collection_id = db
1✔
2166
            .add_layer_collection(
1✔
2167
                AddLayerCollection {
1✔
2168
                    name: "mid collection".to_string(),
1✔
2169
                    description: "description".to_string(),
1✔
2170
                    properties: Default::default(),
1✔
2171
                },
1✔
2172
                root_collection_id,
1✔
2173
            )
1✔
2174
            .await
10✔
2175
            .unwrap();
1✔
2176

2177
        let bottom_collection_id = db
1✔
2178
            .add_layer_collection(
1✔
2179
                AddLayerCollection {
1✔
2180
                    name: "bottom collection".to_string(),
1✔
2181
                    description: "description".to_string(),
1✔
2182
                    properties: Default::default(),
1✔
2183
                },
1✔
2184
                &mid_collection_id,
1✔
2185
            )
1✔
2186
            .await
7✔
2187
            .unwrap();
1✔
2188

2189
        let layer_id = db
1✔
2190
            .add_layer(
1✔
2191
                AddLayer {
1✔
2192
                    name: "layer".to_string(),
1✔
2193
                    description: "description".to_string(),
1✔
2194
                    workflow: Workflow {
1✔
2195
                        operator: TypedOperator::Vector(
1✔
2196
                            MockPointSource {
1✔
2197
                                params: MockPointSourceParams {
1✔
2198
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2199
                                },
1✔
2200
                            }
1✔
2201
                            .boxed(),
1✔
2202
                        ),
1✔
2203
                    },
1✔
2204
                    symbology: None,
1✔
2205
                    metadata: Default::default(),
1✔
2206
                    properties: Default::default(),
1✔
2207
                },
1✔
2208
                &mid_collection_id,
1✔
2209
            )
1✔
2210
            .await
42✔
2211
            .unwrap();
1✔
2212

1✔
2213
        // removing the mid collection…
1✔
2214
        db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
2215
            .await
11✔
2216
            .unwrap();
1✔
2217

1✔
2218
        // …should remove itself
1✔
2219
        db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
2220
            .await
3✔
2221
            .unwrap_err();
1✔
2222

1✔
2223
        // …should remove the bottom collection
1✔
2224
        db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
2225
            .await
3✔
2226
            .unwrap_err();
1✔
2227

1✔
2228
        // … and should remove the layer of the bottom collection
1✔
2229
        db.load_layer(&layer_id).await.unwrap_err();
3✔
2230

1✔
2231
        // the root collection is still there
1✔
2232
        db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
2233
            .await
5✔
2234
            .unwrap();
1✔
2235
    }
1✔
2236

2237
    #[ge_context::test]
3✔
2238
    #[allow(clippy::too_many_lines)]
2239
    async fn it_removes_layers_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2240
        let session = app_ctx.default_session().await.unwrap();
18✔
2241

1✔
2242
        let db = app_ctx.session_context(session).db();
1✔
2243

2244
        let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
2245

2246
        let another_collection = db
1✔
2247
            .add_layer_collection(
1✔
2248
                AddLayerCollection {
1✔
2249
                    name: "top collection".to_string(),
1✔
2250
                    description: "description".to_string(),
1✔
2251
                    properties: Default::default(),
1✔
2252
                },
1✔
2253
                root_collection,
1✔
2254
            )
1✔
2255
            .await
10✔
2256
            .unwrap();
1✔
2257

2258
        let layer_in_one_collection = db
1✔
2259
            .add_layer(
1✔
2260
                AddLayer {
1✔
2261
                    name: "layer 1".to_string(),
1✔
2262
                    description: "description".to_string(),
1✔
2263
                    workflow: Workflow {
1✔
2264
                        operator: TypedOperator::Vector(
1✔
2265
                            MockPointSource {
1✔
2266
                                params: MockPointSourceParams {
1✔
2267
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2268
                                },
1✔
2269
                            }
1✔
2270
                            .boxed(),
1✔
2271
                        ),
1✔
2272
                    },
1✔
2273
                    symbology: None,
1✔
2274
                    metadata: Default::default(),
1✔
2275
                    properties: Default::default(),
1✔
2276
                },
1✔
2277
                &another_collection,
1✔
2278
            )
1✔
2279
            .await
42✔
2280
            .unwrap();
1✔
2281

2282
        let layer_in_two_collections = db
1✔
2283
            .add_layer(
1✔
2284
                AddLayer {
1✔
2285
                    name: "layer 2".to_string(),
1✔
2286
                    description: "description".to_string(),
1✔
2287
                    workflow: Workflow {
1✔
2288
                        operator: TypedOperator::Vector(
1✔
2289
                            MockPointSource {
1✔
2290
                                params: MockPointSourceParams {
1✔
2291
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2292
                                },
1✔
2293
                            }
1✔
2294
                            .boxed(),
1✔
2295
                        ),
1✔
2296
                    },
1✔
2297
                    symbology: None,
1✔
2298
                    metadata: Default::default(),
1✔
2299
                    properties: Default::default(),
1✔
2300
                },
1✔
2301
                &another_collection,
1✔
2302
            )
1✔
2303
            .await
9✔
2304
            .unwrap();
1✔
2305

1✔
2306
        db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
2307
            .await
3✔
2308
            .unwrap();
1✔
2309

1✔
2310
        // remove first layer --> should be deleted entirely
1✔
2311

1✔
2312
        db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
2313
            .await
7✔
2314
            .unwrap();
1✔
2315

2316
        let number_of_layer_in_collection = db
1✔
2317
            .load_layer_collection(
1✔
2318
                &another_collection,
1✔
2319
                LayerCollectionListOptions {
1✔
2320
                    offset: 0,
1✔
2321
                    limit: 20,
1✔
2322
                },
1✔
2323
            )
1✔
2324
            .await
5✔
2325
            .unwrap()
1✔
2326
            .items
1✔
2327
            .len();
1✔
2328
        assert_eq!(
1✔
2329
            number_of_layer_in_collection,
1✔
2330
            1 /* only the other collection should be here */
1✔
2331
        );
1✔
2332

2333
        db.load_layer(&layer_in_one_collection).await.unwrap_err();
3✔
2334

1✔
2335
        // remove second layer --> should only be gone in collection
1✔
2336

1✔
2337
        db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
2338
            .await
7✔
2339
            .unwrap();
1✔
2340

2341
        let number_of_layer_in_collection = db
1✔
2342
            .load_layer_collection(
1✔
2343
                &another_collection,
1✔
2344
                LayerCollectionListOptions {
1✔
2345
                    offset: 0,
1✔
2346
                    limit: 20,
1✔
2347
                },
1✔
2348
            )
1✔
2349
            .await
5✔
2350
            .unwrap()
1✔
2351
            .items
1✔
2352
            .len();
1✔
2353
        assert_eq!(
1✔
2354
            number_of_layer_in_collection,
1✔
2355
            0 /* both layers were deleted */
1✔
2356
        );
1✔
2357

2358
        db.load_layer(&layer_in_two_collections).await.unwrap();
3✔
2359
    }
1✔
2360

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

1✔
2395
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2396
            OgrSourceDataset,
1✔
2397
            VectorResultDescriptor,
1✔
2398
            VectorQueryRectangle,
1✔
2399
        > {
1✔
2400
            loading_info: loading_info.clone(),
1✔
2401
            result_descriptor: VectorResultDescriptor {
1✔
2402
                data_type: VectorDataType::MultiPoint,
1✔
2403
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2404
                columns: [(
1✔
2405
                    "foo".to_owned(),
1✔
2406
                    VectorColumnInfo {
1✔
2407
                        data_type: FeatureDataType::Float,
1✔
2408
                        measurement: Measurement::Unitless,
1✔
2409
                    },
1✔
2410
                )]
1✔
2411
                .into_iter()
1✔
2412
                .collect(),
1✔
2413
                time: None,
1✔
2414
                bbox: None,
1✔
2415
            },
1✔
2416
            phantom: Default::default(),
1✔
2417
        });
1✔
2418

2419
        let session = app_ctx.default_session().await.unwrap();
18✔
2420

1✔
2421
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2422

1✔
2423
        let db = app_ctx.session_context(session.clone()).db();
1✔
2424
        let dataset_id = db
1✔
2425
            .add_dataset(
1✔
2426
                AddDataset {
1✔
2427
                    name: Some(dataset_name),
1✔
2428
                    display_name: "Ogr Test".to_owned(),
1✔
2429
                    description: "desc".to_owned(),
1✔
2430
                    source_operator: "OgrSource".to_owned(),
1✔
2431
                    symbology: None,
1✔
2432
                    provenance: Some(vec![Provenance {
1✔
2433
                        citation: "citation".to_owned(),
1✔
2434
                        license: "license".to_owned(),
1✔
2435
                        uri: "uri".to_owned(),
1✔
2436
                    }]),
1✔
2437
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2438
                },
1✔
2439
                meta_data,
1✔
2440
            )
1✔
2441
            .await
160✔
2442
            .unwrap()
1✔
2443
            .id;
1✔
2444

1✔
2445
        assert!(db.load_dataset(&dataset_id).await.is_ok());
3✔
2446

2447
        db.delete_dataset(dataset_id).await.unwrap();
3✔
2448

1✔
2449
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2450
    }
1✔
2451

2452
    #[ge_context::test]
3✔
2453
    #[allow(clippy::too_many_lines)]
2454
    async fn it_deletes_admin_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
2455
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2456

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

1✔
2488
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2489
            OgrSourceDataset,
1✔
2490
            VectorResultDescriptor,
1✔
2491
            VectorQueryRectangle,
1✔
2492
        > {
1✔
2493
            loading_info: loading_info.clone(),
1✔
2494
            result_descriptor: VectorResultDescriptor {
1✔
2495
                data_type: VectorDataType::MultiPoint,
1✔
2496
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2497
                columns: [(
1✔
2498
                    "foo".to_owned(),
1✔
2499
                    VectorColumnInfo {
1✔
2500
                        data_type: FeatureDataType::Float,
1✔
2501
                        measurement: Measurement::Unitless,
1✔
2502
                    },
1✔
2503
                )]
1✔
2504
                .into_iter()
1✔
2505
                .collect(),
1✔
2506
                time: None,
1✔
2507
                bbox: None,
1✔
2508
            },
1✔
2509
            phantom: Default::default(),
1✔
2510
        });
1✔
2511

2512
        let session = app_ctx.default_session().await.unwrap();
18✔
2513

1✔
2514
        let db = app_ctx.session_context(session).db();
1✔
2515
        let dataset_id = db
1✔
2516
            .add_dataset(
1✔
2517
                AddDataset {
1✔
2518
                    name: Some(dataset_name),
1✔
2519
                    display_name: "Ogr Test".to_owned(),
1✔
2520
                    description: "desc".to_owned(),
1✔
2521
                    source_operator: "OgrSource".to_owned(),
1✔
2522
                    symbology: None,
1✔
2523
                    provenance: Some(vec![Provenance {
1✔
2524
                        citation: "citation".to_owned(),
1✔
2525
                        license: "license".to_owned(),
1✔
2526
                        uri: "uri".to_owned(),
1✔
2527
                    }]),
1✔
2528
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2529
                },
1✔
2530
                meta_data,
1✔
2531
            )
1✔
2532
            .await
161✔
2533
            .unwrap()
1✔
2534
            .id;
1✔
2535

1✔
2536
        assert!(db.load_dataset(&dataset_id).await.is_ok());
4✔
2537

2538
        db.delete_dataset(dataset_id).await.unwrap();
3✔
2539

1✔
2540
        assert!(db.load_dataset(&dataset_id).await.is_err());
3✔
2541
    }
1✔
2542

2543
    #[ge_context::test]
3✔
2544
    async fn test_missing_layer_dataset_in_collection_listing(app_ctx: PostgresContext<NoTls>) {
1✔
2545
        let session = app_ctx.default_session().await.unwrap();
18✔
2546
        let db = app_ctx.session_context(session).db();
1✔
2547

2548
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2549

2550
        let top_collection_id = db
1✔
2551
            .add_layer_collection(
1✔
2552
                AddLayerCollection {
1✔
2553
                    name: "top collection".to_string(),
1✔
2554
                    description: "description".to_string(),
1✔
2555
                    properties: Default::default(),
1✔
2556
                },
1✔
2557
                root_collection_id,
1✔
2558
            )
1✔
2559
            .await
10✔
2560
            .unwrap();
1✔
2561

1✔
2562
        let faux_layer = LayerId("faux".to_string());
1✔
2563

1✔
2564
        // this should fail
1✔
2565
        db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
2566
            .await
×
2567
            .unwrap_err();
1✔
2568

2569
        let root_collection_layers = db
1✔
2570
            .load_layer_collection(
1✔
2571
                &top_collection_id,
1✔
2572
                LayerCollectionListOptions {
1✔
2573
                    offset: 0,
1✔
2574
                    limit: 20,
1✔
2575
                },
1✔
2576
            )
1✔
2577
            .await
5✔
2578
            .unwrap();
1✔
2579

1✔
2580
        assert_eq!(
1✔
2581
            root_collection_layers,
1✔
2582
            LayerCollection {
1✔
2583
                id: ProviderLayerCollectionId {
1✔
2584
                    provider_id: DataProviderId(
1✔
2585
                        "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
2586
                    ),
1✔
2587
                    collection_id: top_collection_id.clone(),
1✔
2588
                },
1✔
2589
                name: "top collection".to_string(),
1✔
2590
                description: "description".to_string(),
1✔
2591
                items: vec![],
1✔
2592
                entry_label: None,
1✔
2593
                properties: vec![],
1✔
2594
            }
1✔
2595
        );
1✔
2596
    }
1✔
2597

2598
    #[allow(clippy::too_many_lines)]
2599
    #[ge_context::test]
3✔
2600
    async fn it_updates_project_layer_symbology(app_ctx: PostgresContext<NoTls>) {
1✔
2601
        let session = app_ctx.default_session().await.unwrap();
18✔
2602

2603
        let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
171✔
2604

2605
        let db = app_ctx.session_context(session.clone()).db();
1✔
2606

1✔
2607
        let create_project: CreateProject = serde_json::from_value(json!({
1✔
2608
            "name": "Default",
1✔
2609
            "description": "Default project",
1✔
2610
            "bounds": {
1✔
2611
                "boundingBox": {
1✔
2612
                    "lowerLeftCoordinate": {
1✔
2613
                        "x": -180,
1✔
2614
                        "y": -90
1✔
2615
                    },
1✔
2616
                    "upperRightCoordinate": {
1✔
2617
                        "x": 180,
1✔
2618
                        "y": 90
1✔
2619
                    }
1✔
2620
                },
1✔
2621
                "spatialReference": "EPSG:4326",
1✔
2622
                "timeInterval": {
1✔
2623
                    "start": 1_396_353_600_000i64,
1✔
2624
                    "end": 1_396_353_600_000i64
1✔
2625
                }
1✔
2626
            },
1✔
2627
            "timeStep": {
1✔
2628
                "step": 1,
1✔
2629
                "granularity": "months"
1✔
2630
            }
1✔
2631
        }))
1✔
2632
        .unwrap();
1✔
2633

2634
        let project_id = db.create_project(create_project).await.unwrap();
7✔
2635

1✔
2636
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2637
            "id": project_id.to_string(),
1✔
2638
            "layers": [{
1✔
2639
                "name": "NDVI",
1✔
2640
                "workflow": workflow_id.to_string(),
1✔
2641
                "visibility": {
1✔
2642
                    "data": true,
1✔
2643
                    "legend": false
1✔
2644
                },
1✔
2645
                "symbology": {
1✔
2646
                    "type": "raster",
1✔
2647
                    "opacity": 1,
1✔
2648
                    "rasterColorizer": {
1✔
2649
                        "type": "singleBand",
1✔
2650
                        "band": 0,
1✔
2651
                        "bandColorizer": {
1✔
2652
                            "type": "linearGradient",
1✔
2653
                            "breakpoints": [{
1✔
2654
                                "value": 1,
1✔
2655
                                "color": [0, 0, 0, 255]
1✔
2656
                            }, {
1✔
2657
                                "value": 255,
1✔
2658
                                "color": [255, 255, 255, 255]
1✔
2659
                            }],
1✔
2660
                            "noDataColor": [0, 0, 0, 0],
1✔
2661
                            "overColor": [255, 255, 255, 127],
1✔
2662
                            "underColor": [255, 255, 255, 127]
1✔
2663
                        }
1✔
2664
                    }
1✔
2665
                }
1✔
2666
            }]
1✔
2667
        }))
1✔
2668
        .unwrap();
1✔
2669

1✔
2670
        db.update_project(update).await.unwrap();
70✔
2671

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

1✔
2748
        db.update_project(update).await.unwrap();
67✔
2749

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

1✔
2826
        db.update_project(update).await.unwrap();
16✔
2827

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

2904
        // run two updates concurrently
2905
        let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
84✔
2906

2907
        assert!(r0.is_ok());
1✔
2908
        assert!(r1.is_ok());
1✔
2909
    }
1✔
2910

2911
    #[ge_context::test]
3✔
2912
    #[allow(clippy::too_many_lines)]
2913
    async fn it_resolves_dataset_names_to_ids(app_ctx: PostgresContext<NoTls>) {
1✔
2914
        let session = app_ctx.default_session().await.unwrap();
18✔
2915
        let db = app_ctx.session_context(session.clone()).db();
1✔
2916

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

1✔
2948
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2949
            OgrSourceDataset,
1✔
2950
            VectorResultDescriptor,
1✔
2951
            VectorQueryRectangle,
1✔
2952
        > {
1✔
2953
            loading_info: loading_info.clone(),
1✔
2954
            result_descriptor: VectorResultDescriptor {
1✔
2955
                data_type: VectorDataType::MultiPoint,
1✔
2956
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2957
                columns: [(
1✔
2958
                    "foo".to_owned(),
1✔
2959
                    VectorColumnInfo {
1✔
2960
                        data_type: FeatureDataType::Float,
1✔
2961
                        measurement: Measurement::Unitless,
1✔
2962
                    },
1✔
2963
                )]
1✔
2964
                .into_iter()
1✔
2965
                .collect(),
1✔
2966
                time: None,
1✔
2967
                bbox: None,
1✔
2968
            },
1✔
2969
            phantom: Default::default(),
1✔
2970
        });
1✔
2971

2972
        let DatasetIdAndName {
2973
            id: dataset_id1,
1✔
2974
            name: dataset_name1,
1✔
2975
        } = db
1✔
2976
            .add_dataset(
1✔
2977
                AddDataset {
1✔
2978
                    name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2979
                    display_name: "Ogr Test".to_owned(),
1✔
2980
                    description: "desc".to_owned(),
1✔
2981
                    source_operator: "OgrSource".to_owned(),
1✔
2982
                    symbology: None,
1✔
2983
                    provenance: Some(vec![Provenance {
1✔
2984
                        citation: "citation".to_owned(),
1✔
2985
                        license: "license".to_owned(),
1✔
2986
                        uri: "uri".to_owned(),
1✔
2987
                    }]),
1✔
2988
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2989
                },
1✔
2990
                meta_data.clone(),
1✔
2991
            )
1✔
2992
            .await
160✔
2993
            .unwrap();
1✔
2994

1✔
2995
        assert_eq!(
1✔
2996
            db.resolve_dataset_name_to_id(&dataset_name1)
1✔
2997
                .await
3✔
2998
                .unwrap()
1✔
2999
                .unwrap(),
1✔
3000
            dataset_id1
3001
        );
3002
    }
1✔
3003

3004
    #[ge_context::test]
3✔
3005
    #[allow(clippy::too_many_lines)]
3006
    async fn test_postgres_type_serialization(app_ctx: PostgresContext<NoTls>) {
1✔
3007
        let pool = app_ctx.pool.get().await.unwrap();
1✔
3008

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

3011
        assert_sql_type(
1✔
3012
            &pool,
1✔
3013
            "double precision",
1✔
3014
            [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
3015
        )
1✔
3016
        .await;
2✔
3017

3018
        assert_sql_type(
1✔
3019
            &pool,
1✔
3020
            "Breakpoint",
1✔
3021
            [Breakpoint {
1✔
3022
                value: NotNan::<f64>::new(1.0).unwrap(),
1✔
3023
                color: RgbaColor::new(0, 0, 0, 0),
1✔
3024
            }],
1✔
3025
        )
1✔
3026
        .await;
5✔
3027

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

3084
        assert_sql_type(
1✔
3085
            &pool,
1✔
3086
            "ColorParam",
1✔
3087
            [
1✔
3088
                ColorParam::Static {
1✔
3089
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3090
                },
1✔
3091
                ColorParam::Derived(DerivedColor {
1✔
3092
                    attribute: "foobar".to_string(),
1✔
3093
                    colorizer: Colorizer::Rgba,
1✔
3094
                }),
1✔
3095
            ],
1✔
3096
        )
1✔
3097
        .await;
6✔
3098

3099
        assert_sql_type(
1✔
3100
            &pool,
1✔
3101
            "NumberParam",
1✔
3102
            [
1✔
3103
                NumberParam::Static { value: 42 },
1✔
3104
                NumberParam::Derived(DerivedNumber {
1✔
3105
                    attribute: "foobar".to_string(),
1✔
3106
                    factor: 1.0,
1✔
3107
                    default_value: 42.,
1✔
3108
                }),
1✔
3109
            ],
1✔
3110
        )
1✔
3111
        .await;
6✔
3112

3113
        assert_sql_type(
1✔
3114
            &pool,
1✔
3115
            "StrokeParam",
1✔
3116
            [StrokeParam {
1✔
3117
                width: NumberParam::Static { value: 42 },
1✔
3118
                color: ColorParam::Static {
1✔
3119
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3120
                },
1✔
3121
            }],
1✔
3122
        )
1✔
3123
        .await;
4✔
3124

3125
        assert_sql_type(
1✔
3126
            &pool,
1✔
3127
            "TextSymbology",
1✔
3128
            [TextSymbology {
1✔
3129
                attribute: "attribute".to_string(),
1✔
3130
                fill_color: ColorParam::Static {
1✔
3131
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3132
                },
1✔
3133
                stroke: StrokeParam {
1✔
3134
                    width: NumberParam::Static { value: 42 },
1✔
3135
                    color: ColorParam::Static {
1✔
3136
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
3137
                    },
1✔
3138
                },
1✔
3139
            }],
1✔
3140
        )
1✔
3141
        .await;
4✔
3142

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

3241
        assert_sql_type(
1✔
3242
            &pool,
1✔
3243
            "RasterDataType",
1✔
3244
            [
1✔
3245
                RasterDataType::U8,
1✔
3246
                RasterDataType::U16,
1✔
3247
                RasterDataType::U32,
1✔
3248
                RasterDataType::U64,
1✔
3249
                RasterDataType::I8,
1✔
3250
                RasterDataType::I16,
1✔
3251
                RasterDataType::I32,
1✔
3252
                RasterDataType::I64,
1✔
3253
                RasterDataType::F32,
1✔
3254
                RasterDataType::F64,
1✔
3255
            ],
1✔
3256
        )
1✔
3257
        .await;
22✔
3258

3259
        assert_sql_type(
1✔
3260
            &pool,
1✔
3261
            "Measurement",
1✔
3262
            [
1✔
3263
                Measurement::Unitless,
1✔
3264
                Measurement::Continuous(ContinuousMeasurement {
1✔
3265
                    measurement: "Temperature".to_string(),
1✔
3266
                    unit: Some("°C".to_string()),
1✔
3267
                }),
1✔
3268
                Measurement::Classification(ClassificationMeasurement {
1✔
3269
                    measurement: "Color".to_string(),
1✔
3270
                    classes: [(1, "Grayscale".to_string()), (2, "Colorful".to_string())].into(),
1✔
3271
                }),
1✔
3272
            ],
1✔
3273
        )
1✔
3274
        .await;
15✔
3275

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

3278
        assert_sql_type(
1✔
3279
            &pool,
1✔
3280
            "SpatialPartition2D",
1✔
3281
            [
1✔
3282
                SpatialPartition2D::new(Coordinate2D::new(0.0f64, 1.), Coordinate2D::new(2., 0.5))
1✔
3283
                    .unwrap(),
1✔
3284
            ],
1✔
3285
        )
1✔
3286
        .await;
4✔
3287

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

3298
        assert_sql_type(
1✔
3299
            &pool,
1✔
3300
            "SpatialResolution",
1✔
3301
            [SpatialResolution { x: 1.2, y: 2.3 }],
1✔
3302
        )
1✔
3303
        .await;
4✔
3304

3305
        assert_sql_type(
1✔
3306
            &pool,
1✔
3307
            "VectorDataType",
1✔
3308
            [
1✔
3309
                VectorDataType::Data,
1✔
3310
                VectorDataType::MultiPoint,
1✔
3311
                VectorDataType::MultiLineString,
1✔
3312
                VectorDataType::MultiPolygon,
1✔
3313
            ],
1✔
3314
        )
1✔
3315
        .await;
10✔
3316

3317
        assert_sql_type(
1✔
3318
            &pool,
1✔
3319
            "FeatureDataType",
1✔
3320
            [
1✔
3321
                FeatureDataType::Category,
1✔
3322
                FeatureDataType::Int,
1✔
3323
                FeatureDataType::Float,
1✔
3324
                FeatureDataType::Text,
1✔
3325
                FeatureDataType::Bool,
1✔
3326
                FeatureDataType::DateTime,
1✔
3327
            ],
1✔
3328
        )
1✔
3329
        .await;
14✔
3330

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

3333
        assert_sql_type(
1✔
3334
            &pool,
1✔
3335
            "SpatialReference",
1✔
3336
            [
1✔
3337
                SpatialReferenceOption::Unreferenced,
1✔
3338
                SpatialReferenceOption::SpatialReference(SpatialReference::epsg_4326()),
1✔
3339
            ],
1✔
3340
        )
1✔
3341
        .await;
8✔
3342

3343
        assert_sql_type(
1✔
3344
            &pool,
1✔
3345
            "PlotResultDescriptor",
1✔
3346
            [PlotResultDescriptor {
1✔
3347
                spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
3348
                time: None,
1✔
3349
                bbox: None,
1✔
3350
            }],
1✔
3351
        )
1✔
3352
        .await;
4✔
3353

3354
        assert_sql_type(
1✔
3355
            &pool,
1✔
3356
            "VectorResultDescriptor",
1✔
3357
            [VectorResultDescriptor {
1✔
3358
                data_type: VectorDataType::MultiPoint,
1✔
3359
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3360
                    SpatialReference::epsg_4326(),
1✔
3361
                ),
1✔
3362
                columns: [(
1✔
3363
                    "foo".to_string(),
1✔
3364
                    VectorColumnInfo {
1✔
3365
                        data_type: FeatureDataType::Int,
1✔
3366
                        measurement: Measurement::Unitless,
1✔
3367
                    },
1✔
3368
                )]
1✔
3369
                .into(),
1✔
3370
                time: Some(TimeInterval::default()),
1✔
3371
                bbox: Some(
1✔
3372
                    BoundingBox2D::new(Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0))
1✔
3373
                        .unwrap(),
1✔
3374
                ),
1✔
3375
            }],
1✔
3376
        )
1✔
3377
        .await;
7✔
3378

3379
        assert_sql_type(
1✔
3380
            &pool,
1✔
3381
            "RasterResultDescriptor",
1✔
3382
            [RasterResultDescriptor {
1✔
3383
                data_type: RasterDataType::U8,
1✔
3384
                spatial_reference: SpatialReferenceOption::SpatialReference(
1✔
3385
                    SpatialReference::epsg_4326(),
1✔
3386
                ),
1✔
3387
                time: Some(TimeInterval::default()),
1✔
3388
                bbox: Some(
1✔
3389
                    SpatialPartition2D::new(
1✔
3390
                        Coordinate2D::new(0.0f64, 1.),
1✔
3391
                        Coordinate2D::new(2., 0.5),
1✔
3392
                    )
1✔
3393
                    .unwrap(),
1✔
3394
                ),
1✔
3395
                resolution: Some(SpatialResolution { x: 1.2, y: 2.3 }),
1✔
3396
                bands: RasterBandDescriptors::new_single_band(),
1✔
3397
            }],
1✔
3398
        )
1✔
3399
        .await;
7✔
3400

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

3452
        assert_sql_type(
1✔
3453
            &pool,
1✔
3454
            "MockDatasetDataSourceLoadingInfo",
1✔
3455
            [MockDatasetDataSourceLoadingInfo {
1✔
3456
                points: vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3457
            }],
1✔
3458
        )
1✔
3459
        .await;
5✔
3460

3461
        assert_sql_type(
1✔
3462
            &pool,
1✔
3463
            "OgrSourceTimeFormat",
1✔
3464
            [
1✔
3465
                OgrSourceTimeFormat::Auto,
1✔
3466
                OgrSourceTimeFormat::Custom {
1✔
3467
                    custom_format: geoengine_datatypes::primitives::DateTimeParseFormat::custom(
1✔
3468
                        "%Y-%m-%dT%H:%M:%S%.3fZ".to_string(),
1✔
3469
                    ),
1✔
3470
                },
1✔
3471
                OgrSourceTimeFormat::UnixTimeStamp {
1✔
3472
                    timestamp_type: UnixTimeStampType::EpochSeconds,
1✔
3473
                    fmt: geoengine_datatypes::primitives::DateTimeParseFormat::unix(),
1✔
3474
                },
1✔
3475
            ],
1✔
3476
        )
1✔
3477
        .await;
16✔
3478

3479
        assert_sql_type(
1✔
3480
            &pool,
1✔
3481
            "OgrSourceDurationSpec",
1✔
3482
            [
1✔
3483
                OgrSourceDurationSpec::Infinite,
1✔
3484
                OgrSourceDurationSpec::Zero,
1✔
3485
                OgrSourceDurationSpec::Value(TimeStep {
1✔
3486
                    granularity: TimeGranularity::Millis,
1✔
3487
                    step: 1000,
1✔
3488
                }),
1✔
3489
            ],
1✔
3490
        )
1✔
3491
        .await;
12✔
3492

3493
        assert_sql_type(
1✔
3494
            &pool,
1✔
3495
            "OgrSourceDatasetTimeType",
1✔
3496
            [
1✔
3497
                OgrSourceDatasetTimeType::None,
1✔
3498
                OgrSourceDatasetTimeType::Start {
1✔
3499
                    start_field: "start".to_string(),
1✔
3500
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3501
                    duration: OgrSourceDurationSpec::Zero,
1✔
3502
                },
1✔
3503
                OgrSourceDatasetTimeType::StartEnd {
1✔
3504
                    start_field: "start".to_string(),
1✔
3505
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3506
                    end_field: "end".to_string(),
1✔
3507
                    end_format: OgrSourceTimeFormat::Auto,
1✔
3508
                },
1✔
3509
                OgrSourceDatasetTimeType::StartDuration {
1✔
3510
                    start_field: "start".to_string(),
1✔
3511
                    start_format: OgrSourceTimeFormat::Auto,
1✔
3512
                    duration_field: "duration".to_string(),
1✔
3513
                },
1✔
3514
            ],
1✔
3515
        )
1✔
3516
        .await;
16✔
3517

3518
        assert_sql_type(
1✔
3519
            &pool,
1✔
3520
            "FormatSpecifics",
1✔
3521
            [FormatSpecifics::Csv {
1✔
3522
                header: CsvHeader::Yes,
1✔
3523
            }],
1✔
3524
        )
1✔
3525
        .await;
8✔
3526

3527
        assert_sql_type(
1✔
3528
            &pool,
1✔
3529
            "OgrSourceColumnSpec",
1✔
3530
            [OgrSourceColumnSpec {
1✔
3531
                format_specifics: Some(FormatSpecifics::Csv {
1✔
3532
                    header: CsvHeader::Auto,
1✔
3533
                }),
1✔
3534
                x: "x".to_string(),
1✔
3535
                y: Some("y".to_string()),
1✔
3536
                int: vec!["int".to_string()],
1✔
3537
                float: vec!["float".to_string()],
1✔
3538
                text: vec!["text".to_string()],
1✔
3539
                bool: vec!["bool".to_string()],
1✔
3540
                datetime: vec!["datetime".to_string()],
1✔
3541
                rename: Some(
1✔
3542
                    [
1✔
3543
                        ("xx".to_string(), "xx_renamed".to_string()),
1✔
3544
                        ("yx".to_string(), "yy_renamed".to_string()),
1✔
3545
                    ]
1✔
3546
                    .into(),
1✔
3547
                ),
1✔
3548
            }],
1✔
3549
        )
1✔
3550
        .await;
7✔
3551

3552
        assert_sql_type(
1✔
3553
            &pool,
1✔
3554
            "point[]",
1✔
3555
            [MultiPoint::new(vec![
1✔
3556
                Coordinate2D::new(0.0f64, 0.5),
1✔
3557
                Coordinate2D::new(2., 1.0),
1✔
3558
            ])
1✔
3559
            .unwrap()],
1✔
3560
        )
1✔
3561
        .await;
2✔
3562

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

3574
        assert_sql_type(
1✔
3575
            &pool,
1✔
3576
            "\"Polygon\"[]",
1✔
3577
            [MultiPolygon::new(vec![
1✔
3578
                vec![
1✔
3579
                    vec![
1✔
3580
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3581
                        Coordinate2D::new(2., 1.0),
1✔
3582
                        Coordinate2D::new(2., 1.0),
1✔
3583
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3584
                    ],
1✔
3585
                    vec![
1✔
3586
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3587
                        Coordinate2D::new(2., 1.0),
1✔
3588
                        Coordinate2D::new(2., 1.0),
1✔
3589
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3590
                    ],
1✔
3591
                ],
1✔
3592
                vec![
1✔
3593
                    vec![
1✔
3594
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3595
                        Coordinate2D::new(2., 1.0),
1✔
3596
                        Coordinate2D::new(2., 1.0),
1✔
3597
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3598
                    ],
1✔
3599
                    vec![
1✔
3600
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3601
                        Coordinate2D::new(2., 1.0),
1✔
3602
                        Coordinate2D::new(2., 1.0),
1✔
3603
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3604
                    ],
1✔
3605
                ],
1✔
3606
            ])
1✔
3607
            .unwrap()],
1✔
3608
        )
1✔
3609
        .await;
4✔
3610

3611
        assert_sql_type(
1✔
3612
            &pool,
1✔
3613
            "TypedGeometry",
1✔
3614
            [
1✔
3615
                TypedGeometry::Data(NoGeometry),
1✔
3616
                TypedGeometry::MultiPoint(
1✔
3617
                    MultiPoint::new(vec![
1✔
3618
                        Coordinate2D::new(0.0f64, 0.5),
1✔
3619
                        Coordinate2D::new(2., 1.0),
1✔
3620
                    ])
1✔
3621
                    .unwrap(),
1✔
3622
                ),
1✔
3623
                TypedGeometry::MultiLineString(
1✔
3624
                    MultiLineString::new(vec![
1✔
3625
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3626
                        vec![Coordinate2D::new(0.0f64, 0.5), Coordinate2D::new(2., 1.0)],
1✔
3627
                    ])
1✔
3628
                    .unwrap(),
1✔
3629
                ),
1✔
3630
                TypedGeometry::MultiPolygon(
1✔
3631
                    MultiPolygon::new(vec![
1✔
3632
                        vec![
1✔
3633
                            vec![
1✔
3634
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3635
                                Coordinate2D::new(2., 1.0),
1✔
3636
                                Coordinate2D::new(2., 1.0),
1✔
3637
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3638
                            ],
1✔
3639
                            vec![
1✔
3640
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3641
                                Coordinate2D::new(2., 1.0),
1✔
3642
                                Coordinate2D::new(2., 1.0),
1✔
3643
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3644
                            ],
1✔
3645
                        ],
1✔
3646
                        vec![
1✔
3647
                            vec![
1✔
3648
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3649
                                Coordinate2D::new(2., 1.0),
1✔
3650
                                Coordinate2D::new(2., 1.0),
1✔
3651
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3652
                            ],
1✔
3653
                            vec![
1✔
3654
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3655
                                Coordinate2D::new(2., 1.0),
1✔
3656
                                Coordinate2D::new(2., 1.0),
1✔
3657
                                Coordinate2D::new(0.0f64, 0.5),
1✔
3658
                            ],
1✔
3659
                        ],
1✔
3660
                    ])
1✔
3661
                    .unwrap(),
1✔
3662
                ),
1✔
3663
            ],
1✔
3664
        )
1✔
3665
        .await;
11✔
3666

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

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

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

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

3830
        assert_sql_type(
1✔
3831
            &pool,
1✔
3832
            "GdalDatasetGeoTransform",
1✔
3833
            [GdalDatasetGeoTransform {
1✔
3834
                origin_coordinate: Coordinate2D::new(0.0f64, 0.5),
1✔
3835
                x_pixel_size: 1.0,
1✔
3836
                y_pixel_size: 2.0,
1✔
3837
            }],
1✔
3838
        )
1✔
3839
        .await;
4✔
3840

3841
        assert_sql_type(
1✔
3842
            &pool,
1✔
3843
            "FileNotFoundHandling",
1✔
3844
            [FileNotFoundHandling::NoData, FileNotFoundHandling::Error],
1✔
3845
        )
1✔
3846
        .await;
6✔
3847

3848
        assert_sql_type(
1✔
3849
            &pool,
1✔
3850
            "GdalMetadataMapping",
1✔
3851
            [GdalMetadataMapping {
1✔
3852
                source_key: RasterPropertiesKey {
1✔
3853
                    domain: None,
1✔
3854
                    key: "foo".to_string(),
1✔
3855
                },
1✔
3856
                target_key: RasterPropertiesKey {
1✔
3857
                    domain: Some("bar".to_string()),
1✔
3858
                    key: "foo".to_string(),
1✔
3859
                },
1✔
3860
                target_type: RasterPropertiesEntryType::String,
1✔
3861
            }],
1✔
3862
        )
1✔
3863
        .await;
8✔
3864

3865
        assert_sql_type(
1✔
3866
            &pool,
1✔
3867
            "StringPair",
1✔
3868
            [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3869
        )
1✔
3870
        .await;
3✔
3871

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

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

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

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

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

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

4505
        assert_sql_type(
1✔
4506
            &pool,
1✔
4507
            "bytea",
1✔
4508
            [U96::from(
1✔
4509
                arr![u8; 13, 227, 191, 247, 123, 193, 214, 165, 185, 37, 101, 24],
1✔
4510
            )],
1✔
4511
        )
1✔
4512
        .await;
2✔
4513

4514
        test_data_provider_definition_types(&pool).await;
63✔
4515
    }
1✔
4516

4517
    #[test]
1✔
4518
    fn test_postgres_config_translation() {
1✔
4519
        let host = "localhost";
1✔
4520
        let port = 8095;
1✔
4521
        let ge_default = "geoengine";
1✔
4522
        let schema = "geoengine";
1✔
4523

1✔
4524
        let db_config = config::Postgres {
1✔
4525
            host: host.to_string(),
1✔
4526
            port,
1✔
4527
            database: ge_default.to_string(),
1✔
4528
            schema: schema.to_string(),
1✔
4529
            user: ge_default.to_string(),
1✔
4530
            password: ge_default.to_string(),
1✔
4531
            clear_database_on_start: false,
1✔
4532
        };
1✔
4533

1✔
4534
        let pg_config = Config::try_from(db_config).unwrap();
1✔
4535

1✔
4536
        assert_eq!(ge_default, pg_config.get_user().unwrap());
1✔
4537
        assert_eq!(
1✔
4538
            <str as AsRef<[u8]>>::as_ref(ge_default).to_vec(),
1✔
4539
            pg_config.get_password().unwrap()
1✔
4540
        );
1✔
4541
        assert_eq!(ge_default, pg_config.get_dbname().unwrap());
1✔
4542
        assert_eq!(
1✔
4543
            &format!("-c search_path={schema}"),
1✔
4544
            pg_config.get_options().unwrap()
1✔
4545
        );
1✔
4546
        assert_eq!(vec![Host::Tcp(host.to_string())], pg_config.get_hosts());
1✔
4547
        assert_eq!(vec![port], pg_config.get_ports());
1✔
4548
    }
1✔
4549

4550
    #[allow(clippy::too_many_lines)]
4551
    async fn test_data_provider_definition_types(
1✔
4552
        pool: &PooledConnection<'_, PostgresConnectionManager<tokio_postgres::NoTls>>,
1✔
4553
    ) {
1✔
4554
        assert_sql_type(
1✔
4555
            pool,
1✔
4556
            "ArunaDataProviderDefinition",
1✔
4557
            [ArunaDataProviderDefinition {
1✔
4558
                id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0").unwrap(),
1✔
4559
                name: "NFDI".to_string(),
1✔
4560
                description: "NFDI".to_string(),
1✔
4561
                priority: Some(33),
1✔
4562
                api_url: "http://test".to_string(),
1✔
4563
                project_id: "project".to_string(),
1✔
4564
                api_token: "api_token".to_string(),
1✔
4565
                filter_label: "filter".to_string(),
1✔
4566
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4567
            }],
1✔
4568
        )
1✔
4569
        .await;
4✔
4570

4571
        assert_sql_type(
1✔
4572
            pool,
1✔
4573
            "GbifDataProviderDefinition",
1✔
4574
            [GbifDataProviderDefinition {
1✔
4575
                name: "GBIF".to_string(),
1✔
4576
                description: "GFBio".to_string(),
1✔
4577
                priority: None,
1✔
4578
                db_config: DatabaseConnectionConfig {
1✔
4579
                    host: "testhost".to_string(),
1✔
4580
                    port: 1234,
1✔
4581
                    database: "testdb".to_string(),
1✔
4582
                    schema: "testschema".to_string(),
1✔
4583
                    user: "testuser".to_string(),
1✔
4584
                    password: "testpass".to_string(),
1✔
4585
                },
1✔
4586
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4587
                autocomplete_timeout: 3,
1✔
4588
                columns: GbifDataProvider::all_columns(),
1✔
4589
            }],
1✔
4590
        )
1✔
4591
        .await;
6✔
4592

4593
        assert_sql_type(
1✔
4594
            pool,
1✔
4595
            "GfbioAbcdDataProviderDefinition",
1✔
4596
            [GfbioAbcdDataProviderDefinition {
1✔
4597
                name: "GFbio".to_string(),
1✔
4598
                description: "GFBio".to_string(),
1✔
4599
                priority: None,
1✔
4600
                db_config: DatabaseConnectionConfig {
1✔
4601
                    host: "testhost".to_string(),
1✔
4602
                    port: 1234,
1✔
4603
                    database: "testdb".to_string(),
1✔
4604
                    schema: "testschema".to_string(),
1✔
4605
                    user: "testuser".to_string(),
1✔
4606
                    password: "testpass".to_string(),
1✔
4607
                },
1✔
4608
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4609
            }],
1✔
4610
        )
1✔
4611
        .await;
4✔
4612

4613
        assert_sql_type(
1✔
4614
            pool,
1✔
4615
            "GfbioCollectionsDataProviderDefinition",
1✔
4616
            [GfbioCollectionsDataProviderDefinition {
1✔
4617
                name: "GFbio".to_string(),
1✔
4618
                description: "GFBio".to_string(),
1✔
4619
                priority: None,
1✔
4620
                collection_api_url: "http://testhost".try_into().unwrap(),
1✔
4621
                collection_api_auth_token: "token".to_string(),
1✔
4622
                abcd_db_config: DatabaseConnectionConfig {
1✔
4623
                    host: "testhost".to_string(),
1✔
4624
                    port: 1234,
1✔
4625
                    database: "testdb".to_string(),
1✔
4626
                    schema: "testschema".to_string(),
1✔
4627
                    user: "testuser".to_string(),
1✔
4628
                    password: "testpass".to_string(),
1✔
4629
                },
1✔
4630
                pangaea_url: "http://panaea".try_into().unwrap(),
1✔
4631
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4632
            }],
1✔
4633
        )
1✔
4634
        .await;
4✔
4635

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

4638
        assert_sql_type(
1✔
4639
            pool,
1✔
4640
            "EbvPortalDataProviderDefinition",
1✔
4641
            [EbvPortalDataProviderDefinition {
1✔
4642
                name: "ebv".to_string(),
1✔
4643
                description: "EBV".to_string(),
1✔
4644
                priority: None,
1✔
4645
                data: "a_path".into(),
1✔
4646
                base_url: "http://base".try_into().unwrap(),
1✔
4647
                overviews: "another_path".into(),
1✔
4648
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4649
            }],
1✔
4650
        )
1✔
4651
        .await;
4✔
4652

4653
        assert_sql_type(
1✔
4654
            pool,
1✔
4655
            "NetCdfCfDataProviderDefinition",
1✔
4656
            [NetCdfCfDataProviderDefinition {
1✔
4657
                name: "netcdfcf".to_string(),
1✔
4658
                description: "netcdfcf".to_string(),
1✔
4659
                priority: Some(33),
1✔
4660
                data: "a_path".into(),
1✔
4661
                overviews: "another_path".into(),
1✔
4662
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4663
            }],
1✔
4664
        )
1✔
4665
        .await;
4✔
4666

4667
        assert_sql_type(
1✔
4668
            pool,
1✔
4669
            "PangaeaDataProviderDefinition",
1✔
4670
            [PangaeaDataProviderDefinition {
1✔
4671
                name: "pangaea".to_string(),
1✔
4672
                description: "pangaea".to_string(),
1✔
4673
                priority: None,
1✔
4674
                base_url: "http://base".try_into().unwrap(),
1✔
4675
                cache_ttl: CacheTtlSeconds::new(0),
1✔
4676
            }],
1✔
4677
        )
1✔
4678
        .await;
4✔
4679

4680
        assert_sql_type(
1✔
4681
            pool,
1✔
4682
            "DataProviderDefinition",
1✔
4683
            [
1✔
4684
                TypedDataProviderDefinition::ArunaDataProviderDefinition(
1✔
4685
                    ArunaDataProviderDefinition {
1✔
4686
                        id: DataProviderId::from_str("86a7f7ce-1bab-4ce9-a32b-172c0f958ee0")
1✔
4687
                            .unwrap(),
1✔
4688
                        name: "NFDI".to_string(),
1✔
4689
                        description: "NFDI".to_string(),
1✔
4690
                        priority: Some(33),
1✔
4691
                        api_url: "http://test".to_string(),
1✔
4692
                        project_id: "project".to_string(),
1✔
4693
                        api_token: "api_token".to_string(),
1✔
4694
                        filter_label: "filter".to_string(),
1✔
4695
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4696
                    },
1✔
4697
                ),
1✔
4698
                TypedDataProviderDefinition::GbifDataProviderDefinition(
1✔
4699
                    GbifDataProviderDefinition {
1✔
4700
                        name: "GBIF".to_string(),
1✔
4701
                        description: "GFBio".to_string(),
1✔
4702
                        priority: None,
1✔
4703
                        db_config: DatabaseConnectionConfig {
1✔
4704
                            host: "testhost".to_string(),
1✔
4705
                            port: 1234,
1✔
4706
                            database: "testdb".to_string(),
1✔
4707
                            schema: "testschema".to_string(),
1✔
4708
                            user: "testuser".to_string(),
1✔
4709
                            password: "testpass".to_string(),
1✔
4710
                        },
1✔
4711
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4712
                        autocomplete_timeout: 3,
1✔
4713
                        columns: GbifDataProvider::all_columns(),
1✔
4714
                    },
1✔
4715
                ),
1✔
4716
                TypedDataProviderDefinition::GfbioAbcdDataProviderDefinition(
1✔
4717
                    GfbioAbcdDataProviderDefinition {
1✔
4718
                        name: "GFbio".to_string(),
1✔
4719
                        description: "GFBio".to_string(),
1✔
4720
                        priority: None,
1✔
4721
                        db_config: DatabaseConnectionConfig {
1✔
4722
                            host: "testhost".to_string(),
1✔
4723
                            port: 1234,
1✔
4724
                            database: "testdb".to_string(),
1✔
4725
                            schema: "testschema".to_string(),
1✔
4726
                            user: "testuser".to_string(),
1✔
4727
                            password: "testpass".to_string(),
1✔
4728
                        },
1✔
4729
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4730
                    },
1✔
4731
                ),
1✔
4732
                TypedDataProviderDefinition::GfbioCollectionsDataProviderDefinition(
1✔
4733
                    GfbioCollectionsDataProviderDefinition {
1✔
4734
                        name: "GFbio".to_string(),
1✔
4735
                        description: "GFBio".to_string(),
1✔
4736
                        priority: None,
1✔
4737
                        collection_api_url: "http://testhost".try_into().unwrap(),
1✔
4738
                        collection_api_auth_token: "token".to_string(),
1✔
4739
                        abcd_db_config: DatabaseConnectionConfig {
1✔
4740
                            host: "testhost".to_string(),
1✔
4741
                            port: 1234,
1✔
4742
                            database: "testdb".to_string(),
1✔
4743
                            schema: "testschema".to_string(),
1✔
4744
                            user: "testuser".to_string(),
1✔
4745
                            password: "testpass".to_string(),
1✔
4746
                        },
1✔
4747
                        pangaea_url: "http://panaea".try_into().unwrap(),
1✔
4748
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4749
                    },
1✔
4750
                ),
1✔
4751
                TypedDataProviderDefinition::EbvPortalDataProviderDefinition(
1✔
4752
                    EbvPortalDataProviderDefinition {
1✔
4753
                        name: "ebv".to_string(),
1✔
4754
                        description: "ebv".to_string(),
1✔
4755
                        priority: Some(33),
1✔
4756
                        data: "a_path".into(),
1✔
4757
                        base_url: "http://base".try_into().unwrap(),
1✔
4758
                        overviews: "another_path".into(),
1✔
4759
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4760
                    },
1✔
4761
                ),
1✔
4762
                TypedDataProviderDefinition::NetCdfCfDataProviderDefinition(
1✔
4763
                    NetCdfCfDataProviderDefinition {
1✔
4764
                        name: "netcdfcf".to_string(),
1✔
4765
                        description: "netcdfcf".to_string(),
1✔
4766
                        priority: Some(33),
1✔
4767
                        data: "a_path".into(),
1✔
4768
                        overviews: "another_path".into(),
1✔
4769
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4770
                    },
1✔
4771
                ),
1✔
4772
                TypedDataProviderDefinition::PangaeaDataProviderDefinition(
1✔
4773
                    PangaeaDataProviderDefinition {
1✔
4774
                        name: "pangaea".to_string(),
1✔
4775
                        description: "pangaea".to_string(),
1✔
4776
                        priority: None,
1✔
4777
                        base_url: "http://base".try_into().unwrap(),
1✔
4778
                        cache_ttl: CacheTtlSeconds::new(0),
1✔
4779
                    },
1✔
4780
                ),
1✔
4781
            ],
1✔
4782
        )
1✔
4783
        .await;
28✔
4784
    }
1✔
4785
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc