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

geo-engine / geoengine / 12668251541

08 Jan 2025 10:00AM UTC coverage: 90.629% (+0.07%) from 90.56%
12668251541

Pull #1006

github

web-flow
Merge 793062266 into 071ba4e63
Pull Request #1006: Migrate-pro-api

697 of 737 new or added lines in 14 files covered. (94.57%)

218 existing lines in 13 files now uncovered.

133462 of 147262 relevant lines covered (90.63%)

54661.22 hits per line

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

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

29
// TODO: distinguish user-facing errors from system-facing error messages
30

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

49
enum DatabaseStatus {
50
    Unitialized,
51
    InitializedClearDatabase,
52
    InitializedKeepDatabase,
53
}
54

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

71
        let pool = Pool::builder().build(pg_mgr).await?;
160✔
72
        let created_schema = Self::create_database(pool.get().await?).await?;
160✔
73

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

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

93
    async fn check_schema_status(
316✔
94
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
316✔
95
    ) -> Result<DatabaseStatus> {
316✔
96
        let stmt = match conn
316✔
97
            .prepare("SELECT clear_database_on_start from geoengine;")
316✔
98
            .await
316✔
99
        {
100
            Ok(stmt) => stmt,
×
101
            Err(e) => {
316✔
102
                if let Some(code) = e.code() {
316✔
103
                    if *code == SqlState::UNDEFINED_TABLE {
316✔
104
                        info!("Initializing schema.");
316✔
105
                        return Ok(DatabaseStatus::Unitialized);
316✔
106
                    }
×
107
                }
×
108
                return Err(error::Error::TokioPostgres { source: e });
×
109
            }
110
        };
111

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

114
        if row.get(0) {
×
115
            Ok(DatabaseStatus::InitializedClearDatabase)
×
116
        } else {
117
            Ok(DatabaseStatus::InitializedKeepDatabase)
×
118
        }
119
    }
316✔
120

121
    /// Clears the database if the Settings demand and the database properties allows it.
122
    pub(crate) async fn maybe_clear_database(
316✔
123
        conn: &PooledConnection<'_, PostgresConnectionManager<Tls>>,
316✔
124
    ) -> Result<()> {
316✔
125
        let postgres_config = get_config_element::<crate::util::config::Postgres>()?;
316✔
126
        let database_status = Self::check_schema_status(conn).await?;
316✔
127
        let schema_name = postgres_config.schema;
316✔
128

129
        match database_status {
×
130
            DatabaseStatus::InitializedClearDatabase
×
131
                if postgres_config.clear_database_on_start && schema_name != "pg_temp" =>
×
132
            {
×
133
                info!("Clearing schema {}.", schema_name);
×
134
                conn.batch_execute(&format!("DROP SCHEMA {schema_name} CASCADE;"))
×
135
                    .await?;
×
136
            }
137
            DatabaseStatus::InitializedKeepDatabase if postgres_config.clear_database_on_start => {
×
138
                return Err(Error::ClearDatabaseOnStartupNotAllowed)
×
139
            }
140
            DatabaseStatus::InitializedClearDatabase
141
            | DatabaseStatus::InitializedKeepDatabase
142
            | DatabaseStatus::Unitialized => (),
316✔
143
        };
144

145
        Ok(())
316✔
146
    }
316✔
147

148
    /// Creates the database schema. Returns true if the schema was created, false if it already existed.
149
    pub(crate) async fn create_database(
160✔
150
        mut conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
160✔
151
    ) -> Result<bool> {
160✔
152
        Self::maybe_clear_database(&conn).await?;
160✔
153

154
        let migration = initialize_database(
160✔
155
            &mut conn,
160✔
156
            Box::new(CurrentSchemaMigration),
160✔
157
            &all_migrations(),
160✔
158
        )
160✔
159
        .await?;
160✔
160

161
        Ok(migration == MigrationResult::CreatedDatabase)
160✔
162
    }
160✔
163

164
    async fn create_default_session(
160✔
165
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
160✔
166
        session_id: SessionId,
160✔
167
    ) -> Result<()> {
160✔
168
        let stmt = conn
160✔
169
            .prepare("INSERT INTO sessions (id, project_id, view) VALUES ($1, NULL ,NULL);")
160✔
170
            .await?;
160✔
171

172
        conn.execute(&stmt, &[&session_id]).await?;
160✔
173

174
        Ok(())
160✔
175
    }
160✔
176
    async fn load_default_session(
64✔
177
        conn: PooledConnection<'_, PostgresConnectionManager<Tls>>,
64✔
178
    ) -> Result<SimpleSession> {
64✔
179
        let stmt = conn
64✔
180
            .prepare("SELECT id, project_id, view FROM sessions LIMIT 1;")
64✔
181
            .await?;
64✔
182

183
        let row = conn.query_one(&stmt, &[]).await?;
64✔
184

185
        Ok(SimpleSession::new(row.get(0), row.get(1), row.get(2)))
64✔
186
    }
64✔
187
}
188

189
#[async_trait]
190
impl<Tls> SimpleApplicationContext for PostgresContext<Tls>
191
where
192
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
193
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
194
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
195
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
196
{
197
    async fn default_session_id(&self) -> SessionId {
51✔
198
        self.default_session_id
51✔
199
    }
102✔
200

201
    async fn default_session(&self) -> Result<SimpleSession> {
64✔
202
        Self::load_default_session(self.pool.get().await?).await
64✔
203
    }
128✔
204

UNCOV
205
    async fn update_default_session_project(&self, project: ProjectId) -> Result<()> {
×
UNCOV
206
        let conn = self.pool.get().await?;
×
207

UNCOV
208
        let stmt = conn
×
UNCOV
209
            .prepare("UPDATE sessions SET project_id = $1 WHERE id = $2;")
×
UNCOV
210
            .await?;
×
211

UNCOV
212
        conn.execute(&stmt, &[&project, &self.default_session_id])
×
UNCOV
213
            .await?;
×
214

UNCOV
215
        Ok(())
×
UNCOV
216
    }
×
217

UNCOV
218
    async fn update_default_session_view(&self, view: STRectangle) -> Result<()> {
×
UNCOV
219
        let conn = self.pool.get().await?;
×
220

UNCOV
221
        let stmt = conn
×
UNCOV
222
            .prepare("UPDATE sessions SET view = $1 WHERE id = $2;")
×
UNCOV
223
            .await?;
×
224

UNCOV
225
        conn.execute(&stmt, &[&view, &self.default_session_id])
×
UNCOV
226
            .await?;
×
227

UNCOV
228
        Ok(())
×
UNCOV
229
    }
×
230

231
    async fn default_session_context(&self) -> Result<Self::SessionContext> {
247✔
232
        Ok(self.session_context(self.session_by_id(self.default_session_id).await?))
247✔
233
    }
494✔
234
}
235

236
#[async_trait]
237
impl<Tls> ApplicationContext for PostgresContext<Tls>
238
where
239
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
240
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
241
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
242
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
243
{
244
    type SessionContext = PostgresSessionContext<Tls>;
245
    type Session = SimpleSession;
246

247
    fn session_context(&self, session: Self::Session) -> Self::SessionContext {
355✔
248
        PostgresSessionContext {
355✔
249
            session,
355✔
250
            context: self.clone(),
355✔
251
        }
355✔
252
    }
355✔
253

254
    async fn session_by_id(&self, session_id: SessionId) -> Result<Self::Session> {
292✔
255
        let mut conn = self.pool.get().await?;
292✔
256

257
        let tx = conn.build_transaction().start().await?;
290✔
258

259
        let stmt = tx
290✔
260
            .prepare(
290✔
261
                "
290✔
262
            SELECT           
290✔
263
                project_id,
290✔
264
                view
290✔
265
            FROM sessions
290✔
266
            WHERE id = $1;",
290✔
267
            )
290✔
268
            .await?;
290✔
269

270
        let row = tx
290✔
271
            .query_one(&stmt, &[&session_id])
290✔
272
            .await
290✔
273
            .map_err(|_error| error::Error::InvalidSession)?;
290✔
274

275
        Ok(SimpleSession::new(session_id, row.get(0), row.get(1)))
290✔
276
    }
582✔
277
}
278

279
#[derive(Clone)]
280
pub struct PostgresSessionContext<Tls>
281
where
282
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
283
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
284
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
285
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
286
{
287
    session: SimpleSession,
288
    context: PostgresContext<Tls>,
289
}
290

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

302
    type TaskContext = SimpleTaskManagerContext;
303
    type TaskManager = SimpleTaskManager; // this does not persist across restarts
304
    type QueryContext = QueryContextImpl;
305
    type ExecutionContext = ExecutionContextImpl<Self::GeoEngineDB>;
306

307
    fn db(&self) -> Self::GeoEngineDB {
360✔
308
        PostgresDb::new(self.context.pool.clone())
360✔
309
    }
360✔
310

311
    fn tasks(&self) -> Self::TaskManager {
25✔
312
        SimpleTaskManager::new(self.context.task_manager.clone())
25✔
313
    }
25✔
314

315
    fn query_context(&self, _workflow: Uuid, _computation: Uuid) -> Result<Self::QueryContext> {
20✔
316
        Ok(QueryContextImpl::new(
20✔
317
            self.context.query_ctx_chunk_size,
20✔
318
            self.context.thread_pool.clone(),
20✔
319
        ))
20✔
320
    }
20✔
321

322
    fn execution_context(&self) -> Result<Self::ExecutionContext> {
34✔
323
        Ok(ExecutionContextImpl::<PostgresDb<Tls>>::new(
34✔
324
            self.db(),
34✔
325
            self.context.thread_pool.clone(),
34✔
326
            self.context.exe_ctx_tiling_spec,
34✔
327
        ))
34✔
328
    }
34✔
329

UNCOV
330
    fn volumes(&self) -> Result<Vec<Volume>> {
×
UNCOV
331
        Ok(self
×
UNCOV
332
            .context
×
UNCOV
333
            .volumes
×
UNCOV
334
            .volumes
×
UNCOV
335
            .iter()
×
UNCOV
336
            .map(|v| Volume {
×
UNCOV
337
                name: v.name.0.clone(),
×
UNCOV
338
                path: Some(v.path.to_string_lossy().to_string()),
×
UNCOV
339
            })
×
UNCOV
340
            .collect())
×
UNCOV
341
    }
×
342

343
    fn session(&self) -> &Self::Session {
68✔
344
        &self.session
68✔
345
    }
68✔
346
}
347

348
#[derive(Debug)]
349
pub struct PostgresDb<Tls>
350
where
351
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
352
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
353
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
354
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
355
{
356
    pub(crate) conn_pool: Pool<PostgresConnectionManager<Tls>>,
357
}
358

359
impl<Tls> PostgresDb<Tls>
360
where
361
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
362
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
363
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
364
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
365
{
366
    pub fn new(conn_pool: Pool<PostgresConnectionManager<Tls>>) -> Self {
361✔
367
        Self { conn_pool }
361✔
368
    }
361✔
369

370
    /// Check whether the namespace of the given dataset is allowed for insertion
371
    pub(crate) fn check_namespace(id: &DatasetName) -> Result<()> {
69✔
372
        // due to a lack of users, etc., we only allow one namespace for now
69✔
373
        if id.namespace.is_none() {
69✔
374
            Ok(())
69✔
375
        } else {
376
            Err(Error::InvalidDatasetIdNamespace)
×
377
        }
378
    }
69✔
379
}
380

381
impl<Tls> GeoEngineDb for PostgresDb<Tls>
382
where
383
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
384
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
385
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
386
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
387
{
388
}
389

390
impl TryFrom<config::Postgres> for Config {
391
    type Error = Error;
392

393
    fn try_from(db_config: config::Postgres) -> Result<Self> {
26✔
394
        ensure!(
26✔
395
            db_config.schema != "public",
26✔
396
            crate::error::InvalidDatabaseSchema
×
397
        );
398

399
        let mut pg_config = Config::new();
26✔
400
        pg_config
26✔
401
            .user(&db_config.user)
26✔
402
            .password(&db_config.password)
26✔
403
            .host(&db_config.host)
26✔
404
            .dbname(&db_config.database)
26✔
405
            .port(db_config.port)
26✔
406
            // fix schema by providing `search_path` option
26✔
407
            .options(format!("-c search_path={}", db_config.schema));
26✔
408
        Ok(pg_config)
26✔
409
    }
26✔
410
}
411

412
#[cfg(test)]
413
mod tests {
414
    use super::*;
415
    use crate::datasets::external::aruna::ArunaDataProviderDefinition;
416
    use crate::datasets::external::gbif::{GbifDataProvider, GbifDataProviderDefinition};
417
    use crate::datasets::external::gfbio_abcd::GfbioAbcdDataProviderDefinition;
418
    use crate::datasets::external::gfbio_collections::GfbioCollectionsDataProviderDefinition;
419
    use crate::datasets::external::netcdfcf::{
420
        EbvPortalDataProviderDefinition, NetCdfCfDataProviderDefinition,
421
    };
422
    use crate::datasets::external::pangaea::PangaeaDataProviderDefinition;
423
    use crate::datasets::listing::{DatasetListOptions, DatasetListing, ProvenanceOutput};
424
    use crate::datasets::listing::{DatasetProvider, Provenance};
425
    use crate::datasets::storage::{DatasetStore, MetaDataDefinition};
426
    use crate::datasets::upload::{FileId, UploadId};
427
    use crate::datasets::upload::{FileUpload, Upload, UploadDb};
428
    use crate::datasets::{AddDataset, DatasetIdAndName};
429
    use crate::ge_context;
430
    use crate::layers::add_from_directory::UNSORTED_COLLECTION_ID;
431
    use crate::layers::external::TypedDataProviderDefinition;
432
    use crate::layers::layer::{
433
        AddLayer, AddLayerCollection, CollectionItem, LayerCollection, LayerCollectionListOptions,
434
        LayerCollectionListing, LayerListing, Property, ProviderLayerCollectionId, ProviderLayerId,
435
    };
436
    use crate::layers::listing::{
437
        LayerCollectionId, LayerCollectionProvider, SearchParameters, SearchType,
438
    };
439
    use crate::layers::storage::{
440
        LayerDb, LayerProviderDb, LayerProviderListing, LayerProviderListingOptions,
441
        INTERNAL_PROVIDER_ID,
442
    };
443
    use crate::projects::{
444
        ColorParam, CreateProject, DerivedColor, DerivedNumber, LayerUpdate, LineSymbology,
445
        LoadVersion, NumberParam, OrderBy, Plot, PlotUpdate, PointSymbology, PolygonSymbology,
446
        ProjectDb, ProjectId, ProjectLayer, ProjectListOptions, ProjectListing, RasterSymbology,
447
        STRectangle, StrokeParam, Symbology, TextSymbology, UpdateProject,
448
    };
449
    use crate::util::encryption::U96;
450
    use crate::util::postgres::{assert_sql_type, DatabaseConnectionConfig};
451
    use crate::util::tests::register_ndvi_workflow_helper;
452
    use crate::workflows::registry::WorkflowRegistry;
453
    use crate::workflows::workflow::Workflow;
454
    use aes_gcm::aead::generic_array::arr;
455
    use bb8_postgres::tokio_postgres::NoTls;
456
    use futures::join;
457
    use geoengine_datatypes::collections::VectorDataType;
458
    use geoengine_datatypes::dataset::{DataProviderId, LayerId};
459
    use geoengine_datatypes::operations::image::{
460
        Breakpoint, Colorizer, RasterColorizer, RgbParams, RgbaColor,
461
    };
462
    use geoengine_datatypes::primitives::{
463
        BoundingBox2D, ClassificationMeasurement, ColumnSelection, ContinuousMeasurement,
464
        Coordinate2D, DateTimeParseFormat, FeatureDataType, MultiLineString, MultiPoint,
465
        MultiPolygon, NoGeometry, RasterQueryRectangle, SpatialPartition2D, SpatialResolution,
466
        TimeGranularity, TimeInstance, TimeInterval, TimeStep, TypedGeometry, VectorQueryRectangle,
467
    };
468
    use geoengine_datatypes::primitives::{CacheTtlSeconds, Measurement};
469
    use geoengine_datatypes::raster::{
470
        RasterDataType, RasterPropertiesEntryType, RasterPropertiesKey,
471
    };
472
    use geoengine_datatypes::spatial_reference::{SpatialReference, SpatialReferenceOption};
473
    use geoengine_datatypes::test_data;
474
    use geoengine_datatypes::util::test::TestDefault;
475
    use geoengine_datatypes::util::{NotNanF64, StringPair};
476
    use geoengine_operators::engine::{
477
        MetaData, MetaDataProvider, MultipleRasterOrSingleVectorSource, PlotOperator,
478
        PlotResultDescriptor, RasterBandDescriptor, RasterBandDescriptors, RasterResultDescriptor,
479
        StaticMetaData, TypedOperator, TypedResultDescriptor, VectorColumnInfo, VectorOperator,
480
        VectorResultDescriptor,
481
    };
482
    use geoengine_operators::mock::{
483
        MockDatasetDataSourceLoadingInfo, MockPointSource, MockPointSourceParams,
484
    };
485
    use geoengine_operators::plot::{Statistics, StatisticsParams};
486
    use geoengine_operators::source::{
487
        CsvHeader, FileNotFoundHandling, FormatSpecifics, GdalDatasetGeoTransform,
488
        GdalDatasetParameters, GdalLoadingInfo, GdalLoadingInfoTemporalSlice, GdalMetaDataList,
489
        GdalMetaDataRegular, GdalMetaDataStatic, GdalMetadataMapping, GdalMetadataNetCdfCf,
490
        GdalRetryOptions, GdalSourceTimePlaceholder, OgrSourceColumnSpec, OgrSourceDataset,
491
        OgrSourceDatasetTimeType, OgrSourceDurationSpec, OgrSourceErrorSpec, OgrSourceTimeFormat,
492
        TimeReference, UnixTimeStampType,
493
    };
494
    use geoengine_operators::util::input::MultiRasterOrVectorOperator::Raster;
495
    use ordered_float::NotNan;
496
    use serde_json::json;
497
    use std::marker::PhantomData;
498
    use std::path::PathBuf;
499
    use std::str::FromStr;
500
    use tokio_postgres::config::Host;
501

502
    #[ge_context::test]
2✔
503
    async fn test(app_ctx: PostgresContext<NoTls>) {
1✔
504
        let session = app_ctx.default_session().await.unwrap();
1✔
505

1✔
506
        create_projects(&app_ctx, &session).await;
1✔
507

508
        let projects = list_projects(&app_ctx, &session).await;
1✔
509

510
        let project_id = projects[0].id;
1✔
511

1✔
512
        update_projects(&app_ctx, &session, project_id).await;
1✔
513

514
        delete_project(&app_ctx, &session, project_id).await;
1✔
515
    }
1✔
516

517
    async fn delete_project(
1✔
518
        app_ctx: &PostgresContext<NoTls>,
1✔
519
        session: &SimpleSession,
1✔
520
        project_id: ProjectId,
1✔
521
    ) {
1✔
522
        let db = app_ctx.session_context(session.clone()).db();
1✔
523

1✔
524
        db.delete_project(project_id).await.unwrap();
1✔
525

1✔
526
        assert!(db.load_project(project_id).await.is_err());
1✔
527
    }
1✔
528

529
    #[allow(clippy::too_many_lines)]
530
    async fn update_projects(
1✔
531
        app_ctx: &PostgresContext<NoTls>,
1✔
532
        session: &SimpleSession,
1✔
533
        project_id: ProjectId,
1✔
534
    ) {
1✔
535
        let db = app_ctx.session_context(session.clone()).db();
1✔
536

537
        let project = db
1✔
538
            .load_project_version(project_id, LoadVersion::Latest)
1✔
539
            .await
1✔
540
            .unwrap();
1✔
541

542
        let layer_workflow_id = db
1✔
543
            .register_workflow(Workflow {
1✔
544
                operator: TypedOperator::Vector(
1✔
545
                    MockPointSource {
1✔
546
                        params: MockPointSourceParams {
1✔
547
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
548
                        },
1✔
549
                    }
1✔
550
                    .boxed(),
1✔
551
                ),
1✔
552
            })
1✔
553
            .await
1✔
554
            .unwrap();
1✔
555

1✔
556
        assert!(db.load_workflow(&layer_workflow_id).await.is_ok());
1✔
557

558
        let plot_workflow_id = db
1✔
559
            .register_workflow(Workflow {
1✔
560
                operator: Statistics {
1✔
561
                    params: StatisticsParams {
1✔
562
                        column_names: vec![],
1✔
563
                        percentiles: vec![],
1✔
564
                    },
1✔
565
                    sources: MultipleRasterOrSingleVectorSource {
1✔
566
                        source: Raster(vec![]),
1✔
567
                    },
1✔
568
                }
1✔
569
                .boxed()
1✔
570
                .into(),
1✔
571
            })
1✔
572
            .await
1✔
573
            .unwrap();
1✔
574

1✔
575
        assert!(db.load_workflow(&plot_workflow_id).await.is_ok());
1✔
576

577
        // add a plot
578
        let update = UpdateProject {
1✔
579
            id: project.id,
1✔
580
            name: Some("Test9 Updated".into()),
1✔
581
            description: None,
1✔
582
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
583
                workflow: layer_workflow_id,
1✔
584
                name: "TestLayer".into(),
1✔
585
                symbology: PointSymbology::default().into(),
1✔
586
                visibility: Default::default(),
1✔
587
            })]),
1✔
588
            plots: Some(vec![PlotUpdate::UpdateOrInsert(Plot {
1✔
589
                workflow: plot_workflow_id,
1✔
590
                name: "Test Plot".into(),
1✔
591
            })]),
1✔
592
            bounds: None,
1✔
593
            time_step: None,
1✔
594
        };
1✔
595
        db.update_project(update).await.unwrap();
1✔
596

597
        let versions = db.list_project_versions(project_id).await.unwrap();
1✔
598
        assert_eq!(versions.len(), 2);
1✔
599

600
        // add second plot
601
        let update = UpdateProject {
1✔
602
            id: project.id,
1✔
603
            name: Some("Test9 Updated".into()),
1✔
604
            description: None,
1✔
605
            layers: Some(vec![LayerUpdate::UpdateOrInsert(ProjectLayer {
1✔
606
                workflow: layer_workflow_id,
1✔
607
                name: "TestLayer".into(),
1✔
608
                symbology: PointSymbology::default().into(),
1✔
609
                visibility: Default::default(),
1✔
610
            })]),
1✔
611
            plots: Some(vec![
1✔
612
                PlotUpdate::UpdateOrInsert(Plot {
1✔
613
                    workflow: plot_workflow_id,
1✔
614
                    name: "Test Plot".into(),
1✔
615
                }),
1✔
616
                PlotUpdate::UpdateOrInsert(Plot {
1✔
617
                    workflow: plot_workflow_id,
1✔
618
                    name: "Test Plot".into(),
1✔
619
                }),
1✔
620
            ]),
1✔
621
            bounds: None,
1✔
622
            time_step: None,
1✔
623
        };
1✔
624
        db.update_project(update).await.unwrap();
1✔
625

626
        let versions = db.list_project_versions(project_id).await.unwrap();
1✔
627
        assert_eq!(versions.len(), 3);
1✔
628

629
        // delete plots
630
        let update = UpdateProject {
1✔
631
            id: project.id,
1✔
632
            name: None,
1✔
633
            description: None,
1✔
634
            layers: None,
1✔
635
            plots: Some(vec![]),
1✔
636
            bounds: None,
1✔
637
            time_step: None,
1✔
638
        };
1✔
639
        db.update_project(update).await.unwrap();
1✔
640

641
        let versions = db.list_project_versions(project_id).await.unwrap();
1✔
642
        assert_eq!(versions.len(), 4);
1✔
643
    }
1✔
644

645
    async fn list_projects(
1✔
646
        app_ctx: &PostgresContext<NoTls>,
1✔
647
        session: &SimpleSession,
1✔
648
    ) -> Vec<ProjectListing> {
1✔
649
        let options = ProjectListOptions {
1✔
650
            order: OrderBy::NameDesc,
1✔
651
            offset: 0,
1✔
652
            limit: 2,
1✔
653
        };
1✔
654

1✔
655
        let db = app_ctx.session_context(session.clone()).db();
1✔
656

657
        let projects = db.list_projects(options).await.unwrap();
1✔
658

1✔
659
        assert_eq!(projects.len(), 2);
1✔
660
        assert_eq!(projects[0].name, "Test9");
1✔
661
        assert_eq!(projects[1].name, "Test8");
1✔
662
        projects
1✔
663
    }
1✔
664

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

668
        for i in 0..10 {
11✔
669
            let create = CreateProject {
10✔
670
                name: format!("Test{i}"),
10✔
671
                description: format!("Test{}", 10 - i),
10✔
672
                bounds: STRectangle::new(
10✔
673
                    SpatialReferenceOption::Unreferenced,
10✔
674
                    0.,
10✔
675
                    0.,
10✔
676
                    1.,
10✔
677
                    1.,
10✔
678
                    0,
10✔
679
                    1,
10✔
680
                )
10✔
681
                .unwrap(),
10✔
682
                time_step: None,
10✔
683
            };
10✔
684
            db.create_project(create).await.unwrap();
10✔
685
        }
686
    }
1✔
687

688
    #[ge_context::test]
2✔
689
    async fn it_persists_workflows(app_ctx: PostgresContext<NoTls>) {
1✔
690
        let workflow = Workflow {
1✔
691
            operator: TypedOperator::Vector(
1✔
692
                MockPointSource {
1✔
693
                    params: MockPointSourceParams {
1✔
694
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
695
                    },
1✔
696
                }
1✔
697
                .boxed(),
1✔
698
            ),
1✔
699
        };
1✔
700

701
        let session = app_ctx.default_session().await.unwrap();
1✔
702
        let ctx = app_ctx.session_context(session);
1✔
703

1✔
704
        let db = ctx.db();
1✔
705
        let id = db.register_workflow(workflow).await.unwrap();
1✔
706

1✔
707
        drop(ctx);
1✔
708

709
        let workflow = db.load_workflow(&id).await.unwrap();
1✔
710

1✔
711
        let json = serde_json::to_string(&workflow).unwrap();
1✔
712
        assert_eq!(
1✔
713
            json,
1✔
714
            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✔
715
        );
1✔
716
    }
1✔
717

718
    #[allow(clippy::too_many_lines)]
719
    #[ge_context::test]
2✔
720
    async fn it_persists_datasets(app_ctx: PostgresContext<NoTls>) {
1✔
721
        let loading_info = OgrSourceDataset {
1✔
722
            file_name: PathBuf::from("test.csv"),
1✔
723
            layer_name: "test.csv".to_owned(),
1✔
724
            data_type: Some(VectorDataType::MultiPoint),
1✔
725
            time: OgrSourceDatasetTimeType::Start {
1✔
726
                start_field: "start".to_owned(),
1✔
727
                start_format: OgrSourceTimeFormat::Auto,
1✔
728
                duration: OgrSourceDurationSpec::Zero,
1✔
729
            },
1✔
730
            default_geometry: None,
1✔
731
            columns: Some(OgrSourceColumnSpec {
1✔
732
                format_specifics: Some(FormatSpecifics::Csv {
1✔
733
                    header: CsvHeader::Auto,
1✔
734
                }),
1✔
735
                x: "x".to_owned(),
1✔
736
                y: None,
1✔
737
                int: vec![],
1✔
738
                float: vec![],
1✔
739
                text: vec![],
1✔
740
                bool: vec![],
1✔
741
                datetime: vec![],
1✔
742
                rename: None,
1✔
743
            }),
1✔
744
            force_ogr_time_filter: false,
1✔
745
            force_ogr_spatial_filter: false,
1✔
746
            on_error: OgrSourceErrorSpec::Ignore,
1✔
747
            sql_query: None,
1✔
748
            attribute_query: None,
1✔
749
            cache_ttl: CacheTtlSeconds::default(),
1✔
750
        };
1✔
751

1✔
752
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
753
            OgrSourceDataset,
1✔
754
            VectorResultDescriptor,
1✔
755
            VectorQueryRectangle,
1✔
756
        > {
1✔
757
            loading_info: loading_info.clone(),
1✔
758
            result_descriptor: VectorResultDescriptor {
1✔
759
                data_type: VectorDataType::MultiPoint,
1✔
760
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
761
                columns: [(
1✔
762
                    "foo".to_owned(),
1✔
763
                    VectorColumnInfo {
1✔
764
                        data_type: FeatureDataType::Float,
1✔
765
                        measurement: Measurement::Unitless,
1✔
766
                    },
1✔
767
                )]
1✔
768
                .into_iter()
1✔
769
                .collect(),
1✔
770
                time: None,
1✔
771
                bbox: None,
1✔
772
            },
1✔
773
            phantom: Default::default(),
1✔
774
        });
1✔
775

776
        let session = app_ctx.default_session().await.unwrap();
1✔
777

1✔
778
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
779

1✔
780
        let db = app_ctx.session_context(session.clone()).db();
1✔
781
        let DatasetIdAndName {
782
            id: dataset_id,
1✔
783
            name: dataset_name,
1✔
784
        } = db
1✔
785
            .add_dataset(
1✔
786
                AddDataset {
1✔
787
                    name: Some(dataset_name.clone()),
1✔
788
                    display_name: "Ogr Test".to_owned(),
1✔
789
                    description: "desc".to_owned(),
1✔
790
                    source_operator: "OgrSource".to_owned(),
1✔
791
                    symbology: None,
1✔
792
                    provenance: Some(vec![Provenance {
1✔
793
                        citation: "citation".to_owned(),
1✔
794
                        license: "license".to_owned(),
1✔
795
                        uri: "uri".to_owned(),
1✔
796
                    }]),
1✔
797
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
798
                },
1✔
799
                meta_data,
1✔
800
            )
1✔
801
            .await
1✔
802
            .unwrap();
1✔
803

804
        let datasets = db
1✔
805
            .list_datasets(DatasetListOptions {
1✔
806
                filter: None,
1✔
807
                order: crate::datasets::listing::OrderBy::NameAsc,
1✔
808
                offset: 0,
1✔
809
                limit: 10,
1✔
810
                tags: None,
1✔
811
            })
1✔
812
            .await
1✔
813
            .unwrap();
1✔
814

1✔
815
        assert_eq!(datasets.len(), 1);
1✔
816

817
        assert_eq!(
1✔
818
            datasets[0],
1✔
819
            DatasetListing {
1✔
820
                id: dataset_id,
1✔
821
                name: dataset_name,
1✔
822
                display_name: "Ogr Test".to_owned(),
1✔
823
                description: "desc".to_owned(),
1✔
824
                source_operator: "OgrSource".to_owned(),
1✔
825
                symbology: None,
1✔
826
                tags: vec!["upload".to_owned(), "test".to_owned()],
1✔
827
                result_descriptor: TypedResultDescriptor::Vector(VectorResultDescriptor {
1✔
828
                    data_type: VectorDataType::MultiPoint,
1✔
829
                    spatial_reference: SpatialReference::epsg_4326().into(),
1✔
830
                    columns: [(
1✔
831
                        "foo".to_owned(),
1✔
832
                        VectorColumnInfo {
1✔
833
                            data_type: FeatureDataType::Float,
1✔
834
                            measurement: Measurement::Unitless
1✔
835
                        }
1✔
836
                    )]
1✔
837
                    .into_iter()
1✔
838
                    .collect(),
1✔
839
                    time: None,
1✔
840
                    bbox: None,
1✔
841
                })
1✔
842
            },
1✔
843
        );
1✔
844

845
        let provenance = db.load_provenance(&dataset_id).await.unwrap();
1✔
846

1✔
847
        assert_eq!(
1✔
848
            provenance,
1✔
849
            ProvenanceOutput {
1✔
850
                data: dataset_id.into(),
1✔
851
                provenance: Some(vec![Provenance {
1✔
852
                    citation: "citation".to_owned(),
1✔
853
                    license: "license".to_owned(),
1✔
854
                    uri: "uri".to_owned(),
1✔
855
                }])
1✔
856
            }
1✔
857
        );
1✔
858

859
        let meta_data: Box<dyn MetaData<OgrSourceDataset, _, _>> =
1✔
860
            db.meta_data(&dataset_id.into()).await.unwrap();
1✔
861

862
        assert_eq!(
1✔
863
            meta_data
1✔
864
                .loading_info(VectorQueryRectangle {
1✔
865
                    spatial_bounds: BoundingBox2D::new_unchecked(
1✔
866
                        (-180., -90.).into(),
1✔
867
                        (180., 90.).into()
1✔
868
                    ),
1✔
869
                    time_interval: TimeInterval::default(),
1✔
870
                    spatial_resolution: SpatialResolution::zero_point_one(),
1✔
871
                    attributes: ColumnSelection::all()
1✔
872
                })
1✔
873
                .await
1✔
874
                .unwrap(),
1✔
875
            loading_info
876
        );
877
    }
1✔
878

879
    #[ge_context::test]
2✔
880
    async fn it_persists_uploads(app_ctx: PostgresContext<NoTls>) {
1✔
881
        let id = UploadId::from_str("2de18cd8-4a38-4111-a445-e3734bc18a80").unwrap();
1✔
882
        let input = Upload {
1✔
883
            id,
1✔
884
            files: vec![FileUpload {
1✔
885
                id: FileId::from_str("e80afab0-831d-4d40-95d6-1e4dfd277e72").unwrap(),
1✔
886
                name: "test.csv".to_owned(),
1✔
887
                byte_size: 1337,
1✔
888
            }],
1✔
889
        };
1✔
890

891
        let session = app_ctx.default_session().await.unwrap();
1✔
892

1✔
893
        let db = app_ctx.session_context(session.clone()).db();
1✔
894

1✔
895
        db.create_upload(input.clone()).await.unwrap();
1✔
896

897
        let upload = db.load_upload(id).await.unwrap();
1✔
898

1✔
899
        assert_eq!(upload, input);
1✔
900
    }
1✔
901

902
    #[allow(clippy::too_many_lines)]
903
    #[ge_context::test]
2✔
904
    async fn it_persists_layer_providers(app_ctx: PostgresContext<NoTls>) {
1✔
905
        let db = app_ctx.default_session_context().await.unwrap().db();
1✔
906

1✔
907
        let provider = NetCdfCfDataProviderDefinition {
1✔
908
            name: "netcdfcf".to_string(),
1✔
909
            description: "NetCdfCfProviderDefinition".to_string(),
1✔
910
            priority: Some(21),
1✔
911
            data: test_data!("netcdf4d/").into(),
1✔
912
            overviews: test_data!("netcdf4d/overviews/").into(),
1✔
913
            cache_ttl: CacheTtlSeconds::new(0),
1✔
914
        };
1✔
915

916
        let provider_id = db.add_layer_provider(provider.into()).await.unwrap();
1✔
917

918
        let providers = db
1✔
919
            .list_layer_providers(LayerProviderListingOptions {
1✔
920
                offset: 0,
1✔
921
                limit: 10,
1✔
922
            })
1✔
923
            .await
1✔
924
            .unwrap();
1✔
925

1✔
926
        assert_eq!(providers.len(), 1);
1✔
927

928
        assert_eq!(
1✔
929
            providers[0],
1✔
930
            LayerProviderListing {
1✔
931
                id: provider_id,
1✔
932
                name: "netcdfcf".to_owned(),
1✔
933
                priority: 21,
1✔
934
            }
1✔
935
        );
1✔
936

937
        let provider = db.load_layer_provider(provider_id).await.unwrap();
1✔
938

939
        let datasets = provider
1✔
940
            .load_layer_collection(
1✔
941
                &provider.get_root_layer_collection_id().await.unwrap(),
1✔
942
                LayerCollectionListOptions {
1✔
943
                    offset: 0,
1✔
944
                    limit: 10,
1✔
945
                },
1✔
946
            )
1✔
947
            .await
1✔
948
            .unwrap();
1✔
949

1✔
950
        assert_eq!(datasets.items.len(), 5, "{:?}", datasets.items);
1✔
951
    }
1✔
952

953
    #[allow(clippy::too_many_lines)]
954
    #[ge_context::test]
2✔
955
    async fn it_loads_all_meta_data_types(app_ctx: PostgresContext<NoTls>) {
1✔
956
        let session = app_ctx.default_session().await.unwrap();
1✔
957

1✔
958
        let db = app_ctx.session_context(session.clone()).db();
1✔
959

1✔
960
        let vector_descriptor = VectorResultDescriptor {
1✔
961
            data_type: VectorDataType::Data,
1✔
962
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
963
            columns: Default::default(),
1✔
964
            time: None,
1✔
965
            bbox: None,
1✔
966
        };
1✔
967

1✔
968
        let raster_descriptor = RasterResultDescriptor {
1✔
969
            data_type: RasterDataType::U8,
1✔
970
            spatial_reference: SpatialReferenceOption::Unreferenced,
1✔
971
            time: None,
1✔
972
            bbox: None,
1✔
973
            resolution: None,
1✔
974
            bands: RasterBandDescriptors::new_single_band(),
1✔
975
        };
1✔
976

1✔
977
        let vector_ds = AddDataset {
1✔
978
            name: None,
1✔
979
            display_name: "OgrDataset".to_string(),
1✔
980
            description: "My Ogr dataset".to_string(),
1✔
981
            source_operator: "OgrSource".to_string(),
1✔
982
            symbology: None,
1✔
983
            provenance: None,
1✔
984
            tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
985
        };
1✔
986

1✔
987
        let raster_ds = AddDataset {
1✔
988
            name: None,
1✔
989
            display_name: "GdalDataset".to_string(),
1✔
990
            description: "My Gdal dataset".to_string(),
1✔
991
            source_operator: "GdalSource".to_string(),
1✔
992
            symbology: None,
1✔
993
            provenance: None,
1✔
994
            tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
995
        };
1✔
996

1✔
997
        let gdal_params = GdalDatasetParameters {
1✔
998
            file_path: Default::default(),
1✔
999
            rasterband_channel: 0,
1✔
1000
            geo_transform: GdalDatasetGeoTransform {
1✔
1001
                origin_coordinate: Default::default(),
1✔
1002
                x_pixel_size: 0.0,
1✔
1003
                y_pixel_size: 0.0,
1✔
1004
            },
1✔
1005
            width: 0,
1✔
1006
            height: 0,
1✔
1007
            file_not_found_handling: FileNotFoundHandling::NoData,
1✔
1008
            no_data_value: None,
1✔
1009
            properties_mapping: None,
1✔
1010
            gdal_open_options: None,
1✔
1011
            gdal_config_options: None,
1✔
1012
            allow_alphaband_as_mask: false,
1✔
1013
            retry: None,
1✔
1014
        };
1✔
1015

1✔
1016
        let meta = StaticMetaData {
1✔
1017
            loading_info: OgrSourceDataset {
1✔
1018
                file_name: Default::default(),
1✔
1019
                layer_name: String::new(),
1✔
1020
                data_type: None,
1✔
1021
                time: Default::default(),
1✔
1022
                default_geometry: None,
1✔
1023
                columns: None,
1✔
1024
                force_ogr_time_filter: false,
1✔
1025
                force_ogr_spatial_filter: false,
1✔
1026
                on_error: OgrSourceErrorSpec::Ignore,
1✔
1027
                sql_query: None,
1✔
1028
                attribute_query: None,
1✔
1029
                cache_ttl: CacheTtlSeconds::default(),
1✔
1030
            },
1✔
1031
            result_descriptor: vector_descriptor.clone(),
1✔
1032
            phantom: Default::default(),
1✔
1033
        };
1✔
1034

1035
        let id = db.add_dataset(vector_ds, meta.into()).await.unwrap().id;
1✔
1036

1037
        let meta: geoengine_operators::util::Result<
1✔
1038
            Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>>,
1✔
1039
        > = db.meta_data(&id.into()).await;
1✔
1040

1041
        assert!(meta.is_ok());
1✔
1042

1043
        let meta = GdalMetaDataRegular {
1✔
1044
            result_descriptor: raster_descriptor.clone(),
1✔
1045
            params: gdal_params.clone(),
1✔
1046
            time_placeholders: Default::default(),
1✔
1047
            data_time: Default::default(),
1✔
1048
            step: TimeStep {
1✔
1049
                granularity: TimeGranularity::Millis,
1✔
1050
                step: 0,
1✔
1051
            },
1✔
1052
            cache_ttl: CacheTtlSeconds::default(),
1✔
1053
        };
1✔
1054

1055
        let id = db
1✔
1056
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1057
            .await
1✔
1058
            .unwrap()
1✔
1059
            .id;
1060

1061
        let meta: geoengine_operators::util::Result<
1✔
1062
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1063
        > = db.meta_data(&id.into()).await;
1✔
1064

1065
        assert!(meta.is_ok());
1✔
1066

1067
        let meta = GdalMetaDataStatic {
1✔
1068
            time: None,
1✔
1069
            params: gdal_params.clone(),
1✔
1070
            result_descriptor: raster_descriptor.clone(),
1✔
1071
            cache_ttl: CacheTtlSeconds::default(),
1✔
1072
        };
1✔
1073

1074
        let id = db
1✔
1075
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1076
            .await
1✔
1077
            .unwrap()
1✔
1078
            .id;
1079

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

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

1086
        let meta = GdalMetaDataList {
1✔
1087
            result_descriptor: raster_descriptor.clone(),
1✔
1088
            params: vec![],
1✔
1089
        };
1✔
1090

1091
        let id = db
1✔
1092
            .add_dataset(raster_ds.clone(), meta.into())
1✔
1093
            .await
1✔
1094
            .unwrap()
1✔
1095
            .id;
1096

1097
        let meta: geoengine_operators::util::Result<
1✔
1098
            Box<dyn MetaData<GdalLoadingInfo, RasterResultDescriptor, RasterQueryRectangle>>,
1✔
1099
        > = db.meta_data(&id.into()).await;
1✔
1100

1101
        assert!(meta.is_ok());
1✔
1102

1103
        let meta = GdalMetadataNetCdfCf {
1✔
1104
            result_descriptor: raster_descriptor.clone(),
1✔
1105
            params: gdal_params.clone(),
1✔
1106
            start: TimeInstance::MIN,
1✔
1107
            end: TimeInstance::MAX,
1✔
1108
            step: TimeStep {
1✔
1109
                granularity: TimeGranularity::Millis,
1✔
1110
                step: 0,
1✔
1111
            },
1✔
1112
            band_offset: 0,
1✔
1113
            cache_ttl: CacheTtlSeconds::default(),
1✔
1114
        };
1✔
1115

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

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

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

1129
    #[allow(clippy::too_many_lines)]
1130
    #[ge_context::test]
2✔
1131
    async fn it_collects_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1132
        let session = app_ctx.default_session().await.unwrap();
1✔
1133

1✔
1134
        let layer_db = app_ctx.session_context(session).db();
1✔
1135

1✔
1136
        let workflow = Workflow {
1✔
1137
            operator: TypedOperator::Vector(
1✔
1138
                MockPointSource {
1✔
1139
                    params: MockPointSourceParams {
1✔
1140
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1141
                    },
1✔
1142
                }
1✔
1143
                .boxed(),
1✔
1144
            ),
1✔
1145
        };
1✔
1146

1147
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1148

1149
        let layer1 = layer_db
1✔
1150
            .add_layer(
1✔
1151
                AddLayer {
1✔
1152
                    name: "Layer1".to_string(),
1✔
1153
                    description: "Layer 1".to_string(),
1✔
1154
                    symbology: None,
1✔
1155
                    workflow: workflow.clone(),
1✔
1156
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1157
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1158
                },
1✔
1159
                &root_collection_id,
1✔
1160
            )
1✔
1161
            .await
1✔
1162
            .unwrap();
1✔
1163

1164
        assert_eq!(
1✔
1165
            layer_db.load_layer(&layer1).await.unwrap(),
1✔
1166
            crate::layers::layer::Layer {
1✔
1167
                id: ProviderLayerId {
1✔
1168
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1169
                    layer_id: layer1.clone(),
1✔
1170
                },
1✔
1171
                name: "Layer1".to_string(),
1✔
1172
                description: "Layer 1".to_string(),
1✔
1173
                symbology: None,
1✔
1174
                workflow: workflow.clone(),
1✔
1175
                metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1176
                properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1177
            }
1✔
1178
        );
1179

1180
        let collection1_id = layer_db
1✔
1181
            .add_layer_collection(
1✔
1182
                AddLayerCollection {
1✔
1183
                    name: "Collection1".to_string(),
1✔
1184
                    description: "Collection 1".to_string(),
1✔
1185
                    properties: Default::default(),
1✔
1186
                },
1✔
1187
                &root_collection_id,
1✔
1188
            )
1✔
1189
            .await
1✔
1190
            .unwrap();
1✔
1191

1192
        let layer2 = layer_db
1✔
1193
            .add_layer(
1✔
1194
                AddLayer {
1✔
1195
                    name: "Layer2".to_string(),
1✔
1196
                    description: "Layer 2".to_string(),
1✔
1197
                    symbology: None,
1✔
1198
                    workflow: workflow.clone(),
1✔
1199
                    metadata: Default::default(),
1✔
1200
                    properties: Default::default(),
1✔
1201
                },
1✔
1202
                &collection1_id,
1✔
1203
            )
1✔
1204
            .await
1✔
1205
            .unwrap();
1✔
1206

1207
        let collection2_id = layer_db
1✔
1208
            .add_layer_collection(
1✔
1209
                AddLayerCollection {
1✔
1210
                    name: "Collection2".to_string(),
1✔
1211
                    description: "Collection 2".to_string(),
1✔
1212
                    properties: Default::default(),
1✔
1213
                },
1✔
1214
                &collection1_id,
1✔
1215
            )
1✔
1216
            .await
1✔
1217
            .unwrap();
1✔
1218

1✔
1219
        layer_db
1✔
1220
            .add_collection_to_parent(&collection2_id, &collection1_id)
1✔
1221
            .await
1✔
1222
            .unwrap();
1✔
1223

1224
        let root_collection = layer_db
1✔
1225
            .load_layer_collection(
1✔
1226
                &root_collection_id,
1✔
1227
                LayerCollectionListOptions {
1✔
1228
                    offset: 0,
1✔
1229
                    limit: 20,
1✔
1230
                },
1✔
1231
            )
1✔
1232
            .await
1✔
1233
            .unwrap();
1✔
1234

1✔
1235
        assert_eq!(
1✔
1236
            root_collection,
1✔
1237
            LayerCollection {
1✔
1238
                id: ProviderLayerCollectionId {
1✔
1239
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1240
                    collection_id: root_collection_id,
1✔
1241
                },
1✔
1242
                name: "Layers".to_string(),
1✔
1243
                description: "All available Geo Engine layers".to_string(),
1✔
1244
                items: vec![
1✔
1245
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1246
                        id: ProviderLayerCollectionId {
1✔
1247
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1248
                            collection_id: collection1_id.clone(),
1✔
1249
                        },
1✔
1250
                        name: "Collection1".to_string(),
1✔
1251
                        description: "Collection 1".to_string(),
1✔
1252
                        properties: Default::default(),
1✔
1253
                    }),
1✔
1254
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1255
                        id: ProviderLayerCollectionId {
1✔
1256
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1257
                            collection_id: LayerCollectionId(UNSORTED_COLLECTION_ID.to_string()),
1✔
1258
                        },
1✔
1259
                        name: "Unsorted".to_string(),
1✔
1260
                        description: "Unsorted Layers".to_string(),
1✔
1261
                        properties: Default::default(),
1✔
1262
                    }),
1✔
1263
                    CollectionItem::Layer(LayerListing {
1✔
1264
                        id: ProviderLayerId {
1✔
1265
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1266
                            layer_id: layer1,
1✔
1267
                        },
1✔
1268
                        name: "Layer1".to_string(),
1✔
1269
                        description: "Layer 1".to_string(),
1✔
1270
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1271
                    })
1✔
1272
                ],
1✔
1273
                entry_label: None,
1✔
1274
                properties: vec![],
1✔
1275
            }
1✔
1276
        );
1✔
1277

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

1✔
1289
        assert_eq!(
1✔
1290
            collection1,
1✔
1291
            LayerCollection {
1✔
1292
                id: ProviderLayerCollectionId {
1✔
1293
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1294
                    collection_id: collection1_id,
1✔
1295
                },
1✔
1296
                name: "Collection1".to_string(),
1✔
1297
                description: "Collection 1".to_string(),
1✔
1298
                items: vec![
1✔
1299
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1300
                        id: ProviderLayerCollectionId {
1✔
1301
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1302
                            collection_id: collection2_id,
1✔
1303
                        },
1✔
1304
                        name: "Collection2".to_string(),
1✔
1305
                        description: "Collection 2".to_string(),
1✔
1306
                        properties: Default::default(),
1✔
1307
                    }),
1✔
1308
                    CollectionItem::Layer(LayerListing {
1✔
1309
                        id: ProviderLayerId {
1✔
1310
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1311
                            layer_id: layer2,
1✔
1312
                        },
1✔
1313
                        name: "Layer2".to_string(),
1✔
1314
                        description: "Layer 2".to_string(),
1✔
1315
                        properties: vec![],
1✔
1316
                    })
1✔
1317
                ],
1✔
1318
                entry_label: None,
1✔
1319
                properties: vec![],
1✔
1320
            }
1✔
1321
        );
1✔
1322
    }
1✔
1323

1324
    #[allow(clippy::too_many_lines)]
1325
    #[ge_context::test]
2✔
1326
    async fn it_searches_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1327
        let session = app_ctx.default_session().await.unwrap();
1✔
1328

1✔
1329
        let layer_db = app_ctx.session_context(session).db();
1✔
1330

1✔
1331
        let workflow = Workflow {
1✔
1332
            operator: TypedOperator::Vector(
1✔
1333
                MockPointSource {
1✔
1334
                    params: MockPointSourceParams {
1✔
1335
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1336
                    },
1✔
1337
                }
1✔
1338
                .boxed(),
1✔
1339
            ),
1✔
1340
        };
1✔
1341

1342
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1343

1344
        let layer1 = layer_db
1✔
1345
            .add_layer(
1✔
1346
                AddLayer {
1✔
1347
                    name: "Layer1".to_string(),
1✔
1348
                    description: "Layer 1".to_string(),
1✔
1349
                    symbology: None,
1✔
1350
                    workflow: workflow.clone(),
1✔
1351
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1352
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1353
                },
1✔
1354
                &root_collection_id,
1✔
1355
            )
1✔
1356
            .await
1✔
1357
            .unwrap();
1✔
1358

1359
        let collection1_id = layer_db
1✔
1360
            .add_layer_collection(
1✔
1361
                AddLayerCollection {
1✔
1362
                    name: "Collection1".to_string(),
1✔
1363
                    description: "Collection 1".to_string(),
1✔
1364
                    properties: Default::default(),
1✔
1365
                },
1✔
1366
                &root_collection_id,
1✔
1367
            )
1✔
1368
            .await
1✔
1369
            .unwrap();
1✔
1370

1371
        let layer2 = layer_db
1✔
1372
            .add_layer(
1✔
1373
                AddLayer {
1✔
1374
                    name: "Layer2".to_string(),
1✔
1375
                    description: "Layer 2".to_string(),
1✔
1376
                    symbology: None,
1✔
1377
                    workflow: workflow.clone(),
1✔
1378
                    metadata: Default::default(),
1✔
1379
                    properties: Default::default(),
1✔
1380
                },
1✔
1381
                &collection1_id,
1✔
1382
            )
1✔
1383
            .await
1✔
1384
            .unwrap();
1✔
1385

1386
        let collection2_id = layer_db
1✔
1387
            .add_layer_collection(
1✔
1388
                AddLayerCollection {
1✔
1389
                    name: "Collection2".to_string(),
1✔
1390
                    description: "Collection 2".to_string(),
1✔
1391
                    properties: Default::default(),
1✔
1392
                },
1✔
1393
                &collection1_id,
1✔
1394
            )
1✔
1395
            .await
1✔
1396
            .unwrap();
1✔
1397

1398
        let root_collection_all = layer_db
1✔
1399
            .search(
1✔
1400
                &root_collection_id,
1✔
1401
                SearchParameters {
1✔
1402
                    search_type: SearchType::Fulltext,
1✔
1403
                    search_string: String::new(),
1✔
1404
                    limit: 10,
1✔
1405
                    offset: 0,
1✔
1406
                },
1✔
1407
            )
1✔
1408
            .await
1✔
1409
            .unwrap();
1✔
1410

1✔
1411
        assert_eq!(
1✔
1412
            root_collection_all,
1✔
1413
            LayerCollection {
1✔
1414
                id: ProviderLayerCollectionId {
1✔
1415
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1416
                    collection_id: root_collection_id.clone(),
1✔
1417
                },
1✔
1418
                name: "Layers".to_string(),
1✔
1419
                description: "All available Geo Engine layers".to_string(),
1✔
1420
                items: vec![
1✔
1421
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1422
                        id: ProviderLayerCollectionId {
1✔
1423
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1424
                            collection_id: collection1_id.clone(),
1✔
1425
                        },
1✔
1426
                        name: "Collection1".to_string(),
1✔
1427
                        description: "Collection 1".to_string(),
1✔
1428
                        properties: Default::default(),
1✔
1429
                    }),
1✔
1430
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1431
                        id: ProviderLayerCollectionId {
1✔
1432
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1433
                            collection_id: collection2_id.clone(),
1✔
1434
                        },
1✔
1435
                        name: "Collection2".to_string(),
1✔
1436
                        description: "Collection 2".to_string(),
1✔
1437
                        properties: Default::default(),
1✔
1438
                    }),
1✔
1439
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1440
                        id: ProviderLayerCollectionId {
1✔
1441
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1442
                            collection_id: LayerCollectionId(
1✔
1443
                                "ffb2dd9e-f5ad-427c-b7f1-c9a0c7a0ae3f".to_string()
1✔
1444
                            ),
1✔
1445
                        },
1✔
1446
                        name: "Unsorted".to_string(),
1✔
1447
                        description: "Unsorted Layers".to_string(),
1✔
1448
                        properties: Default::default(),
1✔
1449
                    }),
1✔
1450
                    CollectionItem::Layer(LayerListing {
1✔
1451
                        id: ProviderLayerId {
1✔
1452
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1453
                            layer_id: layer1.clone(),
1✔
1454
                        },
1✔
1455
                        name: "Layer1".to_string(),
1✔
1456
                        description: "Layer 1".to_string(),
1✔
1457
                        properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1458
                    }),
1✔
1459
                    CollectionItem::Layer(LayerListing {
1✔
1460
                        id: ProviderLayerId {
1✔
1461
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1462
                            layer_id: layer2.clone(),
1✔
1463
                        },
1✔
1464
                        name: "Layer2".to_string(),
1✔
1465
                        description: "Layer 2".to_string(),
1✔
1466
                        properties: vec![],
1✔
1467
                    }),
1✔
1468
                ],
1✔
1469
                entry_label: None,
1✔
1470
                properties: vec![],
1✔
1471
            }
1✔
1472
        );
1✔
1473

1474
        let root_collection_filtered = layer_db
1✔
1475
            .search(
1✔
1476
                &root_collection_id,
1✔
1477
                SearchParameters {
1✔
1478
                    search_type: SearchType::Fulltext,
1✔
1479
                    search_string: "lection".to_string(),
1✔
1480
                    limit: 10,
1✔
1481
                    offset: 0,
1✔
1482
                },
1✔
1483
            )
1✔
1484
            .await
1✔
1485
            .unwrap();
1✔
1486

1✔
1487
        assert_eq!(
1✔
1488
            root_collection_filtered,
1✔
1489
            LayerCollection {
1✔
1490
                id: ProviderLayerCollectionId {
1✔
1491
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1492
                    collection_id: root_collection_id.clone(),
1✔
1493
                },
1✔
1494
                name: "Layers".to_string(),
1✔
1495
                description: "All available Geo Engine layers".to_string(),
1✔
1496
                items: vec![
1✔
1497
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1498
                        id: ProviderLayerCollectionId {
1✔
1499
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1500
                            collection_id: collection1_id.clone(),
1✔
1501
                        },
1✔
1502
                        name: "Collection1".to_string(),
1✔
1503
                        description: "Collection 1".to_string(),
1✔
1504
                        properties: Default::default(),
1✔
1505
                    }),
1✔
1506
                    CollectionItem::Collection(LayerCollectionListing {
1✔
1507
                        id: ProviderLayerCollectionId {
1✔
1508
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
1509
                            collection_id: collection2_id.clone(),
1✔
1510
                        },
1✔
1511
                        name: "Collection2".to_string(),
1✔
1512
                        description: "Collection 2".to_string(),
1✔
1513
                        properties: Default::default(),
1✔
1514
                    }),
1✔
1515
                ],
1✔
1516
                entry_label: None,
1✔
1517
                properties: vec![],
1✔
1518
            }
1✔
1519
        );
1✔
1520

1521
        let collection1_all = layer_db
1✔
1522
            .search(
1✔
1523
                &collection1_id,
1✔
1524
                SearchParameters {
1✔
1525
                    search_type: SearchType::Fulltext,
1✔
1526
                    search_string: String::new(),
1✔
1527
                    limit: 10,
1✔
1528
                    offset: 0,
1✔
1529
                },
1✔
1530
            )
1✔
1531
            .await
1✔
1532
            .unwrap();
1✔
1533

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

1568
        let collection1_filtered_fulltext = layer_db
1✔
1569
            .search(
1✔
1570
                &collection1_id,
1✔
1571
                SearchParameters {
1✔
1572
                    search_type: SearchType::Fulltext,
1✔
1573
                    search_string: "ay".to_string(),
1✔
1574
                    limit: 10,
1✔
1575
                    offset: 0,
1✔
1576
                },
1✔
1577
            )
1✔
1578
            .await
1✔
1579
            .unwrap();
1✔
1580

1✔
1581
        assert_eq!(
1✔
1582
            collection1_filtered_fulltext,
1✔
1583
            LayerCollection {
1✔
1584
                id: ProviderLayerCollectionId {
1✔
1585
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1586
                    collection_id: collection1_id.clone(),
1✔
1587
                },
1✔
1588
                name: "Collection1".to_string(),
1✔
1589
                description: "Collection 1".to_string(),
1✔
1590
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1591
                    id: ProviderLayerId {
1✔
1592
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1593
                        layer_id: layer2.clone(),
1✔
1594
                    },
1✔
1595
                    name: "Layer2".to_string(),
1✔
1596
                    description: "Layer 2".to_string(),
1✔
1597
                    properties: vec![],
1✔
1598
                }),],
1✔
1599
                entry_label: None,
1✔
1600
                properties: vec![],
1✔
1601
            }
1✔
1602
        );
1✔
1603

1604
        let collection1_filtered_prefix = layer_db
1✔
1605
            .search(
1✔
1606
                &collection1_id,
1✔
1607
                SearchParameters {
1✔
1608
                    search_type: SearchType::Prefix,
1✔
1609
                    search_string: "ay".to_string(),
1✔
1610
                    limit: 10,
1✔
1611
                    offset: 0,
1✔
1612
                },
1✔
1613
            )
1✔
1614
            .await
1✔
1615
            .unwrap();
1✔
1616

1✔
1617
        assert_eq!(
1✔
1618
            collection1_filtered_prefix,
1✔
1619
            LayerCollection {
1✔
1620
                id: ProviderLayerCollectionId {
1✔
1621
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1622
                    collection_id: collection1_id.clone(),
1✔
1623
                },
1✔
1624
                name: "Collection1".to_string(),
1✔
1625
                description: "Collection 1".to_string(),
1✔
1626
                items: vec![],
1✔
1627
                entry_label: None,
1✔
1628
                properties: vec![],
1✔
1629
            }
1✔
1630
        );
1✔
1631

1632
        let collection1_filtered_prefix2 = layer_db
1✔
1633
            .search(
1✔
1634
                &collection1_id,
1✔
1635
                SearchParameters {
1✔
1636
                    search_type: SearchType::Prefix,
1✔
1637
                    search_string: "Lay".to_string(),
1✔
1638
                    limit: 10,
1✔
1639
                    offset: 0,
1✔
1640
                },
1✔
1641
            )
1✔
1642
            .await
1✔
1643
            .unwrap();
1✔
1644

1✔
1645
        assert_eq!(
1✔
1646
            collection1_filtered_prefix2,
1✔
1647
            LayerCollection {
1✔
1648
                id: ProviderLayerCollectionId {
1✔
1649
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
1650
                    collection_id: collection1_id.clone(),
1✔
1651
                },
1✔
1652
                name: "Collection1".to_string(),
1✔
1653
                description: "Collection 1".to_string(),
1✔
1654
                items: vec![CollectionItem::Layer(LayerListing {
1✔
1655
                    id: ProviderLayerId {
1✔
1656
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
1657
                        layer_id: layer2.clone(),
1✔
1658
                    },
1✔
1659
                    name: "Layer2".to_string(),
1✔
1660
                    description: "Layer 2".to_string(),
1✔
1661
                    properties: vec![],
1✔
1662
                }),],
1✔
1663
                entry_label: None,
1✔
1664
                properties: vec![],
1✔
1665
            }
1✔
1666
        );
1✔
1667
    }
1✔
1668

1669
    #[allow(clippy::too_many_lines)]
1670
    #[ge_context::test]
2✔
1671
    async fn it_autocompletes_layers(app_ctx: PostgresContext<NoTls>) {
1✔
1672
        let session = app_ctx.default_session().await.unwrap();
1✔
1673

1✔
1674
        let layer_db = app_ctx.session_context(session).db();
1✔
1675

1✔
1676
        let workflow = Workflow {
1✔
1677
            operator: TypedOperator::Vector(
1✔
1678
                MockPointSource {
1✔
1679
                    params: MockPointSourceParams {
1✔
1680
                        points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1681
                    },
1✔
1682
                }
1✔
1683
                .boxed(),
1✔
1684
            ),
1✔
1685
        };
1✔
1686

1687
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1688

1689
        let _layer1 = layer_db
1✔
1690
            .add_layer(
1✔
1691
                AddLayer {
1✔
1692
                    name: "Layer1".to_string(),
1✔
1693
                    description: "Layer 1".to_string(),
1✔
1694
                    symbology: None,
1✔
1695
                    workflow: workflow.clone(),
1✔
1696
                    metadata: [("meta".to_string(), "datum".to_string())].into(),
1✔
1697
                    properties: vec![("proper".to_string(), "tee".to_string()).into()],
1✔
1698
                },
1✔
1699
                &root_collection_id,
1✔
1700
            )
1✔
1701
            .await
1✔
1702
            .unwrap();
1✔
1703

1704
        let collection1_id = layer_db
1✔
1705
            .add_layer_collection(
1✔
1706
                AddLayerCollection {
1✔
1707
                    name: "Collection1".to_string(),
1✔
1708
                    description: "Collection 1".to_string(),
1✔
1709
                    properties: Default::default(),
1✔
1710
                },
1✔
1711
                &root_collection_id,
1✔
1712
            )
1✔
1713
            .await
1✔
1714
            .unwrap();
1✔
1715

1716
        let _layer2 = layer_db
1✔
1717
            .add_layer(
1✔
1718
                AddLayer {
1✔
1719
                    name: "Layer2".to_string(),
1✔
1720
                    description: "Layer 2".to_string(),
1✔
1721
                    symbology: None,
1✔
1722
                    workflow: workflow.clone(),
1✔
1723
                    metadata: Default::default(),
1✔
1724
                    properties: Default::default(),
1✔
1725
                },
1✔
1726
                &collection1_id,
1✔
1727
            )
1✔
1728
            .await
1✔
1729
            .unwrap();
1✔
1730

1731
        let _collection2_id = layer_db
1✔
1732
            .add_layer_collection(
1✔
1733
                AddLayerCollection {
1✔
1734
                    name: "Collection2".to_string(),
1✔
1735
                    description: "Collection 2".to_string(),
1✔
1736
                    properties: Default::default(),
1✔
1737
                },
1✔
1738
                &collection1_id,
1✔
1739
            )
1✔
1740
            .await
1✔
1741
            .unwrap();
1✔
1742

1743
        let root_collection_all = layer_db
1✔
1744
            .autocomplete_search(
1✔
1745
                &root_collection_id,
1✔
1746
                SearchParameters {
1✔
1747
                    search_type: SearchType::Fulltext,
1✔
1748
                    search_string: String::new(),
1✔
1749
                    limit: 10,
1✔
1750
                    offset: 0,
1✔
1751
                },
1✔
1752
            )
1✔
1753
            .await
1✔
1754
            .unwrap();
1✔
1755

1✔
1756
        assert_eq!(
1✔
1757
            root_collection_all,
1✔
1758
            vec![
1✔
1759
                "Collection1".to_string(),
1✔
1760
                "Collection2".to_string(),
1✔
1761
                "Layer1".to_string(),
1✔
1762
                "Layer2".to_string(),
1✔
1763
                "Unsorted".to_string(),
1✔
1764
            ]
1✔
1765
        );
1✔
1766

1767
        let root_collection_filtered = layer_db
1✔
1768
            .autocomplete_search(
1✔
1769
                &root_collection_id,
1✔
1770
                SearchParameters {
1✔
1771
                    search_type: SearchType::Fulltext,
1✔
1772
                    search_string: "lection".to_string(),
1✔
1773
                    limit: 10,
1✔
1774
                    offset: 0,
1✔
1775
                },
1✔
1776
            )
1✔
1777
            .await
1✔
1778
            .unwrap();
1✔
1779

1✔
1780
        assert_eq!(
1✔
1781
            root_collection_filtered,
1✔
1782
            vec!["Collection1".to_string(), "Collection2".to_string(),]
1✔
1783
        );
1✔
1784

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

1✔
1798
        assert_eq!(
1✔
1799
            collection1_all,
1✔
1800
            vec!["Collection2".to_string(), "Layer2".to_string(),]
1✔
1801
        );
1✔
1802

1803
        let collection1_filtered_fulltext = layer_db
1✔
1804
            .autocomplete_search(
1✔
1805
                &collection1_id,
1✔
1806
                SearchParameters {
1✔
1807
                    search_type: SearchType::Fulltext,
1✔
1808
                    search_string: "ay".to_string(),
1✔
1809
                    limit: 10,
1✔
1810
                    offset: 0,
1✔
1811
                },
1✔
1812
            )
1✔
1813
            .await
1✔
1814
            .unwrap();
1✔
1815

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

1818
        let collection1_filtered_prefix = layer_db
1✔
1819
            .autocomplete_search(
1✔
1820
                &collection1_id,
1✔
1821
                SearchParameters {
1✔
1822
                    search_type: SearchType::Prefix,
1✔
1823
                    search_string: "ay".to_string(),
1✔
1824
                    limit: 10,
1✔
1825
                    offset: 0,
1✔
1826
                },
1✔
1827
            )
1✔
1828
            .await
1✔
1829
            .unwrap();
1✔
1830

1✔
1831
        assert_eq!(collection1_filtered_prefix, Vec::<String>::new());
1✔
1832

1833
        let collection1_filtered_prefix2 = layer_db
1✔
1834
            .autocomplete_search(
1✔
1835
                &collection1_id,
1✔
1836
                SearchParameters {
1✔
1837
                    search_type: SearchType::Prefix,
1✔
1838
                    search_string: "Lay".to_string(),
1✔
1839
                    limit: 10,
1✔
1840
                    offset: 0,
1✔
1841
                },
1✔
1842
            )
1✔
1843
            .await
1✔
1844
            .unwrap();
1✔
1845

1✔
1846
        assert_eq!(collection1_filtered_prefix2, vec!["Layer2".to_string(),]);
1✔
1847
    }
1✔
1848

1849
    #[allow(clippy::too_many_lines)]
1850
    #[ge_context::test]
2✔
1851
    async fn it_reports_search_capabilities(app_ctx: PostgresContext<NoTls>) {
1✔
1852
        let session = app_ctx.default_session().await.unwrap();
1✔
1853

1✔
1854
        let layer_db = app_ctx.session_context(session).db();
1✔
1855

1✔
1856
        let capabilities = layer_db.capabilities().search;
1✔
1857

1858
        let root_collection_id = layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1859

1✔
1860
        if capabilities.search_types.fulltext {
1✔
1861
            assert!(layer_db
1✔
1862
                .search(
1✔
1863
                    &root_collection_id,
1✔
1864
                    SearchParameters {
1✔
1865
                        search_type: SearchType::Fulltext,
1✔
1866
                        search_string: String::new(),
1✔
1867
                        limit: 10,
1✔
1868
                        offset: 0,
1✔
1869
                    },
1✔
1870
                )
1✔
1871
                .await
1✔
1872
                .is_ok());
1✔
1873

1874
            if capabilities.autocomplete {
1✔
1875
                assert!(layer_db
1✔
1876
                    .autocomplete_search(
1✔
1877
                        &root_collection_id,
1✔
1878
                        SearchParameters {
1✔
1879
                            search_type: SearchType::Fulltext,
1✔
1880
                            search_string: String::new(),
1✔
1881
                            limit: 10,
1✔
1882
                            offset: 0,
1✔
1883
                        },
1✔
1884
                    )
1✔
1885
                    .await
1✔
1886
                    .is_ok());
1✔
1887
            } else {
1888
                assert!(layer_db
×
1889
                    .autocomplete_search(
×
1890
                        &root_collection_id,
×
1891
                        SearchParameters {
×
1892
                            search_type: SearchType::Fulltext,
×
1893
                            search_string: String::new(),
×
1894
                            limit: 10,
×
1895
                            offset: 0,
×
1896
                        },
×
1897
                    )
×
1898
                    .await
×
1899
                    .is_err());
×
1900
            }
1901
        }
×
1902
        if capabilities.search_types.prefix {
1✔
1903
            assert!(layer_db
1✔
1904
                .search(
1✔
1905
                    &root_collection_id,
1✔
1906
                    SearchParameters {
1✔
1907
                        search_type: SearchType::Prefix,
1✔
1908
                        search_string: String::new(),
1✔
1909
                        limit: 10,
1✔
1910
                        offset: 0,
1✔
1911
                    },
1✔
1912
                )
1✔
1913
                .await
1✔
1914
                .is_ok());
1✔
1915

1916
            if capabilities.autocomplete {
1✔
1917
                assert!(layer_db
1✔
1918
                    .autocomplete_search(
1✔
1919
                        &root_collection_id,
1✔
1920
                        SearchParameters {
1✔
1921
                            search_type: SearchType::Prefix,
1✔
1922
                            search_string: String::new(),
1✔
1923
                            limit: 10,
1✔
1924
                            offset: 0,
1✔
1925
                        },
1✔
1926
                    )
1✔
1927
                    .await
1✔
1928
                    .is_ok());
1✔
1929
            } else {
1930
                assert!(layer_db
×
1931
                    .autocomplete_search(
×
1932
                        &root_collection_id,
×
1933
                        SearchParameters {
×
1934
                            search_type: SearchType::Prefix,
×
1935
                            search_string: String::new(),
×
1936
                            limit: 10,
×
1937
                            offset: 0,
×
1938
                        },
×
1939
                    )
×
1940
                    .await
×
1941
                    .is_err());
×
1942
            }
1943
        }
×
1944
    }
1✔
1945

1946
    #[allow(clippy::too_many_lines)]
1947
    #[ge_context::test]
2✔
1948
    async fn it_removes_layer_collections(app_ctx: PostgresContext<NoTls>) {
1✔
1949
        let session = app_ctx.default_session().await.unwrap();
1✔
1950

1✔
1951
        let layer_db = app_ctx.session_context(session).db();
1✔
1952

1✔
1953
        let layer = AddLayer {
1✔
1954
            name: "layer".to_string(),
1✔
1955
            description: "description".to_string(),
1✔
1956
            workflow: Workflow {
1✔
1957
                operator: TypedOperator::Vector(
1✔
1958
                    MockPointSource {
1✔
1959
                        params: MockPointSourceParams {
1✔
1960
                            points: vec![Coordinate2D::new(1., 2.); 3],
1✔
1961
                        },
1✔
1962
                    }
1✔
1963
                    .boxed(),
1✔
1964
                ),
1✔
1965
            },
1✔
1966
            symbology: None,
1✔
1967
            metadata: Default::default(),
1✔
1968
            properties: Default::default(),
1✔
1969
        };
1✔
1970

1971
        let root_collection = &layer_db.get_root_layer_collection_id().await.unwrap();
1✔
1972

1✔
1973
        let collection = AddLayerCollection {
1✔
1974
            name: "top collection".to_string(),
1✔
1975
            description: "description".to_string(),
1✔
1976
            properties: Default::default(),
1✔
1977
        };
1✔
1978

1979
        let top_c_id = layer_db
1✔
1980
            .add_layer_collection(collection, root_collection)
1✔
1981
            .await
1✔
1982
            .unwrap();
1✔
1983

1984
        let l_id = layer_db.add_layer(layer, &top_c_id).await.unwrap();
1✔
1985

1✔
1986
        let collection = AddLayerCollection {
1✔
1987
            name: "empty collection".to_string(),
1✔
1988
            description: "description".to_string(),
1✔
1989
            properties: Default::default(),
1✔
1990
        };
1✔
1991

1992
        let empty_c_id = layer_db
1✔
1993
            .add_layer_collection(collection, &top_c_id)
1✔
1994
            .await
1✔
1995
            .unwrap();
1✔
1996

1997
        let items = layer_db
1✔
1998
            .load_layer_collection(
1✔
1999
                &top_c_id,
1✔
2000
                LayerCollectionListOptions {
1✔
2001
                    offset: 0,
1✔
2002
                    limit: 20,
1✔
2003
                },
1✔
2004
            )
1✔
2005
            .await
1✔
2006
            .unwrap();
1✔
2007

1✔
2008
        assert_eq!(
1✔
2009
            items,
1✔
2010
            LayerCollection {
1✔
2011
                id: ProviderLayerCollectionId {
1✔
2012
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2013
                    collection_id: top_c_id.clone(),
1✔
2014
                },
1✔
2015
                name: "top collection".to_string(),
1✔
2016
                description: "description".to_string(),
1✔
2017
                items: vec![
1✔
2018
                    CollectionItem::Collection(LayerCollectionListing {
1✔
2019
                        id: ProviderLayerCollectionId {
1✔
2020
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2021
                            collection_id: empty_c_id.clone(),
1✔
2022
                        },
1✔
2023
                        name: "empty collection".to_string(),
1✔
2024
                        description: "description".to_string(),
1✔
2025
                        properties: Default::default(),
1✔
2026
                    }),
1✔
2027
                    CollectionItem::Layer(LayerListing {
1✔
2028
                        id: ProviderLayerId {
1✔
2029
                            provider_id: INTERNAL_PROVIDER_ID,
1✔
2030
                            layer_id: l_id.clone(),
1✔
2031
                        },
1✔
2032
                        name: "layer".to_string(),
1✔
2033
                        description: "description".to_string(),
1✔
2034
                        properties: vec![],
1✔
2035
                    })
1✔
2036
                ],
1✔
2037
                entry_label: None,
1✔
2038
                properties: vec![],
1✔
2039
            }
1✔
2040
        );
1✔
2041

2042
        // remove empty collection
2043
        layer_db.remove_layer_collection(&empty_c_id).await.unwrap();
1✔
2044

2045
        let items = layer_db
1✔
2046
            .load_layer_collection(
1✔
2047
                &top_c_id,
1✔
2048
                LayerCollectionListOptions {
1✔
2049
                    offset: 0,
1✔
2050
                    limit: 20,
1✔
2051
                },
1✔
2052
            )
1✔
2053
            .await
1✔
2054
            .unwrap();
1✔
2055

1✔
2056
        assert_eq!(
1✔
2057
            items,
1✔
2058
            LayerCollection {
1✔
2059
                id: ProviderLayerCollectionId {
1✔
2060
                    provider_id: INTERNAL_PROVIDER_ID,
1✔
2061
                    collection_id: top_c_id.clone(),
1✔
2062
                },
1✔
2063
                name: "top collection".to_string(),
1✔
2064
                description: "description".to_string(),
1✔
2065
                items: vec![CollectionItem::Layer(LayerListing {
1✔
2066
                    id: ProviderLayerId {
1✔
2067
                        provider_id: INTERNAL_PROVIDER_ID,
1✔
2068
                        layer_id: l_id.clone(),
1✔
2069
                    },
1✔
2070
                    name: "layer".to_string(),
1✔
2071
                    description: "description".to_string(),
1✔
2072
                    properties: vec![],
1✔
2073
                })],
1✔
2074
                entry_label: None,
1✔
2075
                properties: vec![],
1✔
2076
            }
1✔
2077
        );
1✔
2078

2079
        // remove top (not root) collection
2080
        layer_db.remove_layer_collection(&top_c_id).await.unwrap();
1✔
2081

1✔
2082
        layer_db
1✔
2083
            .load_layer_collection(
1✔
2084
                &top_c_id,
1✔
2085
                LayerCollectionListOptions {
1✔
2086
                    offset: 0,
1✔
2087
                    limit: 20,
1✔
2088
                },
1✔
2089
            )
1✔
2090
            .await
1✔
2091
            .unwrap_err();
1✔
2092

1✔
2093
        // should be deleted automatically
1✔
2094
        layer_db.load_layer(&l_id).await.unwrap_err();
1✔
2095

1✔
2096
        // it is not allowed to remove the root collection
1✔
2097
        layer_db
1✔
2098
            .remove_layer_collection(root_collection)
1✔
2099
            .await
1✔
2100
            .unwrap_err();
1✔
2101
        layer_db
1✔
2102
            .load_layer_collection(
1✔
2103
                root_collection,
1✔
2104
                LayerCollectionListOptions {
1✔
2105
                    offset: 0,
1✔
2106
                    limit: 20,
1✔
2107
                },
1✔
2108
            )
1✔
2109
            .await
1✔
2110
            .unwrap();
1✔
2111
    }
1✔
2112

2113
    #[ge_context::test]
2✔
2114
    #[allow(clippy::too_many_lines)]
2115
    async fn it_removes_collections_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2116
        let session = app_ctx.default_session().await.unwrap();
1✔
2117

1✔
2118
        let db = app_ctx.session_context(session).db();
1✔
2119

2120
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2121

2122
        let mid_collection_id = db
1✔
2123
            .add_layer_collection(
1✔
2124
                AddLayerCollection {
1✔
2125
                    name: "mid collection".to_string(),
1✔
2126
                    description: "description".to_string(),
1✔
2127
                    properties: Default::default(),
1✔
2128
                },
1✔
2129
                root_collection_id,
1✔
2130
            )
1✔
2131
            .await
1✔
2132
            .unwrap();
1✔
2133

2134
        let bottom_collection_id = db
1✔
2135
            .add_layer_collection(
1✔
2136
                AddLayerCollection {
1✔
2137
                    name: "bottom collection".to_string(),
1✔
2138
                    description: "description".to_string(),
1✔
2139
                    properties: Default::default(),
1✔
2140
                },
1✔
2141
                &mid_collection_id,
1✔
2142
            )
1✔
2143
            .await
1✔
2144
            .unwrap();
1✔
2145

2146
        let layer_id = db
1✔
2147
            .add_layer(
1✔
2148
                AddLayer {
1✔
2149
                    name: "layer".to_string(),
1✔
2150
                    description: "description".to_string(),
1✔
2151
                    workflow: Workflow {
1✔
2152
                        operator: TypedOperator::Vector(
1✔
2153
                            MockPointSource {
1✔
2154
                                params: MockPointSourceParams {
1✔
2155
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2156
                                },
1✔
2157
                            }
1✔
2158
                            .boxed(),
1✔
2159
                        ),
1✔
2160
                    },
1✔
2161
                    symbology: None,
1✔
2162
                    metadata: Default::default(),
1✔
2163
                    properties: Default::default(),
1✔
2164
                },
1✔
2165
                &mid_collection_id,
1✔
2166
            )
1✔
2167
            .await
1✔
2168
            .unwrap();
1✔
2169

1✔
2170
        // removing the mid collection…
1✔
2171
        db.remove_layer_collection_from_parent(&mid_collection_id, root_collection_id)
1✔
2172
            .await
1✔
2173
            .unwrap();
1✔
2174

1✔
2175
        // …should remove itself
1✔
2176
        db.load_layer_collection(&mid_collection_id, LayerCollectionListOptions::default())
1✔
2177
            .await
1✔
2178
            .unwrap_err();
1✔
2179

1✔
2180
        // …should remove the bottom collection
1✔
2181
        db.load_layer_collection(&bottom_collection_id, LayerCollectionListOptions::default())
1✔
2182
            .await
1✔
2183
            .unwrap_err();
1✔
2184

1✔
2185
        // … and should remove the layer of the bottom collection
1✔
2186
        db.load_layer(&layer_id).await.unwrap_err();
1✔
2187

1✔
2188
        // the root collection is still there
1✔
2189
        db.load_layer_collection(root_collection_id, LayerCollectionListOptions::default())
1✔
2190
            .await
1✔
2191
            .unwrap();
1✔
2192
    }
1✔
2193

2194
    #[ge_context::test]
2✔
2195
    #[allow(clippy::too_many_lines)]
2196
    async fn it_removes_layers_from_collections(app_ctx: PostgresContext<NoTls>) {
1✔
2197
        let session = app_ctx.default_session().await.unwrap();
1✔
2198

1✔
2199
        let db = app_ctx.session_context(session).db();
1✔
2200

2201
        let root_collection = &db.get_root_layer_collection_id().await.unwrap();
1✔
2202

2203
        let another_collection = db
1✔
2204
            .add_layer_collection(
1✔
2205
                AddLayerCollection {
1✔
2206
                    name: "top collection".to_string(),
1✔
2207
                    description: "description".to_string(),
1✔
2208
                    properties: Default::default(),
1✔
2209
                },
1✔
2210
                root_collection,
1✔
2211
            )
1✔
2212
            .await
1✔
2213
            .unwrap();
1✔
2214

2215
        let layer_in_one_collection = db
1✔
2216
            .add_layer(
1✔
2217
                AddLayer {
1✔
2218
                    name: "layer 1".to_string(),
1✔
2219
                    description: "description".to_string(),
1✔
2220
                    workflow: Workflow {
1✔
2221
                        operator: TypedOperator::Vector(
1✔
2222
                            MockPointSource {
1✔
2223
                                params: MockPointSourceParams {
1✔
2224
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2225
                                },
1✔
2226
                            }
1✔
2227
                            .boxed(),
1✔
2228
                        ),
1✔
2229
                    },
1✔
2230
                    symbology: None,
1✔
2231
                    metadata: Default::default(),
1✔
2232
                    properties: Default::default(),
1✔
2233
                },
1✔
2234
                &another_collection,
1✔
2235
            )
1✔
2236
            .await
1✔
2237
            .unwrap();
1✔
2238

2239
        let layer_in_two_collections = db
1✔
2240
            .add_layer(
1✔
2241
                AddLayer {
1✔
2242
                    name: "layer 2".to_string(),
1✔
2243
                    description: "description".to_string(),
1✔
2244
                    workflow: Workflow {
1✔
2245
                        operator: TypedOperator::Vector(
1✔
2246
                            MockPointSource {
1✔
2247
                                params: MockPointSourceParams {
1✔
2248
                                    points: vec![Coordinate2D::new(1., 2.); 3],
1✔
2249
                                },
1✔
2250
                            }
1✔
2251
                            .boxed(),
1✔
2252
                        ),
1✔
2253
                    },
1✔
2254
                    symbology: None,
1✔
2255
                    metadata: Default::default(),
1✔
2256
                    properties: Default::default(),
1✔
2257
                },
1✔
2258
                &another_collection,
1✔
2259
            )
1✔
2260
            .await
1✔
2261
            .unwrap();
1✔
2262

1✔
2263
        db.add_layer_to_collection(&layer_in_two_collections, root_collection)
1✔
2264
            .await
1✔
2265
            .unwrap();
1✔
2266

1✔
2267
        // remove first layer --> should be deleted entirely
1✔
2268

1✔
2269
        db.remove_layer_from_collection(&layer_in_one_collection, &another_collection)
1✔
2270
            .await
1✔
2271
            .unwrap();
1✔
2272

2273
        let number_of_layer_in_collection = db
1✔
2274
            .load_layer_collection(
1✔
2275
                &another_collection,
1✔
2276
                LayerCollectionListOptions {
1✔
2277
                    offset: 0,
1✔
2278
                    limit: 20,
1✔
2279
                },
1✔
2280
            )
1✔
2281
            .await
1✔
2282
            .unwrap()
1✔
2283
            .items
1✔
2284
            .len();
1✔
2285
        assert_eq!(
1✔
2286
            number_of_layer_in_collection,
1✔
2287
            1 /* only the other collection should be here */
1✔
2288
        );
1✔
2289

2290
        db.load_layer(&layer_in_one_collection).await.unwrap_err();
1✔
2291

1✔
2292
        // remove second layer --> should only be gone in collection
1✔
2293

1✔
2294
        db.remove_layer_from_collection(&layer_in_two_collections, &another_collection)
1✔
2295
            .await
1✔
2296
            .unwrap();
1✔
2297

2298
        let number_of_layer_in_collection = db
1✔
2299
            .load_layer_collection(
1✔
2300
                &another_collection,
1✔
2301
                LayerCollectionListOptions {
1✔
2302
                    offset: 0,
1✔
2303
                    limit: 20,
1✔
2304
                },
1✔
2305
            )
1✔
2306
            .await
1✔
2307
            .unwrap()
1✔
2308
            .items
1✔
2309
            .len();
1✔
2310
        assert_eq!(
1✔
2311
            number_of_layer_in_collection,
1✔
2312
            0 /* both layers were deleted */
1✔
2313
        );
1✔
2314

2315
        db.load_layer(&layer_in_two_collections).await.unwrap();
1✔
2316
    }
1✔
2317

2318
    #[ge_context::test]
2✔
2319
    #[allow(clippy::too_many_lines)]
2320
    async fn it_deletes_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
2321
        let loading_info = OgrSourceDataset {
1✔
2322
            file_name: PathBuf::from("test.csv"),
1✔
2323
            layer_name: "test.csv".to_owned(),
1✔
2324
            data_type: Some(VectorDataType::MultiPoint),
1✔
2325
            time: OgrSourceDatasetTimeType::Start {
1✔
2326
                start_field: "start".to_owned(),
1✔
2327
                start_format: OgrSourceTimeFormat::Auto,
1✔
2328
                duration: OgrSourceDurationSpec::Zero,
1✔
2329
            },
1✔
2330
            default_geometry: None,
1✔
2331
            columns: Some(OgrSourceColumnSpec {
1✔
2332
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2333
                    header: CsvHeader::Auto,
1✔
2334
                }),
1✔
2335
                x: "x".to_owned(),
1✔
2336
                y: None,
1✔
2337
                int: vec![],
1✔
2338
                float: vec![],
1✔
2339
                text: vec![],
1✔
2340
                bool: vec![],
1✔
2341
                datetime: vec![],
1✔
2342
                rename: None,
1✔
2343
            }),
1✔
2344
            force_ogr_time_filter: false,
1✔
2345
            force_ogr_spatial_filter: false,
1✔
2346
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2347
            sql_query: None,
1✔
2348
            attribute_query: None,
1✔
2349
            cache_ttl: CacheTtlSeconds::default(),
1✔
2350
        };
1✔
2351

1✔
2352
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2353
            OgrSourceDataset,
1✔
2354
            VectorResultDescriptor,
1✔
2355
            VectorQueryRectangle,
1✔
2356
        > {
1✔
2357
            loading_info: loading_info.clone(),
1✔
2358
            result_descriptor: VectorResultDescriptor {
1✔
2359
                data_type: VectorDataType::MultiPoint,
1✔
2360
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2361
                columns: [(
1✔
2362
                    "foo".to_owned(),
1✔
2363
                    VectorColumnInfo {
1✔
2364
                        data_type: FeatureDataType::Float,
1✔
2365
                        measurement: Measurement::Unitless,
1✔
2366
                    },
1✔
2367
                )]
1✔
2368
                .into_iter()
1✔
2369
                .collect(),
1✔
2370
                time: None,
1✔
2371
                bbox: None,
1✔
2372
            },
1✔
2373
            phantom: Default::default(),
1✔
2374
        });
1✔
2375

2376
        let session = app_ctx.default_session().await.unwrap();
1✔
2377

1✔
2378
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2379

1✔
2380
        let db = app_ctx.session_context(session.clone()).db();
1✔
2381
        let dataset_id = db
1✔
2382
            .add_dataset(
1✔
2383
                AddDataset {
1✔
2384
                    name: Some(dataset_name),
1✔
2385
                    display_name: "Ogr Test".to_owned(),
1✔
2386
                    description: "desc".to_owned(),
1✔
2387
                    source_operator: "OgrSource".to_owned(),
1✔
2388
                    symbology: None,
1✔
2389
                    provenance: Some(vec![Provenance {
1✔
2390
                        citation: "citation".to_owned(),
1✔
2391
                        license: "license".to_owned(),
1✔
2392
                        uri: "uri".to_owned(),
1✔
2393
                    }]),
1✔
2394
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2395
                },
1✔
2396
                meta_data,
1✔
2397
            )
1✔
2398
            .await
1✔
2399
            .unwrap()
1✔
2400
            .id;
1✔
2401

1✔
2402
        assert!(db.load_dataset(&dataset_id).await.is_ok());
1✔
2403

2404
        db.delete_dataset(dataset_id).await.unwrap();
1✔
2405

1✔
2406
        assert!(db.load_dataset(&dataset_id).await.is_err());
1✔
2407
    }
1✔
2408

2409
    #[ge_context::test]
2✔
2410
    #[allow(clippy::too_many_lines)]
2411
    async fn it_deletes_admin_dataset(app_ctx: PostgresContext<NoTls>) {
1✔
2412
        let dataset_name = DatasetName::new(None, "my_dataset");
1✔
2413

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

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

2469
        let session = app_ctx.default_session().await.unwrap();
1✔
2470

1✔
2471
        let db = app_ctx.session_context(session).db();
1✔
2472
        let dataset_id = db
1✔
2473
            .add_dataset(
1✔
2474
                AddDataset {
1✔
2475
                    name: Some(dataset_name),
1✔
2476
                    display_name: "Ogr Test".to_owned(),
1✔
2477
                    description: "desc".to_owned(),
1✔
2478
                    source_operator: "OgrSource".to_owned(),
1✔
2479
                    symbology: None,
1✔
2480
                    provenance: Some(vec![Provenance {
1✔
2481
                        citation: "citation".to_owned(),
1✔
2482
                        license: "license".to_owned(),
1✔
2483
                        uri: "uri".to_owned(),
1✔
2484
                    }]),
1✔
2485
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2486
                },
1✔
2487
                meta_data,
1✔
2488
            )
1✔
2489
            .await
1✔
2490
            .unwrap()
1✔
2491
            .id;
1✔
2492

1✔
2493
        assert!(db.load_dataset(&dataset_id).await.is_ok());
1✔
2494

2495
        db.delete_dataset(dataset_id).await.unwrap();
1✔
2496

1✔
2497
        assert!(db.load_dataset(&dataset_id).await.is_err());
1✔
2498
    }
1✔
2499

2500
    #[ge_context::test]
2✔
2501
    async fn test_missing_layer_dataset_in_collection_listing(app_ctx: PostgresContext<NoTls>) {
1✔
2502
        let session = app_ctx.default_session().await.unwrap();
1✔
2503
        let db = app_ctx.session_context(session).db();
1✔
2504

2505
        let root_collection_id = &db.get_root_layer_collection_id().await.unwrap();
1✔
2506

2507
        let top_collection_id = db
1✔
2508
            .add_layer_collection(
1✔
2509
                AddLayerCollection {
1✔
2510
                    name: "top collection".to_string(),
1✔
2511
                    description: "description".to_string(),
1✔
2512
                    properties: Default::default(),
1✔
2513
                },
1✔
2514
                root_collection_id,
1✔
2515
            )
1✔
2516
            .await
1✔
2517
            .unwrap();
1✔
2518

1✔
2519
        let faux_layer = LayerId("faux".to_string());
1✔
2520

1✔
2521
        // this should fail
1✔
2522
        db.add_layer_to_collection(&faux_layer, &top_collection_id)
1✔
2523
            .await
1✔
2524
            .unwrap_err();
1✔
2525

2526
        let root_collection_layers = db
1✔
2527
            .load_layer_collection(
1✔
2528
                &top_collection_id,
1✔
2529
                LayerCollectionListOptions {
1✔
2530
                    offset: 0,
1✔
2531
                    limit: 20,
1✔
2532
                },
1✔
2533
            )
1✔
2534
            .await
1✔
2535
            .unwrap();
1✔
2536

1✔
2537
        assert_eq!(
1✔
2538
            root_collection_layers,
1✔
2539
            LayerCollection {
1✔
2540
                id: ProviderLayerCollectionId {
1✔
2541
                    provider_id: DataProviderId(
1✔
2542
                        "ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74".try_into().unwrap()
1✔
2543
                    ),
1✔
2544
                    collection_id: top_collection_id.clone(),
1✔
2545
                },
1✔
2546
                name: "top collection".to_string(),
1✔
2547
                description: "description".to_string(),
1✔
2548
                items: vec![],
1✔
2549
                entry_label: None,
1✔
2550
                properties: vec![],
1✔
2551
            }
1✔
2552
        );
1✔
2553
    }
1✔
2554

2555
    #[allow(clippy::too_many_lines)]
2556
    #[ge_context::test]
2✔
2557
    async fn it_updates_project_layer_symbology(app_ctx: PostgresContext<NoTls>) {
1✔
2558
        let session = app_ctx.default_session().await.unwrap();
1✔
2559

2560
        let (_, workflow_id) = register_ndvi_workflow_helper(&app_ctx).await;
1✔
2561

2562
        let db = app_ctx.session_context(session.clone()).db();
1✔
2563

1✔
2564
        let create_project: CreateProject = serde_json::from_value(json!({
1✔
2565
            "name": "Default",
1✔
2566
            "description": "Default project",
1✔
2567
            "bounds": {
1✔
2568
                "boundingBox": {
1✔
2569
                    "lowerLeftCoordinate": {
1✔
2570
                        "x": -180,
1✔
2571
                        "y": -90
1✔
2572
                    },
1✔
2573
                    "upperRightCoordinate": {
1✔
2574
                        "x": 180,
1✔
2575
                        "y": 90
1✔
2576
                    }
1✔
2577
                },
1✔
2578
                "spatialReference": "EPSG:4326",
1✔
2579
                "timeInterval": {
1✔
2580
                    "start": 1_396_353_600_000i64,
1✔
2581
                    "end": 1_396_353_600_000i64
1✔
2582
                }
1✔
2583
            },
1✔
2584
            "timeStep": {
1✔
2585
                "step": 1,
1✔
2586
                "granularity": "months"
1✔
2587
            }
1✔
2588
        }))
1✔
2589
        .unwrap();
1✔
2590

2591
        let project_id = db.create_project(create_project).await.unwrap();
1✔
2592

1✔
2593
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2594
            "id": project_id.to_string(),
1✔
2595
            "layers": [{
1✔
2596
                "name": "NDVI",
1✔
2597
                "workflow": workflow_id.to_string(),
1✔
2598
                "visibility": {
1✔
2599
                    "data": true,
1✔
2600
                    "legend": false
1✔
2601
                },
1✔
2602
                "symbology": {
1✔
2603
                    "type": "raster",
1✔
2604
                    "opacity": 1,
1✔
2605
                    "rasterColorizer": {
1✔
2606
                        "type": "singleBand",
1✔
2607
                        "band": 0,
1✔
2608
                        "bandColorizer": {
1✔
2609
                            "type": "linearGradient",
1✔
2610
                            "breakpoints": [{
1✔
2611
                                "value": 1,
1✔
2612
                                "color": [0, 0, 0, 255]
1✔
2613
                            }, {
1✔
2614
                                "value": 255,
1✔
2615
                                "color": [255, 255, 255, 255]
1✔
2616
                            }],
1✔
2617
                            "noDataColor": [0, 0, 0, 0],
1✔
2618
                            "overColor": [255, 255, 255, 127],
1✔
2619
                            "underColor": [255, 255, 255, 127]
1✔
2620
                        }
1✔
2621
                    }
1✔
2622
                }
1✔
2623
            }]
1✔
2624
        }))
1✔
2625
        .unwrap();
1✔
2626

1✔
2627
        db.update_project(update).await.unwrap();
1✔
2628

1✔
2629
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2630
            "id": project_id.to_string(),
1✔
2631
            "layers": [{
1✔
2632
                "name": "NDVI",
1✔
2633
                "workflow": workflow_id.to_string(),
1✔
2634
                "visibility": {
1✔
2635
                    "data": true,
1✔
2636
                    "legend": false
1✔
2637
                },
1✔
2638
                "symbology": {
1✔
2639
                    "type": "raster",
1✔
2640
                    "opacity": 1,
1✔
2641
                    "rasterColorizer": {
1✔
2642
                        "type": "singleBand",
1✔
2643
                        "band": 0,
1✔
2644
                        "bandColorizer": {
1✔
2645
                            "type": "linearGradient",
1✔
2646
                            "breakpoints": [{
1✔
2647
                                "value": 1,
1✔
2648
                                "color": [0, 0, 4, 255]
1✔
2649
                            }, {
1✔
2650
                                "value": 17.866_666_666_666_667,
1✔
2651
                                "color": [11, 9, 36, 255]
1✔
2652
                            }, {
1✔
2653
                                "value": 34.733_333_333_333_334,
1✔
2654
                                "color": [32, 17, 75, 255]
1✔
2655
                            }, {
1✔
2656
                                "value": 51.6,
1✔
2657
                                "color": [59, 15, 112, 255]
1✔
2658
                            }, {
1✔
2659
                                "value": 68.466_666_666_666_67,
1✔
2660
                                "color": [87, 21, 126, 255]
1✔
2661
                            }, {
1✔
2662
                                "value": 85.333_333_333_333_33,
1✔
2663
                                "color": [114, 31, 129, 255]
1✔
2664
                            }, {
1✔
2665
                                "value": 102.199_999_999_999_99,
1✔
2666
                                "color": [140, 41, 129, 255]
1✔
2667
                            }, {
1✔
2668
                                "value": 119.066_666_666_666_65,
1✔
2669
                                "color": [168, 50, 125, 255]
1✔
2670
                            }, {
1✔
2671
                                "value": 135.933_333_333_333_34,
1✔
2672
                                "color": [196, 60, 117, 255]
1✔
2673
                            }, {
1✔
2674
                                "value": 152.799_999_999_999_98,
1✔
2675
                                "color": [222, 73, 104, 255]
1✔
2676
                            }, {
1✔
2677
                                "value": 169.666_666_666_666_66,
1✔
2678
                                "color": [241, 96, 93, 255]
1✔
2679
                            }, {
1✔
2680
                                "value": 186.533_333_333_333_33,
1✔
2681
                                "color": [250, 127, 94, 255]
1✔
2682
                            }, {
1✔
2683
                                "value": 203.399_999_999_999_98,
1✔
2684
                                "color": [254, 159, 109, 255]
1✔
2685
                            }, {
1✔
2686
                                "value": 220.266_666_666_666_65,
1✔
2687
                                "color": [254, 191, 132, 255]
1✔
2688
                            }, {
1✔
2689
                                "value": 237.133_333_333_333_3,
1✔
2690
                                "color": [253, 222, 160, 255]
1✔
2691
                            }, {
1✔
2692
                                "value": 254,
1✔
2693
                                "color": [252, 253, 191, 255]
1✔
2694
                            }],
1✔
2695
                            "noDataColor": [0, 0, 0, 0],
1✔
2696
                            "overColor": [255, 255, 255, 127],
1✔
2697
                            "underColor": [255, 255, 255, 127]
1✔
2698
                        }
1✔
2699
                    }
1✔
2700
                }
1✔
2701
            }]
1✔
2702
        }))
1✔
2703
        .unwrap();
1✔
2704

1✔
2705
        db.update_project(update).await.unwrap();
1✔
2706

1✔
2707
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2708
            "id": project_id.to_string(),
1✔
2709
            "layers": [{
1✔
2710
                "name": "NDVI",
1✔
2711
                "workflow": workflow_id.to_string(),
1✔
2712
                "visibility": {
1✔
2713
                    "data": true,
1✔
2714
                    "legend": false
1✔
2715
                },
1✔
2716
                "symbology": {
1✔
2717
                    "type": "raster",
1✔
2718
                    "opacity": 1,
1✔
2719
                    "rasterColorizer": {
1✔
2720
                        "type": "singleBand",
1✔
2721
                        "band": 0,
1✔
2722
                        "bandColorizer": {
1✔
2723
                            "type": "linearGradient",
1✔
2724
                            "breakpoints": [{
1✔
2725
                                "value": 1,
1✔
2726
                                "color": [0, 0, 4, 255]
1✔
2727
                            }, {
1✔
2728
                                "value": 17.866_666_666_666_667,
1✔
2729
                                "color": [11, 9, 36, 255]
1✔
2730
                            }, {
1✔
2731
                                "value": 34.733_333_333_333_334,
1✔
2732
                                "color": [32, 17, 75, 255]
1✔
2733
                            }, {
1✔
2734
                                "value": 51.6,
1✔
2735
                                "color": [59, 15, 112, 255]
1✔
2736
                            }, {
1✔
2737
                                "value": 68.466_666_666_666_67,
1✔
2738
                                "color": [87, 21, 126, 255]
1✔
2739
                            }, {
1✔
2740
                                "value": 85.333_333_333_333_33,
1✔
2741
                                "color": [114, 31, 129, 255]
1✔
2742
                            }, {
1✔
2743
                                "value": 102.199_999_999_999_99,
1✔
2744
                                "color": [140, 41, 129, 255]
1✔
2745
                            }, {
1✔
2746
                                "value": 119.066_666_666_666_65,
1✔
2747
                                "color": [168, 50, 125, 255]
1✔
2748
                            }, {
1✔
2749
                                "value": 135.933_333_333_333_34,
1✔
2750
                                "color": [196, 60, 117, 255]
1✔
2751
                            }, {
1✔
2752
                                "value": 152.799_999_999_999_98,
1✔
2753
                                "color": [222, 73, 104, 255]
1✔
2754
                            }, {
1✔
2755
                                "value": 169.666_666_666_666_66,
1✔
2756
                                "color": [241, 96, 93, 255]
1✔
2757
                            }, {
1✔
2758
                                "value": 186.533_333_333_333_33,
1✔
2759
                                "color": [250, 127, 94, 255]
1✔
2760
                            }, {
1✔
2761
                                "value": 203.399_999_999_999_98,
1✔
2762
                                "color": [254, 159, 109, 255]
1✔
2763
                            }, {
1✔
2764
                                "value": 220.266_666_666_666_65,
1✔
2765
                                "color": [254, 191, 132, 255]
1✔
2766
                            }, {
1✔
2767
                                "value": 237.133_333_333_333_3,
1✔
2768
                                "color": [253, 222, 160, 255]
1✔
2769
                            }, {
1✔
2770
                                "value": 254,
1✔
2771
                                "color": [252, 253, 191, 255]
1✔
2772
                            }],
1✔
2773
                            "noDataColor": [0, 0, 0, 0],
1✔
2774
                            "overColor": [255, 255, 255, 127],
1✔
2775
                            "underColor": [255, 255, 255, 127]
1✔
2776
                        }
1✔
2777
                    }
1✔
2778
                }
1✔
2779
            }]
1✔
2780
        }))
1✔
2781
        .unwrap();
1✔
2782

1✔
2783
        db.update_project(update).await.unwrap();
1✔
2784

1✔
2785
        let update: UpdateProject = serde_json::from_value(json!({
1✔
2786
            "id": project_id.to_string(),
1✔
2787
            "layers": [{
1✔
2788
                "name": "NDVI",
1✔
2789
                "workflow": workflow_id.to_string(),
1✔
2790
                "visibility": {
1✔
2791
                    "data": true,
1✔
2792
                    "legend": false
1✔
2793
                },
1✔
2794
                "symbology": {
1✔
2795
                    "type": "raster",
1✔
2796
                    "opacity": 1,
1✔
2797
                    "rasterColorizer": {
1✔
2798
                        "type": "singleBand",
1✔
2799
                        "band": 0,
1✔
2800
                        "bandColorizer": {
1✔
2801
                            "type": "linearGradient",
1✔
2802
                            "breakpoints": [{
1✔
2803
                                "value": 1,
1✔
2804
                                "color": [0, 0, 4, 255]
1✔
2805
                            }, {
1✔
2806
                                "value": 17.933_333_333_333_334,
1✔
2807
                                "color": [11, 9, 36, 255]
1✔
2808
                            }, {
1✔
2809
                                "value": 34.866_666_666_666_67,
1✔
2810
                                "color": [32, 17, 75, 255]
1✔
2811
                            }, {
1✔
2812
                                "value": 51.800_000_000_000_004,
1✔
2813
                                "color": [59, 15, 112, 255]
1✔
2814
                            }, {
1✔
2815
                                "value": 68.733_333_333_333_33,
1✔
2816
                                "color": [87, 21, 126, 255]
1✔
2817
                            }, {
1✔
2818
                                "value": 85.666_666_666_666_66,
1✔
2819
                                "color": [114, 31, 129, 255]
1✔
2820
                            }, {
1✔
2821
                                "value": 102.6,
1✔
2822
                                "color": [140, 41, 129, 255]
1✔
2823
                            }, {
1✔
2824
                                "value": 119.533_333_333_333_32,
1✔
2825
                                "color": [168, 50, 125, 255]
1✔
2826
                            }, {
1✔
2827
                                "value": 136.466_666_666_666_67,
1✔
2828
                                "color": [196, 60, 117, 255]
1✔
2829
                            }, {
1✔
2830
                                "value": 153.4,
1✔
2831
                                "color": [222, 73, 104, 255]
1✔
2832
                            }, {
1✔
2833
                                "value": 170.333_333_333_333_31,
1✔
2834
                                "color": [241, 96, 93, 255]
1✔
2835
                            }, {
1✔
2836
                                "value": 187.266_666_666_666_65,
1✔
2837
                                "color": [250, 127, 94, 255]
1✔
2838
                            }, {
1✔
2839
                                "value": 204.2,
1✔
2840
                                "color": [254, 159, 109, 255]
1✔
2841
                            }, {
1✔
2842
                                "value": 221.133_333_333_333_33,
1✔
2843
                                "color": [254, 191, 132, 255]
1✔
2844
                            }, {
1✔
2845
                                "value": 238.066_666_666_666_63,
1✔
2846
                                "color": [253, 222, 160, 255]
1✔
2847
                            }, {
1✔
2848
                                "value": 255,
1✔
2849
                                "color": [252, 253, 191, 255]
1✔
2850
                            }],
1✔
2851
                            "noDataColor": [0, 0, 0, 0],
1✔
2852
                            "overColor": [255, 255, 255, 127],
1✔
2853
                            "underColor": [255, 255, 255, 127]
1✔
2854
                        }
1✔
2855
                    }
1✔
2856
                }
1✔
2857
            }]
1✔
2858
        }))
1✔
2859
        .unwrap();
1✔
2860

2861
        // run two updates concurrently
2862
        let (r0, r1) = join!(db.update_project(update.clone()), db.update_project(update));
1✔
2863

2864
        assert!(r0.is_ok());
1✔
2865
        assert!(r1.is_ok());
1✔
2866
    }
1✔
2867

2868
    #[ge_context::test]
2✔
2869
    #[allow(clippy::too_many_lines)]
2870
    async fn it_resolves_dataset_names_to_ids(app_ctx: PostgresContext<NoTls>) {
1✔
2871
        let session = app_ctx.default_session().await.unwrap();
1✔
2872
        let db = app_ctx.session_context(session.clone()).db();
1✔
2873

1✔
2874
        let loading_info = OgrSourceDataset {
1✔
2875
            file_name: PathBuf::from("test.csv"),
1✔
2876
            layer_name: "test.csv".to_owned(),
1✔
2877
            data_type: Some(VectorDataType::MultiPoint),
1✔
2878
            time: OgrSourceDatasetTimeType::Start {
1✔
2879
                start_field: "start".to_owned(),
1✔
2880
                start_format: OgrSourceTimeFormat::Auto,
1✔
2881
                duration: OgrSourceDurationSpec::Zero,
1✔
2882
            },
1✔
2883
            default_geometry: None,
1✔
2884
            columns: Some(OgrSourceColumnSpec {
1✔
2885
                format_specifics: Some(FormatSpecifics::Csv {
1✔
2886
                    header: CsvHeader::Auto,
1✔
2887
                }),
1✔
2888
                x: "x".to_owned(),
1✔
2889
                y: None,
1✔
2890
                int: vec![],
1✔
2891
                float: vec![],
1✔
2892
                text: vec![],
1✔
2893
                bool: vec![],
1✔
2894
                datetime: vec![],
1✔
2895
                rename: None,
1✔
2896
            }),
1✔
2897
            force_ogr_time_filter: false,
1✔
2898
            force_ogr_spatial_filter: false,
1✔
2899
            on_error: OgrSourceErrorSpec::Ignore,
1✔
2900
            sql_query: None,
1✔
2901
            attribute_query: None,
1✔
2902
            cache_ttl: CacheTtlSeconds::default(),
1✔
2903
        };
1✔
2904

1✔
2905
        let meta_data = MetaDataDefinition::OgrMetaData(StaticMetaData::<
1✔
2906
            OgrSourceDataset,
1✔
2907
            VectorResultDescriptor,
1✔
2908
            VectorQueryRectangle,
1✔
2909
        > {
1✔
2910
            loading_info: loading_info.clone(),
1✔
2911
            result_descriptor: VectorResultDescriptor {
1✔
2912
                data_type: VectorDataType::MultiPoint,
1✔
2913
                spatial_reference: SpatialReference::epsg_4326().into(),
1✔
2914
                columns: [(
1✔
2915
                    "foo".to_owned(),
1✔
2916
                    VectorColumnInfo {
1✔
2917
                        data_type: FeatureDataType::Float,
1✔
2918
                        measurement: Measurement::Unitless,
1✔
2919
                    },
1✔
2920
                )]
1✔
2921
                .into_iter()
1✔
2922
                .collect(),
1✔
2923
                time: None,
1✔
2924
                bbox: None,
1✔
2925
            },
1✔
2926
            phantom: Default::default(),
1✔
2927
        });
1✔
2928

2929
        let DatasetIdAndName {
2930
            id: dataset_id1,
1✔
2931
            name: dataset_name1,
1✔
2932
        } = db
1✔
2933
            .add_dataset(
1✔
2934
                AddDataset {
1✔
2935
                    name: Some(DatasetName::new(None, "my_dataset".to_owned())),
1✔
2936
                    display_name: "Ogr Test".to_owned(),
1✔
2937
                    description: "desc".to_owned(),
1✔
2938
                    source_operator: "OgrSource".to_owned(),
1✔
2939
                    symbology: None,
1✔
2940
                    provenance: Some(vec![Provenance {
1✔
2941
                        citation: "citation".to_owned(),
1✔
2942
                        license: "license".to_owned(),
1✔
2943
                        uri: "uri".to_owned(),
1✔
2944
                    }]),
1✔
2945
                    tags: Some(vec!["upload".to_owned(), "test".to_owned()]),
1✔
2946
                },
1✔
2947
                meta_data.clone(),
1✔
2948
            )
1✔
2949
            .await
1✔
2950
            .unwrap();
1✔
2951

2952
        assert_eq!(
1✔
2953
            db.resolve_dataset_name_to_id(&dataset_name1)
1✔
2954
                .await
1✔
2955
                .unwrap()
1✔
2956
                .unwrap(),
1✔
2957
            dataset_id1
2958
        );
2959
    }
1✔
2960

2961
    #[ge_context::test]
2✔
2962
    #[allow(clippy::too_many_lines)]
2963
    async fn test_postgres_type_serialization(app_ctx: PostgresContext<NoTls>) {
1✔
2964
        let pool = app_ctx.pool.get().await.unwrap();
1✔
2965

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

2968
        assert_sql_type(
1✔
2969
            &pool,
1✔
2970
            "double precision",
1✔
2971
            [NotNanF64::from(NotNan::<f64>::new(1.0).unwrap())],
1✔
2972
        )
1✔
2973
        .await;
1✔
2974

2975
        assert_sql_type(
1✔
2976
            &pool,
1✔
2977
            "Breakpoint",
1✔
2978
            [Breakpoint {
1✔
2979
                value: NotNan::<f64>::new(1.0).unwrap(),
1✔
2980
                color: RgbaColor::new(0, 0, 0, 0),
1✔
2981
            }],
1✔
2982
        )
1✔
2983
        .await;
1✔
2984

2985
        assert_sql_type(
1✔
2986
            &pool,
1✔
2987
            "Colorizer",
1✔
2988
            [
1✔
2989
                Colorizer::LinearGradient {
1✔
2990
                    breakpoints: vec![
1✔
2991
                        Breakpoint {
1✔
2992
                            value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
2993
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
2994
                        },
1✔
2995
                        Breakpoint {
1✔
2996
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
2997
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
2998
                        },
1✔
2999
                    ],
1✔
3000
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3001
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3002
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3003
                },
1✔
3004
                Colorizer::LogarithmicGradient {
1✔
3005
                    breakpoints: vec![
1✔
3006
                        Breakpoint {
1✔
3007
                            value: NotNan::<f64>::new(1.0).unwrap(),
1✔
3008
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
3009
                        },
1✔
3010
                        Breakpoint {
1✔
3011
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
3012
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
3013
                        },
1✔
3014
                    ],
1✔
3015
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3016
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3017
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3018
                },
1✔
3019
                Colorizer::palette(
1✔
3020
                    [
1✔
3021
                        (NotNan::<f64>::new(1.0).unwrap(), RgbaColor::new(0, 0, 0, 0)),
1✔
3022
                        (
1✔
3023
                            NotNan::<f64>::new(2.0).unwrap(),
1✔
3024
                            RgbaColor::new(255, 0, 0, 255),
1✔
3025
                        ),
1✔
3026
                        (
1✔
3027
                            NotNan::<f64>::new(3.0).unwrap(),
1✔
3028
                            RgbaColor::new(0, 10, 20, 30),
1✔
3029
                        ),
1✔
3030
                    ]
1✔
3031
                    .into(),
1✔
3032
                    RgbaColor::new(1, 2, 3, 4),
1✔
3033
                    RgbaColor::new(5, 6, 7, 8),
1✔
3034
                )
1✔
3035
                .unwrap(),
1✔
3036
            ],
1✔
3037
        )
1✔
3038
        .await;
1✔
3039

3040
        assert_sql_type(
1✔
3041
            &pool,
1✔
3042
            "ColorParam",
1✔
3043
            [
1✔
3044
                ColorParam::Static {
1✔
3045
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3046
                },
1✔
3047
                ColorParam::Derived(DerivedColor {
1✔
3048
                    attribute: "foobar".to_string(),
1✔
3049
                    colorizer: Colorizer::test_default(),
1✔
3050
                }),
1✔
3051
            ],
1✔
3052
        )
1✔
3053
        .await;
1✔
3054

3055
        assert_sql_type(
1✔
3056
            &pool,
1✔
3057
            "NumberParam",
1✔
3058
            [
1✔
3059
                NumberParam::Static { value: 42 },
1✔
3060
                NumberParam::Derived(DerivedNumber {
1✔
3061
                    attribute: "foobar".to_string(),
1✔
3062
                    factor: 1.0,
1✔
3063
                    default_value: 42.,
1✔
3064
                }),
1✔
3065
            ],
1✔
3066
        )
1✔
3067
        .await;
1✔
3068

3069
        assert_sql_type(
1✔
3070
            &pool,
1✔
3071
            "StrokeParam",
1✔
3072
            [StrokeParam {
1✔
3073
                width: NumberParam::Static { value: 42 },
1✔
3074
                color: ColorParam::Static {
1✔
3075
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3076
                },
1✔
3077
            }],
1✔
3078
        )
1✔
3079
        .await;
1✔
3080

3081
        assert_sql_type(
1✔
3082
            &pool,
1✔
3083
            "TextSymbology",
1✔
3084
            [TextSymbology {
1✔
3085
                attribute: "attribute".to_string(),
1✔
3086
                fill_color: ColorParam::Static {
1✔
3087
                    color: RgbaColor::new(0, 10, 20, 30),
1✔
3088
                },
1✔
3089
                stroke: StrokeParam {
1✔
3090
                    width: NumberParam::Static { value: 42 },
1✔
3091
                    color: ColorParam::Static {
1✔
3092
                        color: RgbaColor::new(0, 10, 20, 30),
1✔
3093
                    },
1✔
3094
                },
1✔
3095
            }],
1✔
3096
        )
1✔
3097
        .await;
1✔
3098

3099
        assert_sql_type(
1✔
3100
            &pool,
1✔
3101
            "RasterColorizer",
1✔
3102
            [RasterColorizer::SingleBand {
1✔
3103
                band: 0,
1✔
3104
                band_colorizer: Colorizer::LinearGradient {
1✔
3105
                    breakpoints: vec![
1✔
3106
                        Breakpoint {
1✔
3107
                            value: NotNan::<f64>::new(-10.0).unwrap(),
1✔
3108
                            color: RgbaColor::new(0, 0, 0, 0),
1✔
3109
                        },
1✔
3110
                        Breakpoint {
1✔
3111
                            value: NotNan::<f64>::new(2.0).unwrap(),
1✔
3112
                            color: RgbaColor::new(255, 0, 0, 255),
1✔
3113
                        },
1✔
3114
                    ],
1✔
3115
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3116
                    over_color: RgbaColor::new(1, 2, 3, 4),
1✔
3117
                    under_color: RgbaColor::new(5, 6, 7, 8),
1✔
3118
                },
1✔
3119
            }],
1✔
3120
        )
1✔
3121
        .await;
1✔
3122

3123
        assert_sql_type(
1✔
3124
            &pool,
1✔
3125
            "RasterColorizer",
1✔
3126
            [RasterColorizer::MultiBand {
1✔
3127
                red_band: 0,
1✔
3128
                green_band: 1,
1✔
3129
                blue_band: 2,
1✔
3130
                rgb_params: RgbParams {
1✔
3131
                    red_min: 0.,
1✔
3132
                    red_max: 255.,
1✔
3133
                    red_scale: 1.,
1✔
3134
                    green_min: 0.,
1✔
3135
                    green_max: 255.,
1✔
3136
                    green_scale: 1.,
1✔
3137
                    blue_min: 0.,
1✔
3138
                    blue_max: 255.,
1✔
3139
                    blue_scale: 1.,
1✔
3140
                    no_data_color: RgbaColor::new(0, 10, 20, 30),
1✔
3141
                },
1✔
3142
            }],
1✔
3143
        )
1✔
3144
        .await;
1✔
3145

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

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

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

3279
        assert_sql_type(&pool, "Coordinate2D", [Coordinate2D::new(0.0f64, 1.)]).await;
1✔
3280

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

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

3301
        assert_sql_type(
1✔
3302
            &pool,
1✔
3303
            "SpatialResolution",
1✔
3304
            [SpatialResolution { x: 1.2, y: 2.3 }],
1✔
3305
        )
1✔
3306
        .await;
1✔
3307

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

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

3334
        assert_sql_type(&pool, "TimeInterval", [TimeInterval::default()]).await;
1✔
3335

3336
        assert_sql_type(
1✔
3337
            &pool,
1✔
3338
            "SpatialReference",
1✔
3339
            [
1✔
3340
                SpatialReferenceOption::Unreferenced,
1✔
3341
                SpatialReferenceOption::SpatialReference(SpatialReference::epsg_4326()),
1✔
3342
            ],
1✔
3343
        )
1✔
3344
        .await;
1✔
3345

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3670
        assert_sql_type(&pool, "int", [CacheTtlSeconds::new(100)]).await;
1✔
3671

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

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

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

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

3844
        assert_sql_type(
1✔
3845
            &pool,
1✔
3846
            "FileNotFoundHandling",
1✔
3847
            [FileNotFoundHandling::NoData, FileNotFoundHandling::Error],
1✔
3848
        )
1✔
3849
        .await;
1✔
3850

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

3868
        assert_sql_type(
1✔
3869
            &pool,
1✔
3870
            "StringPair",
1✔
3871
            [StringPair::from(("foo".to_string(), "bar".to_string()))],
1✔
3872
        )
1✔
3873
        .await;
1✔
3874

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

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

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

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

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

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

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

4517
        test_data_provider_definition_types(&pool).await;
1✔
4518
    }
1✔
4519

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

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

1✔
4537
        let pg_config = Config::try_from(db_config).unwrap();
1✔
4538

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

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

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

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

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

4639
        assert_sql_type(pool, "\"PropertyType\"[]", [Vec::<Property>::new()]).await;
1✔
4640

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

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

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

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

© 2026 Coveralls, Inc