VirtualAssetService { public PollableFuture<Void> importLocalizedTextUnits( long assetId, long localeId, List<VirtualAssetTextUnit> textUnitForVirtualAssets) throws VirtualAssetRequiredException, VirutalAssetMissingTextUnitException { logger.debug("Add text unit variants ({}) to virtual assetId: {}", textUnitForVirtualAssets.size(), assetId); List<TextUnitDTO> textUnitDTOs = new ArrayList<>(); Asset asset = assetRepository.findById(assetId).orElse(null); Locale locale = localeService.findById(localeId); for (VirtualAssetTextUnit textUnitForVirtualAsset : textUnitForVirtualAssets) { TextUnitDTO textUnitDTO = new TextUnitDTO(); textUnitDTO.setRepositoryName(asset.getRepository().getName()); textUnitDTO.setAssetPath(asset.getPath()); textUnitDTO.setTargetLocale(locale.getBcp47Tag()); textUnitDTO.setName(textUnitForVirtualAsset.getName()); textUnitDTO.setTarget(textUnitForVirtualAsset.getContent()); textUnitDTO.setComment(textUnitForVirtualAsset.getComment()); textUnitDTO.setIncludedInLocalizedFile(true); textUnitDTO.setStatus(APPROVED); textUnitDTOs.add(textUnitDTO); } return textUnitBatchImporterService.asyncImportTextUnits(textUnitDTOs, false, false); }  @Transactional VirtualAsset createOrUpdateVirtualAsset(VirtualAsset virtualAsset); List<VirtualAssetTextUnit> getTextUnits(long assetId, Boolean doNotTranslateFilter); @Transactional List<VirtualAssetTextUnit> getLocalizedTextUnits(
            long assetId,
            long localeId,
            InheritanceMode inheritanceMode); PollableFuture<Void> addTextUnits(long assetId, List<VirtualAssetTextUnit> virtualAssetTextUnits); PollableFuture<Void> replaceTextUnits(long assetId, List<VirtualAssetTextUnit> virtualAssetTextUnits); PollableFuture<Void> importLocalizedTextUnits(
            long assetId,
            long localeId,
            List<VirtualAssetTextUnit> textUnitForVirtualAssets); @Transactional void deleteTextUnit(Long assetId, String name); void deleteTextUnits(Asset asset, List<String> names); TMTextUnitVariant addTextUnitVariant(long assetId, long localeId, String name, String content, String comment);  }
@Test public void testImportLocalizedTextUnits() throws Exception { Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("testImportLocalizedTextUnits")); RepositoryLocale repositoryLocaleFrFR = repositoryService.addRepositoryLocale(repository, "fr-FR"); long frFRLocaleId = repositoryLocaleFrFR.getLocale().getId(); VirtualAsset virtualAsset = new VirtualAsset(); virtualAsset.setRepositoryId(repository.getId()); virtualAsset.setPath("default"); virtualAsset = virtualAssetService.createOrUpdateVirtualAsset(virtualAsset); List<VirtualAssetTextUnit> virtualAssetTextUnits = new ArrayList<>(); VirtualAssetTextUnit virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name1"); virtualAssetTextUnit.setContent("content1"); virtualAssetTextUnit.setComment("comment1"); virtualAssetTextUnits.add(virtualAssetTextUnit); virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name2"); virtualAssetTextUnit.setContent("content2"); virtualAssetTextUnit.setComment("comment2"); virtualAssetTextUnits.add(virtualAssetTextUnit); virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name3_other"); virtualAssetTextUnit.setContent("content3"); virtualAssetTextUnit.setComment("comment3"); virtualAssetTextUnit.setPluralForm("other"); virtualAssetTextUnit.setPluralFormOther("name3_other"); virtualAssetTextUnits.add(virtualAssetTextUnit); virtualAssetService.addTextUnits(virtualAsset.getId(), virtualAssetTextUnits).get(); List<VirtualAssetTextUnit> localizedVirtualAssetTextUnits = new ArrayList<>(); virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name1"); virtualAssetTextUnit.setContent("content1-fr"); virtualAssetTextUnit.setComment("comment1-fr"); localizedVirtualAssetTextUnits.add(virtualAssetTextUnit); virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name2"); virtualAssetTextUnit.setContent("content2-fr"); virtualAssetTextUnit.setComment("comment2-fr"); localizedVirtualAssetTextUnits.add(virtualAssetTextUnit); virtualAssetTextUnit = new VirtualAssetTextUnit(); virtualAssetTextUnit.setName("name3_other"); virtualAssetTextUnit.setContent("content3-fr"); virtualAssetTextUnit.setComment("comment3-fr"); virtualAssetTextUnit.setPluralForm("other"); virtualAssetTextUnit.setPluralFormOther("name3_other"); localizedVirtualAssetTextUnits.add(virtualAssetTextUnit); PollableFuture importLocalizedTextUnits = virtualAssetService.importLocalizedTextUnits(virtualAsset.getId(), frFRLocaleId, localizedVirtualAssetTextUnits); importLocalizedTextUnits.get(); List<VirtualAssetTextUnit> loalizedTextUnits = virtualAssetService.getLocalizedTextUnits(virtualAsset.getId(), frFRLocaleId, InheritanceMode.REMOVE_UNTRANSLATED); assertEquals(3, loalizedTextUnits.size()); int i = 0; assertEquals("name1", loalizedTextUnits.get(i).getName()); assertEquals("content1-fr", loalizedTextUnits.get(i).getContent()); assertEquals("comment1", loalizedTextUnits.get(i).getComment()); assertNull(loalizedTextUnits.get(i).getPluralForm()); assertNull(loalizedTextUnits.get(i).getPluralFormOther()); i++; assertEquals("name2", loalizedTextUnits.get(i).getName()); assertEquals("content2-fr", loalizedTextUnits.get(i).getContent()); assertEquals("comment2", loalizedTextUnits.get(i).getComment()); assertNull(loalizedTextUnits.get(i).getPluralForm()); assertNull(loalizedTextUnits.get(i).getPluralFormOther()); i++; assertEquals("name3_other", loalizedTextUnits.get(i).getName()); assertEquals("content3-fr", loalizedTextUnits.get(i).getContent()); assertEquals("comment3", loalizedTextUnits.get(i).getComment()); assertEquals("other", loalizedTextUnits.get(i).getPluralForm()); assertEquals("name3_other", loalizedTextUnits.get(i).getPluralFormOther()); }