Search in sources :

Example 1 with CollectionExtension

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();
}
Also used : CollectionsFormatExtension(de.ii.ogcapi.collections.domain.CollectionsFormatExtension) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) Metadata(de.ii.ogcapi.foundation.domain.Metadata) Date(java.util.Date) OgcApiCollection(de.ii.ogcapi.collections.domain.OgcApiCollection) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection) EntityTag(javax.ws.rs.core.EntityTag) Link(de.ii.ogcapi.foundation.domain.Link)

Example 2 with CollectionExtension

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;
}
Also used : ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) LandingPageExtension(de.ii.ogcapi.common.domain.LandingPageExtension) ImmutableLandingPage(de.ii.ogcapi.common.domain.ImmutableLandingPage) Link(de.ii.ogcapi.foundation.domain.Link) Singleton(javax.inject.Singleton) CollectionsConfiguration(de.ii.ogcapi.collections.domain.CollectionsConfiguration) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) ImmutableLink(de.ii.ogcapi.foundation.domain.ImmutableLink) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) Builder(de.ii.ogcapi.common.domain.ImmutableLandingPage.Builder) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Optional(java.util.Optional) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) ImmutableList(com.google.common.collect.ImmutableList) Builder(de.ii.ogcapi.common.domain.ImmutableLandingPage.Builder) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection) ImmutableLink(de.ii.ogcapi.foundation.domain.ImmutableLink) Link(de.ii.ogcapi.foundation.domain.Link) ImmutableLink(de.ii.ogcapi.foundation.domain.ImmutableLink)

Example 3 with CollectionExtension

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;
}
Also used : Builder(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection)

Aggregations

CollectionExtension (de.ii.ogcapi.collections.domain.CollectionExtension)3 ImmutableOgcApiCollection (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection)3 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)2 Link (de.ii.ogcapi.foundation.domain.Link)2 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)2 OgcApiDataV2 (de.ii.ogcapi.foundation.domain.OgcApiDataV2)2 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)1 ImmutableList (com.google.common.collect.ImmutableList)1 CollectionsConfiguration (de.ii.ogcapi.collections.domain.CollectionsConfiguration)1 CollectionsFormatExtension (de.ii.ogcapi.collections.domain.CollectionsFormatExtension)1 Builder (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder)1 OgcApiCollection (de.ii.ogcapi.collections.domain.OgcApiCollection)1 ImmutableLandingPage (de.ii.ogcapi.common.domain.ImmutableLandingPage)1 Builder (de.ii.ogcapi.common.domain.ImmutableLandingPage.Builder)1 LandingPageExtension (de.ii.ogcapi.common.domain.LandingPageExtension)1 ApiMediaType (de.ii.ogcapi.foundation.domain.ApiMediaType)1 ExtensionConfiguration (de.ii.ogcapi.foundation.domain.ExtensionConfiguration)1 ExtensionRegistry (de.ii.ogcapi.foundation.domain.ExtensionRegistry)1 I18n (de.ii.ogcapi.foundation.domain.I18n)1 ImmutableLink (de.ii.ogcapi.foundation.domain.ImmutableLink)1