Skip to content

Commit

Permalink
Segments insert fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Nahornyi committed Mar 1, 2021
1 parent 7bf8a51 commit ac937a5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -986,25 +986,28 @@ private void mergeFirstPartyDataFromUser(ExtUser userExt, ObjectNode result) {
}

private void enrichWithIabAttribute(ObjectNode target, List<Data> data) {
if (containsIabTaxonomyName(data)) {
final List<String> 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> 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<String, List<ExtUserEid>> sourceToUserEidExt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<HttpRequest<BidRequest>>> 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
Expand Down

0 comments on commit ac937a5

Please sign in to comment.