use of de.ii.xtraplatform.web.domain.MustacheRenderer in project ldproxy by interactive-instruments.
the class FeatureEncoderHtml method onEnd.
@Override
public void onEnd(ModifiableContext context) {
// TODO: FeatureTokenEncoderBytes.getOutputStream
OutputStreamWriter writer = new OutputStreamWriter(new OutputStreamToByteConsumer(this::push));
try {
((MustacheRenderer) transformationContext.mustacheRenderer()).render(transformationContext.collectionView(), writer);
writer.flush();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of de.ii.xtraplatform.web.domain.MustacheRenderer in project ldproxy by interactive-instruments.
the class FeaturesFormatHtml method getFeatureEncoder.
@Override
public Optional<FeatureTokenEncoder<?>> getFeatureEncoder(FeatureTransformationContext transformationContext, Optional<Locale> language) {
OgcApi api = transformationContext.getApi();
OgcApiDataV2 apiData = transformationContext.getApiData();
String collectionName = transformationContext.getCollectionId();
String staticUrlPrefix = transformationContext.getOgcApiRequest().getStaticUrlPrefix();
URICustomizer uriCustomizer = transformationContext.getOgcApiRequest().getUriCustomizer();
FeatureCollectionView featureTypeDataset;
boolean bare = transformationContext.getOgcApiRequest().getUriCustomizer().getQueryParams().stream().anyMatch(nameValuePair -> nameValuePair.getName().equals("bare") && nameValuePair.getValue().equals("true"));
if (transformationContext.isFeatureCollection()) {
FeatureTypeConfigurationOgcApi collectionData = apiData.getCollections().get(collectionName);
Integer htmlMaxLimit = collectionData.getExtension(FeaturesHtmlConfiguration.class).map(FeaturesHtmlConfiguration::getMaximumPageSize).orElse(null);
if (Objects.nonNull(htmlMaxLimit) && htmlMaxLimit < transformationContext.getLimit())
throw new IllegalArgumentException(String.format("The HTML output has a maximum page size (parameter 'limit') of %d. Found: %d", htmlMaxLimit, transformationContext.getLimit()));
Optional<FeaturesCoreConfiguration> featuresCoreConfiguration = collectionData.getExtension(FeaturesCoreConfiguration.class);
List<String> queryables = featuresCoreConfiguration.map(FeaturesCoreConfiguration::getQOrOtherFilterParameters).orElse(ImmutableList.of());
Map<String, String> filterableFields = transformationContext.getFeatureSchema().map(schema -> schema.accept(SCHEMA_FLATTENER)).map(schema -> schema.getProperties().stream().filter(property -> queryables.contains(property.getName())).map(property -> new SimpleImmutableEntry<>(property.getName(), property.getLabel().orElse(property.getName()))).collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))).orElse(ImmutableMap.of());
featureTypeDataset = createFeatureCollectionView(api, apiData.getCollections().get(collectionName), uriCustomizer.copy(), filterableFields, staticUrlPrefix, bare, language, isNoIndexEnabledForApi(apiData), getMapPosition(apiData, collectionName), getGeometryProperties(apiData, collectionName));
addDatasetNavigation(featureTypeDataset, apiData.getLabel(), apiData.getCollections().get(collectionName).getLabel(), transformationContext.getLinks(), uriCustomizer.copy(), language, apiData.getSubPath());
} else {
featureTypeDataset = createFeatureDetailsView(api, apiData.getCollections().get(collectionName), uriCustomizer.copy(), transformationContext.getLinks(), apiData.getLabel(), uriCustomizer.getLastPathSegment(), staticUrlPrefix, language, isNoIndexEnabledForApi(apiData), apiData.getSubPath(), getMapPosition(apiData, collectionName), getGeometryProperties(apiData, collectionName));
}
ImmutableFeatureTransformationContextHtml transformationContextHtml = ImmutableFeatureTransformationContextHtml.builder().from(transformationContext).collectionView(featureTypeDataset).codelists(entityRegistry.getEntitiesForType(Codelist.class).stream().collect(Collectors.toMap(c -> c.getId(), c -> c))).mustacheRenderer(mustacheRenderer).i18n(i18n).language(language).build();
return Optional.of(new FeatureEncoderHtml(transformationContextHtml));
}
Aggregations