Class TranslationSolrDocumentBuilderContributor

  • All Implemented Interfaces:
    com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>

    public class TranslationSolrDocumentBuilderContributor
    extends Object
    implements com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
    Contribute translated field values to the SolrInputDocument in the available locales.
    • Constructor Summary

      Constructors 
      Constructor Description
      TranslationSolrDocumentBuilderContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.search.index.core.service.IndexerTenantService tenantService)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void applyTranslation​(com.jayway.jsonpath.DocumentContext context, com.broadleafcommerce.search.api.domain.translation.Translation translation)
      Update the JSON document with the provided translation.
      protected void attachTranslationsForLocale​(Map<String,​Object> json, org.apache.solr.common.SolrInputDocument document, String locale, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
      Populate all translatable fields in the document in the given locale, with values from the provided translated indexable JSON.
      boolean canHandle​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)  
      void contributeInternal​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)  
      protected List<com.broadleafcommerce.search.api.domain.translation.Translation> filterTranslationsForLocale​(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations, String locale)
      Retrieve only translations which apply in the provided locale.
      protected org.modelmapper.ModelMapper getCloneMapper()  
      protected com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper getDocumentBuilderHelper()  
      protected Collection<String> getJsonPaths​(com.broadleafcommerce.search.api.domain.translation.Translation translation)
      Get the JSONPath strings which correspond to the translation field's paths in the indexable JSON payload.
      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()  
      protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()  
      protected com.broadleafcommerce.search.index.core.service.IndexerTenantService getTenantService()  
      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()  
      protected <I> Map<String,​Object> translateIndexableJson​(com.broadleafcommerce.search.api.domain.Indexable<I> indexable, List<com.broadleafcommerce.search.api.domain.translation.Translation> languageTranslations, List<com.broadleafcommerce.search.api.domain.translation.Translation> localeTranslations)
      Translate the given indexable's JSON data with the given translations.
      • Methods inherited from interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor

        contribute
    • Constructor Detail

      • TranslationSolrDocumentBuilderContributor

        public TranslationSolrDocumentBuilderContributor​(com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService,
                                                         com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper,
                                                         com.broadleafcommerce.common.extension.TypeFactory typeFactory,
                                                         com.broadleafcommerce.search.index.core.service.IndexerTenantService tenantService)
    • Method Detail

      • contributeInternal

        public void contributeInternal​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                       org.apache.solr.common.SolrInputDocument document,
                                       com.jayway.jsonpath.DocumentContext context,
                                       List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
        Specified by:
        contributeInternal in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
      • filterTranslationsForLocale

        protected List<com.broadleafcommerce.search.api.domain.translation.Translation> filterTranslationsForLocale​(List<com.broadleafcommerce.search.api.domain.translation.Translation> translations,
                                                                                                                    String locale)
        Retrieve only translations which apply in the provided locale.
        Parameters:
        translations - all translations to be filtered
        locale - locale to filter for
        Returns:
        translations which apply in this locale
      • translateIndexableJson

        protected <I> Map<String,​Object> translateIndexableJson​(com.broadleafcommerce.search.api.domain.Indexable<I> indexable,
                                                                      List<com.broadleafcommerce.search.api.domain.translation.Translation> languageTranslations,
                                                                      List<com.broadleafcommerce.search.api.domain.translation.Translation> localeTranslations)
        Translate the given indexable's JSON data with the given translations.
        Type Parameters:
        I - the ID type for the indexable
        Parameters:
        indexable - indexable to be translated
        languageTranslations - language translations to use for translating
        localeTranslations - locale translations to use for translating
        Returns:
        a map with the indexable's JSON data translated
      • applyTranslation

        protected void applyTranslation​(com.jayway.jsonpath.DocumentContext context,
                                        com.broadleafcommerce.search.api.domain.translation.Translation translation)
        Update the JSON document with the provided translation.
        Parameters:
        context - JSON document to update
        translation - translation to apply
      • getJsonPaths

        protected Collection<String> getJsonPaths​(com.broadleafcommerce.search.api.domain.translation.Translation translation)
        Get the JSONPath strings which correspond to the translation field's paths in the indexable JSON payload.

        This implementation assumes that all translations should be applied from the JSON root.

        Parameters:
        translation - translation to create JSONPath for
        Returns:
        JSONPath for the translation in the indexable JSON
      • attachTranslationsForLocale

        protected void attachTranslationsForLocale​(Map<String,​Object> json,
                                                   org.apache.solr.common.SolrInputDocument document,
                                                   String locale,
                                                   List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
        Populate all translatable fields in the document in the given locale, with values from the provided translated indexable JSON.
        Parameters:
        json - translated indexable JSON
        document - document to which translated fields should be attached
        locale - the locale for the translated fields to be attached
        fields - all fields for the indexable type
      • canHandle

        public boolean canHandle​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
        Specified by:
        canHandle in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
      • getSolrFieldService

        protected com.broadleafcommerce.search.provider.solr.SolrFieldService getSolrFieldService()
      • getDocumentBuilderHelper

        protected com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper getDocumentBuilderHelper()
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
      • getCloneMapper

        protected org.modelmapper.ModelMapper getCloneMapper()
      • getObjectMapper

        protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      • getTenantService

        protected com.broadleafcommerce.search.index.core.service.IndexerTenantService getTenantService()