Open
Conversation
CTMBNara
requested changes
Mar 17, 2026
| .build(); | ||
| } | ||
|
|
||
| private ExtImpTrustx tryParseImpExt(Imp imp) { |
Collaborator
There was a problem hiding this comment.
tryParseImpExt -> parseImpExt
Comment on lines
+91
to
+93
| return impExt.toBuilder() | ||
| .gpid(adSlot != null ? adSlot : impExt.getGpid()) | ||
| .build(); |
Collaborator
There was a problem hiding this comment.
private static ExtImpTrustx modifyImpExt(ExtImpTrustx impExt) {
final String adSlot = Optional.ofNullable(impExt.getData())
.map(ExtImpTrustxData::getAdServer)
.map(ExtImpTrustxDataAdServer::getAdSlot)
.filter(StringUtils::isNotEmpty)
.orElse(null);
return adSlot != null ? impExt.toBuilder().gpid(adSlot).build() : impExt;
}
Comment on lines
+68
to
+74
| private Imp modifyImp(Imp imp) { | ||
| final ExtImpTrustx impExt = tryParseImpExt(imp); | ||
|
|
||
| return impExt == null ? imp : imp.toBuilder() | ||
| .ext(mapper.mapper().valueToTree(modifyImpExt(impExt))) | ||
| .build(); | ||
| } |
Collaborator
There was a problem hiding this comment.
private Imp modifyImp(Imp imp) {
final ExtImpTrustx impExt = parseImpExt(imp);
final ExtImpTrustx modifiedImpExt = impExt != null ? modifyImpExt(impExt) : null;
return impExt != modifiedImpExt
? imp.toBuilder().ext(mapper.mapper().valueToTree(modifiedImpExt)).build()
: imp;
}
Comment on lines
+98
to
+105
| final String referrer = ObjectUtil.getIfNotNull(site, Site::getRef); | ||
| final String domain = ObjectUtil.getIfNotNull(site, Site::getDomain); | ||
|
|
||
| final Device device = request.getDevice(); | ||
| final String ip = StringUtils.firstNonEmpty( | ||
| ObjectUtil.getIfNotNull(device, Device::getIpv6), | ||
| ObjectUtil.getIfNotNull(device, Device::getIp)); | ||
| final String userAgent = ObjectUtil.getIfNotNull(device, Device::getUa); |
Collaborator
There was a problem hiding this comment.
We usually use ObjectUtil.getIfNotNull for cases like
ObjectUtil.getIfNotNull(request.getDevice(), Device::getIpv6)
so you don't need to make a local variable. For me,
device != null ? device.getIpv6() : null
looks simpler.
|
|
||
| private Result<List<BidderBid>> bidsFromResponse(BidResponse bidResponse) { | ||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<BidderBid> bidderBids = Stream.ofNullable(bidResponse) |
Comment on lines
+154
to
+223
| private BidderBid makeBid(Bid bid, List<BidderError> errors) { | ||
| try { | ||
| final BidType bidType = getBidType(bid); | ||
|
|
||
| final ExtBidPrebidVideo videoInfo = (bidType == BidType.video) ? ExtBidPrebidVideo.of( | ||
| bid.getDur() != null && bid.getDur() > 0 ? bid.getDur() : null, | ||
| CollectionUtils.isNotEmpty(bid.getCat()) ? bid.getCat().getFirst() : null | ||
| ) : null; | ||
|
|
||
| final Bid modifiedBid = Optional.ofNullable(tryParseBidExt(bid.getExt())) | ||
| .map(TrustxBidder::modifyBidExt) | ||
| .map(mapper.mapper()::<ObjectNode>valueToTree) | ||
| .map(extBid -> bid.toBuilder().ext(extBid).build()) | ||
| .orElse(bid); | ||
|
|
||
| return BidderBid.builder() | ||
| .bid(modifiedBid) | ||
| .type(bidType) | ||
| .videoInfo(videoInfo) | ||
| .build(); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badInput(e.getMessage())); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static BidType getBidType(Bid bid) { | ||
| final Integer markupType = bid.getMtype(); | ||
| if (markupType == null) { | ||
| throw new PreBidException("Missing MType for bid: " + bid.getId()); | ||
| } | ||
|
|
||
| return switch (markupType) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| default -> throw new PreBidException("Unsupported MType: %d".formatted(markupType)); | ||
| }; | ||
| } | ||
|
|
||
| private ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> tryParseBidExt(ObjectNode bidExt) { | ||
| try { | ||
| return mapper.mapper().convertValue(bidExt, TRUSTX_BID_EXT_TYPE_REFERENCE); | ||
| } catch (IllegalArgumentException e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> modifyBidExt( | ||
| ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> extBid) { | ||
|
|
||
| return Optional.ofNullable(extBid.getBidder()) | ||
| .map(ExtBidBidderTrustx::getTrustx) | ||
| .map(ExtBidTrustx::getNetworkName) | ||
| .filter(StringUtils::isNotEmpty) | ||
| .map(networkName -> ExtBidPrebidMeta.builder().networkName(networkName).build()) | ||
| .map(extBidPrebidMeta -> modifyBidExtMeta(extBid, extBidPrebidMeta)) | ||
| .orElse(extBid); | ||
| } | ||
|
|
||
| private static ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> modifyBidExtMeta( | ||
| ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> extBid, ExtBidPrebidMeta extBidPrebidMeta) { | ||
|
|
||
| final ExtBidPrebid updatedExtBidPrebid = Optional.ofNullable(extBid.getPrebid()) | ||
| .map(ExtBidPrebid::toBuilder) | ||
| .orElseGet(ExtBidPrebid::builder) | ||
| .meta(extBidPrebidMeta) | ||
| .build(); | ||
|
|
||
| return ExtPrebid.of(updatedExtBidPrebid, extBid.getBidder()); | ||
| } |
Collaborator
There was a problem hiding this comment.
private BidderBid makeBidderBid(Bid bid, List<BidderError> errors) {
final BidType bidType;
try {
bidType = getBidType(bid);
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
return null;
}
return BidderBid.builder()
.bid(modifyBid(bid))
.type(bidType)
.videoInfo(bidType == BidType.video ? makeExtBidPrebidVideo(bid) : null)
.build();
}
private Bid modifyBid(Bid bid) {
final ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> ext = parseBidExt(bid.getExt());
if (ext == null) {
return bid;
}
final ExtBidBidderTrustx extBidder = ext.getBidder();
final String networkName = Optional.ofNullable(extBidder)
.map(ExtBidBidderTrustx::getTrustx)
.map(ExtBidTrustx::getNetworkName)
.filter(StringUtils::isNotEmpty)
.orElse(null);
if (networkName == null) {
return bid;
}
final ExtBidPrebid modifiedExtPrebid = Optional.ofNullable(ext.getPrebid())
.map(ExtBidPrebid::toBuilder)
.orElseGet(ExtBidPrebid::builder)
.meta(ExtBidPrebidMeta.builder().networkName(networkName).build())
.build();
final ObjectNode modifiedExt = mapper.mapper().valueToTree(ExtPrebid.of(modifiedExtPrebid, extBidder));
return bid.toBuilder().ext(modifiedExt).build();
}
private ExtPrebid<ExtBidPrebid, ExtBidBidderTrustx> parseBidExt(ObjectNode bidExt) {
try {
return mapper.mapper().convertValue(bidExt, TRUSTX_BID_EXT_TYPE_REFERENCE);
} catch (IllegalArgumentException e) {
return null;
}
}
private static BidType getBidType(Bid bid) {
final Integer markupType = bid.getMtype();
if (markupType == null) {
throw new PreBidException("Missing MType for bid: " + bid.getId());
}
return switch (markupType) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
default -> throw new PreBidException("Unsupported MType: %d".formatted(markupType));
};
}
private static ExtBidPrebidVideo makeExtBidPrebidVideo(Bid bid) {
final Integer dur = bid.getDur();
final List<String> cat = bid.getCat();
return ExtBidPrebidVideo.of(
dur != null && dur > 0 ? dur : null,
CollectionUtils.isNotEmpty(cat) ? cat.getFirst() : null);
}
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value |
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value |
Comment on lines
+31
to
+33
| BidderDeps trustxBidderDeps(BidderConfigurationProperties trustxConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { |
| final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
|
||
| // then | ||
| result.getValue().getFirst().getHeaders().getAll(HttpUtil.X_FORWARDED_FOR_HEADER); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🔧 Type of changes
✨ What's the context?
#4375