From ac937a57312133f91368417ddcbca01dda2c4f7b Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Mon, 1 Mar 2021 15:58:20 +0200 Subject: [PATCH] Segments insert fix --- .../server/bidder/rubicon/RubiconBidder.java | 33 +++++++++------- .../bidder/rubicon/RubiconBidderTest.java | 39 +++++++++++++++++++ 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java index c20c9de1a03..da3efc1c001 100644 --- a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java +++ b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java @@ -986,25 +986,28 @@ private void mergeFirstPartyDataFromUser(ExtUser userExt, ObjectNode result) { } private void enrichWithIabAttribute(ObjectNode target, List data) { - if (containsIabTaxonomyName(data)) { + final List iabValue = CollectionUtils.emptyIfNull(data).stream() + .filter(Objects::nonNull) + .filter(dataRecord -> containsIabTaxonomyName(dataRecord.getExt())) + .map(Data::getSegment) + .filter(Objects::nonNull) + .flatMap(segments -> segments.stream() + .map(Segment::getId)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + if (CollectionUtils.isNotEmpty(iabValue)) { final ArrayNode iab = target.putArray("iab"); - data.stream() - .map(Data::getSegment) - .flatMap(segments -> segments.stream() - .map(Segment::getId)) - .forEach(iab::add); + iabValue.forEach(iab::add); } } - private boolean containsIabTaxonomyName(List data) { - return CollectionUtils.emptyIfNull(data).stream() - .map(Data::getExt) - .filter(Objects::nonNull) - .map(ext -> ext.get("taxonomyname")) - .filter(Objects::nonNull) - .filter(JsonNode::isTextual) - .map(JsonNode::textValue) - .anyMatch(value -> StringUtils.containsIgnoreCase(value, "iab")); + private boolean containsIabTaxonomyName(ObjectNode ext) { + final JsonNode taxonomyname = ext.get("taxonomyname"); + if (taxonomyname != null && taxonomyname.isTextual()) { + return StringUtils.containsIgnoreCase(taxonomyname.textValue(), "iab"); + } + return false; } private static String extractLiverampId(Map> sourceToUserEidExt) { diff --git a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java index 8ff12cc4633..163b39dd877 100644 --- a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java @@ -702,6 +702,45 @@ public void makeHttpRequestsShouldFillUserExtRpWithIabAttributeIfTaxonomynameCon .build())); } + @Test + public void makeHttpRequestsShouldFillWithIabAttributeOnlyIfContainsIabInTaxonomynameAttribute() { + // given + final ObjectNode firstUserDataNode = mapper.createObjectNode(); + firstUserDataNode.put("taxonomyname", "contains IaB"); + final ObjectNode secondUserDataNode = mapper.createObjectNode(); + secondUserDataNode.put("taxonomyname", "not contain"); + final BidRequest bidRequest = givenBidRequest( + builder -> builder.user(User.builder().data(asList(Data.builder() + .segment(singletonList(Segment.builder().id("segmentId") + .build())) + .ext(firstUserDataNode).build(), + Data.builder() + .segment(singletonList(Segment.builder().id("secondSegmentId") + .build())) + .ext(secondUserDataNode).build())).build()), + builder -> builder.video(Video.builder().build()), + identity()); + + // when + final Result>> result = rubiconBidder.makeHttpRequests(bidRequest); + + // then + final ObjectNode expectedTarget = mapper.createObjectNode(); + final ArrayNode expectedIabAttribute = expectedTarget.putArray("iab"); + expectedIabAttribute.add("segmentId"); + + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1).doesNotContainNull() + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .extracting(BidRequest::getUser).doesNotContainNull() + .extracting(User::getExt) + .containsOnly(jacksonMapper.fillExtension( + ExtUser.builder().build(), + RubiconUserExt.builder() + .rp(RubiconUserExtRp.of(expectedTarget)) + .build())); + } + @Test public void makeHttpRequestsShouldIgnoreNotTextualTaxonomynameProperty() { // given