Skip to content

Commit bf8c1fa

Browse files
committed
WIP - LiveIntent Module
1 parent 4e07bbf commit bf8c1fa

8 files changed

Lines changed: 188 additions & 0 deletions

File tree

extra/bundle/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
<artifactId>pb-request-correction</artifactId>
5656
<version>${project.version}</version>
5757
</dependency>
58+
<dependency>
59+
<groupId>org.prebid.server.hooks.modules</groupId>
60+
<artifactId>live-intent-omni-channel-identity</artifactId>
61+
<version>${project.version}</version>
62+
</dependency>
5863
</dependencies>
5964

6065
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.prebid.server.hooks.modules</groupId>
6+
<artifactId>all-modules</artifactId>
7+
<version>3.24.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>live-intent-omni-channel-identity</artifactId>
11+
12+
<name>live-intent-omni-channel-identity</name>
13+
<description>LiveIntent Omni-Channel Identity</description>
14+
15+
<dependencies>
16+
</dependencies>
17+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.config;
2+
3+
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config.ModuleConfig;
4+
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.LiveIntentOmniChannelIdentityModule;
5+
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.hooks.LiveIntentOmniChannelIdentityProcessedAuctionRequestHook;
6+
import org.prebid.server.hooks.v1.Hook;
7+
import org.prebid.server.hooks.v1.InvocationContext;
8+
import org.prebid.server.hooks.v1.Module;
9+
import org.prebid.server.json.JacksonMapper;
10+
import org.prebid.server.vertx.httpclient.HttpClient;
11+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
12+
import org.springframework.boot.context.properties.ConfigurationProperties;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.context.annotation.Configuration;
15+
16+
import java.util.Set;
17+
18+
@Configuration
19+
@ConditionalOnProperty(prefix = "hooks." + LiveIntentOmniChannelIdentityModule.CODE, name = "enabled", havingValue = "true")
20+
public class LiveIntentOmniChannelIdentityConfiguration {
21+
@Bean
22+
@ConfigurationProperties(prefix = "hooks.modules." + LiveIntentOmniChannelIdentityModule.CODE)
23+
ModuleConfig moduleConfig() {
24+
return new ModuleConfig();
25+
}
26+
27+
@Bean
28+
Module liveIntentOmniChannelIdentityModule(ModuleConfig config, JacksonMapper mapper, HttpClient httpClient) {
29+
final Set<? extends Hook<?, ? extends InvocationContext>> hooks = Set.of(
30+
new LiveIntentOmniChannelIdentityProcessedAuctionRequestHook(config, mapper, httpClient)
31+
);
32+
return new LiveIntentOmniChannelIdentityModule(hooks);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model;
2+
3+
import com.iab.openrtb.request.Eid;
4+
import lombok.Builder;
5+
import lombok.Value;
6+
7+
import java.util.List;
8+
9+
@Value
10+
@Builder(toBuilder = true)
11+
public class IdResResponse {
12+
List<Eid> eids;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public final class ModuleConfig {
7+
Long requestTimeout;
8+
String idResUrl;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1;
2+
3+
import org.prebid.server.hooks.v1.Hook;
4+
import org.prebid.server.hooks.v1.InvocationContext;
5+
import org.prebid.server.hooks.v1.Module;
6+
7+
import java.util.Collection;
8+
9+
public record LiveIntentOmniChannelIdentityModule (
10+
Collection<? extends Hook<?, ? extends InvocationContext>> hooks
11+
) implements Module {
12+
public static final String CODE = "liveintent-omni-channel-identity";
13+
14+
@Override
15+
public String code() {
16+
return CODE;
17+
}
18+
19+
@Override
20+
public Collection<? extends Hook<?, ? extends InvocationContext>> hooks() {
21+
return hooks;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.v1.hooks;
2+
3+
import com.iab.openrtb.request.BidRequest;
4+
import com.iab.openrtb.request.Eid;
5+
import com.iab.openrtb.request.User;
6+
import io.vertx.core.Future;
7+
import org.prebid.server.hooks.execution.v1.InvocationResultImpl;
8+
import org.prebid.server.hooks.execution.v1.auction.AuctionRequestPayloadImpl;
9+
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.IdResResponse;
10+
import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config.ModuleConfig;
11+
import org.prebid.server.hooks.v1.InvocationAction;
12+
import org.prebid.server.hooks.v1.InvocationResult;
13+
import org.prebid.server.hooks.v1.InvocationStatus;
14+
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
15+
import org.prebid.server.hooks.v1.auction.AuctionRequestPayload;
16+
import org.prebid.server.hooks.v1.auction.ProcessedAuctionRequestHook;
17+
import org.prebid.server.json.JacksonMapper;
18+
import org.prebid.server.vertx.httpclient.HttpClient;
19+
import org.prebid.server.vertx.httpclient.model.HttpClientResponse;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.Objects;
24+
25+
public class LiveIntentOmniChannelIdentityProcessedAuctionRequestHook implements ProcessedAuctionRequestHook {
26+
27+
private static final String CODE = "liveintent-enrichment-hook";
28+
29+
private final ModuleConfig config;
30+
private final JacksonMapper mapper;
31+
private final HttpClient httpClient;
32+
33+
public LiveIntentOmniChannelIdentityProcessedAuctionRequestHook(
34+
ModuleConfig config,
35+
JacksonMapper mapper,
36+
HttpClient httpClient) {
37+
this.config = Objects.requireNonNull(config);
38+
this.mapper = Objects.requireNonNull(mapper);
39+
this.httpClient = Objects.requireNonNull(httpClient);
40+
}
41+
42+
// TODO: Error handling
43+
@Override
44+
public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayload auctionRequestPayload, AuctionInvocationContext invocationContext) {
45+
return requestEnrichment(auctionRequestPayload)
46+
.map(resolutionResult ->
47+
InvocationResultImpl.<AuctionRequestPayload>builder()
48+
.status(InvocationStatus.success)
49+
.action(InvocationAction.update)
50+
.payloadUpdate(requestPayload -> updatedPayload(requestPayload, resolutionResult))
51+
.build()
52+
);
53+
}
54+
55+
@Override
56+
public String code() {
57+
return CODE;
58+
}
59+
60+
private AuctionRequestPayload updatedPayload(AuctionRequestPayload requestPayload, IdResResponse idResResponse) {
61+
BidRequest bidRequest = requestPayload.bidRequest();
62+
User user = bidRequest.getUser();
63+
64+
List<Eid> allEids = new ArrayList<>();
65+
allEids.addAll(user.getEids());
66+
allEids.addAll(idResResponse.getEids());
67+
68+
User updatedUser = user.toBuilder().eids(allEids).build();
69+
BidRequest updatedBidRequest = requestPayload.bidRequest().toBuilder().user(updatedUser).build();
70+
71+
return AuctionRequestPayloadImpl.of(updatedBidRequest);
72+
}
73+
74+
private Future<IdResResponse> requestEnrichment(AuctionRequestPayload auctionRequestPayload) {
75+
String bidRequestJson = mapper.encodeToString(auctionRequestPayload.bidRequest());
76+
return httpClient.post(
77+
config.getIdResUrl(),
78+
bidRequestJson,
79+
config.getRequestTimeout())
80+
.map(this::processResponse);
81+
}
82+
83+
private IdResResponse processResponse(HttpClientResponse response) {
84+
return mapper.decodeValue(response.getBody(), IdResResponse.class);
85+
}
86+
}

extra/modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<module>pb-response-correction</module>
2525
<module>greenbids-real-time-data</module>
2626
<module>pb-request-correction</module>
27+
<module>live-intent-omni-channel-identity</module>
2728
</modules>
2829

2930
<dependencyManagement>

0 commit comments

Comments
 (0)