diff --git a/webapp/src/main/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapper.java b/webapp/src/main/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapper.java index 742c6f0805..ae1166c0ee 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapper.java +++ b/webapp/src/main/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapper.java @@ -74,7 +74,11 @@ public AndroidStringDocument readFromTextUnits(List textUnits, bool if (OTHER.name().equalsIgnoreCase(textUnit.getPluralForm())) { String name = pluralNameParser.getPrefix(textUnit.getName(), pluralSeparator); - builder.setName((addTextUnitIdInName ? textUnit.getTmTextUnitId() + "#@#" : "") + textUnit.getAssetPath() + assetDelimiter + name); + builder.setName( + (addTextUnitIdInName ? textUnit.getTmTextUnitId() + "#@#" : "") + + textUnit.getAssetPath() + + assetDelimiter + + name); builder.setComment(textUnit.getComment()); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java index 0e86c0f439..c8aeedb086 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java @@ -128,15 +128,16 @@ public PollableFuture pull( String schedulerName, PollableTask currentTask) { - // where to get the list of locale from - doing only FR now - Set repositoryLocales = repository.getRepositoryLocales(); + Set repositoryLocalesWithoutRootLocale = + repositoryService.getRepositoryLocalesWithoutRootLocale(repository); - for (RepositoryLocale repositoryLocale : repositoryLocales) { + for (RepositoryLocale repositoryLocale : repositoryLocalesWithoutRootLocale) { String localeTag = repositoryLocale.getLocale().getBcp47Tag(); + logger.info("Downloading locale: {} from Phrase", localeTag); String fileContent = phraseClient.localeDownload(projectId, localeTag, "xml"); AndroidStringDocumentMapper mapper = - new AndroidStringDocumentMapper(pluralSeparator, null, localeTag, repository.getName()); + new AndroidStringDocumentMapper(pluralSeparator, null, localeTag, repository.getName(), true); List textUnitDTOS = mapper.mapToTextUnits(AndroidStringDocumentReader.fromText(fileContent)); @@ -204,7 +205,7 @@ private static String getFileContent( String pluralSeparator, List textUnitDTOS, boolean useSource) { AndroidStringDocumentMapper androidStringDocumentMapper = - new AndroidStringDocumentMapper(pluralSeparator, null); + new AndroidStringDocumentMapper(pluralSeparator, null, null, null, true); AndroidStringDocument androidStringDocument = androidStringDocumentMapper.readFromTextUnits(textUnitDTOS, useSource); diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java index 4f7b398f32..8d272f7a1a 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java @@ -1,5 +1,6 @@ package com.box.l10n.mojito.service.thirdparty.phrase; +import static com.box.l10n.mojito.io.Files.createDirectories; import static com.box.l10n.mojito.io.Files.createTempDirectory; import static com.box.l10n.mojito.io.Files.write; @@ -51,7 +52,8 @@ Upload waitForUploadToFinish(String projectId, String uploadId) { logger.debug("Waiting for upload to finish: {}", uploadId); Upload upload = uploadsApi.uploadShow(projectId, uploadId, null, null); - logger.debug("Upload info, first fetch: {}", new ObjectMapper().writeValueAsStringUnchecked(upload)); + logger.debug( + "Upload info, first fetch: {}", new ObjectMapper().writeValueAsStringUnchecked(upload)); while (!ImmutableSet.of("success", "error").contains(upload.getState())) { try { @@ -92,9 +94,16 @@ public String uploadCreateFile( try { tmpWorkingDirectory = createTempDirectory("phrase-integration"); + if (tmpWorkingDirectory.toFile().exists()) { + logger.info("Created temporary working directory: {}", tmpWorkingDirectory); + } + Path fileToUpload = tmpWorkingDirectory.resolve(fileName); - logger.debug("Create and upload file to Phrase: {}", fileToUpload); + + logger.info("Create and upload file to Phrase: {}", fileToUpload); + createDirectories(fileToUpload.getParent()); write(fileToUpload, fileContent); + Upload upload = uploadsApi.uploadCreate( projectId, diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java b/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java index 5c7e3c3b0e..1c8ddaa6d1 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java @@ -415,6 +415,7 @@ List skipInvalidAndConvertToTextUnitForBatchImpor textUnitForBatchImport.setRepository( repositoriesCache.getUnchecked(t.getRepositoryName())); if (textUnitForBatchImport.getRepository() != null) { + logger.info("ja- asset path: {}", t.getAssetPath()); textUnitForBatchImport.setAsset( assetsCache.getUnchecked( new SimpleEntry<>( diff --git a/webapp/src/test/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapperTest.java b/webapp/src/test/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapperTest.java index 847e484a07..f603b23f7e 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapperTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/android/strings/AndroidStringDocumentMapperTest.java @@ -163,29 +163,29 @@ public void testReadFromSourceTextUnitsWithPluralsAndWithTmTextUnitIdInName() { textUnits.add(sourceTextUnitDTO(123L, "name0", "content0", "comment0", "my/path0", null, null)); textUnits.add( - sourceTextUnitDTO( - 100L, "name1 _other", "content1_zero", "comment1", "my/path1", "zero", "name1_other")); + sourceTextUnitDTO( + 100L, "name1 _other", "content1_zero", "comment1", "my/path1", "zero", "name1_other")); textUnits.add( - sourceTextUnitDTO( - 101L, "name1 _other", "content1_one", "comment1", "my/path1", "one", "name1_other")); + sourceTextUnitDTO( + 101L, "name1 _other", "content1_one", "comment1", "my/path1", "one", "name1_other")); textUnits.add( - sourceTextUnitDTO( - 102L, "name1 _other", "content1_two", "comment1", "my/path1", "two", "name1_other")); + sourceTextUnitDTO( + 102L, "name1 _other", "content1_two", "comment1", "my/path1", "two", "name1_other")); textUnits.add( - sourceTextUnitDTO( - 103L, "name1 _other", "content1_few", "comment1", "my/path1", "few", "name1_other")); + sourceTextUnitDTO( + 103L, "name1 _other", "content1_few", "comment1", "my/path1", "few", "name1_other")); textUnits.add( - sourceTextUnitDTO( - 104L, "name1 _other", "content1_many", "comment1", "my/path1", "many", "name1_other")); + sourceTextUnitDTO( + 104L, "name1 _other", "content1_many", "comment1", "my/path1", "many", "name1_other")); textUnits.add( - sourceTextUnitDTO( - 105L, - "name1 _other", - "content1_other", - "comment1", - "my/path1", - "other", - "name1_other")); + sourceTextUnitDTO( + 105L, + "name1 _other", + "content1_other", + "comment1", + "my/path1", + "other", + "name1_other")); document = mapper.readFromSourceTextUnits(textUnits); @@ -216,8 +216,6 @@ public void testReadFromSourceTextUnitsWithPluralsAndWithTmTextUnitIdInName() { assertThat(plural.getItems().get(OTHER).getContent()).isEqualTo("content1_other"); } - - @Test public void testReadFromSourceTextUnitsWithDuplicatePlurals() { mapper = new AndroidStringDocumentMapper(" _", assetDelimiter); @@ -751,7 +749,7 @@ public void testReadingTextUnitsFromFile() throws Exception { assertThat(textUnits) .filteredOn(tu -> tu.getName().equalsIgnoreCase("some_string")) - .extracting("name", "target", "comment") + .extracting("name", "target", "comment") .containsOnly(tuple("some_string", "Dela...", "Some string")); assertThat(textUnits) @@ -825,13 +823,13 @@ public void testAddTextUnitDTOAttributesTextUnitIdAndAssetPathAndName() { textUnitDTO.setName("156151#@#asset_path#@#name_part1"); assertThat(mapper.addTextUnitDTOAttributes(textUnitDTO)) - .extracting(TextUnitDTO::getTmTextUnitId, TextUnitDTO::getAssetPath, TextUnitDTO::getName) - .containsExactly(156151L,"asset_path", "name_part1"); + .extracting(TextUnitDTO::getTmTextUnitId, TextUnitDTO::getAssetPath, TextUnitDTO::getName) + .containsExactly(156151L, "asset_path", "name_part1"); textUnitDTO.setName("156152#@#asset_path#@#name_part1#@#name_part2"); assertThat(mapper.addTextUnitDTOAttributes(textUnitDTO)) - .extracting(TextUnitDTO::getTmTextUnitId, TextUnitDTO::getAssetPath, TextUnitDTO::getName) - .containsExactly(156152L,"asset_path", "name_part1#@#name_part2"); + .extracting(TextUnitDTO::getTmTextUnitId, TextUnitDTO::getAssetPath, TextUnitDTO::getName) + .containsExactly(156152L, "asset_path", "name_part1#@#name_part2"); } private TextUnitDTO sourceTextUnitDTO( diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTestData.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTestData.java index 1b081589f3..642bf18ca9 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTestData.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyServiceTestData.java @@ -177,4 +177,8 @@ public ThirdPartyServiceTestData init() throws Exception { logger.debug("Finished init of ThirdPartyServiceTestData"); return this; } + + public String getPluralSeparator() { + return "_"; + } } diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhraseTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhraseTest.java new file mode 100644 index 0000000000..77f7465286 --- /dev/null +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhraseTest.java @@ -0,0 +1,61 @@ +package com.box.l10n.mojito.service.thirdparty; + +import com.box.l10n.mojito.entity.Repository; +import com.box.l10n.mojito.service.assetExtraction.ServiceTestBase; +import com.box.l10n.mojito.test.TestIdWatcher; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; + +public class ThirdPartyTMSPhraseTest extends ServiceTestBase { + + static Logger logger = LoggerFactory.getLogger(ThirdPartyTMSPhraseTest.class); + + @Autowired(required = false) + ThirdPartyTMSPhrase thirdPartyTMSPhrase; + + @Value("${test.phrase-client.projectId}") + String testProjectId; + + @Rule public TestIdWatcher testIdWatcher = new TestIdWatcher(); + + @Test + public void testBasics() { + Assume.assumeNotNull(thirdPartyTMSPhrase); + Assume.assumeNotNull(testProjectId); + + ThirdPartyServiceTestData thirdPartyServiceTestData = + new ThirdPartyServiceTestData(testIdWatcher); + + Repository repository = thirdPartyServiceTestData.repository; + + thirdPartyTMSPhrase.push( + repository, + testProjectId, + thirdPartyServiceTestData.getPluralSeparator(), + null, + null, + null); + thirdPartyTMSPhrase.pull( + repository, + testProjectId, + thirdPartyServiceTestData.getPluralSeparator(), + null, + null, + null, + null, + null, + null); + + // List thirdPartyTextUnits = + // thirdPartyTMSPhrase.getThirdPartyTextUnits(repository, testProjectId, null); + // logger.info("Get") + // thirdPartyTextUnits.stream().forEach(t -> logger.info("third party text unit: {}", + // t)); + + } +}