From b6c74618a53e06f0269bb1535b615bd1c28e5cdd Mon Sep 17 00:00:00 2001 From: antonbabak Date: Thu, 19 Dec 2024 10:28:14 +0100 Subject: [PATCH] Smaato: Send imp.ext object --- .../server/bidder/smaato/SmaatoBidder.java | 32 ++++++++--------- .../bidder/smaato/SmaatoBidderTest.java | 35 ++++++------------- .../smaato/test-auction-smaato-request.json | 25 +++++++++++++ .../smaato/test-smaato-bid-request.json | 32 +++++++++++++++-- 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java b/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java index 414dc9844c3..7387617488a 100644 --- a/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java +++ b/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java @@ -64,14 +64,13 @@ public class SmaatoBidder implements Bidder { private static final TypeReference> 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; @@ -204,7 +203,7 @@ private BidRequest preparePodRequest(BidRequest bidRequest, List 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; @@ -231,14 +230,14 @@ private BidRequest modifyBidRequest(BidRequest bidRequest, String publisherId, S return bidRequestBuilder.imp(impSupplier.get()).build(); } - private List modifyImpsForAdBreak(List imps, String adBreakId, ObjectNode impExtSkadn) { + private List modifyImpsForAdBreak(List 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"))) @@ -246,7 +245,7 @@ private Imp modifyImpForAdBreak(Imp imp, Integer sequence, String adBreakId, Obj return imp.toBuilder() .tagid(adBreakId) .video(modifiedVideo) - .ext(impExtSkadn) + .ext(impExt) .build(); } @@ -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 modifyImpForAdSpace(Imp imp, String adSpaceId, ObjectNode impExtSkadn) { + private List modifyImpForAdSpace(Imp imp, String adSpaceId, ObjectNode impExt) { final Imp modifiedImp = imp.toBuilder() .tagid(adSpaceId) - .ext(impExtSkadn) + .ext(impExt) .build(); return Collections.singletonList(modifiedImp); diff --git a/src/test/java/org/prebid/server/bidder/smaato/SmaatoBidderTest.java b/src/test/java/org/prebid/server/bidder/smaato/SmaatoBidderTest.java index 18b1ba36e8a..d34fd2812a0 100644 --- a/src/test/java/org/prebid/server/bidder/smaato/SmaatoBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/smaato/SmaatoBidderTest.java @@ -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; @@ -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 @@ -352,7 +353,7 @@ public void makeIndividualHttpRequestsShouldCorrectlySplitImps() { } @Test - public void makeHttpShouldPassthouthImpExtSkadnWhenIsPresent() { + public void makeHttpShouldPassthouthImpExt() { // given final ObjectNode impExt = mapper.createObjectNode() .set("bidder", mapper.createObjectNode() @@ -364,6 +365,8 @@ 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)); @@ -371,34 +374,16 @@ public void makeHttpShouldPassthouthImpExtSkadnWhenIsPresent() { final Result>> 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>> result = target.makeHttpRequests(bidRequest); - - // then - assertThat(result.getValue()).isEmpty(); - assertThat(result.getErrors()).containsExactly(BidderError.badInput("Invalid imp.ext.skadn")); + .containsExactly(expectedImpExt); } @Test diff --git a/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-auction-smaato-request.json b/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-auction-smaato-request.json index a2fa2aac8db..9415b0be91e 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-auction-smaato-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-auction-smaato-request.json @@ -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" diff --git a/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-smaato-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-smaato-bid-request.json index 3be139028cb..5230998792c 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-smaato-bid-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/smaato/test-smaato-bid-request.json @@ -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": { @@ -37,6 +65,6 @@ } }, "ext": { - "client": "prebid_server_1.1" + "client": "prebid_server_1.2" } }