-
Notifications
You must be signed in to change notification settings - Fork 224
NextMillennium: Adapter and server version #3814
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
Merged
CTMBNara
merged 13 commits into
master
from
NextMillennium-Adapter-and-server-version-#3744
May 16, 2025
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
333befd
NextMillennium: Adapter and server version
przemkaczmarek 99a129e
fix server_version
przemkaczmarek 34fad7e
fix comments
przemkaczmarek 961a9c8
fix comments
przemkaczmarek 40fdf2f
fix comments
przemkaczmarek 9b6a05e
fix comments
przemkaczmarek 249843e
fix comments
przemkaczmarek 97ab21e
fix comments
przemkaczmarek 8e6da2f
fix comments
przemkaczmarek fa02a9c
fix comments
przemkaczmarek 95c2a5c
fix comments
przemkaczmarek 4ac1dc4
fix comments
przemkaczmarek 2225a20
Merge branch 'master' into NextMillennium-Adapter-and-server-version-…
przemkaczmarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import io.vertx.core.MultiMap; | ||
| import io.vertx.core.http.HttpMethod; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
@@ -22,6 +21,8 @@ | |
| 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.bidder.nextmillennium.proto.NextMillenniumExt; | ||
| import org.prebid.server.bidder.nextmillennium.proto.NextMillenniumExtBidder; | ||
| import org.prebid.server.exception.PreBidException; | ||
| import org.prebid.server.json.DecodeException; | ||
| import org.prebid.server.json.JacksonMapper; | ||
|
|
@@ -31,8 +32,8 @@ | |
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidServer; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtStoredRequest; | ||
| import org.prebid.server.proto.openrtb.ext.request.nextmillennium.ExtImpNextMillennium; | ||
| import org.prebid.server.proto.openrtb.ext.request.nextmillennium.ExtRequestNextMillennium; | ||
| import org.prebid.server.proto.openrtb.ext.response.BidType; | ||
| import org.prebid.server.util.BidderUtil; | ||
| import org.prebid.server.util.HttpUtil; | ||
| import org.prebid.server.util.ObjectUtil; | ||
| import org.prebid.server.version.PrebidVersionProvider; | ||
|
|
@@ -41,6 +42,7 @@ | |
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| public class NextMillenniumBidder implements Bidder<BidRequest> { | ||
|
|
||
|
|
@@ -59,6 +61,7 @@ public NextMillenniumBidder(String endpointUrl, | |
| JacksonMapper mapper, | ||
| List<String> nmmFlags, | ||
| PrebidVersionProvider versionProvider) { | ||
CTMBNara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| this.nmmFlags = nmmFlags; | ||
|
|
@@ -78,7 +81,12 @@ public final Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest b | |
| errors.add(BidderError.badInput(e.getMessage())); | ||
| continue; | ||
| } | ||
| httpRequests.add(makeHttpRequest(updateBidRequest(bidRequest, extImpNextMillennium))); | ||
| final BidRequest updatedRequest = updateBidRequest(bidRequest, extImpNextMillennium); | ||
| httpRequests.add(BidderUtil.defaultRequest( | ||
| updatedRequest, | ||
| headers(), | ||
| endpointUrl, | ||
| mapper)); | ||
| } | ||
|
|
||
| return errors.isEmpty() ? Result.withValues(httpRequests) : Result.withErrors(errors); | ||
|
|
@@ -92,7 +100,7 @@ private ExtImpNextMillennium convertExt(ObjectNode impExt) { | |
| } | ||
| } | ||
|
|
||
| private BidRequest updateBidRequest(BidRequest bidRequest, ExtImpNextMillennium ext) { | ||
| private BidRequest updateBidRequest1(BidRequest bidRequest, ExtImpNextMillennium ext) { | ||
|
||
| final ExtStoredRequest storedRequest = ExtStoredRequest.of(resolveStoredRequestId(bidRequest, ext)); | ||
| final ExtRequest requestExt = bidRequest.getExt(); | ||
| final ExtRequestPrebid existingPrebid = requestExt != null ? requestExt.getPrebid() : null; | ||
|
|
@@ -106,13 +114,15 @@ private BidRequest updateBidRequest(BidRequest bidRequest, ExtImpNextMillennium | |
| final ExtRequest extRequest = ExtRequest.of(createdExtRequestPrebid); | ||
|
|
||
| final ObjectNode nextMillenniumNode = mapper.mapper().valueToTree( | ||
| ExtRequestNextMillennium.of(nmmFlags, NM_ADAPTER_VERSION, versionProvider.getNameVersionRecord())); | ||
| NextMillenniumExtBidder.of(nmmFlags, NM_ADAPTER_VERSION, versionProvider.getNameVersionRecord())); | ||
|
|
||
| extRequest.addProperty("nextMillennium", nextMillenniumNode); | ||
|
|
||
| final Imp firstImp = bidRequest.getImp().getFirst(); | ||
| final ObjectNode updatedImpExt = mapper.mapper().createObjectNode(); | ||
| updatedImpExt.set("nextMillennium", nextMillenniumNode.get("nmmFlags")); | ||
| final ObjectNode impNextMillNode = nextMillenniumNode.deepCopy(); | ||
| impNextMillNode.retain("nmmFlags"); | ||
| updatedImpExt.set("nextMillennium", impNextMillNode); | ||
|
|
||
| final ObjectNode prebidNode = mapper.mapper().createObjectNode(); | ||
| prebidNode.set("storedrequest", mapper.mapper().valueToTree(storedRequest)); | ||
|
|
@@ -131,6 +141,19 @@ private BidRequest updateBidRequest(BidRequest bidRequest, ExtImpNextMillennium | |
| .build(); | ||
| } | ||
|
|
||
| private BidRequest updateBidRequest(BidRequest bidRequest, ExtImpNextMillennium extImp) { | ||
| final String soredRequestId = resolveStoredRequestId(bidRequest, extImp); | ||
| final ExtRequestPrebidServer extRequestPrebidServer = Optional.ofNullable(bidRequest.getExt()) | ||
| .map(ExtRequest::getPrebid) | ||
| .map(ExtRequestPrebid::getServer) | ||
| .orElse(null); | ||
|
|
||
| return bidRequest.toBuilder() | ||
| .imp(modifyFirstImp(bidRequest.getImp(), soredRequestId)) | ||
| .ext(createExtRequest(soredRequestId, extRequestPrebidServer)) | ||
| .build(); | ||
| } | ||
|
|
||
| private static String resolveStoredRequestId(BidRequest bidRequest, ExtImpNextMillennium extImpNextMillennium) { | ||
| final String groupId = extImpNextMillennium.getGroupId(); | ||
| if (StringUtils.isEmpty(groupId)) { | ||
|
|
@@ -168,14 +191,38 @@ private static String formatSize(Integer w, Integer h) { | |
| : null; | ||
| } | ||
|
|
||
| private HttpRequest<BidRequest> makeHttpRequest(BidRequest bidRequest) { | ||
| return HttpRequest.<BidRequest>builder() | ||
| .method(HttpMethod.POST) | ||
| .uri(endpointUrl) | ||
| .headers(headers()) | ||
| .payload(bidRequest) | ||
| .body(mapper.encodeToBytes(bidRequest)) | ||
| private List<Imp> modifyFirstImp(List<Imp> imps, String storedRequestId) { | ||
| final ExtRequestPrebid extRequestPrebid = ExtRequestPrebid.builder() | ||
| .storedrequest(ExtStoredRequest.of(storedRequestId)) | ||
| .build(); | ||
|
|
||
| final NextMillenniumExt nextMillenniumExt = NextMillenniumExt.of( | ||
| NextMillenniumExtBidder.of(nmmFlags, null, null)); | ||
|
|
||
| final ExtRequest extRequest = ExtRequest.of(extRequestPrebid); | ||
| mapper.fillExtension(extRequest, nextMillenniumExt); | ||
|
|
||
| final ObjectNode impExt = mapper.mapper().valueToTree(extRequest); | ||
|
|
||
| final List<Imp> modifiedImps = new ArrayList<>(imps); | ||
| modifiedImps.set(0, imps.getFirst().toBuilder().ext(impExt).build()); | ||
|
|
||
| return modifiedImps; | ||
| } | ||
|
|
||
| private ExtRequest createExtRequest(String storedRequestId, ExtRequestPrebidServer extRequestPrebidServer) { | ||
| final ExtRequestPrebid extRequestPrebid = ExtRequestPrebid.builder() | ||
| .storedrequest(ExtStoredRequest.of(storedRequestId)) | ||
| .server(extRequestPrebidServer) | ||
| .build(); | ||
|
|
||
| final NextMillenniumExt nextMillenniumExt = NextMillenniumExt.of( | ||
| NextMillenniumExtBidder.of(nmmFlags, NM_ADAPTER_VERSION, versionProvider.getNameVersionRecord())); | ||
|
|
||
| final ExtRequest extRequest = ExtRequest.of(extRequestPrebid); | ||
| mapper.fillExtension(extRequest, nextMillenniumExt); | ||
|
|
||
| return extRequest; | ||
| } | ||
|
|
||
| private static MultiMap headers() { | ||
|
|
||
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prebid/server/bidder/nextmillennium/proto/NextMillenniumExt.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.prebid.server.bidder.nextmillennium.proto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class NextMillenniumExt { | ||
|
|
||
| @JsonProperty("nextMillennium") | ||
| NextMillenniumExtBidder nextMillennium; | ||
| } |
4 changes: 2 additions & 2 deletions
4
...tmillennium/ExtRequestNextMillennium.java → ...ennium/proto/NextMillenniumExtBidder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.