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