fix(content): 언어 감지와 관리자 수정 시 번역 작업 누락을 막는다
This commit is contained in:
@@ -9,8 +9,11 @@ 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.common.SodaException
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import kr.co.vividnext.sodalive.content.main.tab.GetContentMainTabItem
|
import kr.co.vividnext.sodalive.content.main.tab.GetContentMainTabItem
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationEvent
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
@@ -26,6 +29,7 @@ class AdminContentService(
|
|||||||
private val contentMainTabRepository: AdminContentMainTabRepository,
|
private val contentMainTabRepository: AdminContentMainTabRepository,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val s3Uploader: S3Uploader,
|
private val s3Uploader: S3Uploader,
|
||||||
|
private val applicationEventPublisher: ApplicationEventPublisher,
|
||||||
@Value("\${cloud.aws.s3.bucket}")
|
@Value("\${cloud.aws.s3.bucket}")
|
||||||
private val bucket: String
|
private val bucket: String
|
||||||
) {
|
) {
|
||||||
@@ -158,6 +162,16 @@ class AdminContentService(
|
|||||||
}
|
}
|
||||||
audioContent.settlementRatio = request.settlementRatio
|
audioContent.settlementRatio = request.settlementRatio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.title != null || request.detail != null) {
|
||||||
|
applicationEventPublisher.publishEvent(
|
||||||
|
LanguageTranslationEvent(
|
||||||
|
id = request.id,
|
||||||
|
targetType = LanguageTranslationTargetType.CONTENT,
|
||||||
|
waitTransactionCommit = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContentMainTabList(): List<GetContentMainTabItem> {
|
fun getContentMainTabList(): List<GetContentMainTabItem> {
|
||||||
|
|||||||
@@ -8,12 +8,11 @@ import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository
|
|||||||
import kr.co.vividnext.sodalive.content.series.ContentSeriesRepository
|
import kr.co.vividnext.sodalive.content.series.ContentSeriesRepository
|
||||||
import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository
|
import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository
|
||||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunityRepository
|
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunityRepository
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationEvent
|
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationLanguages.getTranslatableLanguageCodes
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationLanguages.getTranslatableLanguageCodes
|
||||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.scheduling.annotation.Async
|
import org.springframework.scheduling.annotation.Async
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
@@ -64,8 +63,7 @@ class LanguageDetectListener(
|
|||||||
private val languageDetectionCacheService: LanguageDetectionCacheService,
|
private val languageDetectionCacheService: LanguageDetectionCacheService,
|
||||||
private val creatorCommunityTranslationService: CreatorCommunityTranslationService,
|
private val creatorCommunityTranslationService: CreatorCommunityTranslationService,
|
||||||
private val entityManager: EntityManager,
|
private val entityManager: EntityManager,
|
||||||
|
private val resourceTranslationJobScheduler: ResourceTranslationJobScheduler
|
||||||
private val applicationEventPublisher: ApplicationEventPublisher
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(LanguageDetectListener::class.java)
|
private val log = LoggerFactory.getLogger(LanguageDetectListener::class.java)
|
||||||
@@ -116,11 +114,9 @@ class LanguageDetectListener(
|
|||||||
character.languageCode = langCode
|
character.languageCode = langCode
|
||||||
chatCharacterRepository.save(character)
|
chatCharacterRepository.save(character)
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
resourceTranslationJobScheduler.scheduleResourceTranslations(
|
||||||
LanguageTranslationEvent(
|
resourceType = LanguageTranslationTargetType.CHARACTER,
|
||||||
id = characterId,
|
resourceId = characterId
|
||||||
targetType = LanguageTranslationTargetType.CHARACTER
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
@@ -156,11 +152,9 @@ class LanguageDetectListener(
|
|||||||
// REQUIRES_NEW 트랜잭션 내에서 변경 내용을 저장한다.
|
// REQUIRES_NEW 트랜잭션 내에서 변경 내용을 저장한다.
|
||||||
audioContentRepository.save(audioContent)
|
audioContentRepository.save(audioContent)
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
resourceTranslationJobScheduler.scheduleResourceTranslations(
|
||||||
LanguageTranslationEvent(
|
resourceType = LanguageTranslationTargetType.CONTENT,
|
||||||
id = contentId,
|
resourceId = contentId
|
||||||
targetType = LanguageTranslationTargetType.CONTENT
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
@@ -288,11 +282,9 @@ class LanguageDetectListener(
|
|||||||
series.languageCode = langCode
|
series.languageCode = langCode
|
||||||
seriesRepository.save(series)
|
seriesRepository.save(series)
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
resourceTranslationJobScheduler.scheduleResourceTranslations(
|
||||||
LanguageTranslationEvent(
|
resourceType = LanguageTranslationTargetType.SERIES,
|
||||||
id = seriesId,
|
resourceId = seriesId
|
||||||
targetType = LanguageTranslationTargetType.SERIES
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
@@ -326,12 +318,9 @@ class LanguageDetectListener(
|
|||||||
originalWork.languageCode = langCode
|
originalWork.languageCode = langCode
|
||||||
originalWorkRepository.save(originalWork)
|
originalWorkRepository.save(originalWork)
|
||||||
|
|
||||||
// 언어 감지가 완료된 후 언어 번역 이벤트 호출
|
resourceTranslationJobScheduler.scheduleResourceTranslations(
|
||||||
applicationEventPublisher.publishEvent(
|
resourceType = LanguageTranslationTargetType.ORIGINAL_WORK,
|
||||||
LanguageTranslationEvent(
|
resourceId = originalWorkId
|
||||||
id = originalWorkId,
|
|
||||||
targetType = LanguageTranslationTargetType.ORIGINAL_WORK
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
@@ -352,11 +341,9 @@ class LanguageDetectListener(
|
|||||||
category.languageCode = langCode
|
category.languageCode = langCode
|
||||||
categoryRepository.save(category)
|
categoryRepository.save(category)
|
||||||
|
|
||||||
applicationEventPublisher.publishEvent(
|
resourceTranslationJobScheduler.scheduleResourceTranslations(
|
||||||
LanguageTranslationEvent(
|
resourceType = LanguageTranslationTargetType.CREATOR_CONTENT_CATEGORY,
|
||||||
id = categoryId,
|
resourceId = categoryId
|
||||||
targetType = LanguageTranslationTargetType.CREATOR_CONTENT_CATEGORY
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -199,7 +199,9 @@ class CreatorAdminContentService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
audioContent.audioContentHashTags.addAll(newAudioContentHashTagList)
|
audioContent.audioContentHashTags.addAll(newAudioContentHashTagList)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.title != null || request.detail != null || !request.tags.isNullOrBlank()) {
|
||||||
applicationEventPublisher.publishEvent(
|
applicationEventPublisher.publishEvent(
|
||||||
LanguageTranslationEvent(
|
LanguageTranslationEvent(
|
||||||
id = request.id,
|
id = request.id,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.BeforeEach
|
|||||||
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.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
import java.util.Optional
|
import java.util.Optional
|
||||||
|
|
||||||
class AdminContentServiceTest {
|
class AdminContentServiceTest {
|
||||||
@@ -43,6 +44,7 @@ class AdminContentServiceTest {
|
|||||||
contentMainTabRepository = contentMainTabRepository,
|
contentMainTabRepository = contentMainTabRepository,
|
||||||
objectMapper = jacksonObjectMapper(),
|
objectMapper = jacksonObjectMapper(),
|
||||||
s3Uploader = s3Uploader,
|
s3Uploader = s3Uploader,
|
||||||
|
applicationEventPublisher = Mockito.mock(ApplicationEventPublisher::class.java),
|
||||||
bucket = "test-bucket"
|
bucket = "test-bucket"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+199
@@ -0,0 +1,199 @@
|
|||||||
|
package kr.co.vividnext.sodalive.content
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.admin.content.series.genre.SeriesGenre
|
||||||
|
import kr.co.vividnext.sodalive.chat.character.ChatCharacter
|
||||||
|
import kr.co.vividnext.sodalive.chat.original.OriginalWork
|
||||||
|
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||||
|
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||||
|
import kr.co.vividnext.sodalive.content.category.Category
|
||||||
|
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
||||||
|
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
||||||
|
import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.DetectedLanguage
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageProviderId
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationJob
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobRepository
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobScheduler
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobStatus
|
||||||
|
import kr.co.vividnext.sodalive.i18n.translation.TranslationSourceExtractor
|
||||||
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import kr.co.vividnext.sodalive.member.MemberRole
|
||||||
|
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
||||||
|
import org.junit.jupiter.api.AfterEach
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.Assertions.assertThrows
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest
|
||||||
|
import org.junit.jupiter.params.provider.EnumSource
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean
|
||||||
|
import org.springframework.context.annotation.Import
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate
|
||||||
|
import org.springframework.test.util.AopTestUtils
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager
|
||||||
|
import org.springframework.transaction.annotation.Propagation
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
|
import javax.persistence.EntityManager
|
||||||
|
|
||||||
|
@DataJpaTest(
|
||||||
|
properties = [
|
||||||
|
"spring.cache.type=none",
|
||||||
|
"spring.datasource.url=jdbc:h2:mem:metadata-language-detect;MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||||
|
@Import(
|
||||||
|
QueryDslConfig::class,
|
||||||
|
AudioContentThemeQueryRepository::class,
|
||||||
|
LanguageDetectListener::class,
|
||||||
|
TranslationSourceExtractor::class,
|
||||||
|
ResourceTranslationJobScheduler::class,
|
||||||
|
TranslationJobScheduler::class
|
||||||
|
)
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
|
class MetadataLanguageDetectTransactionTest @Autowired constructor(
|
||||||
|
private val languageDetectListener: LanguageDetectListener,
|
||||||
|
private val jobRepository: TranslationJobRepository,
|
||||||
|
private val entityManager: EntityManager,
|
||||||
|
private val jdbcTemplate: JdbcTemplate,
|
||||||
|
transactionManager: PlatformTransactionManager
|
||||||
|
) {
|
||||||
|
private val transaction = TransactionTemplate(transactionManager)
|
||||||
|
private val fixtures = mutableListOf<BaseEntity>()
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var detectionCache: LanguageDetectionCacheService
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var communityTranslationService: CreatorCommunityTranslationService
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
fun cleanUp() {
|
||||||
|
transaction.executeWithoutResult {
|
||||||
|
jobRepository.deleteAll()
|
||||||
|
fixtures.asReversed().forEach { entity ->
|
||||||
|
entityManager.remove(entityManager.find(entity.javaClass, entity.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(MetadataTarget::class)
|
||||||
|
@DisplayName("메타데이터 감지는 언어와 전체 번역 작업을 커밋 전 같은 트랜잭션에 저장한다")
|
||||||
|
fun shouldPersistDetectedLanguageAndJobsInSameTransaction(target: MetadataTarget) {
|
||||||
|
val event = prepareDetection(target)
|
||||||
|
// 비동기 어댑터를 제외한 실제 리스너와 Spring scheduler를 하나의 DB 트랜잭션에서 실행한다.
|
||||||
|
val listener: LanguageDetectListener = AopTestUtils.getTargetObject(languageDetectListener)
|
||||||
|
|
||||||
|
val beforeCommit = transaction.execute {
|
||||||
|
listener.detectLanguage(event)
|
||||||
|
readState(target, event.id)
|
||||||
|
}!!
|
||||||
|
val afterCommit = transaction.execute { readState(target, event.id) }!!
|
||||||
|
|
||||||
|
val expectedJobs = target.fields.flatMap { (field, text) ->
|
||||||
|
listOf(Triple(field, "en", text), Triple(field, "ja", text))
|
||||||
|
}.toSet()
|
||||||
|
listOf(beforeCommit, afterCommit).forEach { (languageCode, jobs) ->
|
||||||
|
assertEquals("ko", languageCode)
|
||||||
|
assertEquals(expectedJobs.size, jobs.size)
|
||||||
|
assertEquals(expectedJobs, jobs.map { Triple(it.fieldKey, it.targetLanguage, it.sourceText) }.toSet())
|
||||||
|
assertEquals(setOf("ko"), jobs.map { it.sourceLanguage }.toSet())
|
||||||
|
assertEquals(setOf(TranslationJobStatus.PENDING), jobs.map { it.status }.toSet())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(MetadataTarget::class)
|
||||||
|
@DisplayName("번역 작업 INSERT 실패는 감지 언어와 먼저 저장한 작업을 모두 롤백한다")
|
||||||
|
fun shouldRollBackDetectedLanguageAndJobsWhenJobInsertFails(target: MetadataTarget) {
|
||||||
|
val event = prepareDetection(target)
|
||||||
|
val listener: LanguageDetectListener = AopTestUtils.getTargetObject(languageDetectListener)
|
||||||
|
// H2 전용 일시 제약으로 en INSERT 이후 ja INSERT를 실제 DB에서 실패시킨다.
|
||||||
|
jdbcTemplate.execute(
|
||||||
|
"ALTER TABLE translation_job ADD CONSTRAINT metadata_reject_ja CHECK (target_language <> 'ja')"
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
assertThrows(DataIntegrityViolationException::class.java) {
|
||||||
|
transaction.executeWithoutResult { listener.detectLanguage(event) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val (languageCode, jobs) = transaction.execute { readState(target, event.id) }!!
|
||||||
|
assertNull(languageCode)
|
||||||
|
assertEquals(emptyList<TranslationJob>(), jobs)
|
||||||
|
} finally {
|
||||||
|
jdbcTemplate.execute("ALTER TABLE translation_job DROP CONSTRAINT metadata_reject_ja")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareDetection(target: MetadataTarget): LanguageDetectEvent {
|
||||||
|
Mockito.`when`(detectionCache.detectWithCache("원문 제목"))
|
||||||
|
.thenReturn(DetectedLanguage("ko", LanguageProviderId.PAPAGO))
|
||||||
|
val id = transaction.execute {
|
||||||
|
val owner = persist(Member(password = "password", nickname = "metadata-owner", role = MemberRole.CREATOR))
|
||||||
|
val metadata = when (target) {
|
||||||
|
MetadataTarget.CONTENT -> AudioContent("원문 제목", "원문 설명", null).apply {
|
||||||
|
member = owner
|
||||||
|
theme = persist(AudioContentTheme("theme", "theme.png"))
|
||||||
|
}
|
||||||
|
MetadataTarget.CHARACTER -> ChatCharacter(
|
||||||
|
characterUUID = "metadata-character",
|
||||||
|
name = "원문 제목",
|
||||||
|
description = "원문 설명",
|
||||||
|
systemPrompt = "system prompt"
|
||||||
|
).apply { creatorMember = owner }
|
||||||
|
MetadataTarget.SERIES -> Series("원문 제목", "원문 설명").apply {
|
||||||
|
member = owner
|
||||||
|
genre = persist(SeriesGenre("genre"))
|
||||||
|
}
|
||||||
|
MetadataTarget.ORIGINAL_WORK -> OriginalWork(
|
||||||
|
title = "원문 제목",
|
||||||
|
contentType = "소설",
|
||||||
|
category = "판타지",
|
||||||
|
description = "원문 설명"
|
||||||
|
)
|
||||||
|
MetadataTarget.CREATOR_CONTENT_CATEGORY -> Category("원문 제목").apply { member = owner }
|
||||||
|
}
|
||||||
|
requireNotNull(persist(metadata).id)
|
||||||
|
}!!
|
||||||
|
return LanguageDetectEvent(id, "원문 제목", LanguageDetectTargetType.valueOf(target.name))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T : BaseEntity> persist(entity: T): T {
|
||||||
|
entityManager.persist(entity)
|
||||||
|
fixtures.add(entity)
|
||||||
|
return entity
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readState(target: MetadataTarget, id: Long): Pair<String?, List<TranslationJob>> {
|
||||||
|
entityManager.flush()
|
||||||
|
entityManager.clear()
|
||||||
|
val languageCode = entityManager.createQuery(
|
||||||
|
"select metadata.languageCode from ${target.entityClass.simpleName} metadata where metadata.id = :id",
|
||||||
|
String::class.java
|
||||||
|
).setParameter("id", id).singleResult
|
||||||
|
val jobs = jobRepository.findAll().filter {
|
||||||
|
it.resourceType == LanguageTranslationTargetType.valueOf(target.name) && it.resourceId == id
|
||||||
|
}
|
||||||
|
return languageCode to jobs
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class MetadataTarget(val entityClass: Class<out BaseEntity>, val fields: Map<String, String>) {
|
||||||
|
CONTENT(AudioContent::class.java, mapOf("title" to "원문 제목", "detail" to "원문 설명")),
|
||||||
|
CHARACTER(ChatCharacter::class.java, mapOf("name" to "원문 제목", "description" to "원문 설명")),
|
||||||
|
SERIES(Series::class.java, mapOf("title" to "원문 제목", "introduction" to "원문 설명")),
|
||||||
|
ORIGINAL_WORK(
|
||||||
|
OriginalWork::class.java,
|
||||||
|
mapOf("title" to "원문 제목", "contentType" to "소설", "category" to "판타지", "description" to "원문 설명")
|
||||||
|
),
|
||||||
|
CREATOR_CONTENT_CATEGORY(Category::class.java, mapOf("category" to "원문 제목"))
|
||||||
|
}
|
||||||
|
}
|
||||||
+137
@@ -0,0 +1,137 @@
|
|||||||
|
package kr.co.vividnext.sodalive.i18n.translation
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import kr.co.vividnext.sodalive.admin.content.AdminContentController
|
||||||
|
import kr.co.vividnext.sodalive.admin.content.AdminContentService
|
||||||
|
import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront
|
||||||
|
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||||
|
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||||
|
import kr.co.vividnext.sodalive.content.AudioContent
|
||||||
|
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
||||||
|
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
||||||
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
import kr.co.vividnext.sodalive.member.MemberRole
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Import
|
||||||
|
import org.springframework.core.task.SyncTaskExecutor
|
||||||
|
import org.springframework.mock.web.MockMultipartFile
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
|
||||||
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager
|
||||||
|
import org.springframework.transaction.annotation.Propagation
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.util.concurrent.Executor
|
||||||
|
import javax.persistence.EntityManager
|
||||||
|
|
||||||
|
@DataJpaTest(
|
||||||
|
properties = [
|
||||||
|
"spring.cache.type=none",
|
||||||
|
"spring.datasource.url=jdbc:h2:mem:metadata-translation-http;MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||||
|
@Import(
|
||||||
|
QueryDslConfig::class,
|
||||||
|
AdminContentService::class,
|
||||||
|
AudioContentThemeQueryRepository::class,
|
||||||
|
TranslationSourceExtractor::class,
|
||||||
|
ResourceTranslationJobScheduler::class,
|
||||||
|
TranslationJobScheduler::class,
|
||||||
|
LanguageTranslationListener::class,
|
||||||
|
MetadataTranslationHttpIntegrationTest.Configuration::class
|
||||||
|
)
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
|
class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||||
|
private val service: AdminContentService,
|
||||||
|
private val jobs: TranslationJobRepository,
|
||||||
|
private val entityManager: EntityManager,
|
||||||
|
transactionManager: PlatformTransactionManager
|
||||||
|
) {
|
||||||
|
private val transaction = TransactionTemplate(transactionManager)
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var uploader: S3Uploader
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private lateinit var cloudFront: AudioContentCloudFront
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("관리자 multipart 수정 HTTP 요청은 커밋 후 같은 FAILED 행을 재개하고 번역 작업을 저장한다")
|
||||||
|
fun shouldRestartFailedTranslationAfterAdminHttpUpdateCommits() {
|
||||||
|
val (contentId, failedId) = transaction.execute {
|
||||||
|
val member = Member(password = "test", nickname = "http-translation", role = MemberRole.CREATOR)
|
||||||
|
val theme = AudioContentTheme("테마", "theme.png")
|
||||||
|
entityManager.persist(member)
|
||||||
|
entityManager.persist(theme)
|
||||||
|
val content = AudioContent("원문 제목", "원문 설명", "ko").apply {
|
||||||
|
this.member = member
|
||||||
|
this.theme = theme
|
||||||
|
}
|
||||||
|
entityManager.persist(content)
|
||||||
|
val failed = jobs.saveAndFlush(
|
||||||
|
TranslationJob(
|
||||||
|
LanguageTranslationTargetType.CONTENT, content.id!!, "title", SourceTextNormalizer.hash("원문 제목"),
|
||||||
|
"원문 제목", "ko", "en", TranslationJobStatus.FAILED, 6, "exhausted", LocalDateTime.of(2040, 1, 1, 0, 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
content.id!! to failed.id!!
|
||||||
|
}!!
|
||||||
|
|
||||||
|
val response = MockMvcBuilders.standaloneSetup(AdminContentController(service)).build()
|
||||||
|
.perform(
|
||||||
|
multipart("/admin/audio-content")
|
||||||
|
.file(
|
||||||
|
MockMultipartFile(
|
||||||
|
"request",
|
||||||
|
"",
|
||||||
|
"application/json",
|
||||||
|
"""{"id":$contentId,"title":"원문 제목","isDefaultCoverImage":false}""".toByteArray()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.with { request -> request.apply { method = "PUT" } }
|
||||||
|
)
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andReturn().response
|
||||||
|
|
||||||
|
transaction.executeWithoutResult {
|
||||||
|
val restarted = jobs.findById(failedId).orElseThrow()
|
||||||
|
assertEquals(TranslationJobStatus.PENDING, restarted.status)
|
||||||
|
assertEquals(0, restarted.retryCount)
|
||||||
|
assertNull(restarted.lastErrorMessage)
|
||||||
|
val stored = jobs.findAll().filter { it.resourceId == contentId }
|
||||||
|
assertEquals(
|
||||||
|
setOf("title" to "en", "title" to "ja", "detail" to "en", "detail" to "ja"),
|
||||||
|
stored.map { it.fieldKey to it.targetLanguage }.toSet()
|
||||||
|
)
|
||||||
|
assertEquals(4, stored.size)
|
||||||
|
}
|
||||||
|
println(
|
||||||
|
"HTTP QA: status=${response.status}, body=${response.contentAsString}, " +
|
||||||
|
"contentId=$contentId, restartedJobId=$failedId"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
@EnableAsync
|
||||||
|
class Configuration {
|
||||||
|
@Bean
|
||||||
|
fun objectMapper(): ObjectMapper = jacksonObjectMapper()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun taskExecutor(): Executor = SyncTaskExecutor()
|
||||||
|
}
|
||||||
|
}
|
||||||
+51
@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.api.admin.aicharacter.content
|
|||||||
|
|
||||||
import com.amazonaws.services.s3.AmazonS3Client
|
import com.amazonaws.services.s3.AmazonS3Client
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import kr.co.vividnext.sodalive.admin.content.AdminContentService
|
||||||
import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront
|
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.common.SodaException
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
@@ -26,6 +27,8 @@ import org.junit.jupiter.api.Assertions.assertTrue
|
|||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
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.CsvSource
|
||||||
import org.mockito.ArgumentCaptor
|
import org.mockito.ArgumentCaptor
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
@@ -35,6 +38,8 @@ import org.springframework.context.ApplicationEventPublisher
|
|||||||
import org.springframework.data.domain.PageRequest
|
import org.springframework.data.domain.PageRequest
|
||||||
import org.springframework.mock.web.MockMultipartFile
|
import org.springframework.mock.web.MockMultipartFile
|
||||||
import org.springframework.test.context.ContextConfiguration
|
import org.springframework.test.context.ContextConfiguration
|
||||||
|
import org.springframework.test.context.event.ApplicationEvents
|
||||||
|
import org.springframework.test.context.event.RecordApplicationEvents
|
||||||
import org.springframework.transaction.annotation.Propagation
|
import org.springframework.transaction.annotation.Propagation
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.springframework.transaction.support.TransactionTemplate
|
import org.springframework.transaction.support.TransactionTemplate
|
||||||
@@ -45,6 +50,7 @@ import javax.persistence.EntityManager
|
|||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Transactional
|
@Transactional
|
||||||
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
|
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
|
||||||
|
@RecordApplicationEvents
|
||||||
class LegacyCreatorAdminAudioContentCharacterizationTest @Autowired constructor(
|
class LegacyCreatorAdminAudioContentCharacterizationTest @Autowired constructor(
|
||||||
private val audioContentService: AudioContentService,
|
private val audioContentService: AudioContentService,
|
||||||
private val repository: CreatorAdminContentRepository,
|
private val repository: CreatorAdminContentRepository,
|
||||||
@@ -53,6 +59,15 @@ class LegacyCreatorAdminAudioContentCharacterizationTest @Autowired constructor(
|
|||||||
private val entityManager: EntityManager,
|
private val entityManager: EntityManager,
|
||||||
private val transactionTemplate: TransactionTemplate
|
private val transactionTemplate: TransactionTemplate
|
||||||
) {
|
) {
|
||||||
|
@Autowired
|
||||||
|
private lateinit var adminContentService: AdminContentService
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var creatorAdminContentService: CreatorAdminContentService
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private lateinit var applicationEvents: ApplicationEvents
|
||||||
|
|
||||||
private lateinit var audioContentCloudFront: AudioContentCloudFront
|
private lateinit var audioContentCloudFront: AudioContentCloudFront
|
||||||
|
|
||||||
@MockBean
|
@MockBean
|
||||||
@@ -224,6 +239,42 @@ class LegacyCreatorAdminAudioContentCharacterizationTest @Autowired constructor(
|
|||||||
return member
|
return member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource(
|
||||||
|
"true,title,",
|
||||||
|
"true,detail,",
|
||||||
|
"false,title,",
|
||||||
|
"false,detail,",
|
||||||
|
"false,title,''",
|
||||||
|
"false,detail,''",
|
||||||
|
"false,title,' '",
|
||||||
|
"false,detail,' '"
|
||||||
|
)
|
||||||
|
@DisplayName("관리자와 크리에이터 관리자의 제목 또는 상세 수정은 태그 없이도 커밋 후 번역을 요청한다")
|
||||||
|
fun shouldRequestTranslationAfterCommitWhenMetadataIsUpdatedWithoutTags(asAdmin: Boolean, field: String, tags: String?) {
|
||||||
|
val owner = saveMember("metadata-update-owner")
|
||||||
|
val content = saveAudioContent(owner, "before title", "00:10:00")
|
||||||
|
entityManager.flush()
|
||||||
|
val tagsField = tags?.let { ",\"tags\":\"$it\"" }.orEmpty()
|
||||||
|
val coverField = if (asAdmin) ",\"isDefaultCoverImage\":false" else ""
|
||||||
|
val request = """{"id":${content.id},"$field":"updated text"$tagsField$coverField}"""
|
||||||
|
|
||||||
|
if (asAdmin) {
|
||||||
|
adminContentService.updateAudioContent(null, request)
|
||||||
|
} else {
|
||||||
|
creatorAdminContentService.updateAudioContent(null, request, owner)
|
||||||
|
}
|
||||||
|
|
||||||
|
entityManager.flush()
|
||||||
|
entityManager.clear()
|
||||||
|
val updated = entityManager.find(AudioContent::class.java, content.id)
|
||||||
|
assertEquals("updated text", if (field == "title") updated.title else updated.detail)
|
||||||
|
val events = applicationEvents.stream(LanguageTranslationEvent::class.java).filter { it.id == content.id }.toList()
|
||||||
|
assertEquals(1, events.size)
|
||||||
|
assertEquals(LanguageTranslationTargetType.CONTENT, events.single().targetType)
|
||||||
|
assertTrue(events.single().waitTransactionCommit)
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveAudioContent(owner: Member, title: String, duration: String): AudioContent {
|
private fun saveAudioContent(owner: Member, title: String, duration: String): AudioContent {
|
||||||
val theme = AudioContentTheme(theme = "theme-$title", image = "theme.png")
|
val theme = AudioContentTheme(theme = "theme-$title", image = "theme.png")
|
||||||
entityManager.persist(theme)
|
entityManager.persist(theme)
|
||||||
|
|||||||
Reference in New Issue
Block a user