Search in sources :

Example 1 with Datetime

use of com.github.sebastianfrey.joa.models.Datetime in project joa by sebastianfrey.

the class GeoPackageQuery method buildDatetimeWhere.

public void buildDatetimeWhere(StringBuilder whereBuilder, List<String> whereArgs) {
    // verify datetime
    Datetime datetime = query.getDatetime();
    if (datetime == null) {
        return;
    }
    // get all datetime columns
    List<FeatureColumn> columns = featureDao.getColumns().stream().filter((column) -> {
        return column.getDataType().equals(GeoPackageDataType.DATETIME);
    }).toList();
    if (columns.isEmpty()) {
        return;
    }
    for (FeatureColumn column : columns) {
        whereBuilder.append(" AND (").append(column.getName());
        switch(datetime.getType()) {
            case DATETIME:
                whereBuilder.append(" =  ?");
                whereArgs.add(datetime.getLower());
                break;
            case INTERVAL_CLOSED:
                whereBuilder.append(" BETWEEN ? AND ?");
                whereArgs.add(datetime.getLower());
                whereArgs.add(datetime.getUpper());
                break;
            case INTERVAL_OPEN_START:
                whereBuilder.append(" <= ?");
                whereArgs.add(datetime.getUpper());
                break;
            case INTERVAL_OPEN_END:
                whereBuilder.append(" >= ?");
                whereArgs.add(datetime.getLower());
                break;
        }
        whereBuilder.append(")");
    }
}
Also used : Bbox(com.github.sebastianfrey.joa.models.Bbox) Position(mil.nga.sf.geojson.Position) FeatureColumn(mil.nga.geopackage.features.user.FeatureColumn) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) GeoPackageDataType(mil.nga.geopackage.db.GeoPackageDataType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FeatureQuery(com.github.sebastianfrey.joa.models.FeatureQuery) Polygon(mil.nga.sf.geojson.Polygon) FeatureResultSet(mil.nga.geopackage.features.user.FeatureResultSet) ArrayList(java.util.ArrayList) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) Datetime(com.github.sebastianfrey.joa.models.Datetime) FeatureColumn(mil.nga.geopackage.features.user.FeatureColumn) Datetime(com.github.sebastianfrey.joa.models.Datetime)

Example 2 with Datetime

use of com.github.sebastianfrey.joa.models.Datetime in project joa by sebastianfrey.

the class GeoPackageServiceTest method should_return_items_from_collection.

@Test
public void should_return_items_from_collection() throws Exception {
    FeatureQueryRequest query = new FeatureQueryRequest().offset(Long.valueOf(0)).limit(10).datetime(new Datetime("2021-03-04T17:44:25.873Z")).bbox(new Bbox().minX(-180.0).minY(-90.0).maxX(80.0).maxY(90.0));
    GeoPackageItems items = geoPackageService.getItems(TEST_SERVICE, TEST_COLLECTION_POINT, query);
    assertThat(items).isNotNull();
    assertThat(items.getServiceId()).isEqualTo("example");
    assertThat(items.getCollectionId()).isEqualTo("point1");
    assertThat(items.getFeatures()).isNotEmpty();
    assertThat(items.getNumberMatched()).isGreaterThan(Long.valueOf(0));
    assertThat(items.getNumberReturned()).isGreaterThan(0);
    assertThatCode(() -> Instant.parse(items.getTimeStamp())).doesNotThrowAnyException();
}
Also used : FeatureQueryRequest(com.github.sebastianfrey.joa.resources.request.FeatureQueryRequest) Bbox(com.github.sebastianfrey.joa.models.Bbox) Datetime(com.github.sebastianfrey.joa.models.Datetime) Test(org.junit.jupiter.api.Test)

Aggregations

Bbox (com.github.sebastianfrey.joa.models.Bbox)2 Datetime (com.github.sebastianfrey.joa.models.Datetime)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FeatureQuery (com.github.sebastianfrey.joa.models.FeatureQuery)1 FeatureQueryRequest (com.github.sebastianfrey.joa.resources.request.FeatureQueryRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 GeoPackageDataType (mil.nga.geopackage.db.GeoPackageDataType)1 FeatureColumn (mil.nga.geopackage.features.user.FeatureColumn)1 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)1 FeatureResultSet (mil.nga.geopackage.features.user.FeatureResultSet)1 Polygon (mil.nga.sf.geojson.Polygon)1 Position (mil.nga.sf.geojson.Position)1 Test (org.junit.jupiter.api.Test)1