Search in sources :

Example 1 with FeatureTypeConfigurationOgcApi

use of de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi in project ldproxy by interactive-instruments.

the class AbstractEndpointTileSetSingleCollection method getTileSet.

protected Response getTileSet(OgcApiDataV2 apiData, ApiRequestContext requestContext, String definitionPath, String collectionId, String tileMatrixSetId) {
    checkPathParameter(extensionRegistry, apiData, definitionPath, "collectionId", collectionId);
    checkPathParameter(extensionRegistry, apiData, definitionPath, "tileMatrixSetId", tileMatrixSetId);
    FeatureTypeConfigurationOgcApi featureType = apiData.getCollections().get(collectionId);
    TilesConfiguration tilesConfiguration = featureType.getExtension(TilesConfiguration.class).get();
    TilesQueriesHandler.QueryInputTileSet queryInput = new Builder().from(getGenericQueryInput(apiData)).collectionId(collectionId).tileMatrixSetId(tileMatrixSetId).center(tilesConfiguration.getCenterDerived()).zoomLevels(tilesConfiguration.getZoomLevelsDerived().get(tileMatrixSetId)).path(definitionPath).build();
    return queryHandler.handle(TilesQueriesHandler.Query.TILE_SET, queryInput, requestContext);
}
Also used : FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) TilesQueriesHandler(de.ii.ogcapi.tiles.domain.TilesQueriesHandler) Builder(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileSet.Builder) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration)

Example 2 with FeatureTypeConfigurationOgcApi

use of de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi 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 3 with FeatureTypeConfigurationOgcApi

use of de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi in project ldproxy by interactive-instruments.

the class TileProviderFeatures method getQueryInput.

@Override
@JsonIgnore
@Value.Derived
public QueryInput getQueryInput(OgcApiDataV2 apiData, URICustomizer uriCustomizer, Map<String, String> queryParameters, List<OgcApiQueryParameter> allowedParameters, QueryInput genericInput, Tile tile) {
    if (!tile.getFeatureProvider().map(FeatureProvider2::supportsQueries).orElse(false)) {
        throw new IllegalStateException("Tile cannot be generated. The feature provider does not support feature queries.");
    }
    TileFormatExtension outputFormat = tile.getOutputFormat();
    List<String> collections = tile.getCollectionIds();
    if (collections.isEmpty()) {
        return new ImmutableQueryInputTileEmpty.Builder().from(genericInput).tile(tile).build();
    }
    if (!(outputFormat instanceof TileFormatWithQuerySupportExtension))
        throw new RuntimeException(String.format("Unexpected tile format without query support. Found: %s", outputFormat.getClass().getSimpleName()));
    // first execute the information that is passed as processing parameters (e.g., "properties")
    Map<String, Object> processingParameters = new HashMap<>();
    for (OgcApiQueryParameter parameter : allowedParameters) {
        processingParameters = parameter.transformContext(null, processingParameters, queryParameters, apiData);
    }
    if (tile.isDatasetTile()) {
        if (!outputFormat.canMultiLayer() && collections.size() > 1)
            throw new NotAcceptableException("The requested tile format supports only a single layer. Please select only a single collection.");
        Map<String, Tile> singleLayerTileMap = collections.stream().collect(ImmutableMap.toImmutableMap(collectionId -> collectionId, collectionId -> new ImmutableTile.Builder().from(tile).collectionIds(ImmutableList.of(collectionId)).isDatasetTile(false).build()));
        Map<String, FeatureQuery> queryMap = collections.stream().filter(collectionId -> {
            Optional<FeaturesCoreConfiguration> featuresConfiguration = apiData.getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class);
            return featuresConfiguration.isPresent() && featuresConfiguration.get().getQueryables().isPresent() && !featuresConfiguration.get().getQueryables().get().getSpatial().isEmpty();
        }).collect(ImmutableMap.toImmutableMap(collectionId -> collectionId, collectionId -> {
            String featureTypeId = apiData.getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class).map(cfg -> cfg.getFeatureType().orElse(collectionId)).orElse(collectionId);
            TilesConfiguration layerConfiguration = apiData.getExtension(TilesConfiguration.class, collectionId).orElseThrow();
            FeatureQuery query = ((TileFormatWithQuerySupportExtension) outputFormat).getQuery(singleLayerTileMap.get(collectionId), allowedParameters, queryParameters, layerConfiguration, uriCustomizer);
            return ImmutableFeatureQuery.builder().from(query).type(featureTypeId).build();
        }));
        FeaturesCoreConfiguration coreConfiguration = apiData.getExtension(FeaturesCoreConfiguration.class).orElseThrow();
        return new ImmutableQueryInputTileMultiLayer.Builder().from(genericInput).tile(tile).singleLayerTileMap(singleLayerTileMap).queryMap(queryMap).processingParameters(processingParameters).defaultCrs(apiData.getExtension(FeaturesCoreConfiguration.class).map(FeaturesCoreConfiguration::getDefaultEpsgCrs).orElseThrow()).build();
    } else {
        String collectionId = tile.getCollectionId();
        FeatureTypeConfigurationOgcApi featureType = apiData.getCollectionData(collectionId).orElseThrow();
        TilesConfiguration layerConfiguration = apiData.getExtension(TilesConfiguration.class, collectionId).orElseThrow();
        FeatureQuery query = ((TileFromFeatureQuery) outputFormat).getQuery(tile, allowedParameters, queryParameters, layerConfiguration, uriCustomizer);
        FeaturesCoreConfiguration coreConfiguration = featureType.getExtension(FeaturesCoreConfiguration.class).orElseThrow();
        return new ImmutableQueryInputTileSingleLayer.Builder().from(genericInput).tile(tile).query(query).processingParameters(processingParameters).defaultCrs(featureType.getExtension(FeaturesCoreConfiguration.class).map(FeaturesCoreConfiguration::getDefaultEpsgCrs).orElseThrow()).build();
    }
}
Also used : FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) TileFromFeatureQuery(de.ii.ogcapi.tiles.domain.TileFromFeatureQuery) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) HashMap(java.util.HashMap) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) PredefinedFilter(de.ii.ogcapi.tiles.domain.PredefinedFilter) SeedingOptions(de.ii.ogcapi.tiles.domain.SeedingOptions) Rule(de.ii.ogcapi.tiles.domain.Rule) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Tile(de.ii.ogcapi.tiles.domain.Tile) Nullable(javax.annotation.Nullable) ImmutableQueryInputTileSingleLayer(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileSingleLayer) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableMap(com.google.common.collect.ImmutableMap) MinMax(de.ii.ogcapi.tiles.domain.MinMax) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) Maps(com.google.common.collect.Maps) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) Objects(java.util.Objects) ImmutableQueryInputTileEmpty(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileEmpty) List(java.util.List) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) TileProvider(de.ii.ogcapi.tiles.domain.TileProvider) ImmutableFeatureQuery(de.ii.xtraplatform.features.domain.ImmutableFeatureQuery) Optional(java.util.Optional) ImmutableTile(de.ii.ogcapi.tiles.domain.ImmutableTile) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) ImmutableQueryInputTileMultiLayer(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileMultiLayer) HashMap(java.util.HashMap) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) ImmutableQueryInputTileMultiLayer(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileMultiLayer) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) TileFromFeatureQuery(de.ii.ogcapi.tiles.domain.TileFromFeatureQuery) ImmutableFeatureQuery(de.ii.xtraplatform.features.domain.ImmutableFeatureQuery) ImmutableQueryInputTileEmpty(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileEmpty) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) TileFromFeatureQuery(de.ii.ogcapi.tiles.domain.TileFromFeatureQuery) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) Optional(java.util.Optional) Tile(de.ii.ogcapi.tiles.domain.Tile) ImmutableTile(de.ii.ogcapi.tiles.domain.ImmutableTile) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) NotAcceptableException(javax.ws.rs.NotAcceptableException) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 4 with FeatureTypeConfigurationOgcApi

use of de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi in project ldproxy by interactive-instruments.

the class StyleFormatHtml method getStyleEntity.

@Override
public Object getStyleEntity(StylesheetContent stylesheetContent, OgcApi api, Optional<String> collectionId, String styleId, ApiRequestContext requestContext) {
    OgcApiDataV2 apiData = api.getData();
    URICustomizer uriCustomizer = new URICustomizer(servicesUri).ensureLastPathSegments(apiData.getSubPath().toArray(String[]::new));
    String serviceUrl = uriCustomizer.toString();
    if (collectionId.isPresent())
        uriCustomizer.ensureLastPathSegments("collections", collectionId.get());
    uriCustomizer.ensureLastPathSegments("styles", styleId).addParameter("f", "mbs");
    String styleUrl = uriCustomizer.toString();
    boolean popup = apiData.getExtension(StylesConfiguration.class).map(StylesConfiguration::getWebmapWithPopup).orElse(true);
    boolean layerControl = apiData.getExtension(StylesConfiguration.class).map(StylesConfiguration::getWebmapWithLayerControl).orElse(false);
    boolean allLayers = apiData.getExtension(StylesConfiguration.class).map(StylesConfiguration::getLayerControlAllLayers).orElse(false);
    ArrayListMultimap<String, String> layerMap = ArrayListMultimap.create();
    if (layerControl) {
        MbStyleStylesheet mbStyle = StyleFormatMbStyle.parse(stylesheetContent, serviceUrl, true, false).get();
        if (allLayers) {
            Map<String, FeatureTypeConfigurationOgcApi> collectionData = apiData.getCollections();
            mbStyle.getLayers().stream().forEach(styleLayer -> {
                if (styleLayer.getSourceLayer().isPresent()) {
                    layerMap.put(collectionData.containsKey(styleLayer.getSourceLayer().get()) ? collectionData.get(styleLayer.getSourceLayer().get()).getLabel() : styleLayer.getSourceLayer().get(), styleLayer.getId());
                } else {
                    layerMap.put(styleLayer.getId(), styleLayer.getId());
                }
            });
        } else {
            Set<String> vectorSources = mbStyle.getSources().entrySet().stream().filter(source -> source.getValue() instanceof MbStyleVectorSource).map(Map.Entry::getKey).collect(Collectors.toUnmodifiableSet());
            Map<String, FeatureTypeConfigurationOgcApi> collectionData = apiData.getCollections();
            mbStyle.getLayers().stream().filter(styleLayer -> styleLayer.getSource().isPresent() && vectorSources.contains(styleLayer.getSource().get()) && styleLayer.getSourceLayer().isPresent() && collectionData.containsKey(styleLayer.getSourceLayer().get())).forEach(styleLayer -> layerMap.put(collectionData.containsKey(styleLayer.getSourceLayer().get()) ? collectionData.get(styleLayer.getSourceLayer().get()).getLabel() : styleLayer.getSourceLayer().get(), styleLayer.getId()));
        }
    }
    return new StyleView(styleUrl, apiData, api.getSpatialExtent(), styleId, popup, layerControl, layerMap.asMap(), requestContext.getStaticUrlPrefix());
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) ImmutableApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ImmutableApiMediaTypeContent) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) Inject(javax.inject.Inject) ImmutableApiMediaType(de.ii.ogcapi.foundation.domain.ImmutableApiMediaType) MbStyleStylesheet(de.ii.ogcapi.styles.domain.MbStyleStylesheet) MediaType(javax.ws.rs.core.MediaType) SchemaGenerator(de.ii.ogcapi.foundation.domain.SchemaGenerator) Map(java.util.Map) Schema(io.swagger.v3.oas.models.media.Schema) URI(java.net.URI) ApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ApiMediaTypeContent) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) ImmutableMbStyleStylesheet(de.ii.ogcapi.styles.domain.ImmutableMbStyleStylesheet) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) StylesheetContent(de.ii.ogcapi.styles.domain.StylesheetContent) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) MbStyleVectorSource(de.ii.ogcapi.styles.domain.MbStyleVectorSource) Optional(java.util.Optional) StyleFormatExtension(de.ii.ogcapi.styles.domain.StyleFormatExtension) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) ServicesContext(de.ii.xtraplatform.services.domain.ServicesContext) MbStyleStylesheet(de.ii.ogcapi.styles.domain.MbStyleStylesheet) ImmutableMbStyleStylesheet(de.ii.ogcapi.styles.domain.ImmutableMbStyleStylesheet) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) MbStyleVectorSource(de.ii.ogcapi.styles.domain.MbStyleVectorSource) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) Map(java.util.Map)

Example 5 with FeatureTypeConfigurationOgcApi

use of de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi in project ldproxy by interactive-instruments.

the class FeaturesFormatHtml method onStartup.

@Override
public ValidationResult onStartup(OgcApi api, MODE apiValidation) {
    // no additional operational checks for now, only validation; we can stop, if no validation is requested
    if (apiValidation == MODE.NONE)
        return ValidationResult.of();
    ImmutableValidationResult.Builder builder = ImmutableValidationResult.builder().mode(apiValidation);
    Map<String, FeatureSchema> featureSchemas = providers.getFeatureSchemas(api.getData());
    // get HTML configurations to process
    Map<String, FeaturesHtmlConfiguration> htmlConfigurationMap = api.getData().getCollections().entrySet().stream().map(entry -> {
        final FeatureTypeConfigurationOgcApi collectionData = entry.getValue();
        final FeaturesHtmlConfiguration config = collectionData.getExtension(FeaturesHtmlConfiguration.class).orElse(null);
        if (Objects.isNull(config))
            return null;
        return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), config);
    }).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
    Map<String, Collection<String>> keyMap = htmlConfigurationMap.entrySet().stream().map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().getTransformations().keySet())).collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
    for (Map.Entry<String, Collection<String>> stringCollectionEntry : featuresCoreValidator.getInvalidPropertyKeys(keyMap, featureSchemas).entrySet()) {
        for (String property : stringCollectionEntry.getValue()) {
            builder.addStrictErrors(MessageFormat.format("A transformation for property ''{0}'' in collection ''{1}'' is invalid, because the property was not found in the provider schema.", property, stringCollectionEntry.getKey()));
        }
    }
    Set<String> codelists = entityRegistry.getEntitiesForType(Codelist.class).stream().map(Codelist::getId).collect(Collectors.toUnmodifiableSet());
    for (Map.Entry<String, FeaturesHtmlConfiguration> entry : htmlConfigurationMap.entrySet()) {
        String collectionId = entry.getKey();
        for (Map.Entry<String, List<PropertyTransformation>> entry2 : entry.getValue().getTransformations().entrySet()) {
            String property = entry2.getKey();
            for (PropertyTransformation transformation : entry2.getValue()) {
                builder = transformation.validate(builder, collectionId, property, codelists);
            }
        }
    }
    return builder.build();
}
Also used : ImmutableApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ImmutableApiMediaTypeContent) MustacheRenderer(de.ii.xtraplatform.web.domain.MustacheRenderer) URISyntaxException(java.net.URISyntaxException) Link(de.ii.ogcapi.foundation.domain.Link) ImmutableValidationResult(de.ii.xtraplatform.store.domain.entities.ImmutableValidationResult) MODE(de.ii.xtraplatform.store.domain.entities.ValidationResult.MODE) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) ImmutableApiMediaType(de.ii.ogcapi.foundation.domain.ImmutableApiMediaType) MediaType(javax.ws.rs.core.MediaType) Builder(de.ii.xtraplatform.features.domain.transform.ImmutablePropertyTransformation.Builder) Locale(java.util.Locale) Map(java.util.Map) URI(java.net.URI) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) WithTransformationsApplied(de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied) ApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ApiMediaTypeContent) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) Collection(java.util.Collection) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) Set(java.util.Set) Collectors(java.util.stream.Collectors) PropertyTransformation(de.ii.xtraplatform.features.domain.transform.PropertyTransformation) Objects(java.util.Objects) MapClient(de.ii.ogcapi.html.domain.MapClient) List(java.util.List) StringTemplateFilters(de.ii.xtraplatform.strings.domain.StringTemplateFilters) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Entry(java.util.Map.Entry) Optional(java.util.Optional) FeaturesCoreValidation(de.ii.ogcapi.features.core.domain.FeaturesCoreValidation) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) ServicesContext(de.ii.xtraplatform.services.domain.ServicesContext) ItemTypeSpecificConformanceClass(de.ii.ogcapi.features.core.domain.ItemTypeSpecificConformanceClass) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) POSITION(de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration.POSITION) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) ValidationResult(de.ii.xtraplatform.store.domain.entities.ValidationResult) Schema(io.swagger.v3.oas.models.media.Schema) NavigationDTO(de.ii.ogcapi.html.domain.NavigationDTO) FeaturesHtmlConfiguration(de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration) FeatureFormatExtension(de.ii.ogcapi.features.core.domain.FeatureFormatExtension) I18n(de.ii.ogcapi.foundation.domain.I18n) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) AbstractMap(java.util.AbstractMap) DEFAULT_FLATTENING_SEPARATOR(de.ii.ogcapi.features.core.domain.SchemaGeneratorFeatureOpenApi.DEFAULT_FLATTENING_SEPARATOR) FeatureTransformationContext(de.ii.ogcapi.features.core.domain.FeatureTransformationContext) Metadata(de.ii.ogcapi.foundation.domain.Metadata) Comparator(java.util.Comparator) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) ImmutableValidationResult(de.ii.xtraplatform.store.domain.entities.ImmutableValidationResult) FeaturesHtmlConfiguration(de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) PropertyTransformation(de.ii.xtraplatform.features.domain.transform.PropertyTransformation) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) Collection(java.util.Collection) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap)

Aggregations

FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)42 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)34 Optional (java.util.Optional)29 Objects (java.util.Objects)28 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)26 Inject (javax.inject.Inject)26 Singleton (javax.inject.Singleton)26 ImmutableList (com.google.common.collect.ImmutableList)25 ImmutableMap (com.google.common.collect.ImmutableMap)25 List (java.util.List)25 Map (java.util.Map)25 Collectors (java.util.stream.Collectors)23 ExtensionConfiguration (de.ii.ogcapi.foundation.domain.ExtensionConfiguration)21 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)21 FeaturesCoreConfiguration (de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)20 FeatureSchema (de.ii.xtraplatform.features.domain.FeatureSchema)20 FeaturesCoreProviders (de.ii.ogcapi.features.core.domain.FeaturesCoreProviders)19 AbstractMap (java.util.AbstractMap)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16