@Test public void testPushInBatchesWithSingularsAndNoPlurals() throws RepositoryNameAlreadyUsedException { int batchSize = 3; List<SmartlingFile> result; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("batchRepo")); tmsSmartling = new ThirdPartyTMSSmartling(smartlingClient, textUnitSearcher, assetPathAndTextUnitNameKeys, textUnitBatchImporterService, resultProcessor, batchSize); TM tm = repository.getTm(); Asset asset = assetService.createAssetWithContent(repository.getId(), "fake_for_test", "fake for test"); AssetExtraction assetExtraction = new AssetExtraction(); assetExtraction.setAsset(asset); assetExtraction = assetExtractionRepository.save(assetExtraction); int singularTextUnits = 16; int singularBatches = 6; for (int i = 0; i < singularTextUnits; i++){ String name = "singular_message_test" + i; String content = "Singular Message Test " + i; String comment = "Singular Comment" + i; tmService.addTMTextUnit(tm.getId(), asset.getId(), name, content, comment); assetExtractionService.createAssetTextUnit(assetExtraction, name, content, comment); } prepareAssetAndTextUnits(assetExtraction, asset, tm); tmsSmartling.push(repository, "projectId", pluralSep, null, null, Collections.emptyList()); result = resultProcessor.pushFiles; assertThat(result).hasSize(singularBatches); assertThat(result).allSatisfy(file -> assertThat(file.getFileName()).endsWith("singular_source.xml")); assertThat(result.subList(0, 4)).allSatisfy(file -> assertThat(readTextUnits(file, pluralSep)).hasSize(batchSize)); assertThat(result.get(5)).satisfies(file -> assertThat(readTextUnits(file, pluralSep)).hasSize(singularTextUnits % batchSize)); }
@Override public void push(Repository repository, String projectId, String pluralSeparator, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream<SmartlingFile> singularFiles = mapWithIndex( partitionSingulars(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.SINGULAR)); Stream<SmartlingFile> pluralFiles = mapWithIndex( partitionPlurals(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.PLURAL)); List<SmartlingFile> result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void push(Repository repository, String projectId, String pluralSeparator, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream<SmartlingFile> singularFiles = mapWithIndex( partitionSingulars(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.SINGULAR)); Stream<SmartlingFile> pluralFiles = mapWithIndex( partitionPlurals(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.PLURAL)); List<SmartlingFile> result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); } }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void push(Repository repository, String projectId, String pluralSeparator, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream<SmartlingFile> singularFiles = mapWithIndex( partitionSingulars(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.SINGULAR)); Stream<SmartlingFile> pluralFiles = mapWithIndex( partitionPlurals(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.PLURAL)); List<SmartlingFile> result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void push(Repository repository, String projectId, String pluralSeparator, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream<SmartlingFile> singularFiles = mapWithIndex( partitionSingulars(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.SINGULAR)); Stream<SmartlingFile> pluralFiles = mapWithIndex( partitionPlurals(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.PLURAL)); List<SmartlingFile> result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); @Override ThirdPartyTMSImage uploadImage(String projectId, String name, byte[] content); @Override List<ThirdPartyTextUnit> getThirdPartyTextUnits(Repository repository, String projectId); @Override void createImageToTextUnitMappings(String projectId, List<ThirdPartyImageToTextUnit> thirdPartyImageToTextUnits); @Override void push(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pull(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     Map<String, String> localeMapping,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pushTranslations(Repository repository,
                                 String projectId,
                                 String pluralSeparator,
                                 Map<String, String> localeMapping,
                                 String skipTextUnitsWithPattern,
                                 String skipAssetsWithPathPattern,
                                 List<String> optionList); }
ThirdPartyTMSSmartling implements ThirdPartyTMS { @Override public void push(Repository repository, String projectId, String pluralSeparator, String skipTextUnitsWithPattern, String skipAssetsWithPathPattern, List<String> optionList) { SmartlingOptions options = SmartlingOptions.parseList(optionList); AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream<SmartlingFile> singularFiles = mapWithIndex( partitionSingulars(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.SINGULAR)); Stream<SmartlingFile> pluralFiles = mapWithIndex( partitionPlurals(repository.getId(), LOCALE_EN, skipTextUnitsWithPattern, skipAssetsWithPathPattern), (batch, index) -> processPushBatch(batch, index, mapper, repository, projectId, options, Prefix.PLURAL)); List<SmartlingFile> result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); } @Autowired  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor);  ThirdPartyTMSSmartling(SmartlingClient smartlingClient,
                                  TextUnitSearcher textUnitSearcher,
                                  AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys,
                                  TextUnitBatchImporterService textUnitBatchImporterService,
                                  SmartlingResultProcessor resultProcessor,
                                  int batchSize); @Override ThirdPartyTMSImage uploadImage(String projectId, String name, byte[] content); @Override List<ThirdPartyTextUnit> getThirdPartyTextUnits(Repository repository, String projectId); @Override void createImageToTextUnitMappings(String projectId, List<ThirdPartyImageToTextUnit> thirdPartyImageToTextUnits); @Override void push(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pull(Repository repository,
                     String projectId,
                     String pluralSeparator,
                     Map<String, String> localeMapping,
                     String skipTextUnitsWithPattern,
                     String skipAssetsWithPathPattern,
                     List<String> optionList); @Override void pushTranslations(Repository repository,
                                 String projectId,
                                 String pluralSeparator,
                                 Map<String, String> localeMapping,
                                 String skipTextUnitsWithPattern,
                                 String skipAssetsWithPathPattern,
                                 List<String> optionList);  }