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

Add timestamp and biddercode to event URL #635

Merged
merged 12 commits into from
Apr 6, 2020
16 changes: 8 additions & 8 deletions src/main/java/org/prebid/server/cache/CacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,28 +415,28 @@ private PutObject createXmlPutObjectOpenrtb(CacheBid cacheBid,
Map<String, List<String>> bidderToVideoBidIdsToModify,
String accountId, Long timestamp) {
final com.iab.openrtb.response.Bid bid = cacheBid.getBid();
final String[] vastXml = new String[1];
String vastXml;
if (bid.getAdm() == null) {
vastXml[0] = "<VAST version=\"3.0\"><Ad><Wrapper>"
vastXml = "<VAST version=\"3.0\"><Ad><Wrapper>"
+ "<AdSystem>prebid.org wrapper</AdSystem>"
+ "<VASTAdTagURI><![CDATA[" + bid.getNurl() + "]]></VASTAdTagURI>"
+ "<Impression></Impression><Creatives></Creatives>"
+ "</Wrapper></Ad></VAST>";
} else {
vastXml[0] = bid.getAdm();
vastXml = bid.getAdm();
}

final String bidId = bid.getId();
bidderToVideoBidIdsToModify.entrySet().stream()
final String modifiedVastXml = bidderToVideoBidIdsToModify.entrySet().stream()
.filter(biddersAndBidIds -> biddersAndBidIds.getValue().contains(bidId))
.findFirst()
.map(Map.Entry::getKey)
.ifPresent(bidder -> {
vastXml[0] = modifyVastXml(vastXml[0], bidId, bidder, accountId, timestamp);
});
.map(bidder -> modifyVastXml(vastXml, bidId, bidder, accountId, timestamp))
.orElse(vastXml);

return PutObject.builder()
.type("xml")
.value(new TextNode(vastXml[0]))
.value(new TextNode(modifiedVastXml))
.expiry(cacheBid.getTtl())
.build();
}
Expand Down
29 changes: 14 additions & 15 deletions src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
import com.iab.openrtb.response.Response;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.Future;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -61,15 +69,6 @@
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.VideoStoredDataResult;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

AndriyPavlyuk marked this conversation as resolved.
Show resolved Hide resolved
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
Expand Down Expand Up @@ -309,14 +308,14 @@ public void shouldSetExpectedConstantResponseFields() {

// when
final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, bidRequest,
null, null, ACCOUNT, timeout, 1000,false).result();
null, null, ACCOUNT, timeout, 1000, false).result();

// then
final BidResponse responseWithExpectedFields = BidResponse.builder()
.id("123")
.cur("USD")
.ext(mapper.valueToTree(
ExtBidResponse.of(null, null, singletonMap("bidder1", 100), 1000L, null, (long)1000 )))
ExtBidResponse.of(null, null, singletonMap("bidder1", 100), 1000L, null, 1000L)))
.build();

assertThat(bidResponse)
Expand All @@ -332,7 +331,7 @@ public void shouldSetNbrValueTwoAndEmptySeatbidWhenIncomingBidResponsesAreEmpty(

// when
final BidResponse bidResponse = bidResponseCreator.create(emptyList(), bidRequest, null,
null, ACCOUNT, timeout,0, false).result();
null, ACCOUNT, timeout, 0, false).result();

// then
assertThat(bidResponse).returns(0, BidResponse::getNbr);
Expand Down Expand Up @@ -724,7 +723,7 @@ public void shouldPopulateTargetingKeywordsWithEventsUrl() {

// when
final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, bidRequest,
targeting, CACHE_INFO, account, timeout, 0,false).result();
targeting, CACHE_INFO, account, timeout, 0, false).result();

// then
verify(eventsService).winUrlTargeting(eq("bidder1"), eq("accountId"), eq(0L));
Expand Down Expand Up @@ -874,7 +873,7 @@ public void shouldNotPopulateBidderKeysTargetingIfIncludeBidderKeysFlagIsFalse()

// when
final BidResponse bidResponse = bidResponseCreator.create(bidderResponses, bidRequest,
targeting, cacheInfo, ACCOUNT, timeout, 0,false).result();
targeting, cacheInfo, ACCOUNT, timeout, 0, false).result();

// then
assertThat(bidResponse.getSeatbid()).flatExtracting(SeatBid::getBid)
Expand Down Expand Up @@ -990,7 +989,7 @@ public void impToStoredVideoJsonShouldTolerateWhenStoredVideoFetchIsFailed() {

// when
final Future<BidResponse> result =
bidResponseCreator.create(bidderResponses, bidRequest, null, CACHE_INFO, ACCOUNT, timeout, 0,false);
bidResponseCreator.create(bidderResponses, bidRequest, null, CACHE_INFO, ACCOUNT, timeout, 0, false);

// then
verify(storedRequestProcessor).videoStoredDataResult(eq(singletonList(imp)), any(), eq(timeout));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ public void shouldTolerateResponseBidValidationErrors() throws JsonProcessingExc
// imp ids are not really used for matching, included them here for clarity
givenImp(singletonMap("bidder1", 1), builder -> builder.id("impId1"))),
builder -> builder.ext(mapper.valueToTree(ExtBidRequest.of(ExtRequestPrebid.builder()
.auctiontimestamp(1000L).build()))));
.auctiontimestamp(1000L)
.build()))));

given(responseBidValidator.validate(any()))
.willReturn(ValidationResult.error("bid validation error"));
Expand Down
Loading