From 8b9fb5ad0c2d0bcff4e3aa0b1cbf80fa74350ab5 Mon Sep 17 00:00:00 2001 From: Matt <43931909+mattwilshire@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:50:27 +0000 Subject: [PATCH] Fix null asset mapping on text unit mapping that would throw exception before filtering (#188) --- .../service/thirdparty/ThirdPartyService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java index b37cc6ce35..4ddcfa1c91 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyService.java @@ -286,20 +286,20 @@ void mapMojitoAndThirdPartyTextUnits( logger.debug("Batch the third party text units by asset"); LoadingCache> assetCache = getAssetCache(repository); + Map> thirdPartyTextUnitsByAsset = thirdPartyTextUnits.stream() + .filter(o -> assetCache.getUnchecked(o.getAssetPath()).isPresent()) .collect( groupingBy( - o -> assetCache.getUnchecked(o.getAssetPath()).orElse(null), + o -> assetCache.getUnchecked(o.getAssetPath()).get(), LinkedHashMap::new, toList())); - logger.debug( - "Perform mapping by asset (exclude null asset, that could appear if asset path didn't match)"); - thirdPartyTextUnitsByAsset.entrySet().stream() - .filter(e -> e.getKey() != null) - .forEach( - e -> mapThirdPartyTextUnitsToTextUnitDTOs(e.getKey(), e.getValue(), pluralSeparator)); + logger.debug("Perform mapping by asset"); + thirdPartyTextUnitsByAsset.forEach( + (asset, textUnits) -> + mapThirdPartyTextUnitsToTextUnitDTOs(asset, textUnits, pluralSeparator)); } @Pollable(message = "Push AI translations to third party service.")