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

Metax: Update bidder (#3631) #3660

Merged
merged 5 commits into from
Jan 23, 2025
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
26 changes: 22 additions & 4 deletions src/main/java/org/prebid/server/bidder/metax/MetaxBidder.java
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also see a slight difference in logic with GO:

    private String resolveEndpoint(ExtImpMetax extImpMetax) {
        final String publisherIdAsString = Optional.ofNullable(extImpMetax.getPublisherId())
                .map(Object::toString)
                .orElse(StringUtils.EMPTY);
        final String adUnitAsString = Optional.ofNullable(extImpMetax.getAdUnit())
                .map(Object::toString)
                .orElse(StringUtils.EMPTY);

In both cases we need to set the default value to "0" instead of "".
Please, fix this if you don't mind.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import org.apache.commons.collections4.CollectionUtils;
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;
Expand All @@ -22,6 +21,7 @@
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.metax.ExtImpMetax;
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 Down Expand Up @@ -106,10 +106,10 @@ private static Imp modifyImp(Imp imp) {
private String resolveEndpoint(ExtImpMetax extImpMetax) {
final String publisherIdAsString = Optional.ofNullable(extImpMetax.getPublisherId())
.map(Object::toString)
.orElse(StringUtils.EMPTY);
.orElse("0");
final String adUnitAsString = Optional.ofNullable(extImpMetax.getAdUnit())
.map(Object::toString)
.orElse(StringUtils.EMPTY);
.orElse("0");

return endpointUrl
.replace(PUBLISHER_ID_MACRO, publisherIdAsString)
Expand All @@ -136,7 +136,12 @@ private static List<BidderBid> extractBids(BidResponse bidResponse) {
.map(SeatBid::getBid).filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(Objects::nonNull)
.map(bid -> BidderBid.of(bid, getBidType(bid), bidResponse.getCur()))
.map(bid -> BidderBid.builder()
.bid(bid)
.type(getBidType(bid))
.bidCurrency(bidResponse.getCur())
.videoInfo(videoInfo(bid))
.build())
.toList();
}

Expand All @@ -155,4 +160,17 @@ private static BidType getBidType(Bid bid) {
.formatted(bid.getImpid()));
};
}

private static ExtBidPrebidVideo videoInfo(Bid bid) {
final List<String> cat = bid.getCat();
final Integer duration = bid.getDur();

final boolean catNotEmpty = CollectionUtils.isNotEmpty(cat);
final boolean durationValid = duration != null && duration > 0;
return catNotEmpty || durationValid
? ExtBidPrebidVideo.of(
durationValid ? duration : null,
catNotEmpty ? cat.getFirst() : null)
: null;
}
}
33 changes: 33 additions & 0 deletions src/test/java/org/prebid/server/bidder/metax/MetaxBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.prebid.server.bidder.model.Result;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.metax.ExtImpMetax;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -338,6 +339,38 @@ public void makeBidsShouldThrowErrorWhenMediaTypeIsMissing() throws JsonProcessi
});
}

@Test
public void makeBidsShouldReturnVideoInfoWithDuration() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bid -> bid.dur(1).mtype(2)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getValue())
.extracting(BidderBid::getVideoInfo)
.containsExactly(ExtBidPrebidVideo.of(1, null));
assertThat(result.getErrors()).isEmpty();
}

@Test
public void makeBidsShouldReturnVideoInfoWithPrimaryCategory() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bid -> bid.cat(List.of("1", "2")).mtype(2)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getValue())
.extracting(BidderBid::getVideoInfo)
.containsExactly(ExtBidPrebidVideo.of(null, "1"));
assertThat(result.getErrors()).isEmpty();
}

private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer) {

return BidRequest.builder()
Expand Down
Loading