Skip to content

Commit

Permalink
Adtarget and Adtelligent Bidders: Change Aid Type
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic committed Aug 21, 2024
1 parent 39c7a9f commit c431768
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.adtarget.proto.AdtargetImpExt;
import org.prebid.server.bidder.adtarget.proto.ExtImpAdtargetBidRequest;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderCall;
import org.prebid.server.bidder.model.BidderError;
Expand Down Expand Up @@ -67,16 +68,16 @@ private Result<Map<Integer, List<Imp>>> mapSourceIdToImp(List<Imp> imps) {
final Map<Integer, List<Imp>> sourceToImps = new HashMap<>();
for (Imp imp : imps) {
final ExtImpAdtarget extImpAdtarget;
final Integer sourceId;
try {
validateImpression(imp);
extImpAdtarget = parseImpAdtarget(imp);
sourceId = resolveSourceId(imp.getId(), extImpAdtarget.getSourceId());
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
continue;
}
final Imp updatedImp = updateImp(imp, extImpAdtarget);

final Integer sourceId = extImpAdtarget.getSourceId();
final Imp updatedImp = updateImp(imp, sourceId, extImpAdtarget);
sourceToImps.computeIfAbsent(sourceId, ignored -> new ArrayList<>()).add(updatedImp);
}
return Result.of(sourceToImps, errors);
Expand All @@ -103,15 +104,24 @@ private static void validateImpression(Imp imp) {
}
}

private Imp updateImp(Imp imp, ExtImpAdtarget extImpAdtarget) {
final AdtargetImpExt adtargetImpExt = AdtargetImpExt.of(extImpAdtarget);
private Imp updateImp(Imp imp, Integer sourceId, ExtImpAdtarget extImpAdtarget) {
final AdtargetImpExt adtargetImpExt = AdtargetImpExt.of(
ExtImpAdtargetBidRequest.from(sourceId, extImpAdtarget));
final BigDecimal bidFloor = extImpAdtarget.getBidFloor();
return imp.toBuilder()
.bidfloor(BidderUtil.isValidPrice(bidFloor) ? bidFloor : imp.getBidfloor())
.ext(mapper.mapper().valueToTree(adtargetImpExt))
.build();
}

private static Integer resolveSourceId(String impId, String sourceId) {
try {
return sourceId == null ? 0 : Integer.parseInt(sourceId);
} catch (NumberFormatException e) {
throw new PreBidException("ignoring imp id=%s, aid parsing err: %s".formatted(impId, e.getMessage()));
}
}

@Override
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
final List<BidderError> errors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.prebid.server.bidder.adtarget.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.prebid.server.proto.openrtb.ext.request.adtarget.ExtImpAdtarget;

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

@JsonProperty("adtarget")
ExtImpAdtarget extImpAdtarget;
ExtImpAdtargetBidRequest extImp;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.prebid.server.bidder.adtarget.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;
import org.prebid.server.proto.openrtb.ext.request.adtarget.ExtImpAdtarget;

import java.math.BigDecimal;

@Value(staticConstructor = "of")
public class ExtImpAdtargetBidRequest {

@JsonProperty("aid")
Integer sourceId;

@JsonProperty("placementId")
Integer placementId;

@JsonProperty("siteId")
Integer siteId;

@JsonProperty("bidFloor")
BigDecimal bidFloor;

public static ExtImpAdtargetBidRequest from(Integer sourceId, ExtImpAdtarget impExt) {
return ExtImpAdtargetBidRequest.of(
sourceId,
impExt.getPlacementId(),
impExt.getSiteId(),
impExt.getBidFloor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.adtelligent.proto.AdtelligentImpExt;
import org.prebid.server.bidder.adtelligent.proto.ExtImpAdtelligentBidRequest;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderCall;
import org.prebid.server.bidder.model.BidderError;
Expand Down Expand Up @@ -86,16 +87,17 @@ private Result<Map<Integer, List<Imp>>> mapSourceIdToImp(List<Imp> imps) {
final Map<Integer, List<Imp>> sourceToImps = new HashMap<>();
for (final Imp imp : imps) {
final ExtImpAdtelligent extImpAdtelligent;
final Integer sourceId;
try {
validateImpression(imp);
extImpAdtelligent = getExtImpAdtelligent(imp);
sourceId = resolveSourceId(imp.getId(), extImpAdtelligent.getSourceId());
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
continue;
}
final Imp updatedImp = updateImp(imp, extImpAdtelligent);
final Imp updatedImp = updateImp(imp, sourceId, extImpAdtelligent);

final Integer sourceId = extImpAdtelligent.getSourceId();
final List<Imp> sourceIdImps = sourceToImps.get(sourceId);
if (sourceIdImps == null) {
sourceToImps.put(sourceId, new ArrayList<>(Collections.singleton(updatedImp)));
Expand Down Expand Up @@ -164,15 +166,24 @@ private void validateImpression(Imp imp) {
/**
* Updates {@link Imp} with bidfloor if it is present in imp.ext.bidder
*/
private Imp updateImp(Imp imp, ExtImpAdtelligent extImpAdtelligent) {
final AdtelligentImpExt adtelligentImpExt = AdtelligentImpExt.of(extImpAdtelligent);
private Imp updateImp(Imp imp, Integer sourceId, ExtImpAdtelligent extImpAdtelligent) {
final AdtelligentImpExt adtelligentImpExt = AdtelligentImpExt.of(
ExtImpAdtelligentBidRequest.from(sourceId, extImpAdtelligent));
final BigDecimal bidFloor = extImpAdtelligent.getBidFloor();
return imp.toBuilder()
.bidfloor(BidderUtil.isValidPrice(bidFloor) ? bidFloor : imp.getBidfloor())
.ext(mapper.mapper().valueToTree(adtelligentImpExt))
.build();
}

private static Integer resolveSourceId(String impId, String sourceId) {
try {
return sourceId == null ? 0 : Integer.parseInt(sourceId);
} catch (NumberFormatException e) {
throw new PreBidException("ignoring imp id=%s, aid parsing err: %s".formatted(impId, e.getMessage()));
}
}

/**
* Extracts {@link Bid}s from response.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.prebid.server.bidder.adtelligent.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.prebid.server.proto.openrtb.ext.request.adtelligent.ExtImpAdtelligent;

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

@JsonProperty("adtelligent")
ExtImpAdtelligent extImpAdtelligent;
ExtImpAdtelligentBidRequest extImp;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.prebid.server.bidder.adtelligent.proto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;
import org.prebid.server.proto.openrtb.ext.request.adtelligent.ExtImpAdtelligent;

import java.math.BigDecimal;

@Value(staticConstructor = "of")
public class ExtImpAdtelligentBidRequest {

@JsonProperty("aid")
Integer sourceId;

@JsonProperty("placementId")
Integer placementId;

@JsonProperty("siteId")
Integer siteId;

@JsonProperty("bidFloor")
BigDecimal bidFloor;

public static ExtImpAdtelligentBidRequest from(Integer sourceId, ExtImpAdtelligent impExt) {
return ExtImpAdtelligentBidRequest.of(
sourceId,
impExt.getPlacementId(),
impExt.getSiteId(),
impExt.getBidFloor());
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
package org.prebid.server.proto.openrtb.ext.request.adtarget;

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

import java.math.BigDecimal;

/**
* Defines the contract for bidrequest.imp[i].ext.adtarget
*/
@AllArgsConstructor(staticName = "of")
@Value
@Value(staticConstructor = "of")
public class ExtImpAdtarget {

/**
* Defines the contract for bidrequest.imp[i].ext.adtarget.aid
*/
@JsonProperty("aid")
Integer sourceId;
String sourceId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtarget.placementId
*/
@JsonProperty("placementId")
Integer placementId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtarget.siteId
*/
@JsonProperty("siteId")
Integer siteId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtarget.bidFloor
*/
@JsonProperty("bidFloor")
BigDecimal bidFloor;
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
package org.prebid.server.proto.openrtb.ext.request.adtelligent;

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

import java.math.BigDecimal;

/**
* Defines the contract for bidrequest.imp[i].ext.adtelligent
*/
@AllArgsConstructor(staticName = "of")
@Value
@Value(staticConstructor = "of")
public class ExtImpAdtelligent {

/**
* Defines the contract for bidrequest.imp[i].ext.adtelligent.aid
*/
@JsonProperty("aid")
Integer sourceId;
String sourceId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtelligent.placementId
*/
@JsonProperty("placementId")
Integer placementId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtelligent.siteId
*/
@JsonProperty("siteId")
Integer siteId;

/**
* Defines the contract for bidrequest.imp[i].ext.adtelligent.bidFloor
*/
@JsonProperty("bidFloor")
BigDecimal bidFloor;
}
6 changes: 4 additions & 2 deletions src/main/resources/static/bidder-params/adtelligent.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Adtelligent Adapter Params",
"description": "A schema which validates params accepted by the Adtelligent adapter",

"type": "object",
"properties": {
"placementId": {
Expand All @@ -14,7 +13,10 @@
"description": "An ID which identifies the site selling the impression"
},
"aid": {
"type": "integer",
"type": [
"integer",
"string"
],
"description": "An ID which identifies the channel"
},
"bidFloor": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.jupiter.api.Test;
import org.prebid.server.VertxTest;
import org.prebid.server.bidder.adtarget.proto.AdtargetImpExt;
import org.prebid.server.bidder.adtarget.proto.ExtImpAdtargetBidRequest;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderCall;
import org.prebid.server.bidder.model.BidderError;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void makeHttpRequestsShouldReturnHttpRequestWithCorrectBodyHeadersAndMeth
.imp(singletonList(bidRequest.getImp().getFirst().toBuilder()
.bidfloor(BigDecimal.valueOf(3))
.ext(mapper.valueToTree(AdtargetImpExt.of(
ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3)))))
ExtImpAdtargetBidRequest.of(15, 1, 2, BigDecimal.valueOf(3)))))
.build()))
.build();
assertThat(result.getErrors()).isEmpty();
Expand Down Expand Up @@ -133,7 +134,7 @@ public void makeHttpRequestShouldReturnHttpRequestWithErrorMessage() {
.id("impId2")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3)))))
ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, BigDecimal.valueOf(3)))))
.build()))
.build();

Expand All @@ -157,7 +158,7 @@ public void makeHttpRequestShouldReturnWithBidFloorPopulatedFromImpWhenIsMissedI
.imp(singletonList(Imp.builder()
.banner(Banner.builder().build())
.bidfloor(BigDecimal.valueOf(16))
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, null))))
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, null))))
.build()))
.build();

Expand All @@ -179,12 +180,12 @@ public void makeHttpRequestShouldReturnTwoHttpRequestsWhenTwoImpsHasDifferentSou
.imp(asList(Imp.builder()
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3)))))
ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, BigDecimal.valueOf(3)))))
.build(),
Imp.builder()
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(16, 1, 2, BigDecimal.valueOf(3)))))
ExtPrebid.of(null, ExtImpAdtarget.of("16", 1, 2, BigDecimal.valueOf(3)))))
.build()))
.build();

Expand Down Expand Up @@ -224,12 +225,12 @@ public void makeHttpRequestShouldReturnOneHttpRequestForTowImpsWhenImpsHasSameSo
.imp(asList(Imp.builder()
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3)))))
ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, BigDecimal.valueOf(3)))))
.build(),
Imp.builder()
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3)))))
ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, BigDecimal.valueOf(3)))))
.build()))
.build();

Expand Down Expand Up @@ -409,7 +410,7 @@ private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomiz
.id("impId")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(
ExtPrebid.of(null, ExtImpAdtarget.of(15, 1, 2, BigDecimal.valueOf(3))))))
ExtPrebid.of(null, ExtImpAdtarget.of("15", 1, 2, BigDecimal.valueOf(3))))))
.build();
}

Expand Down
Loading

0 comments on commit c431768

Please sign in to comment.