Skip to content

Commit

Permalink
I18N-1324 - Update TextUnitSearcherParameters to support Builder pattern
Browse files Browse the repository at this point in the history
Updated TextUnitSearcherParameters to support Builder pattern in ThirdPartyTMSSmartling class
  • Loading branch information
DarKhaos committed Oct 29, 2024
1 parent f0b6b55 commit ad6dae1
Show file tree
Hide file tree
Showing 4 changed files with 764 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class ThirdPartyTMSSmartling implements ThirdPartyTMS {

private final SmartlingClient smartlingClient;
private final AssetPathAndTextUnitNameKeys assetPathAndTextUnitNameKeys;
private final TextUnitSearcher textUnitSearcher;
TextUnitSearcher textUnitSearcher;
private final TextUnitBatchImporterService textUnitBatchImporterService;
private final SmartlingResultProcessor resultProcessor;
private final Integer batchSize;
Expand Down Expand Up @@ -827,15 +827,16 @@ private Stream<List<TextUnitDTO>> partitionSingulars(
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern) {
TextUnitSearcherParameters parameters =
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null);
parameters.setOrderByTextUnitID(true);
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null)
.isOrderedByTextUnitID(true)
.build();
return partitionedStream(parameters, textUnitSearcher::search);
}

Expand All @@ -846,16 +847,17 @@ private Stream<List<TextUnitDTO>> partitionSingulars(
String skipAssetsWithPathPattern,
String includeTextUnitWithPattern) {
TextUnitSearcherParameters parameters =
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null,
includeTextUnitWithPattern);
parameters.setOrderByTextUnitID(true);
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null,
includeTextUnitWithPattern)
.isOrderedByTextUnitID(true)
.build();
return partitionedStream(parameters, textUnitSearcher::search);
}

Expand All @@ -865,15 +867,16 @@ private Stream<List<TextUnitDTO>> partitionPlurals(
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern) {
TextUnitSearcherParameters parameters =
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%");
parameters.setOrderByTextUnitID(true);
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%")
.isOrderedByTextUnitID(true)
.build();
return partitionedStream(parameters, textUnitSearcher::search);
}

Expand All @@ -898,17 +901,17 @@ private Stream<List<TextUnitDTO>> partitionPlurals(
}

TextUnitSearcherParameters parameters =
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%",
includeTextUnitsWithPattern);

parameters.setOrderByTextUnitID(true);
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%",
includeTextUnitsWithPattern)
.isOrderedByTextUnitID(true)
.build();

return partitionedStream(parameters, searchFunction);
}
Expand All @@ -927,14 +930,15 @@ private Long singularCount(
String skipAssetsWithPathPattern) {
return textUnitSearcher
.countTextUnitAndWordCount(
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null))
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
true,
true,
null)
.build())
.getTextUnitCount();
}

Expand All @@ -945,47 +949,48 @@ private Long pluralCount(
String skipAssetsWithPathPattern) {
return textUnitSearcher
.countTextUnitAndWordCount(
baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%"))
this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
false,
false,
"%")
.build())
.getTextUnitCount();
}

private TextUnitSearcherParameters baseParams(
private TextUnitSearcherParameters.Builder baseParams(
Long repositoryId,
String localeTag,
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern,
boolean pluralFormsFiltered,
boolean pluralFormsExcluded,
String pluralFormOther) {
TextUnitSearcherParameters result = new TextUnitSearcherParameters();
result.setRepositoryIds(repositoryId);
result.setLocaleTags(ImmutableList.of(localeTag));
result.setRootLocaleExcluded(false);
result.setDoNotTranslateFilter(false);
result.setSearchType(SearchType.ILIKE);
result.setStatusFilter(StatusFilter.TRANSLATED);
result.setUsedFilter(UsedFilter.USED);
result.setPluralFormsFiltered(pluralFormsFiltered);
result.setPluralFormsExcluded(pluralFormsExcluded);
result.setSkipTextUnitWithPattern(skipTextUnitsWithPattern);
result.setSkipAssetPathWithPattern(skipAssetsWithPathPattern);
result.setExcludeUnexpiredPendingMT(aiTranslationConfiguration.isEnabled());
result.setAiTranslationExpiryDuration(aiTranslationConfiguration.getExpiryDuration());
TextUnitSearcherParameters.Builder builder =
new TextUnitSearcherParameters.Builder()
.repositoryIds(repositoryId)
.localeTags(ImmutableList.of(localeTag))
.rootLocaleExcluded(false)
.doNotTranslateFilter(false)
.searchType(SearchType.ILIKE)
.statusFilter(StatusFilter.TRANSLATED)
.usedFilter(UsedFilter.USED)
.pluralFormsFiltered(pluralFormsFiltered)
.pluralFormsExcluded(pluralFormsExcluded)
.skipTextUnitWithPattern(skipTextUnitsWithPattern)
.skipAssetPathWithPattern(skipAssetsWithPathPattern)
.isExcludeUnexpiredPendingMT(aiTranslationConfiguration.isEnabled())
.aiTranslationExpiryDuration(aiTranslationConfiguration.getExpiryDuration());
if (!Strings.isNullOrEmpty(pluralFormOther)) {
result.setPluralFormOther(pluralFormOther);
builder.pluralFormOther(pluralFormOther);
}

return result;
return builder;
}

private TextUnitSearcherParameters baseParams(
private TextUnitSearcherParameters.Builder baseParams(
Long repositoryId,
String localeTag,
String skipTextUnitsWithPattern,
Expand All @@ -994,17 +999,15 @@ private TextUnitSearcherParameters baseParams(
boolean pluralFormsExcluded,
String pluralFormOther,
String includeTextUnitsWithPattern) {
TextUnitSearcherParameters result =
baseParams(
return this.baseParams(
repositoryId,
localeTag,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
pluralFormsFiltered,
pluralFormsExcluded,
pluralFormOther);
result.setIncludeTextUnitsWithPattern(includeTextUnitsWithPattern);
return result;
pluralFormOther)
.includeTextUnitsWithPattern(includeTextUnitsWithPattern);
}

/**
Expand Down
Loading

0 comments on commit ad6dae1

Please sign in to comment.