Search in sources :

Example 1 with FeaturesCollectionQueryables

use of de.ii.ogcapi.features.core.domain.FeaturesCollectionQueryables 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)

Aggregations

AutoBind (com.github.azahnen.dagger.annotations.AutoBind)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 OgcApiExtent (de.ii.ogcapi.common.domain.OgcApiExtent)1 FeatureFormatExtension (de.ii.ogcapi.features.core.domain.FeatureFormatExtension)1 FeaturesCollectionQueryables (de.ii.ogcapi.features.core.domain.FeaturesCollectionQueryables)1 FeaturesCoreConfiguration (de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)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 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)1 I18n (de.ii.ogcapi.foundation.domain.I18n)1 ImmutableLink (de.ii.ogcapi.foundation.domain.ImmutableLink)1 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)1 TemporalExtent (de.ii.ogcapi.foundation.domain.TemporalExtent)1 URICustomizer (de.ii.ogcapi.foundation.domain.URICustomizer)1 BoundingBox (de.ii.xtraplatform.crs.domain.BoundingBox)1 List (java.util.List)1