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.ApplicationContext
appContext
private CommonProperties
commonProperties
private JobsManagementService
jobService
private LanguageRepository
languageRepository
private com.fasterxml.jackson.databind.ObjectMapper
mapper
private org.springframework.data.mongodb.core.MongoTemplate
mongoTemplate
private SequenceGeneratorService
sequenceGenerator
private MongoStorageService
storageService
private TranslationProxy
translationProxy
private TranslationsRepository
translationsRepository
private UserPrincipalDetailsService
userDetailsService
private UserManagementService
userManagementService
private WebSocketService
webSocketService
-
Constructor Summary
Constructors Constructor Description TranslationServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addRelationsForTranslation(LocalizedText translationUI)
void
addTranslation(java.lang.String lang, java.util.HashSet<LocalizedText> translations, java.util.Optional<Language> languageOptional)
This method creates all relationships between database entities.Language
createLanguage(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.LocalizedText
createTranslation(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.LocalizedText
findOrCreateTranslation(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.String
getDefaultLanguage()
This method returns the default language.java.lang.String
getLangFromContext()
This method returns data as text from context.LanguageRepository
getLanguageRepository()
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.TranslationsRepository
getRepository()
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.LocalizedText
getTranslationById(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.String
getTranslationValue(java.lang.String id, java.lang.String repositoryName)
This method returns translation for entity.java.lang.String
getTranslationValue(java.lang.String id, java.lang.String lang, java.lang.String repositoryName)
This method returns translation for entity.void
init()
private void
prepareRelationsForTranslation(LocalizedText translationUI)
void
removeLanguageAndClean(java.lang.String langId)
This method removes a database entity and clean all relationships from another entities.void
removeLanguagesByIds(java.util.ArrayList<java.lang.String> languageIds)
This method removes a list of database entities.private void
removeRelationsForTranslation(LocalizedText translationUI, LocalizedText translationDB)
void
removeTranslationAndClean(java.lang.String translationId)
This method removes a database entity and clean all relationships from another entities.void
removeTranslationsByIds(java.util.ArrayList<java.lang.String> translationIds)
This method removes a list of database entities.void
removeTranslationsByLanguage(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.void
uploadTranslations(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:
getRepository
in interfaceTranslationService
-
getLanguageRepository
public LanguageRepository getLanguageRepository()
- Specified by:
getLanguageRepository
in interfaceTranslationService
-
getPaginationFilter
public java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>> getPaginationFilter(java.lang.String requestJson)
Description copied from interface:TranslationService
This method does calculation for a pages based on the request.- Specified by:
getPaginationFilter
in 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:TranslationService
This method does search requests and returns data as list.- Specified by:
searchTranslations
in 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:TranslationService
This method does search requests and returns data as pages.- Specified by:
searchTranslationsPaged
in 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:TranslationService
This method does search requests and returns data as list.- Specified by:
searchTranslations
in 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:TranslationService
This method does search requests and returns data as list.- Specified by:
searchTranslationsById
in interfaceTranslationService
- Parameters:
regex
- regexp for identifier definition- Returns:
- database entities as list
-
findTranslations
public java.util.List<LocalizedText> findTranslations()
Description copied from interface:TranslationService
This method returns database entities as list.- Specified by:
findTranslations
in interfaceTranslationService
- Returns:
- database entities as list
-
findTranslationsByLangCode
public java.util.List<LocalizedText> findTranslationsByLangCode(java.lang.String lang)
Description copied from interface:TranslationService
This method returns database entity.- Specified by:
findTranslationsByLangCode
in 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:TranslationService
This method returns data as map.- Specified by:
getTranslationsByLangCode
in interfaceTranslationService
- Parameters:
lang
- field for filter and return data- Returns:
- data as map
-
getLangFromContext
public java.lang.String getLangFromContext()
Description copied from interface:TranslationService
This method returns data as text from context.- Specified by:
getLangFromContext
in 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:TranslationService
This method returns data as map.- Specified by:
getTranslatedTimeDuration
in interfaceTranslationService
- Parameters:
date
- field for translated- Returns:
- data as map
-
getTranslationById
public LocalizedText getTranslationById(java.lang.String id)
Description copied from interface:TranslationService
This method returns data as map.- Specified by:
getTranslationById
in 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:TranslationService
This method returns data as map.- Specified by:
getTranslation
in 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:TranslationService
This method returns data as map.- Specified by:
getTranslation
in 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:TranslationService
This method returns translation for entity.- Specified by:
getTranslationValue
in 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:TranslationService
This method returns translation for entity.- Specified by:
getTranslationValue
in 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:TranslationService
This method does search requests and returns data as list.- Specified by:
searchLanguages
in 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:TranslationService
This method returns database entities as list.- Specified by:
findLanguages
in 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:TranslationService
This method creates a database entity.- Specified by:
createTranslation
in interfaceTranslationService
- Parameters:
translationAsMap
- map-representation of database entity- Returns:
- optional value to externally interaction
-
createTranslation
public LocalizedText createTranslation(LocalizedText translation)
Description copied from interface:TranslationService
This method creates a database entity.- Specified by:
createTranslation
in 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:TranslationService
This method creates a database entity.- Specified by:
createLanguage
in interfaceTranslationService
- Parameters:
langAsMap
- map-representation of database entity- Returns:
- optional value to externally interaction
-
createLanguage
public Language createLanguage(Language language)
Description copied from interface:TranslationService
This method creates a database entity.- Specified by:
createLanguage
in 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:TranslationService
This method save an updates of database entity.- Specified by:
saveTranslation
in 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:TranslationService
This method saves a database entity.- Specified by:
saveArticle
in 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:TranslationService
This method saves a database entity.- Specified by:
saveTranslation
in 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:TranslationService
This method save an updates of database entity.- Specified by:
saveLanguage
in 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:TranslationService
This method saves a database entity.- Specified by:
saveLanguage
in 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:TranslationService
This method removes a database entity and clean all relationships from another entities.- Specified by:
removeTranslationAndClean
in 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:TranslationService
This method removes a list of database entities.- Specified by:
removeTranslationsByIds
in interfaceTranslationService
- Parameters:
translationIds
- the list of database entities which will be removed
-
removeTranslationsByLanguage
public void removeTranslationsByLanguage(java.lang.String langId)
Description copied from interface:TranslationService
This method removes a list of database entities.- Specified by:
removeTranslationsByLanguage
in interfaceTranslationService
- Parameters:
langId
- language identification
-
removeLanguageAndClean
@Transactional public void removeLanguageAndClean(java.lang.String langId)
Description copied from interface:TranslationService
This method removes a database entity and clean all relationships from another entities.- Specified by:
removeLanguageAndClean
in 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:TranslationService
This method removes a list of database entities.- Specified by:
removeLanguagesByIds
in 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:TranslationService
This method returns data as set.- Specified by:
getTranslations
in 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:TranslationService
This method creates all relationships between database entities.- Specified by:
addTranslation
in 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:TranslationService
Return alphabets of active language code- Specified by:
getAlphabetForActiveLanguage
in 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:TranslationService
Return alphabets of active language code- Specified by:
getAlphabetForLanguage
in 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:TranslationService
This method returns the default language.- Specified by:
getDefaultLanguage
in interfaceTranslationService
- Returns:
- A String representing the default language.
-
findOrCreateTranslation
public LocalizedText findOrCreateTranslation(LocalizedText tr)
Description copied from interface:TranslationService
Finds 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:
findOrCreateTranslation
in 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:TranslationService
Exports translations based on the given search request.- Specified by:
exportTranslations
in 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:TranslationService
Uploads translations to the server for the given user.- Specified by:
uploadTranslations
in 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)
-
-