Search in sources :

Example 1 with OgcApiDataV2

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

the class TilesQueriesHandlerImpl method getTileSetResponse.

private Response getTileSetResponse(QueryInputTileSet queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    String tileMatrixSetId = queryInput.getTileMatrixSetId();
    Optional<String> collectionId = queryInput.getCollectionId();
    String definitionPath = queryInput.getPath();
    String path = collectionId.map(value -> definitionPath.replace("{collectionId}", value)).orElse(definitionPath).replace("{tileMatrixSetId}", tileMatrixSetId);
    TileSetFormatExtension outputFormat = api.getOutputFormat(TileSetFormatExtension.class, requestContext.getMediaType(), path, collectionId).orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported for this resource.", requestContext.getMediaType())));
    List<TileFormatExtension> tileFormats = extensionRegistry.getExtensionsForType(TileFormatExtension.class).stream().filter(format -> collectionId.map(s -> format.isApplicable(apiData, s, definitionPath)).orElseGet(() -> format.isApplicable(apiData, definitionPath))).collect(Collectors.toUnmodifiableList());
    DataType dataType = tileFormats.stream().map(TileFormatExtension::getDataType).findAny().orElseThrow(() -> new NotFoundException("No encoding found for this tile set."));
    final TilesLinkGenerator tilesLinkGenerator = new TilesLinkGenerator();
    List<Link> links = tilesLinkGenerator.generateTileSetLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), tileFormats, i18n, requestContext.getLanguage());
    MinMax zoomLevels = queryInput.getZoomLevels();
    List<Double> center = queryInput.getCenter();
    TileSet tileset = TilesHelper.buildTileSet(api, getTileMatrixSetById(tileMatrixSetId), zoomLevels, center, collectionId, dataType, links, Optional.of(requestContext.getUriCustomizer().copy()), crsTransformerFactory, limitsGenerator, providers, entityRegistry);
    Date lastModified = getLastModified(queryInput, requestContext.getApi());
    EntityTag etag = !outputFormat.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE) || (collectionId.isEmpty() ? apiData.getExtension(HtmlConfiguration.class) : apiData.getExtension(HtmlConfiguration.class, collectionId.get())).map(HtmlConfiguration::getSendEtags).orElse(false) ? getEtag(tileset, TileSet.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.%s", tileset.getTileMatrixSetId(), outputFormat.getMediaType().fileExtension())).entity(outputFormat.getTileSetEntity(tileset, apiData, collectionId, requestContext)).build();
}
Also used : Date(java.util.Date) Link(de.ii.ogcapi.foundation.domain.Link) LoggerFactory(org.slf4j.LoggerFactory) TileSetFormatExtension(de.ii.ogcapi.tiles.domain.TileSetFormatExtension) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) TileSetsFormatExtension(de.ii.ogcapi.tiles.domain.TileSetsFormatExtension) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) TileMatrixSetRepository(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetRepository) Tile(de.ii.ogcapi.tiles.domain.Tile) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer) PersistentEntity(de.ii.xtraplatform.store.domain.entities.PersistentEntity) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ImmutableFeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.ImmutableFeatureTransformationContextTiles) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) TilesQueriesHandler(de.ii.ogcapi.tiles.domain.TilesQueriesHandler) Builder(de.ii.ogcapi.tiles.domain.ImmutableTileSets.Builder) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) ByteStreams(com.google.common.io.ByteStreams) Sink(de.ii.xtraplatform.streams.domain.Reactive.Sink) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) TileSet(de.ii.ogcapi.tiles.domain.TileSet) LogContext(de.ii.xtraplatform.base.domain.LogContext) DataType(de.ii.ogcapi.tiles.domain.TileSet.DataType) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ClientBuilder(javax.ws.rs.client.ClientBuilder) TileMatrixSetLimitsGenerator(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimitsGenerator) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) QueriesHandler(de.ii.ogcapi.foundation.domain.QueriesHandler) ImmutableTileSets(de.ii.ogcapi.tiles.domain.ImmutableTileSets) FeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.FeatureTransformationContextTiles) TileCache(de.ii.ogcapi.tiles.domain.TileCache) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) MinMax(de.ii.ogcapi.tiles.domain.MinMax) I18n(de.ii.ogcapi.foundation.domain.I18n) IOException(java.io.IOException) FeatureStream(de.ii.xtraplatform.features.domain.FeatureStream) EntityTag(javax.ws.rs.core.EntityTag) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) StaticTileProviderStore(de.ii.ogcapi.tiles.domain.StaticTileProviderStore) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) SinkReduced(de.ii.xtraplatform.streams.domain.Reactive.SinkReduced) ServerErrorException(javax.ws.rs.ServerErrorException) ResultReduced(de.ii.xtraplatform.features.domain.FeatureStream.ResultReduced) TileSets(de.ii.ogcapi.tiles.domain.TileSets) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) NotFoundException(javax.ws.rs.NotFoundException) MinMax(de.ii.ogcapi.tiles.domain.MinMax) TileSet(de.ii.ogcapi.tiles.domain.TileSet) Date(java.util.Date) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) NotAcceptableException(javax.ws.rs.NotAcceptableException) DataType(de.ii.ogcapi.tiles.domain.TileSet.DataType) EntityTag(javax.ws.rs.core.EntityTag) TileSetFormatExtension(de.ii.ogcapi.tiles.domain.TileSetFormatExtension) Link(de.ii.ogcapi.foundation.domain.Link)

Example 2 with OgcApiDataV2

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

the class TilesQueriesHandlerImpl method getMultiLayerTileResponse.

private Response getMultiLayerTileResponse(QueryInputTileMultiLayer queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    Tile multiLayerTile = queryInput.getTile();
    List<String> collectionIds = multiLayerTile.getCollectionIds();
    Map<String, FeatureQuery> queryMap = queryInput.getQueryMap();
    Map<String, Tile> singleLayerTileMap = queryInput.getSingleLayerTileMap();
    FeatureProvider2 featureProvider = multiLayerTile.getFeatureProvider().get();
    TileMatrixSet tileMatrixSet = multiLayerTile.getTileMatrixSet();
    int tileLevel = multiLayerTile.getTileLevel();
    int tileRow = multiLayerTile.getTileRow();
    int tileCol = multiLayerTile.getTileCol();
    if (!(multiLayerTile.getOutputFormat() instanceof TileFormatWithQuerySupportExtension))
        throw new RuntimeException(String.format("Unexpected tile format without query support. Found: %s", multiLayerTile.getOutputFormat().getClass().getSimpleName()));
    TileFormatWithQuerySupportExtension outputFormat = (TileFormatWithQuerySupportExtension) multiLayerTile.getOutputFormat();
    // process parameters and generate query
    Optional<CrsTransformer> crsTransformer = Optional.empty();
    EpsgCrs targetCrs = tileMatrixSet.getCrs();
    if (featureProvider.supportsCrs()) {
        EpsgCrs sourceCrs = featureProvider.crs().getNativeCrs();
        crsTransformer = crsTransformerFactory.getTransformer(sourceCrs, targetCrs);
    }
    List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), i18n, requestContext.getLanguage());
    Map<String, ByteArrayOutputStream> byteArrayMap = new HashMap<>();
    for (String collectionId : collectionIds) {
        // TODO limitation of the current model: all layers have to come from the same feature provider and use the same CRS
        Tile tile = singleLayerTileMap.get(collectionId);
        if (!multiLayerTile.getTemporary()) {
            // use cached tile
            try {
                Optional<InputStream> tileContent = tileCache.getTile(tile);
                if (tileContent.isPresent()) {
                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                    ByteStreams.copy(tileContent.get(), buffer);
                    byteArrayMap.put(collectionId, buffer);
                    continue;
                }
            } catch (SQLException | IOException e) {
            // could not read the cache, generate the tile
            }
        }
        String featureTypeId = apiData.getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class).map(cfg -> cfg.getFeatureType().orElse(collectionId)).orElse(collectionId);
        FeatureQuery query = queryMap.get(collectionId);
        ImmutableFeatureTransformationContextTiles transformationContext;
        try {
            transformationContext = new ImmutableFeatureTransformationContextTiles.Builder().api(api).apiData(apiData).featureSchema(featureProvider.getData().getTypes().get(featureTypeId)).tile(tile).tileCache(tileCache).collectionId(collectionId).ogcApiRequest(requestContext).crsTransformer(crsTransformer).codelists(entityRegistry.getEntitiesForType(Codelist.class).stream().collect(Collectors.toMap(PersistentEntity::getId, c -> c))).defaultCrs(queryInput.getDefaultCrs()).links(links).isFeatureCollection(true).fields(query.getFields()).limit(query.getLimit()).offset(0).i18n(i18n).outputStream(new OutputStreamToByteConsumer()).build();
        } catch (Exception e) {
            throw new RuntimeException("Error building the tile transformation context.", e);
        }
        Optional<FeatureTokenEncoder<?>> encoder = outputFormat.getFeatureEncoder(transformationContext);
        if (outputFormat.supportsFeatureQuery() && encoder.isPresent()) {
            FeatureStream featureStream = featureProvider.queries().getFeatureStream(query);
            ResultReduced<byte[]> result = generateTile(featureStream, encoder.get(), transformationContext, outputFormat);
            if (result.isSuccess()) {
                byte[] bytes = result.reduced();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream(bytes.length);
                buffer.write(bytes, 0, bytes.length);
                byteArrayMap.put(collectionId, buffer);
            }
        } else {
            throw new NotAcceptableException(MessageFormat.format("The requested media type {0} cannot be generated, because it does not support streaming.", requestContext.getMediaType().type()));
        }
    }
    TileFormatWithQuerySupportExtension.MultiLayerTileContent result;
    try {
        result = outputFormat.combineSingleLayerTilesToMultiLayerTile(tileMatrixSet, singleLayerTileMap, byteArrayMap);
    } catch (IOException e) {
        throw new RuntimeException("Error accessing the tile cache.", e);
    }
    // try to write/update tile in cache, if all collections have been processed
    if (result.isComplete) {
        try {
            tileCache.storeTile(multiLayerTile, result.byteArray);
        } catch (Throwable e) {
            String msg = "Failure to write the multi-layer file of tile {}/{}/{}/{} in dataset '{}', format '{}' to the cache";
            LogContext.errorAsInfo(LOGGER, e, msg, tileMatrixSet.getId(), tileLevel, tileRow, tileCol, api.getId(), outputFormat.getExtension());
        }
    }
    Date lastModified = null;
    EntityTag etag = getEtag(result.byteArray);
    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_%d_%d_%d.%s", tileMatrixSet.getId(), tileLevel, tileRow, tileCol, outputFormat.getMediaType().fileExtension())).entity(result.byteArray).build();
}
Also used : Date(java.util.Date) Link(de.ii.ogcapi.foundation.domain.Link) LoggerFactory(org.slf4j.LoggerFactory) TileSetFormatExtension(de.ii.ogcapi.tiles.domain.TileSetFormatExtension) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) TileSetsFormatExtension(de.ii.ogcapi.tiles.domain.TileSetsFormatExtension) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) TileMatrixSetRepository(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetRepository) Tile(de.ii.ogcapi.tiles.domain.Tile) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer) PersistentEntity(de.ii.xtraplatform.store.domain.entities.PersistentEntity) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) CompletionException(java.util.concurrent.CompletionException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ImmutableFeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.ImmutableFeatureTransformationContextTiles) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) TilesQueriesHandler(de.ii.ogcapi.tiles.domain.TilesQueriesHandler) Builder(de.ii.ogcapi.tiles.domain.ImmutableTileSets.Builder) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) ByteStreams(com.google.common.io.ByteStreams) Sink(de.ii.xtraplatform.streams.domain.Reactive.Sink) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) TileSet(de.ii.ogcapi.tiles.domain.TileSet) LogContext(de.ii.xtraplatform.base.domain.LogContext) DataType(de.ii.ogcapi.tiles.domain.TileSet.DataType) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ClientBuilder(javax.ws.rs.client.ClientBuilder) TileMatrixSetLimitsGenerator(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimitsGenerator) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) QueriesHandler(de.ii.ogcapi.foundation.domain.QueriesHandler) ImmutableTileSets(de.ii.ogcapi.tiles.domain.ImmutableTileSets) FeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.FeatureTransformationContextTiles) TileCache(de.ii.ogcapi.tiles.domain.TileCache) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) MinMax(de.ii.ogcapi.tiles.domain.MinMax) I18n(de.ii.ogcapi.foundation.domain.I18n) IOException(java.io.IOException) FeatureStream(de.ii.xtraplatform.features.domain.FeatureStream) EntityTag(javax.ws.rs.core.EntityTag) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) StaticTileProviderStore(de.ii.ogcapi.tiles.domain.StaticTileProviderStore) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) SinkReduced(de.ii.xtraplatform.streams.domain.Reactive.SinkReduced) ServerErrorException(javax.ws.rs.ServerErrorException) ResultReduced(de.ii.xtraplatform.features.domain.FeatureStream.ResultReduced) TileSets(de.ii.ogcapi.tiles.domain.TileSets) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) FeatureStream(de.ii.xtraplatform.features.domain.FeatureStream) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) PersistentEntity(de.ii.xtraplatform.store.domain.entities.PersistentEntity) FeatureQuery(de.ii.xtraplatform.features.domain.FeatureQuery) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) CrsTransformer(de.ii.xtraplatform.crs.domain.CrsTransformer) EntityTag(javax.ws.rs.core.EntityTag) ImmutableFeatureTransformationContextTiles(de.ii.ogcapi.tiles.domain.ImmutableFeatureTransformationContextTiles) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Tile(de.ii.ogcapi.tiles.domain.Tile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) SQLException(java.sql.SQLException) NotAcceptableException(javax.ws.rs.NotAcceptableException) IOException(java.io.IOException) ServerErrorException(javax.ws.rs.ServerErrorException) Date(java.util.Date) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) EpsgCrs(de.ii.xtraplatform.crs.domain.EpsgCrs) NotAcceptableException(javax.ws.rs.NotAcceptableException) TileFormatWithQuerySupportExtension(de.ii.ogcapi.tiles.domain.TileFormatWithQuerySupportExtension) Link(de.ii.ogcapi.foundation.domain.Link)

Example 3 with OgcApiDataV2

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

the class AbstractEndpointTileSingleCollection method computeDefinition.

protected ApiEndpointDefinition computeDefinition(OgcApiDataV2 apiData, String apiEntrypoint, int sortPriority, String basePath, String subSubPath, List<String> tags) {
    ImmutableApiEndpointDefinition.Builder definitionBuilder = new ImmutableApiEndpointDefinition.Builder().apiEntrypoint(apiEntrypoint).sortPriority(sortPriority);
    final String path = basePath + subSubPath;
    final HttpMethods method = HttpMethods.GET;
    final List<OgcApiPathParameter> pathParameters = getPathParameters(extensionRegistry, apiData, path);
    final Optional<OgcApiPathParameter> optCollectionIdParam = pathParameters.stream().filter(param -> param.getName().equals("collectionId")).findAny();
    if (optCollectionIdParam.isEmpty()) {
        LOGGER.error("Path parameter 'collectionId' missing for resource at path '" + path + "'. The GET method will not be available.");
    } else {
        final OgcApiPathParameter collectionIdParam = optCollectionIdParam.get();
        boolean explode = collectionIdParam.getExplodeInOpenApi(apiData);
        final List<String> collectionIds = (explode) ? collectionIdParam.getValues(apiData) : ImmutableList.of("{collectionId}");
        for (String collectionId : collectionIds) {
            List<OgcApiQueryParameter> queryParameters = getQueryParameters(extensionRegistry, apiData, path, collectionId);
            String operationSummary = "fetch a tile of the collection '" + collectionId + "'";
            Optional<String> operationDescription = Optional.of("The tile in the requested tiling scheme ('{tileMatrixSetId}'), " + "on the requested zoom level ('{tileMatrix}'), with the requested grid coordinates ('{tileRow}', '{tileCol}') is returned. " + "The tile has a single layer with all selected features in the bounding box of the tile with the requested properties.");
            String resourcePath = path.replace("{collectionId}", collectionId);
            ImmutableOgcApiResourceData.Builder resourceBuilder = new ImmutableOgcApiResourceData.Builder().path(resourcePath).pathParameters(pathParameters);
            ApiOperation operation = addOperation(apiData, HttpMethods.GET, queryParameters, collectionId, subSubPath, operationSummary, operationDescription, tags);
            if (operation != null)
                resourceBuilder.putOperations(method.name(), operation);
            definitionBuilder.putResources(resourcePath, resourceBuilder.build());
        }
    }
    return definitionBuilder.build();
}
Also used : TileMatrixSetLimits(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimits) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) CrsTransformationException(de.ii.xtraplatform.crs.domain.CrsTransformationException) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) LoggerFactory(org.slf4j.LoggerFactory) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) EndpointSubCollection(de.ii.ogcapi.collections.domain.EndpointSubCollection) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) MessageFormat(java.text.MessageFormat) TileMatrixSetLimitsGenerator(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetLimitsGenerator) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TileMatrixSetRepository(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetRepository) ImmutableOgcApiResourceData(de.ii.ogcapi.collections.domain.ImmutableOgcApiResourceData) Tile(de.ii.ogcapi.tiles.domain.Tile) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) TileCache(de.ii.ogcapi.tiles.domain.TileCache) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) MinMax(de.ii.ogcapi.tiles.domain.MinMax) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) IOException(java.io.IOException) FeatureProvider2(de.ii.xtraplatform.features.domain.FeatureProvider2) StaticTileProviderStore(de.ii.ogcapi.tiles.domain.StaticTileProviderStore) NotFoundException(javax.ws.rs.NotFoundException) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) Objects(java.util.Objects) ApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ApiEndpointDefinition) List(java.util.List) TilesQueriesHandler(de.ii.ogcapi.tiles.domain.TilesQueriesHandler) ServerErrorException(javax.ws.rs.ServerErrorException) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileFormatExtension(de.ii.ogcapi.tiles.domain.TileFormatExtension) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) CrsTransformerFactory(de.ii.xtraplatform.crs.domain.CrsTransformerFactory) TileProvider(de.ii.ogcapi.tiles.domain.TileProvider) Optional(java.util.Optional) Builder(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileStream.Builder) ImmutableTile(de.ii.ogcapi.tiles.domain.ImmutableTile) UriInfo(javax.ws.rs.core.UriInfo) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) InputStream(java.io.InputStream) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) Builder(de.ii.ogcapi.tiles.domain.ImmutableQueryInputTileStream.Builder) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) ImmutableOgcApiResourceData(de.ii.ogcapi.collections.domain.ImmutableOgcApiResourceData) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation)

Example 4 with OgcApiDataV2

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

the class EndpointStylesCollection method computeDefinition.

protected ApiEndpointDefinition computeDefinition(OgcApiDataV2 apiData) {
    ImmutableApiEndpointDefinition.Builder definitionBuilder = new ImmutableApiEndpointDefinition.Builder().apiEntrypoint("collections").sortPriority(ApiEndpointDefinition.SORT_PRIORITY_STYLES_COLLECTION);
    final String subSubPath = "/styles";
    final String path = "/collections/{collectionId}" + subSubPath;
    final HttpMethods method = HttpMethods.GET;
    final List<OgcApiPathParameter> pathParameters = getPathParameters(extensionRegistry, apiData, path);
    final Optional<OgcApiPathParameter> optCollectionIdParam = pathParameters.stream().filter(param -> param.getName().equals("collectionId")).findAny();
    if (!optCollectionIdParam.isPresent()) {
        LOGGER.error("Path parameter 'collectionId' missing for resource at path '" + path + "'. The GET method will not be available.");
    } else {
        final OgcApiPathParameter collectionIdParam = optCollectionIdParam.get();
        boolean explode = collectionIdParam.getExplodeInOpenApi(apiData);
        final List<String> collectionIds = (explode) ? collectionIdParam.getValues(apiData) : ImmutableList.of("{collectionId}");
        for (String collectionId : collectionIds) {
            List<OgcApiQueryParameter> queryParameters = getQueryParameters(extensionRegistry, apiData, path, collectionId);
            String operationSummary = "retrieve a list of the available styles for collection `" + collectionId + "`";
            Optional<String> operationDescription = Optional.of("This operation fetches the set of styles available for this collection. " + "For each style the id, a title, links to the stylesheet of the style in each supported encoding, " + "and the link to the metadata is provided.");
            String resourcePath = path.replace("{collectionId}", collectionId);
            ImmutableOgcApiResourceSet.Builder resourceBuilder = new ImmutableOgcApiResourceSet.Builder().path(resourcePath).pathParameters(pathParameters).subResourceType("Style");
            ApiOperation operation = addOperation(apiData, HttpMethods.GET, queryParameters, collectionId, subSubPath, operationSummary, operationDescription, TAGS);
            if (operation != null)
                resourceBuilder.putOperations(method.name(), operation);
            definitionBuilder.putResources(resourcePath, resourceBuilder.build());
        }
    }
    return definitionBuilder.build();
}
Also used : PathParam(javax.ws.rs.PathParam) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) EndpointSubCollection(de.ii.ogcapi.collections.domain.EndpointSubCollection) ImmutableOgcApiResourceSet(de.ii.ogcapi.foundation.domain.ImmutableOgcApiResourceSet) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) ConformanceClass(de.ii.ogcapi.foundation.domain.ConformanceClass) ImmutableList(com.google.common.collect.ImmutableList) Builder(de.ii.ogcapi.styles.domain.ImmutableQueryInputStyles.Builder) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) QueriesHandlerStyles(de.ii.ogcapi.styles.domain.QueriesHandlerStyles) ApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ApiEndpointDefinition) List(java.util.List) StylesFormatExtension(de.ii.ogcapi.styles.domain.StylesFormatExtension) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) Optional(java.util.Optional) FormatExtension(de.ii.ogcapi.foundation.domain.FormatExtension) ImmutableApiEndpointDefinition(de.ii.ogcapi.foundation.domain.ImmutableApiEndpointDefinition) HttpMethods(de.ii.ogcapi.foundation.domain.HttpMethods) Builder(de.ii.ogcapi.styles.domain.ImmutableQueryInputStyles.Builder) ImmutableOgcApiResourceSet(de.ii.ogcapi.foundation.domain.ImmutableOgcApiResourceSet) OgcApiPathParameter(de.ii.ogcapi.foundation.domain.OgcApiPathParameter) OgcApiQueryParameter(de.ii.ogcapi.foundation.domain.OgcApiQueryParameter) ApiOperation(de.ii.ogcapi.foundation.domain.ApiOperation)

Example 5 with OgcApiDataV2

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

the class EndpointStylesCollection method getStyles.

/**
 * fetch all available styles for the service
 *
 * @return all styles in a JSON styles object or an HTML page
 */
@Path("/{collectionId}/styles")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
public Response getStyles(@Context OgcApi api, @Context ApiRequestContext requestContext, @PathParam("collectionId") String collectionId) {
    OgcApiDataV2 apiData = api.getData();
    checkPathParameter(extensionRegistry, apiData, "/collections/{collectionId}/styles", "collectionId", collectionId);
    checkCollectionExists(apiData, collectionId);
    QueriesHandlerStyles.QueryInputStyles queryInput = new Builder().from(getGenericQueryInput(api.getData())).collectionId(collectionId).build();
    return queryHandler.handle(QueriesHandlerStyles.Query.STYLES, queryInput, requestContext);
}
Also used : OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) QueriesHandlerStyles(de.ii.ogcapi.styles.domain.QueriesHandlerStyles) Builder(de.ii.ogcapi.styles.domain.ImmutableQueryInputStyles.Builder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)111 Optional (java.util.Optional)70 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)65 Inject (javax.inject.Inject)65 Singleton (javax.inject.Singleton)65 List (java.util.List)64 ImmutableList (com.google.common.collect.ImmutableList)58 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)58 Map (java.util.Map)54 Objects (java.util.Objects)53 ExtensionRegistry (de.ii.ogcapi.foundation.domain.ExtensionRegistry)51 Collectors (java.util.stream.Collectors)50 Logger (org.slf4j.Logger)50 LoggerFactory (org.slf4j.LoggerFactory)50 ApiRequestContext (de.ii.ogcapi.foundation.domain.ApiRequestContext)49 Response (javax.ws.rs.core.Response)44 ExtensionConfiguration (de.ii.ogcapi.foundation.domain.ExtensionConfiguration)40 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)40 MediaType (javax.ws.rs.core.MediaType)40 ImmutableMap (com.google.common.collect.ImmutableMap)39