use of de.ii.ogcapi.tiles.domain.TileSetsFormatExtension in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method getTileSetsResponse.
private Response getTileSetsResponse(QueryInputTileSets queryInput, ApiRequestContext requestContext) {
OgcApi api = requestContext.getApi();
OgcApiDataV2 apiData = api.getData();
Optional<String> collectionId = queryInput.getCollectionId();
String definitionPath = queryInput.getPath();
String path = collectionId.map(value -> definitionPath.replace("{collectionId}", value)).orElse(definitionPath);
boolean onlyWebMercatorQuad = queryInput.getOnlyWebMercatorQuad();
TileSetsFormatExtension outputFormat = api.getOutputFormat(TileSetsFormatExtension.class, requestContext.getMediaType(), path, collectionId).orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported for this resource.", requestContext.getMediaType())));
final TilesLinkGenerator tilesLinkGenerator = new TilesLinkGenerator();
Optional<FeatureTypeConfigurationOgcApi> featureType = collectionId.map(s -> apiData.getCollections().get(s));
Map<String, MinMax> tileMatrixSetZoomLevels = queryInput.getTileMatrixSetZoomLevels();
List<Double> center = queryInput.getCenter();
List<TileFormatExtension> tileFormats = extensionRegistry.getExtensionsForType(TileFormatExtension.class).stream().filter(format -> collectionId.map(s -> format.isApplicable(apiData, s, definitionPath)).orElseGet(() -> format.isApplicable(apiData, definitionPath))).sorted(Comparator.comparing(format -> queryInput.getTileEncodings().indexOf(format.getMediaType().label()))).collect(Collectors.toUnmodifiableList());
Optional<DataType> dataType = tileFormats.stream().map(TileFormatExtension::getDataType).findAny();
List<Link> links = tilesLinkGenerator.generateTileSetsLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), tileFormats, i18n, requestContext.getLanguage());
Builder builder = ImmutableTileSets.builder().title(featureType.isPresent() ? featureType.get().getLabel() : apiData.getLabel()).description(featureType.map(ft -> ft.getDescription().orElse("")).orElseGet(() -> apiData.getDescription().orElse(""))).links(links);
List<TileMatrixSet> tileMatrixSets = tileMatrixSetZoomLevels.keySet().stream().map(this::getTileMatrixSetById).filter(tileMatrixSet -> !onlyWebMercatorQuad || tileMatrixSet.getId().equals("WebMercatorQuad")).collect(Collectors.toUnmodifiableList());
dataType.ifPresent(type -> builder.tilesets(tileMatrixSets.stream().map(tileMatrixSet -> TilesHelper.buildTileSet(api, tileMatrixSet, tileMatrixSetZoomLevels.get(tileMatrixSet.getId()), center, collectionId, type, tilesLinkGenerator.generateTileSetEmbeddedLinks(requestContext.getUriCustomizer(), tileMatrixSet.getId(), tileFormats, i18n, requestContext.getLanguage()), Optional.of(requestContext.getUriCustomizer().copy()), crsTransformerFactory, limitsGenerator, providers, entityRegistry)).collect(Collectors.toUnmodifiableList())));
TileSets tileSets = builder.build();
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(tileSets, TileSets.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("tilesets.%s", outputFormat.getMediaType().fileExtension())).entity(outputFormat.getTileSetsEntity(tileSets, collectionId, api, requestContext)).build();
}
Aggregations