use of de.ii.ogcapi.collections.domain.CollectionExtension in project ldproxy by interactive-instruments.
the class QueriesHandlerCollectionsImpl method getCollectionResponse.
private Response getCollectionResponse(QueryInputFeatureCollection queryInput, ApiRequestContext requestContext) {
OgcApi api = requestContext.getApi();
OgcApiDataV2 apiData = api.getData();
String collectionId = queryInput.getCollectionId();
Optional<String> licenseUrl = apiData.getMetadata().flatMap(Metadata::getLicenseUrl);
Optional<String> licenseName = apiData.getMetadata().flatMap(Metadata::getLicenseName);
List<Link> links = new CollectionLinksGenerator().generateLinks(requestContext.getUriCustomizer().copy(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), licenseUrl, licenseName, i18n, requestContext.getLanguage());
CollectionsFormatExtension outputFormatExtension = api.getOutputFormat(CollectionsFormatExtension.class, requestContext.getMediaType(), "/collections/" + collectionId, Optional.of(collectionId)).orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type ''{0}'' is not supported for this resource.", requestContext.getMediaType())));
ImmutableOgcApiCollection.Builder ogcApiCollection = ImmutableOgcApiCollection.builder().id(collectionId).links(links).addAllLinks(queryInput.getAdditionalLinks());
FeatureTypeConfigurationOgcApi featureTypeConfiguration = apiData.getCollections().get(collectionId);
for (CollectionExtension ogcApiCollectionExtension : getCollectionExtenders()) {
ogcApiCollection = ogcApiCollectionExtension.process(ogcApiCollection, featureTypeConfiguration, api, requestContext.getUriCustomizer().copy(), false, requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), requestContext.getLanguage());
}
OgcApiCollection responseObject = ogcApiCollection.build();
Date lastModified = getLastModified(queryInput, requestContext.getApi());
EntityTag etag = !outputFormatExtension.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE) || api.getData().getExtension(HtmlConfiguration.class, collectionId).map(HtmlConfiguration::getSendEtags).orElse(false) ? getEtag(responseObject, OgcApiCollection.FUNNEL, outputFormatExtension) : null;
Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
if (Objects.nonNull(response))
return response.build();
return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? responseObject.getLinks() : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("%s.%s", collectionId, outputFormatExtension.getMediaType().fileExtension())).entity(outputFormatExtension.getCollectionEntity(responseObject, api, requestContext)).build();
}
use of de.ii.ogcapi.collections.domain.CollectionExtension in project ldproxy by interactive-instruments.
the class CollectionsOnLandingPage method process.
@Override
public ImmutableLandingPage.Builder process(Builder landingPageBuilder, OgcApi api, URICustomizer uriCustomizer, ApiMediaType mediaType, List<ApiMediaType> alternateMediaTypes, Optional<Locale> language) {
OgcApiDataV2 apiData = api.getData();
if (!isEnabledForApi(apiData)) {
return landingPageBuilder;
}
List<String> collectionNames = apiData.getCollections().values().stream().filter(featureType -> featureType.getEnabled()).map(featureType -> featureType.getLabel()).collect(Collectors.toList());
String suffix = (collectionNames.size() > 0 && collectionNames.size() <= 4) ? " (" + String.join(", ", collectionNames) + ")" : "";
landingPageBuilder.addLinks(new ImmutableLink.Builder().href(uriCustomizer.copy().ensureNoTrailingSlash().ensureLastPathSegment("collections").removeParameters("f").toString()).rel("data").title(i18n.get("dataLink", language) + suffix).build()).addLinks(new ImmutableLink.Builder().href(uriCustomizer.copy().ensureNoTrailingSlash().ensureLastPathSegment("collections").removeParameters("f").toString()).rel("http://www.opengis.net/def/rel/ogc/1.0/data").title(i18n.get("dataLink", language) + suffix).build());
ImmutableList.Builder<Link> distributionLinks = new ImmutableList.Builder<Link>().addAll(apiData.getExtension(CollectionsConfiguration.class).map(CollectionsConfiguration::getAdditionalLinks).orElse(ImmutableList.<Link>of()).stream().filter(link -> Objects.equals(link.getRel(), "enclosure")).collect(Collectors.toUnmodifiableList()));
// links to the features in the API)
if (apiData.getCollections().size() == 1) {
String collectionId = apiData.getCollections().keySet().iterator().next();
FeatureTypeConfigurationOgcApi featureTypeConfiguration = apiData.getCollections().get(collectionId);
distributionLinks.addAll(featureTypeConfiguration.getAdditionalLinks().stream().filter(link -> Objects.equals(link.getRel(), "enclosure")).collect(Collectors.toUnmodifiableList()));
ImmutableOgcApiCollection.Builder ogcApiCollection = ImmutableOgcApiCollection.builder().id(collectionId);
for (CollectionExtension ogcApiCollectionExtension : extensionRegistry.getExtensionsForType(CollectionExtension.class)) {
ogcApiCollection = ogcApiCollectionExtension.process(ogcApiCollection, featureTypeConfiguration, api, uriCustomizer.copy().clearParameters().ensureLastPathSegments("collections", collectionId).ensureNoTrailingSlash(), false, mediaType, alternateMediaTypes, language);
}
distributionLinks.addAll(ogcApiCollection.build().getLinks().stream().filter(link -> Objects.equals(link.getRel(), "items") && !Objects.equals(link.getType(), "text/html")).collect(Collectors.toUnmodifiableList()));
}
landingPageBuilder.putExtensions("datasetDownloadLinks", distributionLinks.build());
return landingPageBuilder;
}
use of de.ii.ogcapi.collections.domain.CollectionExtension in project ldproxy by interactive-instruments.
the class CollectionExtensionFeatures method createNestedCollection.
public static OgcApiCollection createNestedCollection(FeatureTypeConfigurationOgcApi featureType, OgcApi api, ApiMediaType mediaType, List<ApiMediaType> alternateMediaTypes, Optional<Locale> language, URICustomizer uriCustomizer, List<CollectionExtension> collectionExtenders) {
ImmutableOgcApiCollection.Builder ogcApiCollection = ImmutableOgcApiCollection.builder().id(featureType.getId());
for (CollectionExtension ogcApiCollectionExtension : collectionExtenders) {
ogcApiCollection = ogcApiCollectionExtension.process(ogcApiCollection, featureType, api, uriCustomizer.copy(), true, mediaType, alternateMediaTypes, language);
}
ImmutableOgcApiCollection result = null;
try {
result = ogcApiCollection.build();
} catch (Throwable e) {
result = null;
}
return result;
}
Aggregations