diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/ai/translation/AITranslationService.java b/webapp/src/main/java/com/box/l10n/mojito/service/ai/translation/AITranslationService.java index 6dcf7b501c..98d884f16e 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/ai/translation/AITranslationService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/ai/translation/AITranslationService.java @@ -72,7 +72,7 @@ public void createPendingMTEntitiesInBatches(Long repositoryId, Set tmText } @Transactional - public void updateVariantStatusToMTReview(List currentVariantIds) { + public void updateVariantStatusToMTReviewNeeded(List currentVariantIds) { for (int i = 0; i < currentVariantIds.size(); i += batchSize) { logger.debug("Updating variant statuses to MT_REVIEW in batches of {}", batchSize); diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java index ad84835d03..5775934841 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java @@ -76,6 +76,9 @@ @Component public class ThirdPartyTMSSmartling implements ThirdPartyTMS { + public static final String PUBLISHED = "PUBLISHED"; + public static final String POST_TRANSLATION = "POST_TRANSLATION"; + static Logger logger = LoggerFactory.getLogger(ThirdPartyTMSSmartling.class); /* @@ -111,9 +114,6 @@ protected static String getSmartlingLocale(Map localeMapping, St return localeMapping.getOrDefault(localeTag, localeTag); } - private final String PUBLISHED = "PUBLISHED"; - private final String POST_TRANSLATION = "POST_TRANSLATION"; - @Autowired public ThirdPartyTMSSmartling( SmartlingClient smartlingClient, @@ -869,7 +869,7 @@ private SmartlingFile uploadAiTranslationBatch( options, localeMapping, filterTmTextUnitIds); - aiTranslationService.updateVariantStatusToMTReview( + aiTranslationService.updateVariantStatusToMTReviewNeeded( batch.stream().map(TextUnitDTO::getTmTextUnitCurrentVariantId).toList()); meterRegistry .counter( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java index 79228bef3d..0b06d68784 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java @@ -1,5 +1,7 @@ package com.box.l10n.mojito.service.thirdparty; +import static com.box.l10n.mojito.service.thirdparty.ThirdPartyTMSSmartling.POST_TRANSLATION; +import static com.box.l10n.mojito.service.thirdparty.ThirdPartyTMSSmartling.PUBLISHED; import static com.box.l10n.mojito.service.thirdparty.ThirdPartyTMSUtils.isFileEqualToPreviousRun; import static com.box.l10n.mojito.service.thirdparty.smartling.SmartlingFileUtils.isPluralFile; @@ -8,6 +10,7 @@ import com.box.l10n.mojito.iterators.PageFetcherOffsetAndLimitSplitIterator; import com.box.l10n.mojito.iterators.Spliterators; import com.box.l10n.mojito.service.ai.translation.AITranslationConfiguration; +import com.box.l10n.mojito.service.ai.translation.AITranslationService; import com.box.l10n.mojito.service.thirdparty.smartling.SmartlingJsonConverter; import com.box.l10n.mojito.service.thirdparty.smartling.SmartlingOptions; import com.box.l10n.mojito.service.tm.importer.TextUnitBatchImporterService; @@ -36,6 +39,7 @@ import java.util.stream.StreamSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -65,6 +69,8 @@ public class ThirdPartyTMSSmartlingWithJson { AITranslationConfiguration aiTranslationConfiguration; + AITranslationService aiTranslationService; + int batchSize = 5000; public ThirdPartyTMSSmartlingWithJson( @@ -75,7 +81,8 @@ public ThirdPartyTMSSmartlingWithJson( SmartlingJsonKeys smartlingJsonKeys, MeterRegistry meterRegistry, ThirdPartyFileChecksumRepository thirdPartyFileChecksumRepository, - AITranslationConfiguration aiTranslationConfiguration) { + AITranslationConfiguration aiTranslationConfiguration, + @Autowired(required = false) AITranslationService aiTranslationService) { this.smartlingClient = smartlingClient; this.smartlingJsonConverter = smartlingJsonConverter; this.textUnitSearcher = textUnitSearcher; @@ -84,6 +91,7 @@ public ThirdPartyTMSSmartlingWithJson( this.meterRegistry = meterRegistry; this.thirdPartyFileChecksumRepository = thirdPartyFileChecksumRepository; this.aiTranslationConfiguration = aiTranslationConfiguration; + this.aiTranslationService = aiTranslationService; } void push( @@ -288,7 +296,8 @@ public void pushAiTranslations( skipTextUnitsWithPattern, skipAssetsWithPathPattern, includeTextUnitsWithPattern, - StatusFilter.MT_TRANSLATED), + StatusFilter.MT_TRANSLATED, + true), false) .collect(Collectors.groupingBy(TextUnitDTO::getUploadedFileUri)); @@ -305,7 +314,12 @@ public void pushAiTranslations( localeMapping, repositoryLocale, uploadedFileUri, - textUnitDTOS); + textUnitDTOS, + POST_TRANSLATION); + aiTranslationService.updateVariantStatusToMTReviewNeeded( + textUnitDTOS.stream() + .map(TextUnitDTO::getTmTextUnitCurrentVariantId) + .collect(Collectors.toList())); meterRegistry .counter( "SmartlingSync.uploadAiTranslationsBatch", @@ -326,6 +340,17 @@ private void uploadLocalizedFile( RepositoryLocale repositoryLocale, String uploadedFileUri, List textUnitDTOS) { + uploadLocalizedFile( + projectId, localeMapping, repositoryLocale, uploadedFileUri, textUnitDTOS, PUBLISHED); + } + + private void uploadLocalizedFile( + String projectId, + Map localeMapping, + RepositoryLocale repositoryLocale, + String uploadedFileUri, + List textUnitDTOS, + String translationState) { String fileContent = smartlingJsonConverter.textUnitDTOsToJsonString(textUnitDTOS, TextUnitDTO::getTarget); String smartlingLocale = getSmartlingLocale(localeMapping, repositoryLocale); @@ -333,7 +358,14 @@ private void uploadLocalizedFile( Mono.fromCallable( () -> smartlingClient.uploadLocalizedFile( - projectId, uploadedFileUri, "json", smartlingLocale, fileContent, null, null)) + projectId, + uploadedFileUri, + "json", + smartlingLocale, + fileContent, + null, + null, + translationState)) .retryWhen( smartlingClient .getRetryConfiguration() @@ -442,7 +474,8 @@ PageFetcherOffsetAndLimitSplitIterator getTargetTextUnitIterator( String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, String includeTextUnitsWithPattern, - StatusFilter statusFilter) { + StatusFilter statusFilter, + boolean isRetrieveFileUploadUri) { PageFetcherOffsetAndLimitSplitIterator textUnitDTOPageFetcherOffsetAndLimitSplitIterator = @@ -460,6 +493,7 @@ PageFetcherOffsetAndLimitSplitIterator getTargetTextUnitIterator( parameters.setOffset(offset); parameters.setLimit(limit); parameters.setPluralFormsFiltered(true); + parameters.setIsRetrieveUploadedFileUri(isRetrieveFileUploadUri); List search = textUnitSearcher.search(parameters); return search; }, diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java index 863eb01f2e..d890b582ea 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java @@ -1909,7 +1909,7 @@ public void testPushAiTranslationsSingleFile() throws Exception { eq("POST_TRANSLATION")); }); - verify(aiTranslationService, times(4)).updateVariantStatusToMTReview(any()); + verify(aiTranslationService, times(4)).updateVariantStatusToMTReviewNeeded(any()); } @Test @@ -2075,7 +2075,7 @@ public void testPushAiTranslationsMultiFile() throws Exception { } }); - verify(aiTranslationService, times(20)).updateVariantStatusToMTReview(any()); + verify(aiTranslationService, times(20)).updateVariantStatusToMTReviewNeeded(any()); } private List searchTextUnits(List ids) { diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java index b09391fc90..68f924c6a7 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java @@ -8,6 +8,7 @@ import com.box.l10n.mojito.entity.*; import com.box.l10n.mojito.json.ObjectMapper; import com.box.l10n.mojito.service.ai.translation.AITranslationConfiguration; +import com.box.l10n.mojito.service.ai.translation.AITranslationService; import com.box.l10n.mojito.service.asset.AssetService; import com.box.l10n.mojito.service.assetExtraction.AssetExtractionService; import com.box.l10n.mojito.service.assetExtraction.ServiceTestBase; @@ -86,6 +87,8 @@ public class ThirdPartyTMSSmartlingWithJsonTest extends ServiceTestBase { @Mock AITranslationConfiguration aiTranslationConfiguration; + @Mock AITranslationService aiTranslationService; + SmartlingJsonConverter smartlingJsonConverter = new SmartlingJsonConverter(ObjectMapper.withIndentedOutput(), new SmartlingJsonKeys()); @@ -265,7 +268,8 @@ public void testGetTranslatedUnits() { null, meterRegistryMock, thirdPartyFileChecksumRepositoryMock, - aiTranslationConfiguration); + aiTranslationConfiguration, + aiTranslationService); ImmutableList result = thirdPartyTMSSmartlingWithJson.getTranslatedUnits(