Search in sources :

Example 1 with Queryables

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

the class OGCAPIServiceResourceTest method setup.

@BeforeEach
void setup() {
    queryables = new Queryables();
    service = new Service().serviceId("service1").title("service1 title").description("service1 description");
    services = new Services().service(service);
    bbox = new Bbox().minX(-104.807496).minY(39.71408499999999).maxX(-104.79948).maxY(39.72001399999999);
    spatial = new Spatial().bbox(bbox).crs(CrsUtils.crs84());
    collection = new Collection().serviceId("service1").collectionId("collection1").crs(CrsUtils.crs84()).spatial(spatial).title("collection1 title").description("collection1 description");
    collections = new Collections().serviceId("serviceId").title("collections title").collection(collection);
    items = new TestItems().serviceId("service1").collectionId("collection1").numberMatched(Long.valueOf(0));
    item = new TestItem().serviceId("service1").collectionId("collection1");
    conformance = new Conformance().serviceId("service1").conformsTo(Conformance.FEATURES_CORE).conformsTo(Conformance.FEATURES_GEOJSON).conformsTo(Conformance.FEATURES_OAS30);
}
Also used : Queryables(com.github.sebastianfrey.joa.models.Queryables) Services(com.github.sebastianfrey.joa.models.Services) Spatial(com.github.sebastianfrey.joa.models.Spatial) Bbox(com.github.sebastianfrey.joa.models.Bbox) OGCAPIService(com.github.sebastianfrey.joa.services.OGCAPIService) Service(com.github.sebastianfrey.joa.models.Service) Collection(com.github.sebastianfrey.joa.models.Collection) Conformance(com.github.sebastianfrey.joa.models.Conformance) Collections(com.github.sebastianfrey.joa.models.Collections) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Queryables

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

the class GeoPackageServiceTest method should_return_queryables_from_collection_of_lines.

@Test
public void should_return_queryables_from_collection_of_lines() {
    Queryables queryables = geoPackageService.getQueryables(TEST_SERVICE, TEST_COLLECTION_LINE);
    assertThat(queryables).isNotNull();
    assertThat(queryables.getServiceId()).isEqualTo("example");
    assertThat(queryables.getCollectionId()).isEqualTo("line1");
    assertThat(queryables.getSchema()).satisfies((schema) -> {
        assertThat(schema.getProperties()).isNotEmpty();
        assertThat(schema.getProperties()).containsKey("geometry");
        assertThat(schema.getProperties()).containsValue(Schemas.GeoJSON.lineString());
    });
}
Also used : Queryables(com.github.sebastianfrey.joa.models.Queryables) Test(org.junit.jupiter.api.Test)

Example 3 with Queryables

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

the class GeoPackageServiceTest method should_return_queryables_from_collection_of_points.

@Test
public void should_return_queryables_from_collection_of_points() {
    Queryables queryables = geoPackageService.getQueryables(TEST_SERVICE, TEST_COLLECTION_POINT);
    assertThat(queryables).isNotNull();
    assertThat(queryables.getServiceId()).isEqualTo("example");
    assertThat(queryables.getCollectionId()).isEqualTo("point1");
    assertThat(queryables.getSchema()).satisfies((schema) -> {
        assertThat(schema.getProperties()).isNotEmpty();
        assertThat(schema.getProperties()).containsKey("geometry");
        assertThat(schema.getProperties()).containsValue(Schemas.GeoJSON.point());
    });
}
Also used : Queryables(com.github.sebastianfrey.joa.models.Queryables) Test(org.junit.jupiter.api.Test)

Example 4 with Queryables

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

the class GeoPackageService method getQueryables.

@Override
public Queryables getQueryables(String serviceId, String collectionId) {
    try (GeoPackage gpkg = loadService(serviceId)) {
        ObjectType schema = JSONSchemaBuilder.objectType().title(collectionId).schema(Schemas.DRAFT_2019_09);
        FeatureDao featureDao = loadCollection(gpkg, collectionId);
        String geometryColumn = featureDao.getGeometryColumnName();
        featureDao.getColumns().stream().forEach((column) -> {
            if (column.isGeometry()) {
                return;
            }
            Long max = column.getMax();
            Object defaultValue = column.getDefaultValue();
            GenericType<?> type = null;
            switch(column.getDataType()) {
                case BOOLEAN:
                    type = JSONSchemaBuilder.booleanType();
                    break;
                case BLOB:
                case TINYINT:
                case TEXT:
                    type = JSONSchemaBuilder.stringType().maxLength(max);
                    break;
                case DATE:
                    type = JSONSchemaBuilder.stringType().maxLength(max).format("date");
                    break;
                case DATETIME:
                    type = JSONSchemaBuilder.stringType().maxLength(max).format("date-time");
                    break;
                case DOUBLE:
                case FLOAT:
                case REAL:
                    type = JSONSchemaBuilder.numberType();
                    break;
                case INT:
                case INTEGER:
                case MEDIUMINT:
                case SMALLINT:
                    type = JSONSchemaBuilder.integerType().maximum(max);
                    break;
                default:
                    break;
            }
            if (type == null) {
                return;
            }
            String columnName = column.getName();
            type.title(columnName);
            if (defaultValue != null) {
                type.defaultValue(defaultValue.toString());
            }
            schema.property(columnName, type);
        });
        GeometryType geometryType = featureDao.getGeometryType();
        JSONSchema geometrySchema = null;
        switch(geometryType) {
            case GEOMETRY:
                geometrySchema = Schemas.GeoJSON.geometry();
                break;
            case POINT:
                geometrySchema = Schemas.GeoJSON.point();
                break;
            case LINESTRING:
                geometrySchema = Schemas.GeoJSON.lineString();
                break;
            case POLYGON:
                geometrySchema = Schemas.GeoJSON.polygon();
                break;
            case MULTIPOINT:
                geometrySchema = Schemas.GeoJSON.multiPoint();
                break;
            case MULTILINESTRING:
                geometrySchema = Schemas.GeoJSON.multiLineString();
                break;
            case MULTIPOLYGON:
                geometrySchema = Schemas.GeoJSON.multiPolygon();
                break;
            default:
                break;
        }
        if (geometrySchema != null) {
            schema.property(geometryColumn, geometrySchema);
        }
        return new Queryables().serviceId(serviceId).collectionId(collectionId).schema(schema);
    }
}
Also used : ObjectType(com.github.sebastianfrey.joa.models.schema.type.ObjectType) GeometryType(mil.nga.sf.GeometryType) Queryables(com.github.sebastianfrey.joa.models.Queryables) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) JSONSchema(com.github.sebastianfrey.joa.models.schema.JSONSchema) GeoPackage(mil.nga.geopackage.GeoPackage)

Example 5 with Queryables

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

the class GeoPackageServiceTest method should_return_queryables_from_collection_of_polygons.

@Test
public void should_return_queryables_from_collection_of_polygons() {
    Queryables queryables = geoPackageService.getQueryables(TEST_SERVICE, TEST_COLLECTION_POLYGON);
    assertThat(queryables).isNotNull();
    assertThat(queryables.getServiceId()).isEqualTo("example");
    assertThat(queryables.getCollectionId()).isEqualTo("polygon1");
    assertThat(queryables.getSchema()).satisfies((schema) -> {
        assertThat(schema.getProperties()).isNotEmpty();
        assertThat(schema.getProperties()).containsKey("geometry");
        assertThat(schema.getProperties()).containsValue(Schemas.GeoJSON.polygon());
    });
}
Also used : Queryables(com.github.sebastianfrey.joa.models.Queryables) Test(org.junit.jupiter.api.Test)

Aggregations

Queryables (com.github.sebastianfrey.joa.models.Queryables)5 Test (org.junit.jupiter.api.Test)3 Bbox (com.github.sebastianfrey.joa.models.Bbox)1 Collection (com.github.sebastianfrey.joa.models.Collection)1 Collections (com.github.sebastianfrey.joa.models.Collections)1 Conformance (com.github.sebastianfrey.joa.models.Conformance)1 Service (com.github.sebastianfrey.joa.models.Service)1 Services (com.github.sebastianfrey.joa.models.Services)1 Spatial (com.github.sebastianfrey.joa.models.Spatial)1 JSONSchema (com.github.sebastianfrey.joa.models.schema.JSONSchema)1 ObjectType (com.github.sebastianfrey.joa.models.schema.type.ObjectType)1 OGCAPIService (com.github.sebastianfrey.joa.services.OGCAPIService)1 GeoPackage (mil.nga.geopackage.GeoPackage)1 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)1 GeometryType (mil.nga.sf.GeometryType)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1