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

PG: Add more information to LineItemStatusReport. #1898

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public LineItemStatusReport getLineItemStatusReport(String lineItemId) {
.readyToServeTimestamp(lineItem.getReadyAt())
.spentTokens(activeDeliveryPlan.getSpentTokens())
.pacingFrequency(activeDeliveryPlan.getDeliveryRateInMilliseconds())
.accountId(lineItem.getAccountId())
.target(lineItem.getTargeting())
.build();
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/prebid/server/deals/lineitem/LineItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.prebid.server.deals.lineitem;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -189,6 +190,10 @@ public List<LineItemSize> getSizes() {
return metaData.getSizes();
}

public ObjectNode getTargeting() {
return metaData.getTargeting();
}

public TargetingDefinition getTargetingDefinition() {
return targetingDefinition;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.deals.proto.report;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Builder;
import lombok.Value;

Expand All @@ -24,4 +25,9 @@ public class LineItemStatusReport {

@JsonProperty("pacingFrequency")
Long pacingFrequency;

@JsonProperty("accountId")
String accountId;

ObjectNode target;
}
146 changes: 106 additions & 40 deletions src/test/java/org/prebid/server/deals/DeliveryProgressServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.UnaryOperator;
import java.util.stream.IntStream;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -86,13 +86,32 @@ public void setUp() {
@Test
public void updateLineItemsShouldUpdateCurrentDeliveryReportIfUpdatedPlanUpdateTimeStampIsInFuture() {
// given
final LineItemMetaData firstPlanResponse = givenLineItemMetaData("lineItem1", "1001", "rubicon",
singletonList(givenDeliverySchedule("planId1", now.minusHours(1),
now.plusHours(1), now, singleton(Token.of(1, 100)))), now);

final LineItemMetaData secondPlanResponse = givenLineItemMetaData("lineItem1", "1001", "rubicon",
singletonList(givenDeliverySchedule("planId1", now.minusHours(1),
now.plusHours(1), now.plusMinutes(1), singleton(Token.of(1, 200)))), now);
final LineItemMetaData firstPlanResponse = givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId("lineItem1")
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"planId1",
now.minusHours(1),
now.plusHours(1),
now,
singleton(Token.of(1, 100))))));
final LineItemMetaData secondPlanResponse = givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId("lineItem1")
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"planId1",
now.minusHours(1),
now.plusHours(1),
now.plusMinutes(1),
singleton(Token.of(1, 200))))));

LineItem lineItem1 = LineItem.of(firstPlanResponse, null, null, now);
LineItem lineItem12 = LineItem.of(secondPlanResponse, null, null, now);
Expand Down Expand Up @@ -161,15 +180,38 @@ public void processAuctionEventShouldUpdateCurrentPlan() {
final String lineItemId1 = "lineItemId1";
final String lineItemId2 = "lineItemId2";

final LineItem lineItem1 = LineItem.of(givenLineItemMetaData(lineItemId1, "1001", "rubicon",
singletonList(givenDeliverySchedule("plan1", now.minusHours(1), now.plusHours(1),
new HashSet<>(asList(Token.of(1, 100), Token.of(2, 100))))),
now), null, null, now);

final LineItem lineItem2 = LineItem.of(givenLineItemMetaData(lineItemId2, "1001", "rubicon",
singletonList(givenDeliverySchedule("plan2", now.minusHours(1), now.plusHours(1),
new HashSet<>(asList(Token.of(1, 100), Token.of(2, 100))))),
now), null, null, now);
final LineItem lineItem1 = LineItem.of(
givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId(lineItemId1)
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"plan1",
now.minusHours(1),
now.plusHours(1),
Set.of(Token.of(1, 100), Token.of(2, 100)))))),
null,
null,
now);
final LineItem lineItem2 = LineItem.of(
givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId(lineItemId2)
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"plan2",
now.minusHours(1),
now.plusHours(1),
Set.of(Token.of(1, 100), Token.of(2, 100)))))),
null,
null,
now);

given(lineItemService.getLineItemById(eq(lineItemId1))).willReturn(lineItem1);
given(lineItemService.getLineItemById(eq(lineItemId2))).willReturn(lineItem2);
Expand Down Expand Up @@ -249,10 +291,22 @@ public void processAuctionEventShouldUpdateCurrentPlan() {
@Test
public void trackWinEventShouldCreateLineItemStatusAndUpdateWinEventsMetric() {
// given
final LineItem lineItem = LineItem.of(givenLineItemMetaData("lineItemId1", "1001", "rubicon",
singletonList(givenDeliverySchedule("plan1", now.minusHours(1), now.plusHours(1),
new HashSet<>(asList(Token.of(1, 100), Token.of(2, 100))))),
now), null, null, now);
final LineItem lineItem = LineItem.of(
givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId("lineItemId1")
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"plan1",
now.minusHours(1),
now.plusHours(1),
Set.of(Token.of(1, 100), Token.of(2, 100)))))),
null,
null,
now);

given(lineItemService.getLineItemById(eq("lineItemId1"))).willReturn(lineItem);

Expand All @@ -278,10 +332,23 @@ public void trackWinEventShouldCreateLineItemStatusAndUpdateWinEventsMetric() {
@Test
public void getLineItemStatusReportShouldReturnExpectedResult() {
// given
final DeliverySchedule deliverySchedule = givenDeliverySchedule("plan1", now.minusHours(1), now.plusHours(1),
singleton(Token.of(1, 100)));
final LineItem lineItem = LineItem.of(givenLineItemMetaData("lineItemId1", "1001", "rubicon",
singletonList(deliverySchedule), now), null, null, now);
final LineItem lineItem = LineItem.of(
givenLineItemMetaData(
now,
lineItemMetaData -> lineItemMetaData
.lineItemId("lineItemId1")
.accountId("1001")
.source("rubicon")
.deliverySchedules(singletonList(
givenDeliverySchedule(
"plan1",
now.minusHours(1),
now.plusHours(1),
singleton(Token.of(1, 100)))))
.targeting(mapper.createObjectNode().put("targetingField", "targetingValue"))),
null,
null,
now);
given(lineItemService.getLineItemById(anyString())).willReturn(lineItem);

// when
Expand All @@ -300,25 +367,24 @@ public void getLineItemStatusReportShouldReturnExpectedResult() {
.readyToServeTimestamp(now)
.spentTokens(0L)
.pacingFrequency(72000L)
.accountId("1001")
.target(mapper.createObjectNode().put("targetingField", "targetingValue"))
.build());
}

private static LineItemMetaData givenLineItemMetaData(
String lineItemId, String account, String bidderCode, List<DeliverySchedule> deliverySchedules,
ZonedDateTime now) {

return LineItemMetaData.builder()
.lineItemId(lineItemId)
.dealId("dealId")
.status("active")
.accountId(account)
.source(bidderCode)
.price(Price.of(BigDecimal.ONE, "USD"))
.relativePriority(5)
.startTimeStamp(now.minusHours(1))
.endTimeStamp(now.plusHours(1))
.updatedTimeStamp(now)
.deliverySchedules(deliverySchedules)
ZonedDateTime now,
UnaryOperator<LineItemMetaData.LineItemMetaDataBuilder> lineItemMetaDataCustomizer) {

return lineItemMetaDataCustomizer
.apply(LineItemMetaData.builder()
.dealId("dealId")
.status("active")
.price(Price.of(BigDecimal.ONE, "USD"))
.relativePriority(5)
.startTimeStamp(now.minusHours(1))
.endTimeStamp(now.plusHours(1))
.updatedTimeStamp(now))
.build();
}

Expand Down