Class DefaultTranslationEntityService<P extends Translation>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>,TranslationEntityService<P>
- Author:
- Nathan Moore (nathandmoore), Samarth Dhruva (samarthd)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultTranslationEntityService(TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) -
Method Summary
Modifier and TypeMethodDescriptionbulkReplaceTranslationsForEntityInLocale(String entityType, Object entity, String entityId, Locale locale, List<P> fieldTranslations, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates/updates/deletesTranslationrecords for the givenentityType/entityId/localecombination using the givenfieldTranslationslist of translations.bulkReplaceTranslationsForEntityInLocale(String entityType, String entityId, Locale locale, List<P> fieldTranslations, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.longcountNonProductionRecordsByEntityInTenant(String entityType, String entityId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the count of non-production records that match the given entity info and the given tenant context.findAllByEntities(String entityType, List<String> entityIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for the given entity info.findAllByEntitiesAndLocales(String entityType, List<String> entities, List<Locale> locales, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for multiple entities.findAllByEntitiesAndLocalesAndFieldStartsWith(String entityType, List<String> entities, List<Locale> locales, String field, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for multiple entities for a specific field.findAllByEntity(String entityType, String entityId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for the given entity info.findAllByEntityAndLocale(String entityType, String entityId, Locale locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for the given entity info.findByFieldAndLocale(String entityType, String entityId, String entityField, Locale locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translation for the given entity field.org.springframework.data.domain.Page<P>findPageByEntityAndLocale(String entityType, String entityId, Locale locale, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds the translations for the given entity info.protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGenDefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALEprotected List<TranslationFieldTransformerHandler>protected org.modelmapper.ModelMapperAModelMapperused to clone instances ofTranslation.protected TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected TranslationCommonPropertiesgetTranslationsForUpdateAndUnchanged(List<P> existingTranslations, Map<String, Object> requestedTranslationsMap) Accepts a list of all existing field translations for a givenentityType/entityId/localecombination, and a map of the requested field translations.getTranslationsToCreate(String entityType, String entityId, Locale locale, List<P> fieldTranslationsRequest, List<P> existingTranslations) Accepts the request of field translations and the list of translations that already exist, and for each field in the request that doesn't already have an existing translation, creates a newTranslationobject with the appropriate values.protected com.broadleafcommerce.common.extension.TypeFactorypersistAllChangesAndReturnFinalResult(List<P> translationsToCreate, List<P> translationsForUpdate, List<P> translationsToDelete, List<P> unchangedTranslations, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) For each of the given lists, performs the appropriate persistence operation and returns the final list of translations after all operations have been performed.voidsetCacheByEntityLocaleKeyGen(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByEntityLocaleKeyGen) DefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALEvoidsetFieldTransformerHandlers(List<TranslationFieldTransformerHandler> fieldTransformerHandlers) voidsetTranslationCommonProperties(TranslationCommonProperties translationCommonProperties) protected voidupdateTranslationEntityField(String entityType, Object entity, List<P> fieldTranslations) Updates the translation entity fields for a given entity based on the provided field translations.protected voidvalidateTranslations(List<P> translations) Accepts aListofTranslations, and ensures the list is not null and everyTranslation: is not null has anTranslation.getEntityField()that is not blank has aTranslation.getValue()that is not nullMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSortMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Field Details
-
CACHE_BY_ENTITY_LOCALE
- See Also:
-
-
Constructor Details
-
DefaultTranslationEntityService
public DefaultTranslationEntityService(TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, @Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
-
-
Method Details
-
setFieldTransformerHandlers
@Autowired(required=false) public void setFieldTransformerHandlers(@Nullable List<TranslationFieldTransformerHandler> fieldTransformerHandlers) -
findPageByEntityAndLocale
public org.springframework.data.domain.Page<P> findPageByEntityAndLocale(String entityType, String entityId, Locale locale, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for the given entity info.- Specified by:
findPageByEntityAndLocalein interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- The context ID of the entity.locale- The translation's locale.pageInfo-Pagingation inforegarding the current page of data to retrieve.context-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the given entity.
-
findAllByEntityAndLocale
public List<P> findAllByEntityAndLocale(String entityType, String entityId, Locale locale, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for the given entity info.- Specified by:
findAllByEntityAndLocalein interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- The context ID of the entity.locale- The translation's locale.context-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the given entity.
-
findAllByEntitiesAndLocales
public List<P> findAllByEntitiesAndLocales(String entityType, List<String> entities, List<Locale> locales, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for multiple entities.- Specified by:
findAllByEntitiesAndLocalesin interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entities- The context IDs of multiple entities to check.locales- The translation's locale(s).context-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the requested entities.
-
findAllByEntitiesAndLocalesAndFieldStartsWith
public List<P> findAllByEntitiesAndLocalesAndFieldStartsWith(String entityType, List<String> entities, List<Locale> locales, String field, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for multiple entities for a specific field.- Specified by:
findAllByEntitiesAndLocalesAndFieldStartsWithin interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entities- The context IDs of multiple entities to check.locales- The translation's locale(s).field- entity field name prefix, so you can search as a startsWithcontext-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the requested entities.
-
findByFieldAndLocale
public P findByFieldAndLocale(String entityType, String entityId, String entityField, Locale locale, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translation for the given entity field.- Specified by:
findByFieldAndLocalein interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- The context ID of the entity.entityField- The name of the field on the entity to which the translation applies.locale- The translation's locale.context-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translation for the given entity field.
-
findAllByEntity
public List<P> findAllByEntity(String entityType, String entityId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for the given entity info.- Specified by:
findAllByEntityin interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- The context ID of the entity.context-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the given entity.
-
countNonProductionRecordsByEntityInTenant
public long countNonProductionRecordsByEntityInTenant(String entityType, String entityId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceReturns the count of non-production records that match the given entity info and the given tenant context.This is useful to determine if there are outstanding sandbox changes before an entity can be deleted. For example, this is used for checking if any outstanding sandbox changes exist for Product translations before the Product can be deleted.
- Specified by:
countNonProductionRecordsByEntityInTenantin interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- The context ID of the entity.context-context informationrelated to multitenancy.- Returns:
- the count of non-production records that match the given entity info and the given tenant context.
-
findAllByEntities
public List<P> findAllByEntities(String entityType, List<String> entityIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityServiceFinds the translations for the given entity info.- Specified by:
findAllByEntitiesin interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- The type of the entity such as PRODUCT, CATEGORY, or OFFER.entityIds- The context IDs of the entitiescontext-context informationrelated to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the given entities
-
bulkReplaceTranslationsForEntityInLocale
@Deprecated public List<P> bulkReplaceTranslationsForEntityInLocale(String entityType, String entityId, Locale locale, List<P> fieldTranslations, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.UsebulkReplaceTranslationsForEntityInLocale(String, Object, String, Locale, List, ContextInfo)instead to include better coverage for embedded collection translations.Description copied from interface:TranslationEntityServiceCreates/updates/deletesTranslationrecords for the givenentityType/entityId/localecombination using the givenfieldTranslationslist of translations.The result of this operation should be that the only
Translationrecords for the givenentityType/entityId/localecombination should be those supplied in thefieldTranslationslist. There will be exactly oneTranslationrecord for eachTranslationin thefieldTranslationslist.This means that:
- If a field translation in the given
fieldTranslationsis not already present in the data store, a newTranslationrecord will be created for it - If a field in the given
fieldTranslationsalready has a translation in the data store, the existingTranslationrecord is updated to have the new translation value - If there is a
Translationrecord in the data store (for theentityType/entityId/localecombination) that is not found in the givenfieldTranslationslist, the record is deleted
Note, if the entity whose fields and subordinate objects are being translated contains embedded collections that are translatable, thenTranslationEntityService.bulkReplaceTranslationsForEntityInLocale(String, Object, String, Locale, List, ContextInfo)is more appropriate for that case.- Specified by:
bulkReplaceTranslationsForEntityInLocalein interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- the type of the entity such as PRODUCT, CATEGORY, or OFFER.entityId- the context ID of the entity.locale- the locale for which this operation should be performedfieldTranslations- a list ofTranslations, with only theirTranslation.entityFieldandTranslation.valueproperties populated. Both of those properties must be supplied for eachTranslationin the list. All other properties of the translations are ignored, as they will be automatically overridden by the other arguments provided to this method.contextInfo- the context surrounding sandboxing and multitenant state- Returns:
- the new list of all translations for the given
entityType/entityId/localecombination after performing the necessary updates
- If a field translation in the given
-
bulkReplaceTranslationsForEntityInLocale
public List<P> bulkReplaceTranslationsForEntityInLocale(String entityType, Object entity, String entityId, Locale locale, List<P> fieldTranslations, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TranslationEntityServiceCreates/updates/deletesTranslationrecords for the givenentityType/entityId/localecombination using the givenfieldTranslationslist of translations.The result of this operation should be that the only
Translationrecords for the givenentityType/entityId/localecombination should be those supplied in thefieldTranslationslist. There will be exactly oneTranslationrecord for eachTranslationin thefieldTranslationslist.This means that:
- If a field translation in the given
fieldTranslationsis not already present in the data store, a newTranslationrecord will be created for it - If a field in the given
fieldTranslationsalready has a translation in the data store, the existingTranslationrecord is updated to have the new translation value - If there is a
Translationrecord in the data store (for theentityType/entityId/localecombination) that is not found in the givenfieldTranslationslist, the record is deleted
This version differs fromTranslationEntityService.bulkReplaceTranslationsForEntityInLocale(String, String, Locale, List, ContextInfo)in that this version will inspect embedded collections (if applicable) whose members implementSubIdentifiableand are translatable. It will setup the persisted field path for the translation to include the identifier (rather than rely on position alone). This facilitates accurate translation matching for embedded collection members, regardless of collection member ordering mutation.- Specified by:
bulkReplaceTranslationsForEntityInLocalein interfaceTranslationEntityService<P extends Translation>- Parameters:
entityType- the type of the entity such as PRODUCT, CATEGORY, or OFFER.entity- the projection instance of the entity.entityId- the context ID of the entity.locale- the locale for which this operation should be performedfieldTranslations- a list ofTranslations, with only theirTranslation.entityFieldandTranslation.valueproperties populated. Both of those properties must be supplied for eachTranslationin the list. All other properties of the translations are ignored, as they will be automatically overridden by the other arguments provided to this method.contextInfo- the context surrounding sandboxing and multitenant state- Returns:
- the new list of all translations for the given
entityType/entityId/localecombination after performing the necessary updates
- If a field translation in the given
-
updateTranslationEntityField
protected void updateTranslationEntityField(String entityType, Object entity, List<P> fieldTranslations) Updates the translation entity fields for a given entity based on the provided field translations.- Parameters:
entityType- the type of the entity being updatedentity- the entity instance whose translation fields will be updatedfieldTranslations- the list of field translation objects containing path and transformation details- Since:
- TranslationCommon 2.0.5
-
validateTranslations
Accepts aListofTranslations, and ensures the list is not null and everyTranslation:- is not null
- has an
Translation.getEntityField()that is not blank - has a
Translation.getValue()that is not null
- Parameters:
translations- the list of translations to validate- Throws:
InvalidTranslationRequestException- if the translations list was invalid
-
getTranslationsToCreate
protected List<P> getTranslationsToCreate(String entityType, String entityId, Locale locale, List<P> fieldTranslationsRequest, List<P> existingTranslations) Accepts the request of field translations and the list of translations that already exist, and for each field in the request that doesn't already have an existing translation, creates a newTranslationobject with the appropriate values. A list of these new objects is returned (nothing is persisted to the data store).- Parameters:
entityType- the entity type that the newTranslationsshould haveentityId- the entity ID that the newTranslationsshould havelocale- theLocalethat the newTranslationsshould havefieldTranslationsRequest- the request list of translationsexistingTranslations- all translations currently present in the data store for the givenentityType/entityId/localecombination- Returns:
- a list of
Translationsthat should be created in the data store
-
getTranslationsForUpdateAndUnchanged
protected org.apache.commons.lang3.tuple.Pair<List<P>,List<P>> getTranslationsForUpdateAndUnchanged(List<P> existingTranslations, Map<String, Object> requestedTranslationsMap) Accepts a list of all existing field translations for a givenentityType/entityId/localecombination, and a map of the requested field translations. The method examines the field translations that are present in both. If the requested value for a field is different from the existing value, it is added to the list of translations that should be updated. If the requested value is the same as the existing value, it is added to the list of translations that should not be updated. Both lists will have newly created instances for eachTranslation.The two lists are returned in a
Pairwhere the left value is the list of translations which should be sent to the data store to persist their changes, and the right value is the list of translations which should not be sent to the data store as they are already current.- Parameters:
existingTranslations- all translations currently present in the data store for someentityType/entityId/localecombinationrequestedTranslationsMap- the requested map of field names to translation values- Returns:
- a
PairofTranslationlists, where the left value is the list of translations which should be sent to the data store for updates, and the right value is the list of translations which should not be sent to the data store as they are already current.
-
persistAllChangesAndReturnFinalResult
protected List<P> persistAllChangesAndReturnFinalResult(List<P> translationsToCreate, List<P> translationsForUpdate, List<P> translationsToDelete, List<P> unchangedTranslations, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) For each of the given lists, performs the appropriate persistence operation and returns the final list of translations after all operations have been performed.- Parameters:
translationsToCreate- the translations which should be created in the data storetranslationsForUpdate- the translations which should be replaced in the data storetranslationsToDelete- the translations which should be deleted in the data storeunchangedTranslations- the translations which are already valid and thus do not need to be sent to the data storecontextInfo- the context surrounding sandboxing and multitenant state- Returns:
- the final, combined list of all translations for a particular
entityType/entityId/localecombination
-
getRepository
@NonNull protected TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepositoryin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Translation>
-
getTypeFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setCacheByEntityLocaleKeyGen
@Autowired @Qualifier("translationCacheByEntityLocale") public void setCacheByEntityLocaleKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByEntityLocaleKeyGen) DefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALE -
getCacheByEntityLocaleKeyGen
@Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getCacheByEntityLocaleKeyGen()DefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALE -
getModelMapper
protected org.modelmapper.ModelMapper getModelMapper()AModelMapperused to clone instances ofTranslation. -
getTranslationCommonProperties
-
setTranslationCommonProperties
@Autowired public void setTranslationCommonProperties(TranslationCommonProperties translationCommonProperties) -
getFieldTransformerHandlers
-
bulkReplaceTranslationsForEntityInLocale(String, Object, String, Locale, List, ContextInfo)instead to include better coverage for embedded collection translations.