use of de.ii.ogcapi.foundation.domain.Link in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method getEmptyTileResponse.
private Response getEmptyTileResponse(QueryInputTileEmpty queryInput, ApiRequestContext requestContext) {
List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), i18n, requestContext.getLanguage());
Tile tile = queryInput.getTile();
if (!(tile.getOutputFormat() instanceof TileFormatWithQuerySupportExtension))
throw new RuntimeException(String.format("Unexpected tile format without query support. Found: %s", tile.getOutputFormat().getClass().getSimpleName()));
TileFormatWithQuerySupportExtension outputFormat = (TileFormatWithQuerySupportExtension) tile.getOutputFormat();
Date lastModified = null;
EntityTag etag = getEtag(tile.getOutputFormat().getEmptyTile(tile));
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", tile.getTileMatrixSet().getId(), tile.getTileLevel(), tile.getTileRow(), tile.getTileCol(), tile.getOutputFormat().getMediaType().fileExtension())).entity(tile.getOutputFormat().getEmptyTile(tile)).build();
}
use of de.ii.ogcapi.foundation.domain.Link in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method getMbtilesTileResponse.
private Response getMbtilesTileResponse(QueryInputTileMbtilesTile queryInput, ApiRequestContext requestContext) {
String mbtilesFilename = queryInput.getProvider().getFilename();
java.nio.file.Path provider = staticTileProviderStore.getTileProvider(queryInput.getTile().getApiData(), mbtilesFilename);
if (!provider.toFile().exists())
throw new RuntimeException(String.format("Mbtiles file '%s' does not exist", provider));
StreamingOutput streamingOutput = outputStream -> ByteStreams.copy(staticTileProviderStore.getTile(provider, queryInput.getTile()), outputStream);
List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), ImmutableList.of(), i18n, requestContext.getLanguage());
Date lastModified = getLastModified(provider.toFile());
EntityTag etag = getEtag(staticTileProviderStore.getTile(provider, queryInput.getTile()));
Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
if (Objects.nonNull(response))
return response.build();
Tile tile = queryInput.getTile();
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", tile.getTileMatrixSet().getId(), tile.getTileLevel(), tile.getTileRow(), tile.getTileCol(), tile.getOutputFormat().getMediaType().fileExtension())).entity(streamingOutput).build();
}
use of de.ii.ogcapi.foundation.domain.Link 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.foundation.domain.Link in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method getTileStreamResponse.
private Response getTileStreamResponse(QueryInputTileStream queryInput, ApiRequestContext requestContext) {
byte[] content;
try {
content = queryInput.getTileContent().readAllBytes();
} catch (IOException e) {
throw new RuntimeException("Could not read tile from cache.", e);
}
StreamingOutput streamingOutput = outputStream -> ByteStreams.copy(new ByteArrayInputStream(content), outputStream);
List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), i18n, requestContext.getLanguage());
Date lastModified = queryInput.getLastModified().orElse(null);
EntityTag etag = getEtag(content);
Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
if (Objects.nonNull(response))
return response.build();
Tile tile = queryInput.getTile();
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", tile.getTileMatrixSet().getId(), tile.getTileLevel(), tile.getTileRow(), tile.getTileCol(), tile.getOutputFormat().getMediaType().fileExtension())).entity(streamingOutput).build();
}
use of de.ii.ogcapi.foundation.domain.Link in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method getTileServerTileResponse.
private Response getTileServerTileResponse(QueryInputTileTileServerTile queryInput, ApiRequestContext requestContext) {
Tile tile = queryInput.getTile();
final String urlTemplate = tile.isDatasetTile() ? queryInput.getProvider().getUrlTemplate() : queryInput.getProvider().getUrlTemplateSingleCollection();
if (Objects.isNull(urlTemplate))
throw new IllegalStateException("The MAP_TILES configuration is invalid, no 'urlTemplate' was found.");
ApiMediaType mediaType = tile.getOutputFormat().getMediaType();
WebTarget client = ClientBuilder.newClient().target(urlTemplate).resolveTemplate("tileMatrix", tile.getTileLevel()).resolveTemplate("tileRow", tile.getTileRow()).resolveTemplate("tileCol", tile.getTileCol()).resolveTemplate("fileExtension", mediaType.fileExtension());
if (Objects.nonNull(tile.getCollectionId()))
client = client.resolveTemplate("collectionId", tile.getCollectionId());
Response response = client.request(mediaType.type()).get();
// unsuccessful? just forward the error response
if (response.getStatus() != 200)
return response;
List<Link> links = new DefaultLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), ImmutableList.of(), i18n, requestContext.getLanguage());
byte[] content;
try {
content = response.readEntity(InputStream.class).readAllBytes();
} catch (IOException e) {
throw new RuntimeException("Could not read map tile from TileServer.", e);
}
Date lastModified = null;
EntityTag etag = getEtag(content);
Response.ResponseBuilder responseBuilder = evaluatePreconditions(requestContext, lastModified, etag);
if (Objects.nonNull(responseBuilder))
return responseBuilder.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", tile.getTileMatrixSet().getId(), tile.getTileLevel(), tile.getTileRow(), tile.getTileCol(), tile.getOutputFormat().getMediaType().fileExtension())).entity(content).build();
}
Aggregations