Search in sources :

Example 1 with MustacheRenderer

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);
    }
}
Also used : MustacheRenderer(de.ii.xtraplatform.web.domain.MustacheRenderer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamToByteConsumer(de.ii.xtraplatform.streams.domain.OutputStreamToByteConsumer)

Example 2 with MustacheRenderer

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));
}
Also used : ImmutableApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ImmutableApiMediaTypeContent) MustacheRenderer(de.ii.xtraplatform.web.domain.MustacheRenderer) URISyntaxException(java.net.URISyntaxException) Link(de.ii.ogcapi.foundation.domain.Link) ImmutableValidationResult(de.ii.xtraplatform.store.domain.entities.ImmutableValidationResult) MODE(de.ii.xtraplatform.store.domain.entities.ValidationResult.MODE) ApiMediaType(de.ii.ogcapi.foundation.domain.ApiMediaType) ImmutableApiMediaType(de.ii.ogcapi.foundation.domain.ImmutableApiMediaType) MediaType(javax.ws.rs.core.MediaType) Builder(de.ii.xtraplatform.features.domain.transform.ImmutablePropertyTransformation.Builder) Locale(java.util.Locale) Map(java.util.Map) URI(java.net.URI) FeatureSchema(de.ii.xtraplatform.features.domain.FeatureSchema) HtmlConfiguration(de.ii.ogcapi.html.domain.HtmlConfiguration) WithTransformationsApplied(de.ii.xtraplatform.features.domain.transform.WithTransformationsApplied) ApiMediaTypeContent(de.ii.ogcapi.foundation.domain.ApiMediaTypeContent) FeaturesCoreProviders(de.ii.ogcapi.features.core.domain.FeaturesCoreProviders) ImmutableMap(com.google.common.collect.ImmutableMap) FeatureTokenEncoder(de.ii.xtraplatform.features.domain.FeatureTokenEncoder) Collection(java.util.Collection) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) Set(java.util.Set) Collectors(java.util.stream.Collectors) PropertyTransformation(de.ii.xtraplatform.features.domain.transform.PropertyTransformation) Objects(java.util.Objects) MapClient(de.ii.ogcapi.html.domain.MapClient) List(java.util.List) StringTemplateFilters(de.ii.xtraplatform.strings.domain.StringTemplateFilters) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) Entry(java.util.Map.Entry) Optional(java.util.Optional) FeaturesCoreValidation(de.ii.ogcapi.features.core.domain.FeaturesCoreValidation) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) EntityRegistry(de.ii.xtraplatform.store.domain.entities.EntityRegistry) ServicesContext(de.ii.xtraplatform.services.domain.ServicesContext) ItemTypeSpecificConformanceClass(de.ii.ogcapi.features.core.domain.ItemTypeSpecificConformanceClass) ExtensionConfiguration(de.ii.ogcapi.foundation.domain.ExtensionConfiguration) PropertyTransformations(de.ii.xtraplatform.features.domain.transform.PropertyTransformations) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Singleton(javax.inject.Singleton) AutoBind(com.github.azahnen.dagger.annotations.AutoBind) POSITION(de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration.POSITION) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) ValidationResult(de.ii.xtraplatform.store.domain.entities.ValidationResult) Schema(io.swagger.v3.oas.models.media.Schema) NavigationDTO(de.ii.ogcapi.html.domain.NavigationDTO) FeaturesHtmlConfiguration(de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration) FeatureFormatExtension(de.ii.ogcapi.features.core.domain.FeatureFormatExtension) I18n(de.ii.ogcapi.foundation.domain.I18n) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration) AbstractMap(java.util.AbstractMap) DEFAULT_FLATTENING_SEPARATOR(de.ii.ogcapi.features.core.domain.SchemaGeneratorFeatureOpenApi.DEFAULT_FLATTENING_SEPARATOR) FeatureTransformationContext(de.ii.ogcapi.features.core.domain.FeatureTransformationContext) Metadata(de.ii.ogcapi.foundation.domain.Metadata) Comparator(java.util.Comparator) Codelist(de.ii.xtraplatform.codelists.domain.Codelist) OgcApi(de.ii.ogcapi.foundation.domain.OgcApi) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) URICustomizer(de.ii.ogcapi.foundation.domain.URICustomizer) OgcApiDataV2(de.ii.ogcapi.foundation.domain.OgcApiDataV2) FeatureTypeConfigurationOgcApi(de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) FeaturesCoreConfiguration(de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)

Aggregations

MustacheRenderer (de.ii.xtraplatform.web.domain.MustacheRenderer)2 AutoBind (com.github.azahnen.dagger.annotations.AutoBind)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FeatureFormatExtension (de.ii.ogcapi.features.core.domain.FeatureFormatExtension)1 FeatureTransformationContext (de.ii.ogcapi.features.core.domain.FeatureTransformationContext)1 FeaturesCoreConfiguration (de.ii.ogcapi.features.core.domain.FeaturesCoreConfiguration)1 FeaturesCoreProviders (de.ii.ogcapi.features.core.domain.FeaturesCoreProviders)1 FeaturesCoreValidation (de.ii.ogcapi.features.core.domain.FeaturesCoreValidation)1 ItemTypeSpecificConformanceClass (de.ii.ogcapi.features.core.domain.ItemTypeSpecificConformanceClass)1 DEFAULT_FLATTENING_SEPARATOR (de.ii.ogcapi.features.core.domain.SchemaGeneratorFeatureOpenApi.DEFAULT_FLATTENING_SEPARATOR)1 FeaturesHtmlConfiguration (de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration)1 POSITION (de.ii.ogcapi.features.html.domain.FeaturesHtmlConfiguration.POSITION)1 ApiMediaType (de.ii.ogcapi.foundation.domain.ApiMediaType)1 ApiMediaTypeContent (de.ii.ogcapi.foundation.domain.ApiMediaTypeContent)1 ExtensionConfiguration (de.ii.ogcapi.foundation.domain.ExtensionConfiguration)1 FeatureTypeConfigurationOgcApi (de.ii.ogcapi.foundation.domain.FeatureTypeConfigurationOgcApi)1 I18n (de.ii.ogcapi.foundation.domain.I18n)1 ImmutableApiMediaType (de.ii.ogcapi.foundation.domain.ImmutableApiMediaType)1 ImmutableApiMediaTypeContent (de.ii.ogcapi.foundation.domain.ImmutableApiMediaTypeContent)1