Search in sources :

Example 1 with JsonSchemaDocument

use of de.ii.ogcapi.features.core.domain.JsonSchemaDocument in project ldproxy by interactive-instruments.

the class TilesHelper method buildTileSet.

// TODO: move to TileSet as static of()
/**
 * generate the tile set metadata according to the OGC Tile Matrix Set standard (version 2.0.0, draft from June 2021)
 * @param api the API
 * @param tileMatrixSet the tile matrix set
 * @param zoomLevels the range of zoom levels
 * @param center the center point
 * @param collectionId the collection, empty = all collections in the dataset
 * @param dataType vector, map or coverage
 * @param links links to include in the object
 * @param uriCustomizer optional URI of the resource
 * @param limitsGenerator helper to generate the limits for each zoom level based on the bbox of the data
 * @param providers helper to access feature providers
 * @return the tile set metadata
 */
public static TileSet buildTileSet(OgcApi api, TileMatrixSet tileMatrixSet, MinMax zoomLevels, List<Double> center, Optional<String> collectionId, TileSet.DataType dataType, List<Link> links, Optional<URICustomizer> uriCustomizer, CrsTransformerFactory crsTransformerFactory, TileMatrixSetLimitsGenerator limitsGenerator, FeaturesCoreProviders providers, EntityRegistry entityRegistry) {
    OgcApiDataV2 apiData = api.getData();
    Builder builder = ImmutableTileSet.builder().dataType(dataType);
    builder.tileMatrixSetId(tileMatrixSet.getId());
    if (tileMatrixSet.getURI().isPresent())
        builder.tileMatrixSetURI(tileMatrixSet.getURI().get().toString());
    else
        builder.tileMatrixSet(tileMatrixSet.getTileMatrixSetData());
    uriCustomizer.ifPresent(uriCustomizer1 -> builder.tileMatrixSetDefinition(uriCustomizer1.removeLastPathSegments(collectionId.isPresent() ? 3 : 1).clearParameters().ensureLastPathSegments("tileMatrixSets", tileMatrixSet.getId()).toString()));
    if (Objects.isNull(zoomLevels))
        builder.tileMatrixSetLimits(ImmutableList.of());
    else
        builder.tileMatrixSetLimits(collectionId.isPresent() ? limitsGenerator.getCollectionTileMatrixSetLimits(api, collectionId.get(), tileMatrixSet, zoomLevels) : limitsGenerator.getTileMatrixSetLimits(api, tileMatrixSet, zoomLevels));
    try {
        BoundingBox boundingBox = api.getSpatialExtent(collectionId).orElse(tileMatrixSet.getBoundingBoxCrs84(crsTransformerFactory));
        builder.boundingBox(ImmutableTilesBoundingBox.builder().lowerLeft(BigDecimal.valueOf(boundingBox.getXmin()).setScale(7, RoundingMode.HALF_UP), BigDecimal.valueOf(boundingBox.getYmin()).setScale(7, RoundingMode.HALF_UP)).upperRight(BigDecimal.valueOf(boundingBox.getXmax()).setScale(7, RoundingMode.HALF_UP), BigDecimal.valueOf(boundingBox.getYmax()).setScale(7, RoundingMode.HALF_UP)).crs(OgcCrs.CRS84.toUriString()).build());
    } catch (CrsTransformationException e) {
    // ignore, just skip the boundingBox
    }
    if ((Objects.nonNull(zoomLevels) && zoomLevels.getDefault().isPresent()) || !center.isEmpty()) {
        ImmutableTilePoint.Builder builder2 = new ImmutableTilePoint.Builder();
        if (Objects.nonNull(zoomLevels))
            zoomLevels.getDefault().ifPresent(def -> builder2.tileMatrix(String.valueOf(def)));
        if (!center.isEmpty())
            builder2.coordinates(center);
        builder.centerPoint(builder2.build());
    }
    // prepare a map with the JSON schemas of the feature collections used in the style
    JsonSchemaCache schemas = new SchemaCacheTileSet(() -> entityRegistry.getEntitiesForType(Codelist.class));
    Map<String, JsonSchemaDocument> schemaMap = collectionId.isPresent() ? apiData.getCollectionData(collectionId.get()).filter(collectionData -> {
        Optional<TilesConfiguration> config = collectionData.getExtension(TilesConfiguration.class);
        return collectionData.getEnabled() && config.isPresent() && config.get().isEnabled();
    }).map(collectionData -> {
        Optional<FeatureSchema> schema = providers.getFeatureSchema(apiData, collectionData);
        if (schema.isPresent())
            return ImmutableMap.of(collectionId.get(), schemas.getSchema(schema.get(), apiData, collectionData, Optional.empty()));
        return null;
    }).filter(Objects::nonNull).orElse(ImmutableMap.of()) : apiData.getCollections().entrySet().stream().filter(entry -> {
        Optional<TilesConfiguration> config = entry.getValue().getExtension(TilesConfiguration.class);
        return entry.getValue().getEnabled() && config.isPresent() && config.get().isMultiCollectionEnabled();
    }).map(entry -> {
        Optional<FeatureSchema> schema = providers.getFeatureSchema(apiData, entry.getValue());
        if (schema.isPresent())
            return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), schemas.getSchema(schema.get(), apiData, entry.getValue(), Optional.empty()));
        return null;
    }).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
    // TODO: replace with SchemaDeriverTileLayers
    schemaMap.entrySet().stream().forEach(entry -> {
        String collectionId2 = entry.getKey();
        FeatureTypeConfigurationOgcApi collectionData = apiData.getCollections().get(collectionId2);
        JsonSchemaDocument schema = entry.getValue();
        ImmutableTileLayer.Builder builder2 = ImmutableTileLayer.builder().id(collectionId2).title(collectionData.getLabel()).description(collectionData.getDescription()).dataType(dataType);
        collectionData.getExtension(TilesConfiguration.class).map(config -> config.getZoomLevelsDerived().get(tileMatrixSet.getId())).ifPresent(minmax -> builder2.minTileMatrix(String.valueOf(minmax.getMin())).maxTileMatrix(String.valueOf(minmax.getMax())));
        final JsonSchema geometry = schema.getProperties().get("geometry");
        if (Objects.nonNull(geometry)) {
            String geomAsString = geometry.toString();
            boolean point = geomAsString.contains("GeoJSON Point") || geomAsString.contains("GeoJSON MultiPoint");
            boolean line = geomAsString.contains("GeoJSON LineString") || geomAsString.contains("GeoJSON MultiLineString");
            boolean polygon = geomAsString.contains("GeoJSON Polygon") || geomAsString.contains("GeoJSON MultiPolygon");
            if (point && !line && !polygon)
                builder2.geometryType(TileLayer.GeometryType.points);
            else if (!point && line && !polygon)
                builder2.geometryType(TileLayer.GeometryType.lines);
            else if (!point && !line && polygon)
                builder2.geometryType(TileLayer.GeometryType.polygons);
        }
        final JsonSchemaObject properties = (JsonSchemaObject) schema.getProperties().get("properties");
        builder2.propertiesSchema(ImmutableJsonSchemaObject.builder().required(properties.getRequired()).properties(properties.getProperties()).patternProperties(properties.getPatternProperties()).build());
        builder.addLayers(builder2.build());
    });
    builder.links(links);
    return builder.build();
}
Also used : ImmutableTileSet(de.ii.ogcapi.tiles.domain.ImmutableTileSet) SimpleFeatureGeometry(de.ii.xtraplatform.geometries.domain.SimpleFeatureGeometry) CrsTransformationException(de.ii.xtraplatform.crs.domain.CrsTransformationException) Link(de.ii.ogcapi.foundation.domain.Link) LoggerFactory(org.slf4j.LoggerFactory) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) JsonSchemaObject(de.ii.ogcapi.features.core.domain.JsonSchemaObject) VectorLayer(de.ii.ogcapi.tiles.domain.VectorLayer) TileLayer(de.ii.ogcapi.tiles.domain.TileLayer) BigDecimal(java.math.BigDecimal) JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) Locale(java.util.Locale) Map(java.util.Map) JsonSchemaCache(de.ii.ogcapi.features.core.domain.JsonSchemaCache) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) RoundingMode(java.math.RoundingMode) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableVectorLayer(de.ii.ogcapi.tiles.domain.ImmutableVectorLayer) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) Collectors(java.util.stream.Collectors) TilePoint(de.ii.ogcapi.tiles.domain.TilePoint) Objects(java.util.Objects) List(java.util.List) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) Optional(java.util.Optional) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) TileMatrixSetLimits(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimits) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) TileSet(de.ii.ogcapi.tiles.domain.TileSet) AtomicReference(java.util.concurrent.atomic.AtomicReference) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) ImmutableTileLayer(de.ii.ogcapi.tiles.domain.ImmutableTileLayer) ImmutableTilePoint(de.ii.ogcapi.tiles.domain.ImmutableTilePoint) TileMatrixSetLimitsGenerator(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimitsGenerator) SchemaBase(de.ii.xtraplatform.features.domain.SchemaBase) ImmutableList(com.google.common.collect.ImmutableList) OgcCrs(de.ii.xtraplatform.crs.domain.OgcCrs) ImmutableFields(de.ii.ogcapi.tiles.domain.ImmutableFields) Builder(de.ii.ogcapi.tiles.domain.ImmutableTileSet.Builder) Logger(org.slf4j.Logger) ImmutableJsonSchemaObject(de.ii.ogcapi.features.core.domain.ImmutableJsonSchemaObject) MinMax(de.ii.ogcapi.tiles.domain.MinMax) TilesBoundingBox(de.ii.ogcapi.tiles.domain.tileMatrixSet.TilesBoundingBox) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) GeoJsonConfiguration(de.ii.ogcapi.features.geojson.domain.GeoJsonConfiguration) JsonSchema(de.ii.ogcapi.features.core.domain.JsonSchema) ImmutableTilesBoundingBox(de.ii.ogcapi.tiles.domain.tileMatrixSet.ImmutableTilesBoundingBox) AbstractMap(java.util.AbstractMap) SchemaInfo(de.ii.ogcapi.features.core.domain.SchemaInfo) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) Builder(de.ii.ogcapi.tiles.domain.ImmutableTileSet.Builder) JsonSchema(de.ii.ogcapi.features.core.domain.JsonSchema) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) ImmutableTilePoint(de.ii.ogcapi.tiles.domain.ImmutableTilePoint) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) ImmutableTileLayer(de.ii.ogcapi.tiles.domain.ImmutableTileLayer) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) TilesBoundingBox(de.ii.ogcapi.tiles.domain.tileMatrixSet.TilesBoundingBox) ImmutableTilesBoundingBox(de.ii.ogcapi.tiles.domain.tileMatrixSet.ImmutableTilesBoundingBox) JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) Optional(java.util.Optional) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) JsonSchemaCache(de.ii.ogcapi.features.core.domain.JsonSchemaCache) CrsTransformationException(de.ii.xtraplatform.crs.domain.CrsTransformationException) Objects(java.util.Objects) JsonSchemaObject(de.ii.ogcapi.features.core.domain.JsonSchemaObject) ImmutableJsonSchemaObject(de.ii.ogcapi.features.core.domain.ImmutableJsonSchemaObject)

Example 2 with JsonSchemaDocument

use of de.ii.ogcapi.features.core.domain.JsonSchemaDocument in project ldproxy by interactive-instruments.

the class QueriesHandlerSchemaImpl method getSchemaResponse.

private Response getSchemaResponse(QueryInputSchema queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    String collectionId = queryInput.getCollectionId();
    checkCollectionId(apiData, collectionId);
    FeatureTypeConfigurationOgcApi collectionData = apiData.getCollections().get(collectionId);
    SchemaFormatExtension outputFormat = api.getOutputFormat(SchemaFormatExtension.class, requestContext.getMediaType(), "/collections/" + collectionId + "/schemas/" + queryInput.getType(), Optional.of(collectionId)).orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported for this resource.", requestContext.getMediaType())));
    List<ApiMediaType> alternateMediaTypes = requestContext.getAlternateMediaTypes();
    List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), alternateMediaTypes, i18n, requestContext.getLanguage());
    Optional<String> schemaUri = links.stream().filter(link -> Objects.equals(link.getRel(), "self")).map(Link::getHref).findAny();
    FeatureSchema featureSchema = providers.getFeatureSchema(apiData, collectionData).orElse(new ImmutableFeatureSchema.Builder().name(collectionId).type(SchemaBase.Type.OBJECT).build());
    JsonSchemaDocument schema = null;
    if (queryInput.getType().equals("feature"))
        schema = schemaCache.getSchema(featureSchema, apiData, collectionData, schemaUri, getVersion(queryInput.getProfile()));
    else if (queryInput.getType().equals("collection"))
        schema = schemaCacheCollection.getSchema(featureSchema, apiData, collectionData, schemaUri, getVersion(queryInput.getProfile()));
    Date lastModified = getLastModified(queryInput, api);
    EntityTag etag = !outputFormat.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE) || apiData.getExtension(HtmlConfiguration.class, collectionId).map(HtmlConfiguration::getSendEtags).orElse(false) ? getEtag(schema, JsonSchema.FUNNEL, outputFormat) : null;
    Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
    if (Objects.nonNull(response))
        return response.build();
    return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? links : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("%s.schema.%s", collectionId, outputFormat.getMediaType().fileExtension())).entity(outputFormat.getEntity(schema, collectionId, api, requestContext)).build();
}
Also used : JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) Date(java.util.Date) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableFeatureSchema(de.ii.xtraplatform.features.domain.ImmutableFeatureSchema) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) SchemaFormatExtension(de.ii.ogcapi.collections.schema.domain.SchemaFormatExtension) EntityTag(javax.ws.rs.core.EntityTag) Link(de.ii.ogcapi.foundation.domain.Link)

Example 3 with JsonSchemaDocument

use of de.ii.ogcapi.features.core.domain.JsonSchemaDocument in project ldproxy by interactive-instruments.

the class SchemaCacheReturnables method deriveSchema.

@Override
protected JsonSchemaDocument deriveSchema(FeatureSchema schema, OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData, Optional<String> schemaUri, VERSION version) {
    Optional<PropertyTransformations> propertyTransformations = collectionData.getExtension(GeoJsonConfiguration.class).map(geoJsonConfiguration -> (PropertyTransformations) geoJsonConfiguration);
    WithTransformationsApplied schemaTransformer = propertyTransformations.map(WithTransformationsApplied::new).orElse(new WithTransformationsApplied());
    SchemaDeriverReturnables schemaDeriverReturnables = new SchemaDeriverReturnables(version, schemaUri, collectionData.getLabel(), Optional.empty(), codelistSupplier.get());
    return (JsonSchemaDocument) schema.accept(schemaTransformer).accept(schemaDeriverReturnables);
}
Also used : JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) GeoJsonConfiguration(de.ii.ogcapi.features.geojson.domain.GeoJsonConfiguration) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) SchemaDeriverReturnables(de.ii.ogcapi.features.geojson.domain.SchemaDeriverReturnables) WithTransformationsApplied(de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied)

Example 4 with JsonSchemaDocument

use of de.ii.ogcapi.features.core.domain.JsonSchemaDocument in project ldproxy by interactive-instruments.

the class SchemaCacheTileSet method deriveSchema.

@Override
protected JsonSchemaDocument deriveSchema(FeatureSchema schema, OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData, Optional<String> schemaUri, VERSION version) {
    WithTransformationsApplied schemaFlattener = new WithTransformationsApplied(ImmutableMap.of(PropertyTransformations.WILDCARD, new Builder().flatten(DEFAULT_FLATTENING_SEPARATOR).build()));
    SchemaDeriverReturnables schemaDeriverReturnables = new SchemaDeriverReturnables(version, schemaUri, collectionData.getLabel(), Optional.empty(), codelistSupplier.get());
    return (JsonSchemaDocument) schema.accept(schemaFlattener).accept(schemaDeriverReturnables);
}
Also used : JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) SchemaDeriverReturnables(de.ii.ogcapi.features.geojson.domain.SchemaDeriverReturnables) Builder(de.ii.xtraplatform.features.domain.transform.ImmutablePropertyTransformation.Builder) WithTransformationsApplied(de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied)

Example 5 with JsonSchemaDocument

use of de.ii.ogcapi.features.core.domain.JsonSchemaDocument in project ldproxy by interactive-instruments.

the class SchemaCacheSortables method deriveSchema.

@Override
protected JsonSchemaDocument deriveSchema(FeatureSchema schema, OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData, Optional<String> schemaUri, VERSION version) {
    List<String> sortables = collectionData.getExtension(SortingConfiguration.class).map(SortingConfiguration::getSortables).orElse(ImmutableList.of());
    WithTransformationsApplied schemaFlattener = new WithTransformationsApplied(ImmutableMap.of(PropertyTransformations.WILDCARD, new Builder().flatten(DEFAULT_FLATTENING_SEPARATOR).build()));
    String flatteningSeparator = schemaFlattener.getFlatteningSeparator(schema).orElse(DEFAULT_FLATTENING_SEPARATOR);
    List<String> sortablesWithSeparator = Objects.equals(flatteningSeparator, DEFAULT_FLATTENING_SEPARATOR) ? sortables : sortables.stream().map(sortable -> sortable.replaceAll(Pattern.quote(DEFAULT_FLATTENING_SEPARATOR), flatteningSeparator)).collect(Collectors.toList());
    SchemaDeriverCollectionProperties schemaDeriverCollectionProperties = new SchemaDeriverCollectionProperties(version, schemaUri, collectionData.getLabel(), Optional.empty(), ImmutableList.of(), sortablesWithSeparator);
    return (JsonSchemaDocument) schema.accept(schemaFlattener).accept(schemaDeriverCollectionProperties);
}
Also used : SchemaDeriverCollectionProperties(de.ii.ogcapi.features.core.domain.SchemaDeriverCollectionProperties) JsonSchemaDocument(de.ii.ogcapi.features.core.domain.JsonSchemaDocument) Builder(de.ii.xtraplatform.features.domain.transform.ImmutablePropertyTransformation.Builder) WithTransformationsApplied(de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied)

Aggregations

JsonSchemaDocument (de.ii.ogcapi.features.core.domain.JsonSchemaDocument)9 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)4 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)4 FeatureSchema (de.ii.xtraplatform.features.domain.FeatureSchema)4 WithTransformationsApplied (de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied)4 JsonSchemaCache (de.ii.ogcapi.features.core.domain.JsonSchemaCache)3 SchemaDeriverReturnables (de.ii.ogcapi.features.geojson.domain.SchemaDeriverReturnables)3 Link (de.ii.ogcapi.foundation.domain.Link)3 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)3 Builder (de.ii.xtraplatform.features.domain.transform.ImmutablePropertyTransformation.Builder)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FeaturesCoreConfiguration (de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)2 FeaturesCoreProviders (de.ii.ogcapi.features.core.domain.FeaturesCoreProviders)2 JsonSchema (de.ii.ogcapi.features.core.domain.JsonSchema)2 SchemaDeriverCollectionProperties (de.ii.ogcapi.features.core.domain.SchemaDeriverCollectionProperties)2 GeoJsonConfiguration (de.ii.ogcapi.features.geojson.domain.GeoJsonConfiguration)2 ApiMediaType (de.ii.ogcapi.foundation.domain.ApiMediaType)2 DefaultLinksGenerator (de.ii.ogcapi.foundation.domain.DefaultLinksGenerator)2 Optional (java.util.Optional)2 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)1