use of de.ii.xtraplatform.features.domain.transform.PropertyTransformations in project ldproxy by interactive-instruments.
the class SchemaCacheFlatgeobuf method deriveSchema.
@Override
protected FeatureSchema deriveSchema(FeatureSchema schema, OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData) {
Optional<PropertyTransformations> propertyTransformations = collectionData.getExtension(FlatgeobufConfiguration.class).map(configuration -> (PropertyTransformations) configuration);
WithTransformationsApplied schemaTransformer = propertyTransformations.map(WithTransformationsApplied::new).orElse(new WithTransformationsApplied());
Optional<String> separator = schemaTransformer.getFlatteningSeparator(schema);
if (separator.isEmpty())
return schema.accept(schemaTransformer);
int maxMultiplicity = collectionData.getExtension(FlatgeobufConfiguration.class).map(FlatgeobufConfiguration::getMaxMultiplicity).orElse(DEFAULT_MULTIPLICITY);
FanOutArrays arrayTransformer = new FanOutArrays(separator.get(), maxMultiplicity);
return schema.accept(schemaTransformer).accept(arrayTransformer).get(0);
}
use of de.ii.xtraplatform.features.domain.transform.PropertyTransformations in project ldproxy by interactive-instruments.
the class SchemaCacheReturnables method deriveSchema.
@Override
protected JsonSchemaDocument deriveSchema(FeatureSchema schema, OgcApiDataV2 apiData, FeatureTypeConfigurationOgcApi collectionData, Optional<String> schemaUri, VERSION version) {
Optional<PropertyTransformations> propertyTransformations = collectionData.getExtension(GeoJsonConfiguration.class).map(geoJsonConfiguration -> (PropertyTransformations) geoJsonConfiguration);
WithTransformationsApplied schemaTransformer = propertyTransformations.map(WithTransformationsApplied::new).orElse(new WithTransformationsApplied());
SchemaDeriverReturnables schemaDeriverReturnables = new SchemaDeriverReturnables(version, schemaUri, collectionData.getLabel(), Optional.empty(), codelistSupplier.get());
return (JsonSchemaDocument) schema.accept(schemaTransformer).accept(schemaDeriverReturnables);
}
use of de.ii.xtraplatform.features.domain.transform.PropertyTransformations in project ldproxy by interactive-instruments.
the class TilesQueriesHandlerImpl method generateTile.
private ResultReduced<byte[]> generateTile(FeatureStream featureStream, FeatureTokenEncoder<?> encoder, FeatureTransformationContextTiles transformationContext, TileFormatWithQuerySupportExtension outputFormat) {
Optional<PropertyTransformations> propertyTransformations = transformationContext.getCollection().flatMap(collection -> outputFormat.getPropertyTransformations(collection, ImmutableMap.of("serviceUrl", transformationContext.getServiceUrl()), outputFormat.getBuildingBlockConfigurationType()));
SinkReduced<Object, byte[]> featureSink = encoder.to(Sink.reduceByteArray());
try {
ResultReduced<byte[]> result = featureStream.runWith(featureSink, propertyTransformations).toCompletableFuture().join();
if (result.isSuccess()) {
Tile tile = transformationContext.tile();
try {
// write/update tile in cache
tileCache.storeTile(tile, result.reduced());
} catch (Throwable e) {
String msg = "Failure to write the multi-layer file of tile {}/{}/{}/{} in dataset '{}', format '{}' to the cache";
LogContext.errorAsInfo(LOGGER, e, msg, tile.getTileMatrixSet().getId(), tile.getTileLevel(), tile.getTileRow(), tile.getTileCol(), transformationContext.getApiData().getId(), outputFormat.getExtension());
}
} else {
result.getError().ifPresent(QueriesHandler::processStreamError);
}
return result;
} catch (CompletionException e) {
if (e.getCause() instanceof WebApplicationException) {
throw (WebApplicationException) e.getCause();
}
throw new IllegalStateException("Feature stream error.", e.getCause());
}
}
use of de.ii.xtraplatform.features.domain.transform.PropertyTransformations in project ldproxy by interactive-instruments.
the class FeaturesCoreQueriesHandlerImpl method getItemsResponse.
private Response getItemsResponse(OgcApi api, ApiRequestContext requestContext, String collectionId, String featureId, QueryInput queryInput, FeatureQuery query, FeatureProvider2 featureProvider, String canonicalUri, FeatureFormatExtension outputFormat, boolean onlyHitsIfMore, Optional<Integer> defaultPageSize, boolean showsFeatureSelfLink, boolean includeLinkHeader, EpsgCrs defaultCrs) {
ensureCollectionIdExists(api.getData(), collectionId);
ensureFeatureProviderSupportsQueries(featureProvider);
Optional<CrsTransformer> crsTransformer = Optional.empty();
EpsgCrs sourceCrs = null;
EpsgCrs targetCrs = query.getCrs().orElse(defaultCrs);
if (featureProvider.supportsCrs()) {
sourceCrs = featureProvider.crs().getNativeCrs();
crsTransformer = crsTransformerFactory.getTransformer(sourceCrs, targetCrs);
}
List<ApiMediaType> alternateMediaTypes = requestContext.getAlternateMediaTypes();
List<Link> links = Objects.isNull(featureId) ? new FeaturesLinksGenerator().generateLinks(requestContext.getUriCustomizer(), query.getOffset(), query.getLimit(), defaultPageSize.orElse(0), requestContext.getMediaType(), alternateMediaTypes, i18n, requestContext.getLanguage()) : new FeatureLinksGenerator().generateLinks(requestContext.getUriCustomizer(), requestContext.getMediaType(), alternateMediaTypes, outputFormat.getCollectionMediaType(), canonicalUri, i18n, requestContext.getLanguage());
String featureTypeId = api.getData().getCollections().get(collectionId).getExtension(FeaturesCoreConfiguration.class).map(cfg -> cfg.getFeatureType().orElse(collectionId)).orElse(collectionId);
ImmutableFeatureTransformationContextGeneric.Builder transformationContext = new ImmutableFeatureTransformationContextGeneric.Builder().api(api).apiData(api.getData()).featureSchema(featureProvider.getData().getTypes().get(featureTypeId)).collectionId(collectionId).ogcApiRequest(requestContext).crsTransformer(crsTransformer).codelists(entityRegistry.getEntitiesForType(Codelist.class).stream().collect(Collectors.toMap(PersistentEntity::getId, c -> c))).defaultCrs(defaultCrs).sourceCrs(Optional.ofNullable(sourceCrs)).links(links).isFeatureCollection(Objects.isNull(featureId)).isHitsOnly(query.hitsOnly()).isPropertyOnly(query.propertyOnly()).fields(query.getFields()).limit(query.getLimit()).offset(query.getOffset()).maxAllowableOffset(query.getMaxAllowableOffset()).geometryPrecision(query.getGeometryPrecision()).isHitsOnlyIfMore(onlyHitsIfMore).showsFeatureSelfLink(showsFeatureSelfLink);
StreamingOutput streamingOutput;
if (outputFormat.canPassThroughFeatures() && featureProvider.supportsPassThrough() && outputFormat.getMediaType().matches(featureProvider.passThrough().getMediaType())) {
FeatureStream featureStream = featureProvider.passThrough().getFeatureStreamPassThrough(query);
ImmutableFeatureTransformationContextGeneric transformationContextGeneric = transformationContext.outputStream(new OutputStreamToByteConsumer()).build();
FeatureTokenEncoder<?> encoder = outputFormat.getFeatureEncoderPassThrough(transformationContextGeneric, requestContext.getLanguage()).get();
streamingOutput = stream(featureStream, Objects.nonNull(featureId), encoder, Optional.empty());
} else if (outputFormat.canEncodeFeatures()) {
FeatureStream featureStream = featureProvider.queries().getFeatureStream(query);
ImmutableFeatureTransformationContextGeneric transformationContextGeneric = transformationContext.outputStream(new OutputStreamToByteConsumer()).build();
FeatureTokenEncoder<?> encoder = outputFormat.getFeatureEncoder(transformationContextGeneric, requestContext.getLanguage()).get();
Optional<PropertyTransformations> propertyTransformations = outputFormat.getPropertyTransformations(api.getData().getCollections().get(collectionId)).map(pt -> pt.withSubstitutions(ImmutableMap.of("serviceUrl", transformationContextGeneric.getServiceUrl())));
streamingOutput = stream(featureStream, Objects.nonNull(featureId), encoder, propertyTransformations);
} else {
throw new NotAcceptableException(MessageFormat.format("The requested media type {0} cannot be generated, because it does not support streaming.", requestContext.getMediaType().type()));
}
Date lastModified = null;
EntityTag etag = null;
byte[] result = null;
if (Objects.nonNull(featureId)) {
// support etag from the content for a single feature
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
streamingOutput.write(baos);
} catch (IOException e) {
throw new IllegalStateException("Feature stream error.", e);
}
result = baos.toByteArray();
etag = !outputFormat.getMediaType().type().equals(MediaType.TEXT_HTML_TYPE) || api.getData().getExtension(HtmlConfiguration.class, collectionId).map(HtmlConfiguration::getSendEtags).orElse(false) ? getEtag(result) : null;
} else {
lastModified = getLastModified(queryInput, requestContext.getApi(), featureProvider);
}
Response.ResponseBuilder response = evaluatePreconditions(requestContext, lastModified, etag);
if (Objects.nonNull(response))
return response.build();
return prepareSuccessResponse(requestContext, includeLinkHeader ? links.stream().filter(link -> !"next".equalsIgnoreCase(link.getRel())).collect(ImmutableList.toImmutableList()) : null, lastModified, etag, queryInput.getCacheControl().orElse(null), queryInput.getExpires().orElse(null), targetCrs, true, String.format("%s.%s", Objects.isNull(featureId) ? collectionId : featureId, outputFormat.getMediaType().fileExtension())).entity(Objects.nonNull(result) ? result : streamingOutput).build();
}
Aggregations