fix(content): 상세 조회에서 미감지 언어의 감지를 요청한다
This commit is contained in:
@@ -891,11 +891,16 @@ class AudioContentService(
|
|||||||
*
|
*
|
||||||
* 파파고로 번역한 데이터를 TranslatedContent로 가공한다
|
* 파파고로 번역한 데이터를 TranslatedContent로 가공한다
|
||||||
*/
|
*/
|
||||||
if (
|
if (audioContent.languageCode.isNullOrBlank()) {
|
||||||
audioContent.languageCode != null &&
|
applicationEventPublisher.publishEvent(
|
||||||
audioContent.languageCode!!.isNotBlank() &&
|
LanguageDetectEvent(
|
||||||
audioContent.languageCode != langContext.lang.code
|
id = id,
|
||||||
) {
|
query = listOf(audioContent.title.trim(), audioContent.detail.trim(), tag.trim())
|
||||||
|
.filter { it.isNotBlank() }
|
||||||
|
.joinToString(" ")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else if (audioContent.languageCode != langContext.lang.code) {
|
||||||
resourceTranslationJobScheduler.restartFailedResourceTranslations(
|
resourceTranslationJobScheduler.restartFailedResourceTranslations(
|
||||||
LanguageTranslationTargetType.CONTENT,
|
LanguageTranslationTargetType.CONTENT,
|
||||||
listOf(id),
|
listOf(id),
|
||||||
|
|||||||
+149
@@ -8,14 +8,37 @@ import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront
|
|||||||
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||||
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||||
import kr.co.vividnext.sodalive.content.AudioContent
|
import kr.co.vividnext.sodalive.content.AudioContent
|
||||||
|
import kr.co.vividnext.sodalive.content.AudioContentController
|
||||||
|
import kr.co.vividnext.sodalive.content.AudioContentService
|
||||||
|
import kr.co.vividnext.sodalive.content.ContentType
|
||||||
|
import kr.co.vividnext.sodalive.content.LanguageDetectListener
|
||||||
|
import kr.co.vividnext.sodalive.content.LanguageDetectionCacheService
|
||||||
|
import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag
|
||||||
|
import kr.co.vividnext.sodalive.content.hashtag.HashTag
|
||||||
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
||||||
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
||||||
|
import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||||
|
import kr.co.vividnext.sodalive.i18n.Lang
|
||||||
|
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||||
|
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import kr.co.vividnext.sodalive.member.MemberAdapter
|
||||||
import kr.co.vividnext.sodalive.member.MemberRole
|
import kr.co.vividnext.sodalive.member.MemberRole
|
||||||
|
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||||
|
import kr.co.vividnext.sodalive.member.contentpreference.ViewerContentPreference
|
||||||
|
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
||||||
|
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
|
||||||
|
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
|
||||||
|
import kr.co.vividnext.sodalive.v2.recommendation.application.CreatorContentViewHistoryService
|
||||||
|
import kr.co.vividnext.sodalive.v2.subtitle.application.SubtitleJobService
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertNull
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.NullAndEmptySource
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource
|
||||||
|
import org.mockito.Mockito
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
@@ -26,7 +49,12 @@ import org.springframework.context.annotation.Import
|
|||||||
import org.springframework.core.task.SyncTaskExecutor
|
import org.springframework.core.task.SyncTaskExecutor
|
||||||
import org.springframework.mock.web.MockMultipartFile
|
import org.springframework.mock.web.MockMultipartFile
|
||||||
import org.springframework.scheduling.annotation.EnableAsync
|
import org.springframework.scheduling.annotation.EnableAsync
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder
|
||||||
|
import org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
import org.springframework.transaction.PlatformTransactionManager
|
import org.springframework.transaction.PlatformTransactionManager
|
||||||
@@ -47,17 +75,33 @@ import javax.persistence.EntityManager
|
|||||||
@Import(
|
@Import(
|
||||||
QueryDslConfig::class,
|
QueryDslConfig::class,
|
||||||
AdminContentService::class,
|
AdminContentService::class,
|
||||||
|
AudioContentService::class,
|
||||||
|
ExplorerQueryRepository::class,
|
||||||
|
SodaMessageSource::class,
|
||||||
AudioContentThemeQueryRepository::class,
|
AudioContentThemeQueryRepository::class,
|
||||||
TranslationSourceExtractor::class,
|
TranslationSourceExtractor::class,
|
||||||
ResourceTranslationJobScheduler::class,
|
ResourceTranslationJobScheduler::class,
|
||||||
TranslationJobScheduler::class,
|
TranslationJobScheduler::class,
|
||||||
TranslationJobSchedulerTestConfiguration::class,
|
TranslationJobSchedulerTestConfiguration::class,
|
||||||
LanguageTranslationListener::class,
|
LanguageTranslationListener::class,
|
||||||
|
LanguageDetectListener::class,
|
||||||
MetadataTranslationHttpIntegrationTest.Configuration::class
|
MetadataTranslationHttpIntegrationTest.Configuration::class
|
||||||
)
|
)
|
||||||
|
@MockBean(
|
||||||
|
classes = [
|
||||||
|
CreatorCommunityTranslationService::class,
|
||||||
|
CreatorContentViewHistoryService::class,
|
||||||
|
CreatorLocalizedNameService::class,
|
||||||
|
HomeFollowingNewsPublishService::class,
|
||||||
|
SubtitleJobService::class
|
||||||
|
]
|
||||||
|
)
|
||||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||||
private val service: AdminContentService,
|
private val service: AdminContentService,
|
||||||
|
private val contentService: AudioContentService,
|
||||||
|
private val localizedNames: CreatorLocalizedNameService,
|
||||||
|
private val langContext: LangContext,
|
||||||
private val jobs: TranslationJobRepository,
|
private val jobs: TranslationJobRepository,
|
||||||
private val entityManager: EntityManager,
|
private val entityManager: EntityManager,
|
||||||
transactionManager: PlatformTransactionManager
|
transactionManager: PlatformTransactionManager
|
||||||
@@ -70,6 +114,108 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
|||||||
@MockBean
|
@MockBean
|
||||||
private lateinit var cloudFront: AudioContentCloudFront
|
private lateinit var cloudFront: AudioContentCloudFront
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var detectionCache: LanguageDetectionCacheService
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var preferences: MemberContentPreferenceService
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@NullAndEmptySource
|
||||||
|
@ValueSource(strings = [" \t "])
|
||||||
|
@DisplayName("언어가 없는 상세 GET은 원문을 반환하고 커밋 후 감지 언어와 번역 작업을 저장한다")
|
||||||
|
fun shouldDetectMissingLanguageAfterDetailHttpGetCommits(languageCode: String?) {
|
||||||
|
val title = " 원문 전체 제목 "
|
||||||
|
val detail = " 원문 전체 설명은 구매 전 미리보기보다 길며 언어 감지에는 잘린 응답 대신 마지막 문장까지 모두 포함되어야 합니다. "
|
||||||
|
val (contentId, viewer) = transaction.execute {
|
||||||
|
val creator = Member(password = "test", nickname = "detect-creator", role = MemberRole.CREATOR)
|
||||||
|
val viewer = Member(password = "test", nickname = "detect-viewer")
|
||||||
|
val theme = AudioContentTheme("테마", "theme.png")
|
||||||
|
listOf(creator, viewer, theme).forEach(entityManager::persist)
|
||||||
|
val content = AudioContent(
|
||||||
|
title,
|
||||||
|
detail,
|
||||||
|
languageCode,
|
||||||
|
price = 50,
|
||||||
|
isCommentAvailable = false,
|
||||||
|
isFullDetailVisible = false
|
||||||
|
).apply {
|
||||||
|
member = creator
|
||||||
|
this.theme = theme
|
||||||
|
this.content = "output/audio.mp3"
|
||||||
|
coverImage = "cover.png"
|
||||||
|
duration = "00:01:00"
|
||||||
|
isActive = true
|
||||||
|
}
|
||||||
|
entityManager.persist(content)
|
||||||
|
listOf("#활성" to true, "#비활성" to false).forEach { (tag, active) ->
|
||||||
|
val hashTag = HashTag(tag)
|
||||||
|
entityManager.persist(hashTag)
|
||||||
|
entityManager.persist(
|
||||||
|
AudioContentHashTag().apply {
|
||||||
|
audioContent = content
|
||||||
|
this.hashTag = hashTag
|
||||||
|
isActive = active
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
requireNotNull(content.id) to viewer
|
||||||
|
}!!
|
||||||
|
val query = "원문 전체 제목 원문 전체 설명은 구매 전 미리보기보다 길며 언어 감지에는 잘린 응답 대신 마지막 문장까지 모두 포함되어야 합니다. #활성"
|
||||||
|
Mockito.`when`(detectionCache.detectWithCache(query)).thenReturn(DetectedLanguage("ko", LanguageProviderId.AWS))
|
||||||
|
Mockito.`when`(preferences.resolveForQuery(viewer))
|
||||||
|
.thenReturn(ViewerContentPreference("KR", false, ContentType.ALL, false))
|
||||||
|
Mockito.`when`(cloudFront.generateSignedURL("preview/audio.mp3", 7_200_000L))
|
||||||
|
.thenReturn("https://signed.test/audio")
|
||||||
|
val principal = MemberAdapter(viewer)
|
||||||
|
SecurityContextHolder.getContext().authentication =
|
||||||
|
UsernamePasswordAuthenticationToken(principal, null, principal.authorities)
|
||||||
|
try {
|
||||||
|
transaction.executeWithoutResult {
|
||||||
|
MockMvcBuilders.standaloneSetup(
|
||||||
|
AudioContentController(contentService, preferences, localizedNames, langContext)
|
||||||
|
)
|
||||||
|
.setCustomArgumentResolvers(AuthenticationPrincipalArgumentResolver())
|
||||||
|
.build()
|
||||||
|
.perform(get("/audio-content/{id}", contentId).param("timezone", "Asia/Seoul"))
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.success").value(true))
|
||||||
|
.andExpect(jsonPath("$.data.title").value(title))
|
||||||
|
.andExpect(jsonPath("$.data.detail").value("${detail.take(30)}..."))
|
||||||
|
.andExpect(jsonPath("$.data.tag").value("#활성"))
|
||||||
|
.andExpect(jsonPath("$.data.translated").doesNotExist())
|
||||||
|
assertEquals(languageCode, entityManager.find(AudioContent::class.java, contentId).languageCode)
|
||||||
|
assertEquals(0, jobs.findAll().count { it.resourceId == contentId })
|
||||||
|
Mockito.verifyNoInteractions(detectionCache)
|
||||||
|
}
|
||||||
|
transaction.executeWithoutResult {
|
||||||
|
entityManager.clear()
|
||||||
|
assertEquals("ko", entityManager.find(AudioContent::class.java, contentId).languageCode)
|
||||||
|
val stored = jobs.findAll().filter {
|
||||||
|
it.resourceType == LanguageTranslationTargetType.CONTENT && it.resourceId == contentId
|
||||||
|
}
|
||||||
|
assertEquals(
|
||||||
|
setOf(
|
||||||
|
"title" to "en",
|
||||||
|
"title" to "ja",
|
||||||
|
"detail" to "en",
|
||||||
|
"detail" to "ja",
|
||||||
|
"tags" to "en",
|
||||||
|
"tags" to "ja"
|
||||||
|
),
|
||||||
|
stored.map { it.fieldKey to it.targetLanguage }.toSet()
|
||||||
|
)
|
||||||
|
assertEquals(6, stored.size)
|
||||||
|
assertEquals(setOf("ko"), stored.map { it.sourceLanguage }.toSet())
|
||||||
|
assertEquals(setOf(TranslationJobStatus.PENDING), stored.map { it.status }.toSet())
|
||||||
|
assertEquals(setOf(title.trim()), stored.filter { it.fieldKey == "title" }.map { it.sourceText }.toSet())
|
||||||
|
assertEquals(setOf(detail.trim()), stored.filter { it.fieldKey == "detail" }.map { it.sourceText }.toSet())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
SecurityContextHolder.clearContext()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("관리자 multipart 수정 HTTP 요청은 커밋 후 같은 FAILED 행을 재개하고 번역 작업을 저장한다")
|
@DisplayName("관리자 multipart 수정 HTTP 요청은 커밋 후 같은 FAILED 행을 재개하고 번역 작업을 저장한다")
|
||||||
fun shouldRestartFailedTranslationAfterAdminHttpUpdateCommits() {
|
fun shouldRestartFailedTranslationAfterAdminHttpUpdateCommits() {
|
||||||
@@ -132,6 +278,9 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
|||||||
@Bean
|
@Bean
|
||||||
fun objectMapper(): ObjectMapper = jacksonObjectMapper()
|
fun objectMapper(): ObjectMapper = jacksonObjectMapper()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun langContext(): LangContext = LangContext().apply { setLang(Lang.EN) }
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun taskExecutor(): Executor = SyncTaskExecutor()
|
fun taskExecutor(): Executor = SyncTaskExecutor()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user