Class TranslationServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.TranslationServiceImpl
-
- All Implemented Interfaces:
TranslationService
@Service public class TranslationServiceImpl extends java.lang.Object implements TranslationService
-
-
Field Summary
Fields Modifier and Type Field Description private org.springframework.context.ApplicationContextappContextprivate CommonPropertiescommonPropertiesprivate JobsManagementServicejobServiceprivate LanguageRepositorylanguageRepositoryprivate com.fasterxml.jackson.databind.ObjectMappermapperprivate org.springframework.data.mongodb.core.MongoTemplatemongoTemplateprivate SequenceGeneratorServicesequenceGeneratorprivate MongoStorageServicestorageServiceprivate TranslationProxytranslationProxyprivate TranslationsRepositorytranslationsRepositoryprivate UserPrincipalDetailsServiceuserDetailsServiceprivate UserManagementServiceuserManagementServiceprivate WebSocketServicewebSocketService
-
Constructor Summary
Constructors Constructor Description TranslationServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddRelationsForTranslation(LocalizedText translationUI)voidaddTranslation(java.lang.String lang, java.util.HashSet<LocalizedText> translations, java.util.Optional<Language> languageOptional)This method creates all relationships between database entities.LanguagecreateLanguage(Language language)This method creates a database entity.java.util.Optional<Language>createLanguage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> langAsMap)This method creates a database entity.LocalizedTextcreateTranslation(LocalizedText translation)This method creates a database entity.java.util.Optional<LocalizedText>createTranslation(java.util.LinkedHashMap<java.lang.String,java.lang.Object> translationAsMap)This method creates a database entity.java.util.List<TranslationExport>exportTranslations(co.mastermindcms.modules.beans.SearchRequest request)Exports translations based on the given search request.java.util.List<Language>findLanguages()This method returns database entities as list.LocalizedTextfindOrCreateTranslation(LocalizedText tr)Finds or creates a translation for the given localized text object.java.util.List<LocalizedText>findTranslations()This method returns database entities as list.java.util.List<LocalizedText>findTranslationsByLangCode(java.lang.String lang)This method returns database entity.java.util.List<java.util.Map<java.lang.String,java.lang.Object>>getAlphabetForActiveLanguage(java.lang.String isUpp)Return alphabets of active language codejava.util.List<java.util.Map<java.lang.String,java.lang.Object>>getAlphabetForLanguage(java.lang.String isUpp, java.lang.String language)Return alphabets of active language codejava.lang.StringgetDefaultLanguage()This method returns the default language.java.lang.StringgetLangFromContext()This method returns data as text from context.LanguageRepositorygetLanguageRepository()java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>>getPaginationFilter(java.lang.String requestJson)This method does calculation for a pages based on the request.TranslationsRepositorygetRepository()java.util.Map<java.lang.String,java.lang.String>getTranslatedTimeDuration(java.lang.String date)This method returns data as map.java.util.Map<java.lang.String,java.lang.String>getTranslation(java.lang.String id, java.lang.String repositoryName)This method returns data as map.java.util.Map<java.lang.String,java.lang.String>getTranslation(java.lang.String id, java.lang.String lang, java.lang.String repositoryName)This method returns data as map.LocalizedTextgetTranslationById(java.lang.String id)This method returns data as map.java.util.HashSet<LocalizedText>getTranslations(java.lang.String langEn, java.lang.String langDe)This method returns data as set.java.util.Map<java.lang.String,java.lang.String>getTranslationsByLangCode(java.lang.String lang)This method returns data as map.java.lang.StringgetTranslationValue(java.lang.String id, java.lang.String repositoryName)This method returns translation for entity.java.lang.StringgetTranslationValue(java.lang.String id, java.lang.String lang, java.lang.String repositoryName)This method returns translation for entity.voidinit()private voidprepareRelationsForTranslation(LocalizedText translationUI)voidremoveLanguageAndClean(java.lang.String langId)This method removes a database entity and clean all relationships from another entities.voidremoveLanguagesByIds(java.util.ArrayList<java.lang.String> languageIds)This method removes a list of database entities.private voidremoveRelationsForTranslation(LocalizedText translationUI, LocalizedText translationDB)voidremoveTranslationAndClean(java.lang.String translationId)This method removes a database entity and clean all relationships from another entities.voidremoveTranslationsByIds(java.util.ArrayList<java.lang.String> translationIds)This method removes a list of database entities.voidremoveTranslationsByLanguage(java.lang.String langId)This method removes a list of database entities.java.util.Optional<LocalizedText>saveArticle(java.lang.String text, java.lang.String articleId)This method saves a database entity.java.util.Optional<Language>saveLanguage(Language language)This method saves a database entity.java.util.Optional<Language>saveLanguage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> langAsMap)This method save an updates of database entity.java.util.Optional<LocalizedText>saveTranslation(LocalizedText translation)This method saves a database entity.java.util.Optional<LocalizedText>saveTranslation(java.util.LinkedHashMap<java.lang.String,java.lang.Object> translationAsMap)This method save an updates of database entity.java.util.List<Language>searchLanguages(java.lang.String query, java.lang.String offset, java.lang.String limit)This method does search requests and returns data as list.java.util.LinkedHashSet<LocalizedText>searchTranslations(java.lang.String requestJson)This method does search requests and returns data as list.java.util.List<LocalizedText>searchTranslations(java.lang.String query, java.lang.String offset, java.lang.String limit)This method does search requests and returns data as list.java.util.List<LocalizedText>searchTranslationsById(java.lang.String regex)This method does search requests and returns data as list.org.springframework.data.domain.Page<LocalizedText>searchTranslationsPaged(java.lang.String requestJson)This method does search requests and returns data as pages.voiduploadTranslations(java.io.File file, java.lang.String username)Uploads translations to the server for the given user.
-
-
-
Field Detail
-
mongoTemplate
@Autowired private org.springframework.data.mongodb.core.MongoTemplate mongoTemplate
-
appContext
@Autowired private org.springframework.context.ApplicationContext appContext
-
translationsRepository
@Autowired private TranslationsRepository translationsRepository
-
languageRepository
@Autowired private LanguageRepository languageRepository
-
sequenceGenerator
@Autowired private SequenceGeneratorService sequenceGenerator
-
userManagementService
@Autowired private UserManagementService userManagementService
-
userDetailsService
@Qualifier("userPrincipalDetailsService") @Autowired private UserPrincipalDetailsService userDetailsService
-
storageService
@Autowired private MongoStorageService storageService
-
translationProxy
@Autowired private TranslationProxy translationProxy
-
commonProperties
@Autowired private CommonProperties commonProperties
-
jobService
@Autowired private JobsManagementService jobService
-
webSocketService
@Autowired private WebSocketService webSocketService
-
mapper
private final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
init
@PostConstruct public void init()
-
getRepository
public TranslationsRepository getRepository()
- Specified by:
getRepositoryin interfaceTranslationService
-
getLanguageRepository
public LanguageRepository getLanguageRepository()
- Specified by:
getLanguageRepositoryin interfaceTranslationService
-
getPaginationFilter
public java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>> getPaginationFilter(java.lang.String requestJson)
Description copied from interface:TranslationServiceThis method does calculation for a pages based on the request.- Specified by:
getPaginationFilterin interfaceTranslationService- Parameters:
requestJson- JSON-object of request contains an instructions for search queries- Returns:
- map-representation of data
-
searchTranslations
public java.util.LinkedHashSet<LocalizedText> searchTranslations(java.lang.String requestJson)
Description copied from interface:TranslationServiceThis method does search requests and returns data as list.- Specified by:
searchTranslationsin interfaceTranslationService- Parameters:
requestJson- search request- Returns:
- data transport entities as list
-
searchTranslationsPaged
public org.springframework.data.domain.Page<LocalizedText> searchTranslationsPaged(java.lang.String requestJson)
Description copied from interface:TranslationServiceThis method does search requests and returns data as pages.- Specified by:
searchTranslationsPagedin interfaceTranslationService- Parameters:
requestJson- JSON-object of request contains an instructions for search queries- Returns:
- database entities separated to pages
-
searchTranslations
public java.util.List<LocalizedText> searchTranslations(java.lang.String query, java.lang.String offset, java.lang.String limit)
Description copied from interface:TranslationServiceThis method does search requests and returns data as list.- Specified by:
searchTranslationsin interfaceTranslationService- Parameters:
query- search queryoffset- offset for returned itemslimit- limit for returned items- Returns:
- database entities as list
-
searchTranslationsById
public java.util.List<LocalizedText> searchTranslationsById(java.lang.String regex)
Description copied from interface:TranslationServiceThis method does search requests and returns data as list.- Specified by:
searchTranslationsByIdin interfaceTranslationService- Parameters:
regex- regexp for identifier definition- Returns:
- database entities as list
-
findTranslations
public java.util.List<LocalizedText> findTranslations()
Description copied from interface:TranslationServiceThis method returns database entities as list.- Specified by:
findTranslationsin interfaceTranslationService- Returns:
- database entities as list
-
findTranslationsByLangCode
public java.util.List<LocalizedText> findTranslationsByLangCode(java.lang.String lang)
Description copied from interface:TranslationServiceThis method returns database entity.- Specified by:
findTranslationsByLangCodein interfaceTranslationService- Parameters:
lang- for filter and return database entity- Returns:
- database entity
-
getTranslationsByLangCode
public java.util.Map<java.lang.String,java.lang.String> getTranslationsByLangCode(java.lang.String lang)
Description copied from interface:TranslationServiceThis method returns data as map.- Specified by:
getTranslationsByLangCodein interfaceTranslationService- Parameters:
lang- field for filter and return data- Returns:
- data as map
-
getLangFromContext
public java.lang.String getLangFromContext()
Description copied from interface:TranslationServiceThis method returns data as text from context.- Specified by:
getLangFromContextin interfaceTranslationService- Returns:
- data as text
-
getTranslatedTimeDuration
public java.util.Map<java.lang.String,java.lang.String> getTranslatedTimeDuration(java.lang.String date)
Description copied from interface:TranslationServiceThis method returns data as map.- Specified by:
getTranslatedTimeDurationin interfaceTranslationService- Parameters:
date- field for translated- Returns:
- data as map
-
getTranslationById
public LocalizedText getTranslationById(java.lang.String id)
Description copied from interface:TranslationServiceThis method returns data as map.- Specified by:
getTranslationByIdin interfaceTranslationService- Parameters:
id- identification for database entity, which will be revers on map- Returns:
- data as entity
-
getTranslation
public java.util.Map<java.lang.String,java.lang.String> getTranslation(java.lang.String id, java.lang.String repositoryName)Description copied from interface:TranslationServiceThis method returns data as map.- Specified by:
getTranslationin interfaceTranslationService- Parameters:
id- identification for database entity, which will be revers on maprepositoryName- repository name from where will be returned data- Returns:
- data as map
-
getTranslation
public java.util.Map<java.lang.String,java.lang.String> getTranslation(java.lang.String id, java.lang.String lang, java.lang.String repositoryName)Description copied from interface:TranslationServiceThis method returns data as map.- Specified by:
getTranslationin interfaceTranslationService- Parameters:
id- identification for database entity, which will be revers on maplang- the language iso-code for translationrepositoryName- repository name from where will be returned data- Returns:
- data as map
-
getTranslationValue
public java.lang.String getTranslationValue(java.lang.String id, java.lang.String repositoryName)Description copied from interface:TranslationServiceThis method returns translation for entity.- Specified by:
getTranslationValuein interfaceTranslationService- Parameters:
id- identification for database entity, which will be revers on maprepositoryName- repository name from where will be returned data- Returns:
- translation
-
getTranslationValue
public java.lang.String getTranslationValue(java.lang.String id, java.lang.String lang, java.lang.String repositoryName)Description copied from interface:TranslationServiceThis method returns translation for entity.- Specified by:
getTranslationValuein interfaceTranslationService- Parameters:
id- identification for database entity, which will be revers on maplang- the language iso-code for translationrepositoryName- repository name from where will be returned data- Returns:
- translation value
-
searchLanguages
public java.util.List<Language> searchLanguages(java.lang.String query, java.lang.String offset, java.lang.String limit)
Description copied from interface:TranslationServiceThis method does search requests and returns data as list.- Specified by:
searchLanguagesin interfaceTranslationService- Parameters:
query- search queryoffset- offset for returned itemslimit- limit for returned items- Returns:
- database entities as list
-
findLanguages
public java.util.List<Language> findLanguages()
Description copied from interface:TranslationServiceThis method returns database entities as list.- Specified by:
findLanguagesin interfaceTranslationService- Returns:
- database entities as list
-
createTranslation
@Transactional public java.util.Optional<LocalizedText> createTranslation(java.util.LinkedHashMap<java.lang.String,java.lang.Object> translationAsMap)
Description copied from interface:TranslationServiceThis method creates a database entity.- Specified by:
createTranslationin interfaceTranslationService- Parameters:
translationAsMap- map-representation of database entity- Returns:
- optional value to externally interaction
-
createTranslation
public LocalizedText createTranslation(LocalizedText translation)
Description copied from interface:TranslationServiceThis method creates a database entity.- Specified by:
createTranslationin interfaceTranslationService- Parameters:
translation- database entity- Returns:
- database entity
-
createLanguage
@Transactional public java.util.Optional<Language> createLanguage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> langAsMap)
Description copied from interface:TranslationServiceThis method creates a database entity.- Specified by:
createLanguagein interfaceTranslationService- Parameters:
langAsMap- map-representation of database entity- Returns:
- optional value to externally interaction
-
createLanguage
public Language createLanguage(Language language)
Description copied from interface:TranslationServiceThis method creates a database entity.- Specified by:
createLanguagein interfaceTranslationService- Parameters:
language- database entity- Returns:
- created entity
-
saveTranslation
@Transactional public java.util.Optional<LocalizedText> saveTranslation(java.util.LinkedHashMap<java.lang.String,java.lang.Object> translationAsMap)
Description copied from interface:TranslationServiceThis method save an updates of database entity.- Specified by:
saveTranslationin interfaceTranslationService- Parameters:
translationAsMap- map-representation of database entity- Returns:
- optional value to externally interaction
-
saveArticle
@Transactional public java.util.Optional<LocalizedText> saveArticle(java.lang.String text, java.lang.String articleId)
Description copied from interface:TranslationServiceThis method saves a database entity.- Specified by:
saveArticlein interfaceTranslationService- Parameters:
text- data which will be added in database entityarticleId- identification for database entity which will be saved or updated- Returns:
- optional value to externally interaction
-
saveTranslation
public java.util.Optional<LocalizedText> saveTranslation(LocalizedText translation)
Description copied from interface:TranslationServiceThis method saves a database entity.- Specified by:
saveTranslationin interfaceTranslationService- Parameters:
translation- database entity- Returns:
- optional value to externally interaction
-
saveLanguage
@Transactional public java.util.Optional<Language> saveLanguage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> langAsMap)
Description copied from interface:TranslationServiceThis method save an updates of database entity.- Specified by:
saveLanguagein interfaceTranslationService- Parameters:
langAsMap- map-representation of database entity- Returns:
- optional value to externally interaction
-
saveLanguage
public java.util.Optional<Language> saveLanguage(Language language)
Description copied from interface:TranslationServiceThis method saves a database entity.- Specified by:
saveLanguagein interfaceTranslationService- Parameters:
language- database entity- Returns:
- optional value to externally interaction
-
removeTranslationAndClean
@Transactional @CacheEvict("translations") public void removeTranslationAndClean(java.lang.String translationId)Description copied from interface:TranslationServiceThis method removes a database entity and clean all relationships from another entities.- Specified by:
removeTranslationAndCleanin interfaceTranslationService- Parameters:
translationId- identification for database entity which will be removed
-
removeTranslationsByIds
@Transactional public void removeTranslationsByIds(java.util.ArrayList<java.lang.String> translationIds)
Description copied from interface:TranslationServiceThis method removes a list of database entities.- Specified by:
removeTranslationsByIdsin interfaceTranslationService- Parameters:
translationIds- the list of database entities which will be removed
-
removeTranslationsByLanguage
public void removeTranslationsByLanguage(java.lang.String langId)
Description copied from interface:TranslationServiceThis method removes a list of database entities.- Specified by:
removeTranslationsByLanguagein interfaceTranslationService- Parameters:
langId- language identification
-
removeLanguageAndClean
@Transactional public void removeLanguageAndClean(java.lang.String langId)
Description copied from interface:TranslationServiceThis method removes a database entity and clean all relationships from another entities.- Specified by:
removeLanguageAndCleanin interfaceTranslationService- Parameters:
langId- identification for database entity which will be removed
-
removeLanguagesByIds
@Transactional public void removeLanguagesByIds(java.util.ArrayList<java.lang.String> languageIds)
Description copied from interface:TranslationServiceThis method removes a list of database entities.- Specified by:
removeLanguagesByIdsin interfaceTranslationService- Parameters:
languageIds- the list of database entities which will be removed
-
getTranslations
@Transactional public java.util.HashSet<LocalizedText> getTranslations(java.lang.String langEn, java.lang.String langDe)
Description copied from interface:TranslationServiceThis method returns data as set.- Specified by:
getTranslationsin interfaceTranslationService- Parameters:
langEn- the lang of database entities which will be retrievedlangDe- the lang of database entities which will be retrieved- Returns:
- database entities as list
-
addTranslation
@Transactional public void addTranslation(java.lang.String lang, java.util.HashSet<LocalizedText> translations, java.util.Optional<Language> languageOptional)Description copied from interface:TranslationServiceThis method creates all relationships between database entities.- Specified by:
addTranslationin interfaceTranslationService- Parameters:
lang- the lang of database entities which will be updatedtranslations- the list of database entities where will be added other database entitylanguageOptional- the lang of database entities which will be added in list of other database entities
-
getAlphabetForActiveLanguage
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getAlphabetForActiveLanguage(java.lang.String isUpp)
Description copied from interface:TranslationServiceReturn alphabets of active language code- Specified by:
getAlphabetForActiveLanguagein interfaceTranslationService- Parameters:
isUpp- flag to convert alphabet to uppercase- Returns:
- list with characters
-
getAlphabetForLanguage
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getAlphabetForLanguage(java.lang.String isUpp, java.lang.String language)Description copied from interface:TranslationServiceReturn alphabets of active language code- Specified by:
getAlphabetForLanguagein interfaceTranslationService- Parameters:
isUpp- flag to convert alphabet to uppercaselanguage- language code- Returns:
- list with characters
-
getDefaultLanguage
public java.lang.String getDefaultLanguage()
Description copied from interface:TranslationServiceThis method returns the default language.- Specified by:
getDefaultLanguagein interfaceTranslationService- Returns:
- A String representing the default language.
-
findOrCreateTranslation
public LocalizedText findOrCreateTranslation(LocalizedText tr)
Description copied from interface:TranslationServiceFinds or creates a translation for the given localized text object. This method takes a localized text object as input and searches for an existing translation in the system. If a translation is found, it is returned. If not, a new translation is created and returned.- Specified by:
findOrCreateTranslationin interfaceTranslationService- Parameters:
tr- - The localized text object for which the translation needs to be found or created- Returns:
- The found or created translation
-
exportTranslations
public java.util.List<TranslationExport> exportTranslations(co.mastermindcms.modules.beans.SearchRequest request)
Description copied from interface:TranslationServiceExports translations based on the given search request.- Specified by:
exportTranslationsin interfaceTranslationService- Parameters:
request- the search request containing the necessary criteria for exporting translations- Returns:
- a list of TranslationExport objects representing the exported translations
-
uploadTranslations
@Async("asyncTaskExecutor") public void uploadTranslations(java.io.File file, java.lang.String username)Description copied from interface:TranslationServiceUploads translations to the server for the given user.- Specified by:
uploadTranslationsin interfaceTranslationService- Parameters:
file- the file containing the translations to be uploadedusername- the username of the user uploading the translations
-
prepareRelationsForTranslation
private void prepareRelationsForTranslation(LocalizedText translationUI)
-
removeRelationsForTranslation
private void removeRelationsForTranslation(LocalizedText translationUI, LocalizedText translationDB)
-
addRelationsForTranslation
private void addRelationsForTranslation(LocalizedText translationUI)
-
-