Search in sources :

Example 1 with HtmlConfiguration

use of de.ii.ogcapi.html.domain.HtmlConfiguration 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 HtmlConfiguration

use of de.ii.ogcapi.html.domain.HtmlConfiguration in project ldproxy by interactive-instruments.

the class TileSetsFormatHtml method getTileSetsEntity.

@Override
public Object getTileSetsEntity(TileSets tiles, Optional<String> collectionId, OgcApi api, ApiRequestContext requestContext) {
    String rootTitle = i18n.get("root", requestContext.getLanguage());
    String collectionsTitle = i18n.get("collectionsTitle", requestContext.getLanguage());
    String tilesTitle = i18n.get("tilesTitle", requestContext.getLanguage());
    URICustomizer resourceUri = requestContext.getUriCustomizer().copy().clearParameters();
    final List<NavigationDTO> breadCrumbs = collectionId.isPresent() ? new ImmutableList.Builder<NavigationDTO>().add(new NavigationDTO(rootTitle, resourceUri.copy().removeLastPathSegments(api.getData().getSubPath().size() + 3).toString())).add(new NavigationDTO(api.getData().getLabel(), resourceUri.copy().removeLastPathSegments(3).toString())).add(new NavigationDTO(collectionsTitle, resourceUri.copy().removeLastPathSegments(2).toString())).add(new NavigationDTO(api.getData().getCollections().get(collectionId.get()).getLabel(), resourceUri.copy().removeLastPathSegments(1).toString())).add(new NavigationDTO(tilesTitle)).build() : new ImmutableList.Builder<NavigationDTO>().add(new NavigationDTO(rootTitle, resourceUri.copy().removeLastPathSegments(api.getData().getSubPath().size() + 1).toString())).add(new NavigationDTO(api.getData().getLabel(), resourceUri.copy().removeLastPathSegments(1).toString())).add(new NavigationDTO(tilesTitle)).build();
    Optional<HtmlConfiguration> htmlConfig = collectionId.isPresent() ? api.getData().getExtension(HtmlConfiguration.class, collectionId.get()) : api.getData().getExtension(HtmlConfiguration.class);
    Map<String, TileMatrixSet> tileMatrixSets = tileMatrixSetRepository.getAll();
    Optional<TilesConfiguration> tilesConfig = collectionId.isEmpty() ? api.getData().getExtension(TilesConfiguration.class) : api.getData().getExtension(TilesConfiguration.class, collectionId.get());
    MapClient.Type mapClientType = tilesConfig.map(TilesConfiguration::getMapClientType).orElse(MapClient.Type.MAP_LIBRE);
    String serviceUrl = new URICustomizer(servicesUri).ensureLastPathSegments(api.getData().getSubPath().toArray(String[]::new)).toString();
    String styleUrl = htmlConfig.map(cfg -> cfg.getStyle(tilesConfig.map(TilesConfiguration::getStyle), collectionId, serviceUrl)).orElse(null);
    boolean removeZoomLevelConstraints = tilesConfig.map(TilesConfiguration::getRemoveZoomLevelConstraints).orElse(false);
    return new TileSetsView(api.getData(), tiles, collectionId, api.getSpatialExtent(collectionId), api.getTemporalExtent(collectionId), tileMatrixSets, breadCrumbs, requestContext.getStaticUrlPrefix(), mapClientType, styleUrl, removeZoomLevelConstraints, htmlConfig.orElseThrow(), isNoIndexEnabledForApi(api.getData()), requestContext.getUriCustomizer(), i18n, requestContext.getLanguage());
}
Also used : ImmutableApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ImmutableApiMediaTypeContent) TileSetsFormatExtension(de.ii.ogcapi.tiles.domain.TileSetsFormatExtension) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) Inject(javax.inject.Inject) ImmutableApiMediaType(de.ii.ogcapi.foundation.domain.ImmutableApiMediaType) MediaType(javax.ws.rs.core.MediaType) COLLECTION_ID_PATTERN(de.ii.ogcapi.collections.domain.AbstractPathParameterCollectionId.COLLECTION_ID_PATTERN) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TileMatrixSetRepository(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSetRepository) AppContext(de.ii.xtraplatform.base.domain.AppContext) URI(java.net.URI) NavigationDTO(de.ii.ogcapi.html.domain.NavigationDTO) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ApiMediaTypeContent) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) TileSetsView(de.ii.ogcapi.tiles.domain.TileSetsView) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) MapClient(de.ii.ogcapi.html.domain.MapClient) List(java.util.List) StringSchema(io.swagger.v3.oas.models.media.StringSchema) TileSets(de.ii.ogcapi.tiles.domain.TileSets) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) Optional(java.util.Optional) ServicesContext(de.ii.xtraplatform.services.domain.ServicesContext) TileMatrixSet(de.ii.ogcapi.tiles.domain.tileMatrixSet.TileMatrixSet) NavigationDTO(de.ii.ogcapi.html.domain.NavigationDTO) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ImmutableList(com.google.common.collect.ImmutableList) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) TilesConfiguration(de.ii.ogcapi.tiles.domain.TilesConfiguration) TileSetsView(de.ii.ogcapi.tiles.domain.TileSetsView) MapClient(de.ii.ogcapi.html.domain.MapClient)

Example 3 with HtmlConfiguration

use of de.ii.ogcapi.html.domain.HtmlConfiguration in project ldproxy by interactive-instruments.

the class QueriesHandlerStylesImpl method getStyleMetadataResponse.

private Response getStyleMetadataResponse(QueryInputStyle queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    Optional<String> collectionId = queryInput.getCollectionId();
    StyleMetadata metadata = styleRepository.getStyleMetadata(apiData, collectionId, queryInput.getStyleId(), requestContext);
    StyleMetadataFormatExtension format = styleRepository.getStyleMetadataFormatStream(apiData, collectionId).filter(f -> requestContext.getMediaType().matches(f.getMediaType().type())).findAny().orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported, the following media types are available: {1}", requestContext.getMediaType(), String.join(", ", styleRepository.getStyleMetadataFormatStream(apiData, collectionId).map(f -> f.getMediaType().type().toString()).collect(Collectors.toUnmodifiableList())))));
    Date lastModified = styleRepository.getStyleLastModified(apiData, collectionId, queryInput.getStyleId());
    EntityTag etag = !format.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(metadata, StyleMetadata.FUNNEL, format) : null;
    Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
    if (Objects.nonNull(response))
        return response.build();
    return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? metadata.getLinks() : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("%s.metadata.%s", queryInput.getStyleId(), format.getMediaType().fileExtension())).entity(format.getStyleMetadataEntity(metadata, apiData, collectionId, requestContext)).build();
}
Also used : OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) Date(java.util.Date) StyleRepository(de.ii.ogcapi.styles.domain.StyleRepository) Link(de.ii.ogcapi.foundation.domain.Link) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableMap(com.google.common.collect.ImmutableMap) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) Instant(java.time.Instant) EntityTag(javax.ws.rs.core.EntityTag) Collectors(java.util.stream.Collectors) StyleMetadataFormatExtension(de.ii.ogcapi.styles.domain.StyleMetadataFormatExtension) QueriesHandlerStyles(de.ii.ogcapi.styles.domain.QueriesHandlerStyles) Objects(java.util.Objects) StylesheetContent(de.ii.ogcapi.styles.domain.StylesheetContent) List(java.util.List) StyleMetadata(de.ii.ogcapi.styles.domain.StyleMetadata) StylesFormatExtension(de.ii.ogcapi.styles.domain.StylesFormatExtension) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Optional(java.util.Optional) StyleFormatExtension(de.ii.ogcapi.styles.domain.StyleFormatExtension) Styles(de.ii.ogcapi.styles.domain.Styles) Response(javax.ws.rs.core.Response) StyleMetadataFormatExtension(de.ii.ogcapi.styles.domain.StyleMetadataFormatExtension) StyleMetadata(de.ii.ogcapi.styles.domain.StyleMetadata) NotAcceptableException(javax.ws.rs.NotAcceptableException) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) EntityTag(javax.ws.rs.core.EntityTag) Date(java.util.Date)

Example 4 with HtmlConfiguration

use of de.ii.ogcapi.html.domain.HtmlConfiguration in project ldproxy by interactive-instruments.

the class StyleMetadataFormatHtml method getStyleMetadataEntity.

@Override
public Object getStyleMetadataEntity(StyleMetadata metadata, OgcApiDataV2 apiData, Optional<String> collectionId, ApiRequestContext requestContext) {
    String rootTitle = i18n.get("root", requestContext.getLanguage());
    String collectionsTitle = i18n.get("collectionsTitle", requestContext.getLanguage());
    String stylesTitle = i18n.get("stylesTitle", requestContext.getLanguage());
    String styleTitle = metadata.getTitle().orElse(metadata.getId().orElse("?"));
    String metadataTitle = i18n.get("metadataTitle", requestContext.getLanguage());
    ImmutableList.Builder<NavigationDTO> breadCrumbBuilder = collectionId.isPresent() ? new ImmutableList.Builder<NavigationDTO>().add(new NavigationDTO(rootTitle, requestContext.getUriCustomizer().copy().removeLastPathSegments(apiData.getSubPath().size() + 5).toString())).add(new NavigationDTO(apiData.getLabel(), requestContext.getUriCustomizer().copy().removeLastPathSegments(5).toString())).add(new NavigationDTO(collectionsTitle, requestContext.getUriCustomizer().copy().removeLastPathSegments(4).toString())).add(new NavigationDTO(apiData.getCollections().get(collectionId.get()).getLabel(), requestContext.getUriCustomizer().copy().removeLastPathSegments(3).toString())) : new ImmutableList.Builder<NavigationDTO>().add(new NavigationDTO(rootTitle, requestContext.getUriCustomizer().copy().removeLastPathSegments(apiData.getSubPath().size() + 3).toString())).add(new NavigationDTO(apiData.getLabel(), requestContext.getUriCustomizer().copy().removeLastPathSegments(3).toString()));
    URICustomizer resourceUri = requestContext.getUriCustomizer().copy().clearParameters();
    final List<NavigationDTO> breadCrumbs = breadCrumbBuilder.add(new NavigationDTO(stylesTitle, resourceUri.copy().removeLastPathSegments(2).toString())).add(new NavigationDTO(styleTitle, resourceUri.copy().removeLastPathSegments(1).toString())).add(new NavigationDTO(metadataTitle)).build();
    HtmlConfiguration htmlConfig = apiData.getExtension(HtmlConfiguration.class).orElse(null);
    return new StyleMetadataView(apiData, metadata, breadCrumbs, requestContext.getStaticUrlPrefix(), htmlConfig, isNoIndexEnabledForApi(apiData), requestContext.getUriCustomizer(), i18n, requestContext.getLanguage());
}
Also used : NavigationDTO(de.ii.ogcapi.html.domain.NavigationDTO) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ImmutableList(com.google.common.collect.ImmutableList) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer)

Example 5 with HtmlConfiguration

use of de.ii.ogcapi.html.domain.HtmlConfiguration in project ldproxy by interactive-instruments.

the class QueriesHandlerStylesImpl method getStylesResponse.

private Response getStylesResponse(QueryInputStyles queryInput, ApiRequestContext requestContext) {
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    Optional<String> collectionId = queryInput.getCollectionId();
    Styles styles = styleRepository.getStyles(apiData, collectionId, requestContext, true);
    StylesFormatExtension format = styleRepository.getStylesFormatStream(apiData, collectionId).filter(f -> requestContext.getMediaType().matches(f.getMediaType().type())).findAny().orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported, the following media types are available: {1}", requestContext.getMediaType(), String.join(", ", styleRepository.getStylesFormatStream(apiData, collectionId).map(f -> f.getMediaType().type().toString()).collect(Collectors.toUnmodifiableList())))));
    Date lastModified = styles.getLastModified().orElse(null);
    EntityTag etag = !format.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(styles, Styles.FUNNEL, format) : null;
    Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
    if (Objects.nonNull(response))
        return response.build();
    return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? styles.getLinks() : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("styles.%s", format.getMediaType().fileExtension())).entity(format.getStylesEntity(styles, apiData, collectionId, requestContext)).build();
}
Also used : OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) Date(java.util.Date) StyleRepository(de.ii.ogcapi.styles.domain.StyleRepository) Link(de.ii.ogcapi.foundation.domain.Link) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableMap(com.google.common.collect.ImmutableMap) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) DefaultLinksGenerator(de.ii.ogcapi.foundation.domain.DefaultLinksGenerator) Instant(java.time.Instant) EntityTag(javax.ws.rs.core.EntityTag) Collectors(java.util.stream.Collectors) StyleMetadataFormatExtension(de.ii.ogcapi.styles.domain.StyleMetadataFormatExtension) QueriesHandlerStyles(de.ii.ogcapi.styles.domain.QueriesHandlerStyles) Objects(java.util.Objects) StylesheetContent(de.ii.ogcapi.styles.domain.StylesheetContent) List(java.util.List) StyleMetadata(de.ii.ogcapi.styles.domain.StyleMetadata) StylesFormatExtension(de.ii.ogcapi.styles.domain.StylesFormatExtension) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Optional(java.util.Optional) StyleFormatExtension(de.ii.ogcapi.styles.domain.StyleFormatExtension) Styles(de.ii.ogcapi.styles.domain.Styles) Response(javax.ws.rs.core.Response) NotAcceptableException(javax.ws.rs.NotAcceptableException) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) StylesFormatExtension(de.ii.ogcapi.styles.domain.StylesFormatExtension) EntityTag(javax.ws.rs.core.EntityTag) Date(java.util.Date) QueriesHandlerStyles(de.ii.ogcapi.styles.domain.QueriesHandlerStyles) Styles(de.ii.ogcapi.styles.domain.Styles)

Aggregations

HtmlConfiguration (de.ii.ogcapi.html.domain.HtmlConfiguration)27 URICustomizer (de.ii.ogcapi.foundation.domain.URICustomizer)17 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)15 I18n (de.ii.ogcapi.foundation.domain.I18n)15 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)15 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)15 NavigationDTO (de.ii.ogcapi.html.domain.NavigationDTO)15 Inject (javax.inject.Inject)15 Singleton (javax.inject.Singleton)15 MediaType (javax.ws.rs.core.MediaType)15 List (java.util.List)14 Objects (java.util.Objects)14 Optional (java.util.Optional)14 Map (java.util.Map)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 ApiMediaType (de.ii.ogcapi.foundation.domain.ApiMediaType)12 Link (de.ii.ogcapi.foundation.domain.Link)12 MessageFormat (java.text.MessageFormat)12 ApiRequestContext (de.ii.ogcapi.foundation.domain.ApiRequestContext)11