Skip to content

EPlanning: Add schain support#3914

Merged
CTMBNara merged 3 commits into
masterfrom
EPlanning-Add-schain-support
Jun 3, 2025
Merged

EPlanning: Add schain support#3914
CTMBNara merged 3 commits into
masterfrom
EPlanning-Add-schain-support

Conversation

@przemkaczmarek
Copy link
Copy Markdown
Collaborator

@przemkaczmarek przemkaczmarek commented Apr 16, 2025

🔧 Type of changes

  • bid adapter update

✨ What's the context?

#3895

@przemkaczmarek przemkaczmarek self-assigned this Apr 16, 2025
@AntoxaAntoxic AntoxaAntoxic linked an issue Apr 23, 2025 that may be closed by this pull request
Comment on lines +299 to +347
private String makeSupplyChain(SupplyChain supplyChain) {
if (supplyChain.getNodes() == null || supplyChain.getNodes().isEmpty()) {
return Strings.EMPTY;
}

final StringBuilder sb = new StringBuilder();
sb.append(supplyChain.getVer())
.append(",")
.append(supplyChain.getComplete() != null ? supplyChain.getComplete() : 0);

for (SupplyChainNode node : supplyChain.getNodes()) {
sb.append("!")
.append(formatNodeValue(node.getAsi()))
.append(",")
.append(formatNodeValue(node.getSid()))
.append(",")
.append(formatNodeValue(node.getHp()))
.append(",")
.append(formatNodeValue(node.getRid()))
.append(",")
.append(formatNodeValue(node.getName()))
.append(",")
.append(formatNodeValue(node.getDomain()))
.append(",")
.append(formatNodeValue(node.getExt()));
}

return sb.toString();
}

private String formatNodeValue(Object value) {
if (value == null) {
return Strings.EMPTY;
}

if (value instanceof String) {
return (String) value;
}

if (value instanceof Number) {
return value.toString();
}

if (value instanceof ObjectNode) {
return value.toString();
}

return Strings.EMPTY;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

private String getSchainParameter(Source source) {
        return Optional.ofNullable(source)
                .map(Source::getExt)
                .map(ExtSource::getSchain)
                .map(this::resolveSupplyChain)
                .orElse(null);
    }

    private String resolveSupplyChain(SupplyChain schain) {
        final List<SupplyChainNode> nodes = schain.getNodes();
        if (CollectionUtils.isEmpty(nodes) || nodes.size() > 2) {
            return null;
        }

        final StringBuilder schainBuilder = new StringBuilder();

        schainBuilder.append(schain.getVer());
        schainBuilder.append(",");
        schainBuilder.append(ObjectUtils.defaultIfNull(schain.getComplete(), 0));
        for (SupplyChainNode node : schain.getNodes()) {
            schainBuilder.append("!");
            schainBuilder.append(encodeValue(node.getAsi()));
            schainBuilder.append(",");

            schainBuilder.append(encodeValue(node.getSid()));
            schainBuilder.append(",");

            schainBuilder.append(node.getHp() == null ? StringUtils.EMPTY : node.getHp());
            schainBuilder.append(",");

            schainBuilder.append(encodeValue(node.getRid()));
            schainBuilder.append(",");

            schainBuilder.append(encodeValue(node.getName()));
            schainBuilder.append(",");

            schainBuilder.append(encodeValue(node.getDomain()));
            schainBuilder.append(",");

            schainBuilder.append(node.getExt() == null
                    ? StringUtils.EMPTY
                    : HttpUtil.encodeUrl(mapper.encodeToString(node.getExt())));
        }

        return schainBuilder.toString();
    }

    private static String encodeValue(String value) {
        return value == null ? StringUtils.EMPTY : HttpUtil.encodeUrl(value);
    }

Comment on lines +277 to +288
final Source source = request.getSource();
if (source != null && source.getExt() != null && source.getExt().getSchain() != null) {
final SupplyChain supplyChain = source.getExt().getSchain();
if (supplyChain.getNodes() != null && supplyChain.getNodes().size() <= 2) {
final String schValue = makeSupplyChain(supplyChain);
if (StringUtils.isNotEmpty(schValue)) {
uriBuilder.addParameter("sch", schValue);
}
}
}

return uriBuilder.toString().replace("+", "%20");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

        final String schain = getSchainParameter(request.getSource());
        if (schain != null) {
            uriBuilder.addParameter("sch", schain);
        }
      
       return uriBuilder.toString();

Comment thread src/main/java/org/prebid/server/bidder/eplanning/EplanningBidder.java Outdated
Comment thread src/main/java/org/prebid/server/bidder/eplanning/EplanningBidder.java Outdated
@osulzhenko osulzhenko requested a review from CTMBNara May 12, 2025 08:28
Copy link
Copy Markdown
Collaborator

@CTMBNara CTMBNara left a comment

Choose a reason for hiding this comment

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

#3914 (comment)

@przemkaczmarek Please, comment or emote to indicate that logic follows the logic of GO version

@osulzhenko
Copy link
Copy Markdown
Collaborator

ent or emote to indicate that logic follows the logic of GO v

@przemkaczmarek can you confirm this one?

@przemkaczmarek
Copy link
Copy Markdown
Collaborator Author

@osulzhenko logic in Java fallows Go, confim

@CTMBNara CTMBNara merged commit 7037dba into master Jun 3, 2025
8 checks passed
@CTMBNara CTMBNara deleted the EPlanning-Add-schain-support branch June 3, 2025 12:59
riteshghodrao pushed a commit to riteshghodrao/prebid-server-java that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port PR from PBS-Go: EPlanning: Add schain support

4 participants