TMService { public PollableFuture<Void> importLocalizedAssetAsync( Long assetId, String content, Long localeId, StatusForEqualTarget statusForEqualtarget, FilterConfigIdOverride filterConfigIdOverride, List<String> filterOptions) { ImportLocalizedAssetJobInput importLocalizedAssetJobInput = new ImportLocalizedAssetJobInput(); importLocalizedAssetJobInput.setAssetId(assetId); importLocalizedAssetJobInput.setLocaleId(localeId); importLocalizedAssetJobInput.setContent(content); importLocalizedAssetJobInput.setStatusForEqualtarget(statusForEqualtarget); importLocalizedAssetJobInput.setFilterConfigIdOverride(filterConfigIdOverride); importLocalizedAssetJobInput.setFilterOptions(filterOptions); PollableFuture<Void> pollableFuture = quartzPollableTaskScheduler.scheduleJob(ImportLocalizedAssetJob.class, importLocalizedAssetJobInput); return pollableFuture; }  TMTextUnit addTMTextUnit(Long tmId, Long assetId, String name, String content, String comment); TMTextUnit addTMTextUnit(
            TM tm,
            Asset asset,
            String name,
            String content,
            String comment,
            DateTime createdDate,
            PluralForm pluralForm,
            String pluralFormOther); TMTextUnit addTMTextUnit(
            TM tm,
            Asset asset,
            String name,
            String content,
            String comment,
            User createdByUser,
            DateTime createdDate,
            PluralForm pluralForm,
            String pluralFormOther); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content, TMTextUnitVariant.Status status, boolean includedInLocalizedFile); TMTextUnitVariant addCurrentTMTextUnitVariant(Long tmTextUnitId, Long localeId, String content, TMTextUnitVariant.Status status, boolean includedInLocalizedFile, DateTime createdDate); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(Long tmTextUnitId, Long localeId, String content, String comment); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(Long tmTextUnitId, Long localeId, String content, String comment, TMTextUnitVariant.Status status); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile); TMTextUnitCurrentVariant addTMTextUnitCurrentVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
            TMTextUnitCurrentVariant tmTextUnitCurrentVariant,
            Long tmId,
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate,
            User createdBy); boolean isUpdateNeededForTmTextUnitVariant(
            TMTextUnitVariant.Status currentStatus,
            String currentContentMd5,
            boolean currentIncludedInLocalizedFile,
            String currentComment,
            TMTextUnitVariant.Status newStatus,
            String newContentMd5,
            boolean newIncludedInLocalizedFile,
            String newComment); TMTextUnitVariant addTMTextUnitVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate); TMTextUnitVariant addTMTextUnitVariant(
            Long tmTextUnitId,
            Long localeId,
            String content,
            String comment,
            TMTextUnitVariant.Status status,
            boolean includedInLocalizedFile,
            DateTime createdDate,
            User createdBy); UpdateTMWithXLIFFResult updateTMWithTranslationKitXLIFF(
            String xliffContent,
            TMTextUnitVariant.Status importStatus,
            String dropImporterUsernameOverride); UpdateTMWithXLIFFResult updateTMWithXLIFFById(
            String xliffContent,
            TMTextUnitVariant.Status importStatus); UpdateTMWithXLIFFResult updateTMWithXLIFFByMd5(
            String xliffContent,
            TMTextUnitVariant.Status importStatus,
            Repository repository); @Transactional String exportAssetAsXLIFF(Long assetId, String bcp47Tag); String generateLocalized(
            Asset asset,
            String content,
            RepositoryLocale repositoryLocale,
            String outputBcp47tag,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions,
            Status status,
            InheritanceMode inheritanceMode); String generatePseudoLocalized(
            Asset asset,
            String content,
            FilterConfigIdOverride filterConfigIdOverride); PollableFuture<Void> importLocalizedAssetAsync(
            Long assetId,
            String content,
            Long localeId,
            StatusForEqualTarget statusForEqualtarget,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); void importLocalizedAsset(
            Long assetId,
            String content,
            Long localeId,
            StatusForEqualTarget statusForEqualtarget,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); @Pollable(async = true, message = "Export asset as xliff") PollableFuture<String> exportAssetAsXLIFFAsync(
            Long tmXliffId,
            Long assetId,
            String bcp47Tag,
            @InjectCurrentTask PollableTask currentTask); TMXliff createTMXliff(Long assetId, String bcp47Tag, String content, PollableTask pollableTask);  }
@Test public void testImportLocalizedAssetNotFullyTranslated() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException, AssetUpdateException { baseTestImportLocalizedAsset(StatusForEqualTarget.APPROVED); RepositoryLocale repoLocale; try { repoLocale = repositoryService.addRepositoryLocale(repository, "fr-CA", "fr-FR", false); } catch (RepositoryLocaleCreationException e) { throw new RuntimeException(e); } String localizedAssetContent = "hello=Bonjour\nbye=Au revoir CA\nsource=target"; tmService.importLocalizedAssetAsync(assetId, localizedAssetContent, repoLocale.getLocale().getId(), StatusForEqualTarget.APPROVED, null, null).get(); TextUnitSearcherParameters textUnitSearcherParameters = new TextUnitSearcherParameters(); textUnitSearcherParameters.setRepositoryIds(repository.getId()); textUnitSearcherParameters.setStatusFilter(StatusFilter.TRANSLATED); textUnitSearcherParameters.setLocaleId(repoLocale.getLocale().getId()); List<TextUnitDTO> textUnitDTOs = textUnitSearcher.search(textUnitSearcherParameters); Iterator<TextUnitDTO> iterator = textUnitDTOs.iterator(); TextUnitDTO next = iterator.next(); assertEquals("Au revoir CA", next.getTarget()); assertEquals(TMTextUnitVariant.Status.APPROVED, next.getStatus()); assertFalse(iterator.hasNext()); }
@Test public void testReImportLocalizedAsset() throws RepositoryNameAlreadyUsedException, ExecutionException, InterruptedException, AssetUpdateException { baseTestImportLocalizedAsset(StatusForEqualTarget.APPROVED); RepositoryLocale repoLocale; try { repoLocale = repositoryService.addRepositoryLocale(repository, "fr-CA", "fr-FR", false); } catch (RepositoryLocaleCreationException e) { throw new RuntimeException(e); } String localizedAssetContent = "hello=Bonjour\nbye=Au revoir CA\nsource=target"; tmService.importLocalizedAssetAsync(assetId, localizedAssetContent, repoLocale.getLocale().getId(), StatusForEqualTarget.APPROVED, null, null).get(); tmService.importLocalizedAssetAsync(assetId, localizedAssetContent, repoLocale.getLocale().getId(), StatusForEqualTarget.APPROVED, null, null).get(); TextUnitSearcherParameters textUnitSearcherParameters = new TextUnitSearcherParameters(); textUnitSearcherParameters.setRepositoryIds(repository.getId()); textUnitSearcherParameters.setStatusFilter(StatusFilter.TRANSLATED); textUnitSearcherParameters.setLocaleId(repoLocale.getLocale().getId()); List<TextUnitDTO> textUnitDTOs = textUnitSearcher.search(textUnitSearcherParameters); Iterator<TextUnitDTO> iterator = textUnitDTOs.iterator(); TextUnitDTO next = iterator.next(); assertEquals("Au revoir CA", next.getTarget()); assertEquals(TMTextUnitVariant.Status.APPROVED, next.getStatus()); assertFalse(iterator.hasNext()); }
@Test public void testImportLocalizedAssetPoPluralSinglePlural() throws Exception { repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); RepositoryLocale repoLocale; try { repoLocale = repositoryService.addRepositoryLocale(repository, "ja-JP"); } catch (RepositoryLocaleCreationException e) { throw new RuntimeException(e); } String assetContent = "# SOME DESCRIPTIVE TITLE.\n" + "# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n" + "# This file is distributed under the same license as the PACKAGE package.\n" + "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n" + "#\n" + "#, fuzzy\n" + "msgid \"\"\n" + "msgstr \"\"\n" + "\"Project-Id-Version: PACKAGE VERSION\\n\"\n" + "\"Report-Msgid-Bugs-To: \\n\"\n" + "\"POT-Creation-Date: 2017-02-24 11:50-0800\\n\"\n" + "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" + "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" + "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n" + "\"Language: \\n\"\n" + "\"MIME-Version: 1.0\\n\"\n" + "\"Plural-Forms: nplurals=2; plural=(n != 1);\\n\"\n" + "\"Content-Type: text/plain; charset=utf-8\\n\"\n" + "\"Content-Transfer-Encoding: 8bit\\n\"\n" + " \n" + " \n" + "#. Test plural\n" + "#: file.js:20\n" + "msgctxt \"car\"\n" + "msgid \"There is {number} car\"\n" + "msgid_plural \"There are {number} cars\"\n" + "msgstr[0] \"\"\n" + "msgstr[1] \"\"\n" + "\n" + "#. Test plural okapi bug\n" + "#: file.js:24\n" + "msgctxt \"testpluralokapibug\"\n" + "msgid \"test okapi bug\"\n" + "msgstr \"\"\n" + ""; asset = assetService.createAssetWithContent(repository.getId(), "messages.pot", assetContent); asset = assetRepository.findById(asset.getId()).orElse(null); assetId = asset.getId(); tmId = repository.getTm().getId(); PollableFuture<Asset> assetResult = assetService.addOrUpdateAssetAndProcessIfNeeded(repository.getId(), asset.getPath(), assetContent, false, null, null, null, null); try { pollableTaskService.waitForPollableTask(assetResult.getPollableTask().getId()); } catch (PollableTaskException | InterruptedException e) { throw new RuntimeException(e); } assetResult.get(); String localizedAssetContent = "# SOME DESCRIPTIVE TITLE.\n" + "# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n" + "# This file is distributed under the same license as the PACKAGE package.\n" + "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n" + "#\n" + "#, fuzzy\n" + "msgid \"\"\n" + "msgstr \"\"\n" + "\"Project-Id-Version: PACKAGE VERSION\\n\"\n" + "\"Report-Msgid-Bugs-To: \\n\"\n" + "\"POT-Creation-Date: 2017-02-24 11:50-0800\\n\"\n" + "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" + "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" + "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n" + "\"Language: \\n\"\n" + "\"MIME-Version: 1.0\\n\"\n" + "\"Plural-Forms: nplurals=1; plural=0;\\n\"\n" + "\"Content-Type: text/plain; charset=utf-8\\n\"\n" + "\"Content-Transfer-Encoding: 8bit\\n\"\n" + " \n" + " \n" + "#. Test plural\n" + "#: file.js:20\n" + "msgctxt \"car\"\n" + "msgid \"There is {number} car\"\n" + "msgid_plural \"There are {number} cars\"\n" + "msgstr[0] \"There is {number} car\"\n" + "\n" + "#. Test plural okapi bug\n" + "#: file.js:24\n" + "msgctxt \"testpluralokapibug\"\n" + "msgid \"test okapi bug\"\n" + "msgstr \"jp test okapi bug\"\n" + "\n" + ""; tmService.importLocalizedAssetAsync(assetId, localizedAssetContent, repoLocale.getLocale().getId(), StatusForEqualTarget.APPROVED, null, null).get(); }
@Test public void testImportLocalizedWithDuplicatedName() throws Exception { repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); RepositoryLocale repoLocale; try { repoLocale = repositoryService.addRepositoryLocale(repository, "ja-JP"); } catch (RepositoryLocaleCreationException e) { throw new RuntimeException(e); } String assetContent = "k1=v1\n" + "k1=v1b"; asset = assetService.createAssetWithContent(repository.getId(), "demo.properties", assetContent); asset = assetRepository.findById(asset.getId()).orElse(null); assetId = asset.getId(); tmId = repository.getTm().getId(); PollableFuture<Asset> assetResult = assetService.addOrUpdateAssetAndProcessIfNeeded(repository.getId(), asset.getPath(), assetContent, false, null, null, null, null); try { pollableTaskService.waitForPollableTask(assetResult.getPollableTask().getId()); } catch (PollableTaskException | InterruptedException e) { throw new RuntimeException(e); } assetResult.get(); String localizedAssetContent = "k1=v1-localized\n" + "k1=v1b-localized"; tmService.importLocalizedAssetAsync(assetId, localizedAssetContent, repoLocale.getLocale().getId(), StatusForEqualTarget.APPROVED, null, null).get(); TextUnitSearcherParameters textUnitSearcherParameters = new TextUnitSearcherParameters(); textUnitSearcherParameters.setRepositoryIds(repository.getId()); textUnitSearcherParameters.setStatusFilter(StatusFilter.TRANSLATED); textUnitSearcherParameters.setLocaleId(repoLocale.getLocale().getId()); List<TextUnitDTO> textUnitDTOs = textUnitSearcher.search(textUnitSearcherParameters); Iterator<TextUnitDTO> iterator = textUnitDTOs.iterator(); TextUnitDTO next = iterator.next(); assertEquals("v1-localized", next.getTarget()); assertEquals(TMTextUnitVariant.Status.APPROVED, next.getStatus()); next = iterator.next(); assertEquals("v1b-localized", next.getTarget()); assertEquals(TMTextUnitVariant.Status.APPROVED, next.getStatus()); assertFalse(iterator.hasNext()); }