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();
}
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());
}
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();
}
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());
}
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();
}
Aggregations