Search in sources :

Example 1 with Builder

use of de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder in project ldproxy by interactive-instruments.

the class StylesOnCollection method process.

@Override
public ImmutableOgcApiCollection.Builder process(Builder collection, FeatureTypeConfigurationOgcApi featureTypeConfiguration, OgcApi api, URICustomizer uriCustomizer, boolean isNested, ApiMediaType mediaType, List<ApiMediaType> alternateMediaTypes, Optional<Locale> language) {
    // skip link on /collections
    if (isNested)
        return collection;
    OgcApiDataV2 apiData = api.getData();
    // nothing to add if disabled
    String collectionId = featureTypeConfiguration.getId();
    if (!isEnabledForApi(apiData, collectionId)) {
        return collection;
    }
    String defaultStyle = apiData.getCollections().get(collectionId).getExtension(StylesConfiguration.class).map(StylesConfiguration::getDefaultStyle).map(s -> s.equals("NONE") ? null : s).orElse(null);
    if (Objects.isNull(defaultStyle)) {
        defaultStyle = apiData.getCollections().get(collectionId).getExtension(HtmlConfiguration.class).map(HtmlConfiguration::getDefaultStyle).map(s -> s.equals("NONE") ? null : s).orElse(null);
    }
    if (Objects.nonNull(defaultStyle)) {
        Optional<StyleFormatExtension> htmlStyleFormat = styleRepo.getStyleFormatStream(apiData, Optional.of(collectionId)).filter(f -> f.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE)).findAny();
        if (htmlStyleFormat.isPresent() && !styleRepo.stylesheetExists(apiData, Optional.of(collectionId), defaultStyle, htmlStyleFormat.get(), true))
            defaultStyle = null;
    }
    return collection.addAllLinks(new StylesLinkGenerator().generateCollectionLinks(uriCustomizer, Optional.ofNullable(defaultStyle), i18n, language));
}
Also used : OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) I18n(de.ii.ogcapi.foundation.domain.I18n) StyleRepository(de.ii.ogcapi.styles.domain.StyleRepository) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) Builder(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder) Objects(java.util.Objects) Inject(javax.inject.Inject) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) Locale(java.util.Locale) StylesLinkGenerator(de.ii.ogcapi.styles.domain.StylesLinkGenerator) Optional(java.util.Optional) CollectionExtension(de.ii.ogcapi.collections.domain.CollectionExtension) StyleFormatExtension(de.ii.ogcapi.styles.domain.StyleFormatExtension) ImmutableOgcApiCollection(de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) StylesLinkGenerator(de.ii.ogcapi.styles.domain.StylesLinkGenerator) StylesConfiguration(de.ii.ogcapi.styles.domain.StylesConfiguration) StyleFormatExtension(de.ii.ogcapi.styles.domain.StyleFormatExtension)

Example 2 with Builder

use of de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder 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)2 CollectionExtension (de.ii.ogcapi.collections.domain.CollectionExtension)2 ImmutableOgcApiCollection (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection)2 Builder (de.ii.ogcapi.collections.domain.ImmutableOgcApiCollection.Builder)2 ApiMediaType (de.ii.ogcapi.foundation.domain.ApiMediaType)2 ExtensionConfiguration (de.ii.ogcapi.foundation.domain.ExtensionConfiguration)2 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)2 I18n (de.ii.ogcapi.foundation.domain.I18n)2 OgcApi (de.ii.ogcapi.foundation.domain.OgcApi)2 URICustomizer (de.ii.ogcapi.foundation.domain.URICustomizer)2 List (java.util.List)2 Locale (java.util.Locale)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 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