Class TranslationSolrDocumentBuilderContributor
- java.lang.Object
-
- com.broadleafcommerce.search.index.solr.document.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 theSolrInputDocumentin 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 voidapplyTranslation(com.jayway.jsonpath.DocumentContext context, com.broadleafcommerce.search.api.domain.translation.Translation translation)Update the JSON document with the provided translation.protected voidattachTranslationsForLocale(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.booleancanHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)voidcontributeInternal(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.ModelMappergetCloneMapper()protected com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelpergetDocumentBuilderHelper()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.ObjectMappergetObjectMapper()protected com.broadleafcommerce.search.provider.solr.SolrFieldServicegetSolrFieldService()protected com.broadleafcommerce.search.index.core.service.IndexerTenantServicegetTenantService()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()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.
-
-
-
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:
contributeInternalin interfacecom.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 filteredlocale- 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 translatedlanguageTranslations- language translations to use for translatinglocaleTranslations- 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 updatetranslation- 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 JSONdocument- document to which translated fields should be attachedlocale- the locale for the translated fields to be attachedfields- all fields for the indexable type
-
canHandle
public boolean canHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
- Specified by:
canHandlein interfacecom.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()
-
-