Skip to content

Commit

Permalink
Add processing of imp.ext.data to mediagrid (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickluck8 committed Aug 10, 2021
1 parent 969b100 commit 74b0af8
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/org/prebid/server/bidder/grid/GridBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.OpenrtbBidder;
import org.prebid.server.bidder.grid.model.ExtImpGrid;
import org.prebid.server.bidder.grid.model.GridExtImp;
import org.prebid.server.bidder.grid.model.GridExtImpData;
import org.prebid.server.bidder.grid.model.GridExtImpDataAdServer;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.response.BidType;
Expand All @@ -21,6 +25,26 @@ protected Imp modifyImp(Imp imp, ExtImpGrid impExt) {
if (impExt.getUid() == null || impExt.getUid() == 0) {
throw new PreBidException("uid is empty");
}

final GridExtImp gridExtImp;
try {
gridExtImp = mapper.mapper().convertValue(imp.getExt(), GridExtImp.class);
} catch (Exception e) {
throw new PreBidException(e.getMessage());
}

final GridExtImpData extImpData = gridExtImp != null ? gridExtImp.getData() : null;
final GridExtImpDataAdServer adServer = extImpData != null ? extImpData.getAdServer() : null;
final String adSlot = adServer != null ? adServer.getAdSlot() : null;
if (StringUtils.isNotEmpty(adSlot)) {

final GridExtImp modifiedGridExtImp = gridExtImp.toBuilder()
.gpid(adSlot)
.build();

return imp.toBuilder().ext(mapper.mapper().valueToTree(modifiedGridExtImp)).build();
}

return imp;
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/prebid/server/bidder/grid/model/GridExtImp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.bidder.grid.model;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Builder;
import lombok.Value;
import org.prebid.server.proto.openrtb.ext.request.ExtImpPrebid;

@Builder(toBuilder = true)
@Value
public class GridExtImp {

ExtImpPrebid prebid;

JsonNode bidder;

GridExtImpData data;

String gpid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.prebid.server.bidder.grid.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class GridExtImpData {

@JsonProperty("pbadslot")
String pbAdSlot;

@JsonProperty("adserver")
GridExtImpDataAdServer adServer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.bidder.grid.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;

@AllArgsConstructor(staticName = "of")
@Value
public class GridExtImpDataAdServer {

String name;

@JsonProperty("adslot")
String adSlot;
}
20 changes: 20 additions & 0 deletions src/test/java/org/prebid/server/bidder/grid/GridBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.junit.Test;
import org.prebid.server.VertxTest;
import org.prebid.server.bidder.grid.model.ExtImpGrid;
import org.prebid.server.bidder.grid.model.GridExtImp;
import org.prebid.server.bidder.grid.model.GridExtImpData;
import org.prebid.server.bidder.grid.model.GridExtImpDataAdServer;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpCall;
Expand Down Expand Up @@ -231,6 +234,23 @@ public void makeBidsShouldReturnErrorIfImpIdsFromBidAndRequestWereNotMatchedAndI
.containsOnly(BidderError.badServerResponse("Failed to find impression for ID: 123"));
}

@Test
public void modifyImpShouldChangeImpExt() {
// given
final GridExtImp gridExtImp = GridExtImp.builder()
.data(GridExtImpData.of(null, GridExtImpDataAdServer.of("name", "adslot")))
.build();

final Imp imp = Imp.builder().ext(mapper.valueToTree(gridExtImp)).build();

// when
final Imp modifiedImp = gridBidder.modifyImp(imp, ExtImpGrid.of(1));

// then
assertThat(mapper.convertValue(modifiedImp.getExt(), GridExtImp.class).getGpid())
.isEqualTo(gridExtImp.getData().getAdServer().getAdSlot());
}

private static BidResponse givenBidResponse(UnaryOperator<BidResponse.BidResponseBuilder> bidResponseCustomizer,
UnaryOperator<Bid.BidBuilder> bidCustomizer) {
return bidResponseCustomizer.apply(BidResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"ext": {
"grid": {
"uid": 1
},
"data": {
"adserver": {
"name": "some_name",
"adslot": "some_slot"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
"ext": {
"bidder": {
"uid": 1
}
},
"data": {
"adserver": {
"name": "some_name",
"adslot": "some_slot"
}
},
"gpid" : "some_slot"
}
}
],
Expand Down

0 comments on commit 74b0af8

Please sign in to comment.