Class DefaultTranslationEntityService<P extends Translation>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.translation.service.DefaultTranslationEntityService<P>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
,TranslationEntityService<P>
public class DefaultTranslationEntityService<P extends Translation>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
implements 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/deletesTranslation
records for the givenentityType
/entityId
/locale
combination using the givenfieldTranslations
list of translations.bulkReplaceTranslationsForEntityInLocale
(String entityType, String entityId, Locale locale, List<P> fieldTranslations, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.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.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.ContextKeyGen
DefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALEprotected org.modelmapper.ModelMapper
AModelMapper
used to clone instances ofTranslation
.protected TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected com.broadleafcommerce.common.extension.TypeFactory
void
setCacheByEntityLocaleKeyGen
(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen cacheByEntityLocaleKeyGen) DefaultTranslationEntityService#CACHE_BY_ENTITY_LOCALEprotected void
validateTranslations
(List<P> translations) Accepts aList
ofTranslations
, 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, readAll
Methods 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, updateSort
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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, updateSort
Methods 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
-
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:TranslationEntityService
Finds the translations for the given entity info.- Specified by:
findPageByEntityAndLocale
in 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 info
regarding the current page of data to retrieve.context
-context information
related 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:TranslationEntityService
Finds the translations for the given entity info.- Specified by:
findAllByEntityAndLocale
in 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 information
related 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:TranslationEntityService
Finds the translations for multiple entities.- Specified by:
findAllByEntitiesAndLocales
in 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 information
related 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:TranslationEntityService
Finds the translation for the given entity field.- Specified by:
findByFieldAndLocale
in 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 information
related 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:TranslationEntityService
Finds the translations for the given entity info.- Specified by:
findAllByEntity
in 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 information
related to multitenancy. Often used to validate visibility and mutability of persistence operations for a catalog.- Returns:
- the translations for the given entity.
-
findAllByEntities
public List<P> findAllByEntities(String entityType, List<String> entityIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:TranslationEntityService
Finds the translations for the given entity info.- Specified by:
findAllByEntities
in 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 information
related 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:TranslationEntityService
Creates/updates/deletesTranslation
records for the givenentityType
/entityId
/locale
combination using the givenfieldTranslations
list of translations.The result of this operation should be that the only
Translation
records for the givenentityType
/entityId
/locale
combination should be those supplied in thefieldTranslations
list. There will be exactly oneTranslation
record for eachTranslation
in thefieldTranslations
list.This means that:
- If a field translation in the given
fieldTranslations
is not already present in the data store, a newTranslation
record will be created for it - If a field in the given
fieldTranslations
already has a translation in the data store, the existingTranslation
record is updated to have the new translation value - If there is a
Translation
record in the data store (for theentityType
/entityId
/locale
combination) that is not found in the givenfieldTranslations
list, the record is deleted
TranslationEntityService.bulkReplaceTranslationsForEntityInLocale(String, Object, String, Locale, List, ContextInfo)
is more appropriate for that case.- Specified by:
bulkReplaceTranslationsForEntityInLocale
in 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.entityField
andTranslation.value
properties populated. Both of those properties must be supplied for eachTranslation
in 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
/locale
combination 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:TranslationEntityService
Creates/updates/deletesTranslation
records for the givenentityType
/entityId
/locale
combination using the givenfieldTranslations
list of translations.The result of this operation should be that the only
Translation
records for the givenentityType
/entityId
/locale
combination should be those supplied in thefieldTranslations
list. There will be exactly oneTranslation
record for eachTranslation
in thefieldTranslations
list.This means that:
- If a field translation in the given
fieldTranslations
is not already present in the data store, a newTranslation
record will be created for it - If a field in the given
fieldTranslations
already has a translation in the data store, the existingTranslation
record is updated to have the new translation value - If there is a
Translation
record in the data store (for theentityType
/entityId
/locale
combination) that is not found in the givenfieldTranslations
list, the record is deleted
TranslationEntityService.bulkReplaceTranslationsForEntityInLocale(String, String, Locale, List, ContextInfo)
in that this version will inspect embedded collections (if applicable) whose members implementSubIdentifiable
and 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:
bulkReplaceTranslationsForEntityInLocale
in 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.entityField
andTranslation.value
properties populated. Both of those properties must be supplied for eachTranslation
in 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
/locale
combination after performing the necessary updates
- If a field translation in the given
-
validateTranslations
Accepts aList
ofTranslations
, 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
-
getRepository
@NonNull protected TranslationRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepository
in 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()AModelMapper
used to clone instances ofTranslation
.
-
bulkReplaceTranslationsForEntityInLocale(String, Object, String, Locale, List, ContextInfo)
instead to include better coverage for embedded collection translations.