Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaato: Send imp.ext object #3642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ public class SmaatoBidder implements Bidder<BidRequest> {
private static final TypeReference<ExtPrebid<?, ExtImpSmaato>> SMAATO_EXT_TYPE_REFERENCE =
new TypeReference<>() {
};
private static final String CLIENT_VERSION = "prebid_server_1.1";
private static final String CLIENT_VERSION = "prebid_server_1.2";
private static final String SMT_ADTYPE_HEADER = "X-Smt-Adtype";
private static final String SMT_EXPIRES_HEADER = "X-Smt-Expires";
private static final String SMT_AD_TYPE_IMG = "Img";
private static final String SMT_ADTYPE_RICHMEDIA = "Richmedia";
private static final String SMT_ADTYPE_VIDEO = "Video";
private static final String SMT_ADTYPE_NATIVE = "Native";
private static final String IMP_EXT_SKADN_FIELD = "skadn";

private static final int DEFAULT_TTL = 300;

Expand Down Expand Up @@ -204,7 +203,7 @@ private BidRequest preparePodRequest(BidRequest bidRequest, List<Imp> imps, List
final String adBreakId = getIfNotNullOrThrow(extImpSmaato, ExtImpSmaato::getAdbreakId, "adbreakId");

return modifyBidRequest(bidRequest, publisherId, () ->
modifyImpsForAdBreak(imps, adBreakId, resolveImpExtSkadn(impExt)));
modifyImpsForAdBreak(imps, adBreakId, removeBidderNodeFromImpExt(impExt)));
} catch (PreBidException | IllegalArgumentException e) {
errors.add(BidderError.badInput(e.getMessage()));
return null;
Expand All @@ -231,22 +230,22 @@ private BidRequest modifyBidRequest(BidRequest bidRequest, String publisherId, S
return bidRequestBuilder.imp(impSupplier.get()).build();
}

private List<Imp> modifyImpsForAdBreak(List<Imp> imps, String adBreakId, ObjectNode impExtSkadn) {
private List<Imp> modifyImpsForAdBreak(List<Imp> imps, String adBreakId, ObjectNode impExt) {
return IntStream.range(0, imps.size())
.mapToObj(idx ->
modifyImpForAdBreak(imps.get(idx), idx + 1, adBreakId, idx == 0 ? impExtSkadn : null))
modifyImpForAdBreak(imps.get(idx), idx + 1, adBreakId, idx == 0 ? impExt : null))
.toList();
}

private Imp modifyImpForAdBreak(Imp imp, Integer sequence, String adBreakId, ObjectNode impExtSkadn) {
private Imp modifyImpForAdBreak(Imp imp, Integer sequence, String adBreakId, ObjectNode impExt) {
final Video modifiedVideo = imp.getVideo().toBuilder()
.sequence(sequence)
.ext(mapper.mapper().createObjectNode().set("context", TextNode.valueOf("adpod")))
.build();
return imp.toBuilder()
.tagid(adBreakId)
.video(modifiedVideo)
.ext(impExtSkadn)
.ext(impExt)
.build();
}

Expand Down Expand Up @@ -293,27 +292,28 @@ private BidRequest prepareIndividualRequest(BidRequest bidRequest, Imp imp, List
final String adSpaceId = getIfNotNullOrThrow(extImpSmaato, ExtImpSmaato::getAdspaceId, "adspaceId");

return modifyBidRequest(bidRequest, publisherId, () ->
modifyImpForAdSpace(imp, adSpaceId, resolveImpExtSkadn(impExt)));
modifyImpForAdSpace(imp, adSpaceId, removeBidderNodeFromImpExt(impExt)));
} catch (PreBidException | IllegalArgumentException e) {
errors.add(BidderError.badInput(e.getMessage()));
return null;
}
}

private ObjectNode resolveImpExtSkadn(ObjectNode impExt) {
if (!impExt.has(IMP_EXT_SKADN_FIELD)) {
private ObjectNode removeBidderNodeFromImpExt(ObjectNode impExt) {
if (impExt == null) {
return null;
} else if (impExt.get(IMP_EXT_SKADN_FIELD).isEmpty() || !impExt.get(IMP_EXT_SKADN_FIELD).isObject()) {
throw new PreBidException("Invalid imp.ext.skadn");
} else {
return mapper.mapper().createObjectNode().set(IMP_EXT_SKADN_FIELD, impExt.get(IMP_EXT_SKADN_FIELD));
}

final ObjectNode impExtCopy = impExt.deepCopy();

impExtCopy.remove("bidder");
return impExtCopy.isEmpty() ? null : impExtCopy;
}

private List<Imp> modifyImpForAdSpace(Imp imp, String adSpaceId, ObjectNode impExtSkadn) {
private List<Imp> modifyImpForAdSpace(Imp imp, String adSpaceId, ObjectNode impExt) {
final Imp modifiedImp = imp.toBuilder()
.tagid(adSpaceId)
.ext(impExtSkadn)
.ext(impExt)
.build();

return Collections.singletonList(modifiedImp);
Expand Down
35 changes: 10 additions & 25 deletions src/test/java/org/prebid/server/bidder/smaato/SmaatoBidderTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.bidder.smaato;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.iab.openrtb.request.App;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void makeHttpRequestsShouldSetExt() {
.extracting(HttpRequest::getPayload)
.extracting(BidRequest::getExt)
.containsExactly(jacksonMapper.fillExtension(ExtRequest.empty(),
SmaatoBidRequestExt.of("prebid_server_1.1")));
SmaatoBidRequestExt.of("prebid_server_1.2")));
}

@Test
Expand Down Expand Up @@ -352,7 +353,7 @@ public void makeIndividualHttpRequestsShouldCorrectlySplitImps() {
}

@Test
public void makeHttpShouldPassthouthImpExtSkadnWhenIsPresent() {
public void makeHttpShouldPassthouthImpExt() {
// given
final ObjectNode impExt = mapper.createObjectNode()
.set("bidder", mapper.createObjectNode()
Expand All @@ -364,41 +365,25 @@ public void makeHttpShouldPassthouthImpExtSkadnWhenIsPresent() {
.put("fieldOne", "123")
.put("fieldTwo", "321"));

impExt.set("gpid", IntNode.valueOf(1));

// and
final BidRequest bidRequest = givenBidRequest(identity(), impBuilder -> impBuilder.ext(impExt));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
final ObjectNode expectedImpExt = mapper.createObjectNode();
expectedImpExt.set("gpid", IntNode.valueOf(1));
expectedImpExt.set("skadn", impExt.get("skadn").deepCopy());

assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getExt)
.containsExactly(mapper.createObjectNode().set("skadn", impExt.get("skadn").deepCopy()));
}

@Test
public void makeHttpShouldReturnErrorWhenImpExtSkadnInvalidPresent() {
// given
final ObjectNode impExt = mapper.createObjectNode()
.set("bidder", mapper.createObjectNode()
.put("publisherId", "publisherId")
.put("adspaceId", "adspaceId")
.put("adbreakId", "adbreakId"));

impExt.put("skadn", "invalidValue");

// and
final BidRequest bidRequest = givenBidRequest(identity(), impBuilder -> impBuilder.ext(impExt));

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).containsExactly(BidderError.badInput("Invalid imp.ext.skadn"));
.containsExactly(expectedImpExt);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@
},
"instl": 1,
"ext": {
"gpid": 1,
"skadn": {
"versions": [
"2.0",
"2.1",
"2.2",
"3.0",
"4.0"
],
"sourceapp": "880047117",
"productpage": 1,
"skadnetlist": {
"max": 306,
"excl": [
2,
8,
10,
55
],
"addl": [
"cdkw7geqsh.skadnetwork",
"qyJfv329m4.skadnetwork"
]
}
},
"smaato": {
"publisherId": "11000",
"adspaceId": "130563103"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@
"w": 300,
"h": 250
},
"tagid": "130563103"
"tagid": "130563103",
"ext" : {
"gpid": 1,
"skadn": {
"versions": [
"2.0",
"2.1",
"2.2",
"3.0",
"4.0"
],
"sourceapp": "880047117",
"productpage": 1,
"skadnetlist": {
"max": 306,
"excl": [
2,
8,
10,
55
],
"addl": [
"cdkw7geqsh.skadnetwork",
"qyJfv329m4.skadnetwork"
]
}
},
"tid": "${json-unit.any-string}"
}
}
],
"source": {
Expand Down Expand Up @@ -37,6 +65,6 @@
}
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
}
Loading