Skip to content
Merged
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
66 changes: 63 additions & 3 deletions src/main/java/org/prebid/server/bidder/oms/OmsBidder.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package org.prebid.server.bidder.oms;

import com.fasterxml.jackson.core.type.TypeReference;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.model.BidderBid;
import org.prebid.server.bidder.model.BidderCall;
import org.prebid.server.bidder.model.BidderError;
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.omx.ExtImpOms;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;

Expand All @@ -23,6 +32,8 @@

public class OmsBidder implements Bidder<BidRequest> {

private static final TypeReference<ExtPrebid<?, ExtImpOms>> EXT_TYPE_REFERENCE = new TypeReference<>() {
};
private final String endpointUrl;
private final JacksonMapper mapper;

Expand All @@ -32,8 +43,31 @@ public OmsBidder(String endpointUrl, JacksonMapper mapper) {
}

@Override
public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequest) {
return Result.withValue(BidderUtil.defaultRequest(bidRequest, endpointUrl, mapper));
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) {
try {
final ExtImpOms impExt = parseImpExt(request.getImp().getFirst());
final String publisherId = resolverPublisherId(impExt.getPid(), impExt.getPublisherId());
final String encodedPublisherId = HttpUtil.encodeUrl(publisherId);
final String url = "%s?publisherId=%s".formatted(endpointUrl, encodedPublisherId);
return Result.withValue(BidderUtil.defaultRequest(request, url, mapper));
} catch (PreBidException e) {
return Result.withError(BidderError.badInput(e.getMessage()));
}
}

private ExtImpOms parseImpExt(Imp imp) throws PreBidException {
try {
return mapper.mapper().convertValue(imp.getExt(), EXT_TYPE_REFERENCE).getBidder();
} catch (IllegalArgumentException e) {
throw new PreBidException("Invalid ext. Imp.Id: " + imp.getId());
}
}

private String resolverPublisherId(String pid, Integer publisherId) {
if (StringUtils.isEmpty(pid) && publisherId != null && publisherId > 0) {
return String.valueOf(publisherId);
}
return pid;
}

@Override
Expand All @@ -59,7 +93,33 @@ private static List<BidderBid> bidsFromResponse(BidResponse bidResponse) {
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, BidType.banner, bidResponse.getCur()))
.map(bid -> createBidderBid(bid, bidResponse.getCur()))
.toList();
}

private static BidderBid createBidderBid(Bid bid, String currency) {
final BidType bidType = getBidType(bid);
return BidderBid.builder()
.bid(bid)
.type(bidType)
.bidCurrency(currency)
.videoInfo(videoInfo(bidType, bid))
.build();
}

private static BidType getBidType(Bid bid) {
return Objects.equals(bid.getMtype(), 2) ? BidType.video : BidType.banner;
}

private static ExtBidPrebidVideo videoInfo(BidType bidType, Bid bid) {
if (bidType != BidType.video) {
return null;
}
final List<String> cat = bid.getCat();
final Integer duration = bid.getDur();

return ExtBidPrebidVideo.of(
ObjectUtils.defaultIfNull(duration, 0),
CollectionUtils.isNotEmpty(cat) ? cat.getFirst() : StringUtils.EMPTY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.proto.openrtb.ext.request.omx;

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

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

String pid;

@JsonProperty("publisherId")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an empty line

Integer publisherId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add JsonProperty

also I would change the integration test payload to cover publisherId parameter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have cheanged pid to publisherId but IMO its indifferent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pid is declared as deprecated

Copy link
Collaborator

@AntoxaAntoxic AntoxaAntoxic Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, it makes sense to add a publisherId to the test instead of deprecated pid, but pid is still can be used, it's deprecated, not removed, please revert this change

}
2 changes: 2 additions & 0 deletions src/main/resources/bidder-config/oms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ adapters:
maintainer-email: prebid@onlinemediasolutions.com
app-media-types:
- banner
- video
site-media-types:
- banner
- video
supported-vendors:
vendor-id: 0
20 changes: 17 additions & 3 deletions src/main/resources/static/bidder-params/oms.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@
"properties": {
"pid": {
"type": "string",
"description": "An id used to identify OMS publisher.",
"description": "Deprecated: An id used to identify OMS publisher.",
"minLength": 5
},
"publisherId": {
"type": "integer",
"description": "An ID used to identify OMS publisher.",
"minimum": 10000
}
},
"required": [
"pid"
"oneOf": [
{
"required": [
"pid"
]
},
{
"required": [
"publisherId"
]
}
]
}
Loading
Loading