Search in sources :

Example 1 with OgcApiExtent

use of de.ii.ogcapi.common.domain.OgcApiExtent in project ldproxy by interactive-instruments.

the class CollectionExtensionFeatures method process.

@Override
public ImmutableOgcApiCollection.Builder process(Builder collection, FeatureTypeConfigurationOgcApi featureType, OgcApi api, URICustomizer uriCustomizer, boolean isNested, ApiMediaType mediaType, List<ApiMediaType> alternateMediaTypes, Optional<Locale> language) {
    collection.title(featureType.getLabel()).description(featureType.getDescription()).itemType(featureType.getExtension(FeaturesCoreConfiguration.class).filter(ExtensionConfiguration::isEnabled).flatMap(FeaturesCoreConfiguration::getItemType).map(Enum::toString).orElse(FeaturesCoreConfiguration.ItemType.unknown.toString()));
    api.getItemCount(featureType.getId()).filter(count -> count >= 0).ifPresent(count -> collection.putExtensions("itemCount", count));
    URICustomizer uriBuilder = uriCustomizer.copy().ensureNoTrailingSlash().clearParameters();
    if (isNested) {
        // also add an untyped a self link in the Collections resource, otherwise the standard links are already there
        collection.addLinks(new ImmutableLink.Builder().href(uriBuilder.copy().ensureLastPathSegments("collections", featureType.getId()).removeParameters("f").toString()).rel("self").title(i18n.get("selfLinkCollection", language).replace("{{collection}}", featureType.getLabel())).build());
    }
    List<ApiMediaType> featureMediaTypes = extensionRegistry.getExtensionsForType(FeatureFormatExtension.class).stream().filter(outputFormatExtension -> outputFormatExtension.isEnabledForApi(api.getData())).map(outputFormatExtension -> outputFormatExtension.getMediaType()).collect(Collectors.toList());
    featureMediaTypes.stream().forEach(mtype -> collection.addLinks(new ImmutableLink.Builder().href(uriBuilder.ensureLastPathSegments("collections", featureType.getId(), "items").setParameter("f", mtype.parameter()).toString()).rel("items").type(mtype.type().toString()).title(i18n.get("itemsLink", language).replace("{{collection}}", featureType.getLabel()).replace("{{type}}", mtype.label())).build()));
    Optional<String> describeFeatureTypeUrl = Optional.empty();
    if (describeFeatureTypeUrl.isPresent()) {
        collection.addLinks(new ImmutableLink.Builder().href(describeFeatureTypeUrl.get()).rel("describedby").type("application/xml").title(i18n.get("describedByXsdLink", language)).build());
    }
    // only add extents for cases where we can filter using spatial / temporal predicates
    Optional<FeaturesCollectionQueryables> queryables = featureType.getExtension(FeaturesCoreConfiguration.class).flatMap(FeaturesCoreConfiguration::getQueryables);
    boolean hasSpatialQueryable = queryables.map(FeaturesCollectionQueryables::getSpatial).filter(spatial -> !spatial.isEmpty()).isPresent();
    boolean hasTemporalQueryable = queryables.map(FeaturesCollectionQueryables::getTemporal).filter(temporal -> !temporal.isEmpty()).isPresent();
    Optional<BoundingBox> spatial = api.getSpatialExtent(featureType.getId());
    Optional<TemporalExtent> temporal = api.getTemporalExtent(featureType.getId());
    if (hasSpatialQueryable && hasTemporalQueryable && spatial.isPresent() && temporal.isPresent()) {
        collection.extent(new OgcApiExtent(temporal.get().getStart(), temporal.get().getEnd(), spatial.get().getXmin(), spatial.get().getYmin(), spatial.get().getXmax(), spatial.get().getYmax()));
    } else if (hasSpatialQueryable && spatial.isPresent()) {
        collection.extent(new OgcApiExtent(spatial.get().getXmin(), spatial.get().getYmin(), spatial.get().getXmax(), spatial.get().getYmax()));
    } else if (hasTemporalQueryable && temporal.isPresent()) {
        collection.extent(new OgcApiExtent(temporal.get().getStart(), temporal.get().getEnd()));
    }
    return collection;
}
Also used : OgcApiExtent(de.ii.ogcapi.common.domain.OgcApiExtent) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) OgcApiCollection(de.ii.ogcapi.collections.domain.OgcApiCollection) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) Inject(javax.inject.Inject) 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) FeatureFormatExtension(de.ii.ogcapi.features.core.domain.FeatureFormatExtension) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) FeaturesCollectionQueryables(de.ii.ogcapi.features.core.domain.FeaturesCollectionQueryables) Collectors(java.util.stream.Collectors) Builder(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) List(java.util.List) TemporalExtent(de.ii.ogcapi.foundation.domain.TemporalExtent) Optional(java.util.Optional) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) Builder(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder) OgcApiExtent(de.ii.ogcapi.common.domain.OgcApiExtent) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) FeaturesCollectionQueryables(de.ii.ogcapi.features.core.domain.FeaturesCollectionQueryables) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) TemporalExtent(de.ii.ogcapi.foundation.domain.TemporalExtent) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) ImmutableLink(de.ii.ogcapi.foundation.domain.ImmutableLink)

Example 2 with OgcApiExtent

use of de.ii.ogcapi.common.domain.OgcApiExtent in project ldproxy by interactive-instruments.

the class QueriesHandlerCommonImpl method getLandingPageResponse.

private Response getLandingPageResponse(QueryInputLandingPage queryInput, ApiRequestContext requestContext) {
    final LandingPageLinksGenerator linksGenerator = new LandingPageLinksGenerator();
    OgcApi api = requestContext.getApi();
    OgcApiDataV2 apiData = api.getData();
    List<Link> links = linksGenerator.generateLinks(requestContext.getUriCustomizer().copy(), // TODO: support schema links, e.g. for WFS provider new WFSRequest(service.getWfsAdapter(), new DescribeFeatureType()).getAsUrl()
    Optional.empty(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), i18n, requestContext.getLanguage());
    Optional<BoundingBox> bbox = api.getSpatialExtent();
    Optional<TemporalExtent> interval = api.getTemporalExtent();
    OgcApiExtent spatialExtent = bbox.isPresent() && interval.isPresent() ? new OgcApiExtent(interval.get().getStart(), interval.get().getEnd(), bbox.get().getXmin(), bbox.get().getYmin(), bbox.get().getXmax(), bbox.get().getYmax()) : bbox.map(boundingBox -> new OgcApiExtent(boundingBox.getXmin(), boundingBox.getYmin(), boundingBox.getXmax(), boundingBox.getYmax())).orElseGet(() -> interval.map(temporalExtent -> new OgcApiExtent(temporalExtent.getStart(), temporalExtent.getEnd())).orElse(null));
    ;
    Builder builder = new Builder().title(apiData.getLabel()).description(apiData.getDescription().orElse("")).attribution(apiData.getMetadata().flatMap(Metadata::getAttribution)).externalDocs(apiData.getExternalDocs()).extent(Optional.ofNullable(spatialExtent)).links(links).addAllLinks(queryInput.getAdditionalLinks());
    for (LandingPageExtension ogcApiLandingPageExtension : getDatasetExtenders()) {
        builder = ogcApiLandingPageExtension.process(builder, api, requestContext.getUriCustomizer().copy(), requestContext.getMediaType(), requestContext.getAlternateMediaTypes(), requestContext.getLanguage());
    }
    CommonFormatExtension outputFormatExtension = api.getOutputFormat(CommonFormatExtension.class, requestContext.getMediaType(), "/", Optional.empty()).orElseThrow(() -> new NotAcceptableException(MessageFormat.format("The requested media type {0} cannot be generated.", requestContext.getMediaType().type())));
    LandingPage apiLandingPage = builder.build();
    Object entity = outputFormatExtension.getLandingPageEntity(apiLandingPage, requestContext.getApi(), requestContext);
    Date lastModified = getLastModified(queryInput, api);
    EntityTag etag = !outputFormatExtension.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE) || api.getData().getExtension(HtmlConfiguration.class).map(HtmlConfiguration::getSendEtags).orElse(false) ? getEtag(apiLandingPage, PageRepresentation.FUNNEL, outputFormatExtension) : null;
    Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
    if (Objects.nonNull(response))
        return response.build();
    return prepareSuccessResponse(requestContext, queryInput.getIncludeLinkHeader() ? apiLandingPage.getLinks() : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), null, true, String.format("landing-page.%s", outputFormatExtension.getMediaType().fileExtension())).entity(entity).build();
}
Also used : QueryHandler(de.ii.ogcapi.foundation.domain.QueryHandler) QueryIdentifier(de.ii.ogcapi.foundation.domain.QueryIdentifier) OgcApiExtent(de.ii.ogcapi.common.domain.OgcApiExtent) LandingPageExtension(de.ii.ogcapi.common.domain.LandingPageExtension) Date(java.util.Date) Link(de.ii.ogcapi.foundation.domain.Link) ConformanceDeclaration(de.ii.ogcapi.common.domain.ConformanceDeclaration) QueryInput(de.ii.ogcapi.foundation.domain.QueryInput) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) ConformanceClass(de.ii.ogcapi.foundation.domain.ConformanceClass) Value(org.immutables.value.Value) Map(java.util.Map) ImmutableConformanceDeclaration(de.ii.ogcapi.common.domain.ImmutableConformanceDeclaration) ExtensionRegistry(de.ii.ogcapi.foundation.domain.ExtensionRegistry) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) ConformanceDeclarationExtension(de.ii.ogcapi.common.domain.ConformanceDeclarationExtension) ApiRequestContext(de.ii.ogcapi.foundation.domain.ApiRequestContext) Builder(de.ii.ogcapi.common.domain.ImmutableLandingPage.Builder) NotAcceptableException(javax.ws.rs.NotAcceptableException) ImmutableMap(com.google.common.collect.ImmutableMap) I18n(de.ii.ogcapi.foundation.domain.I18n) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) LandingPage(de.ii.ogcapi.common.domain.LandingPage) EntityTag(javax.ws.rs.core.EntityTag) Collectors(java.util.stream.Collectors) QueriesHandlerCommon(de.ii.ogcapi.common.domain.QueriesHandlerCommon) Objects(java.util.Objects) PageRepresentation(de.ii.ogcapi.foundation.domain.PageRepresentation) List(java.util.List) Response(javax.ws.rs.core.Response) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) TemporalExtent(de.ii.ogcapi.foundation.domain.TemporalExtent) Optional(java.util.Optional) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) Metadata(de.ii.ogcapi.foundation.domain.Metadata) CommonFormatExtension(de.ii.ogcapi.common.domain.CommonFormatExtension) ApiDefinitionFormatExtension(de.ii.ogcapi.common.domain.ApiDefinitionFormatExtension) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) OgcApiExtent(de.ii.ogcapi.common.domain.OgcApiExtent) Builder(de.ii.ogcapi.common.domain.ImmutableLandingPage.Builder) CommonFormatExtension(de.ii.ogcapi.common.domain.CommonFormatExtension) LandingPage(de.ii.ogcapi.common.domain.LandingPage) Date(java.util.Date) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Response(javax.ws.rs.core.Response) TemporalExtent(de.ii.ogcapi.foundation.domain.TemporalExtent) LandingPageExtension(de.ii.ogcapi.common.domain.LandingPageExtension) NotAcceptableException(javax.ws.rs.NotAcceptableException) BoundingBox(de.ii.xtraplatform.crs.domain.BoundingBox) EntityTag(javax.ws.rs.core.EntityTag) Link(de.ii.ogcapi.foundation.domain.Link)

Aggregations

AutoBind (com.github.azahnen.dagger.annotations.AutoBind)2 OgcApiExtent (de.ii.ogcapi.common.domain.OgcApiExtent)2 ExtensionRegistry (de.ii.ogcapi.foundation.domain.ExtensionRegistry)2 I18n (de.ii.ogcapi.foundation.domain.I18n)2 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)2 TemporalExtent (de.ii.ogcapi.foundation.domain.TemporalExtent)2 BoundingBox (de.ii.xtraplatform.crs.domain.BoundingBox)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 CollectionExtension (de.ii.ogcapi.collections.domain.CollectionExtension)1 ImmutableOgcApiCollection (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection)1 Builder (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder)1 OgcApiCollection (de.ii.ogcapi.collections.domain.OgcApiCollection)1 ApiDefinitionFormatExtension (de.ii.ogcapi.common.domain.ApiDefinitionFormatExtension)1 CommonFormatExtension (de.ii.ogcapi.common.domain.CommonFormatExtension)1 ConformanceDeclaration (de.ii.ogcapi.common.domain.ConformanceDeclaration)1