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));
}
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;
}
Aggregations