Skip to content

Commit

Permalink
Add option to remove existing third party mapping when synchronizing
Browse files Browse the repository at this point in the history
In some Translation Management Systems (TMS), string IDs may need to be remapped. This is particularly necessary when strings with the same "key" are removed and then recreated, often due to incorrect handling. Different TMS systems handle this differently: some use soft deletion, while others create a completely new entry with a new ID. In these cases, a new mapping is required.
  • Loading branch information
ja-openai committed Aug 28, 2024
1 parent 53be11c commit 403a187
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.box.l10n.mojito.service.tm.search.TextUnitSearcher;
import com.box.l10n.mojito.service.tm.textunitdtocache.TextUnitDTOsCacheService;
import com.box.l10n.mojito.service.tm.textunitdtocache.UpdateType;
import com.box.l10n.mojito.utils.OptionsParser;
import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand Down Expand Up @@ -268,6 +269,9 @@ void mapMojitoAndThirdPartyTextUnits(
repository.getName(),
projectId);

OptionsParser optionsParser = new OptionsParser(options);
Boolean deleteCurrentMapping = optionsParser.getBoolean("deleteCurrentMapping", false);

logger.debug("Get the text units of the third party TMS");
List<ThirdPartyTextUnit> thirdPartyTextUnits =
thirdPartyTMS.getThirdPartyTextUnits(repository, projectId, options);
Expand All @@ -294,15 +298,26 @@ void mapMojitoAndThirdPartyTextUnits(
thirdPartyTextUnitsByAsset.entrySet().stream()
.filter(e -> e.getKey() != null)
.forEach(
e -> mapThirdPartyTextUnitsToTextUnitDTOs(e.getKey(), e.getValue(), pluralSeparator));
e ->
mapThirdPartyTextUnitsToTextUnitDTOs(
e.getKey(), e.getValue(), pluralSeparator, deleteCurrentMapping));
}

void mapThirdPartyTextUnitsToTextUnitDTOs(
Asset asset, List<ThirdPartyTextUnit> thirdPartyTextUnitsToMap, String pluralSeparator) {
Asset asset,
List<ThirdPartyTextUnit> thirdPartyTextUnitsToMap,
String pluralSeparator,
boolean deleteCurrentMapping) {
logger.debug("Map third party text units to text unit DTOs for asset: {}", asset.getId());
Set<Long> alreadyMappedTmTextUnitId =
thirdPartyTextUnitRepository.findTmTextUnitIdsByAsset(asset);

if (deleteCurrentMapping) {
thirdPartyTextUnitRepository
.flush(); // as per recommendation of the javadoc of deleteAllByIdInBatch()
thirdPartyTextUnitRepository.deleteAllByIdInBatch(alreadyMappedTmTextUnitId);
}

boolean allWithTmTextUnitId =
thirdPartyTextUnitsToMap.stream()
.map(ThirdPartyTextUnit::getTmTextUnitId)
Expand Down

0 comments on commit 403a187

Please sign in to comment.