Skip to content

Commit 3913931

Browse files
committed
Fix comments
1 parent b794ade commit 3913931

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/main/java/org/prebid/server/auction/BidResponseCreator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,16 @@ private Bid toBid(BidInfo bidInfo,
15641564
final String seat = targetingInfo.getSeat();
15651565
final String categoryDuration = bidInfo.getCategory();
15661566
targetingKeywords = keywordsCreator != null
1567-
? keywordsCreator.makeFor(bid, seat, isWinningBid, cacheId, bidType.getName(),
1568-
videoCacheId, categoryDuration, account, bidWarnings)
1567+
? keywordsCreator.makeFor(
1568+
bid,
1569+
seat,
1570+
isWinningBid,
1571+
cacheId,
1572+
bidType.getName(),
1573+
videoCacheId,
1574+
categoryDuration,
1575+
account,
1576+
bidWarnings)
15691577
: null;
15701578
} else {
15711579
targetingKeywords = null;

src/main/java/org/prebid/server/auction/TargetingKeywordsCreator.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Set;
17-
import java.util.stream.Collectors;
1817

1918
/**
2019
* Used throughout Prebid to create targeting keys as keys which can be used in an ad server like DFP.
@@ -267,33 +266,36 @@ private static String sizeFrom(Integer width, Integer height) {
267266
private Map<String, String> truncateKeys(Map<String, String> keyValues,
268267
Map<String, List<ExtBidderError>> bidWarnings) {
269268

270-
if (truncateAttrChars > 0) {
271-
final List<String> truncatedKeys = new ArrayList<>();
272-
final Map<String, String> keys = keyValues.entrySet().stream().collect(Collectors.toMap(
273-
keyValue -> truncateKey(keyValue.getKey(), truncatedKeys),
274-
Map.Entry::getValue,
275-
(key1, key2) -> key1));
276-
277-
if (!truncatedKeys.isEmpty()) {
278-
final String errorMessage = "The following keys have been truncated: %s"
279-
.formatted(String.join(", ", truncatedKeys));
280-
bidWarnings.computeIfAbsent("targeting", ignored -> new ArrayList<>())
281-
.add(ExtBidderError.of(BidderError.Type.bad_input.getCode(), errorMessage));
269+
if (truncateAttrChars <= 0) {
270+
return keyValues;
271+
}
272+
273+
final Map<String, String> keys = new HashMap<>();
274+
final List<String> truncatedKeys = new ArrayList<>();
275+
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
276+
final String key = entry.getKey();
277+
final String truncatedKey = truncateKey(key);
278+
keys.putIfAbsent(truncatedKey, entry.getValue());
279+
280+
if (truncatedKey.length() != key.length()) {
281+
truncatedKeys.add(key);
282282
}
283+
}
283284

284-
return keys;
285+
if (!truncatedKeys.isEmpty()) {
286+
final String errorMessage = "The following keys have been truncated: %s"
287+
.formatted(String.join(", ", truncatedKeys));
288+
bidWarnings.computeIfAbsent("targeting", ignored -> new ArrayList<>())
289+
.add(ExtBidderError.of(BidderError.Type.bad_input.getCode(), errorMessage));
285290
}
286291

287-
return keyValues;
292+
return keys;
288293
}
289294

290-
private String truncateKey(String key, List<String> truncatedKeys) {
291-
if (key.length() > truncateAttrChars) {
292-
truncatedKeys.add(key);
293-
return key.substring(0, truncateAttrChars);
294-
}
295-
296-
return key;
295+
private String truncateKey(String key) {
296+
return key.length() > truncateAttrChars
297+
? key.substring(0, truncateAttrChars)
298+
: key;
297299
}
298300

299301
/**

0 commit comments

Comments
 (0)