Skip to content

Commit 0f1e635

Browse files
committed
Fix comments
1 parent 9e78c2c commit 0f1e635

2 files changed

Lines changed: 37 additions & 49 deletions

File tree

src/main/java/org/prebid/server/bidder/msft/MsftBidder.java

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidVideo;
4747
import org.prebid.server.util.BidderUtil;
4848
import org.prebid.server.util.HttpUtil;
49-
import org.prebid.server.util.ObjectUtil;
5049

5150
import java.net.URISyntaxException;
5251
import java.util.ArrayList;
@@ -78,6 +77,7 @@ public MsftBidder(String endpointUrl,
7877
int hbSourceVideo,
7978
Map<Integer, String> iabCategories,
8079
JacksonMapper mapper) {
80+
8181
this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl));
8282
this.hbSource = hbSource;
8383
this.hbSourceVideo = hbSourceVideo;
@@ -98,9 +98,7 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest bidRequ
9898

9999
final Integer memberId = extImp.getMember();
100100
if (memberId != null && memberIdValidator.isInvalid(memberId)) {
101-
errors.add(BidderError.badInput("Member id mismatch:"
102-
+ " all impressions must use the same member id but found two different ids: %s and %s"
103-
.formatted(memberIdValidator.getValue(), memberId)));
101+
errors.add(BidderError.badInput("member id mismatch: all impressions must use the same member id"));
104102
return Result.withErrors(errors);
105103
}
106104

@@ -149,57 +147,50 @@ private ExtImpMsft parseImpExt(Imp imp) {
149147
}
150148

151149
private Imp updateImp(Imp imp, ExtImpMsft extImp, String defaultDisplayManagerVer) {
152-
final Imp.ImpBuilder impBuilder = imp.toBuilder();
153-
154-
if (StringUtils.isNotEmpty(extImp.getInvCode())) {
155-
impBuilder.tagid(extImp.getInvCode());
156-
}
157-
158-
if (imp.getBanner() != null) {
159-
impBuilder.banner(updateBanner(imp.getBanner(), extImp));
160-
}
161-
162-
if (StringUtils.isEmpty(imp.getDisplaymanagerver())) {
163-
impBuilder.displaymanagerver(defaultDisplayManagerVer);
164-
}
165-
166-
impBuilder.ext(updateImpExt(imp, extImp));
167-
168-
return impBuilder.build();
150+
final String invCode = extImp.getInvCode();
151+
final Banner banner = imp.getBanner();
152+
final String displayManagerVer = StringUtils.defaultIfEmpty(
153+
imp.getDisplaymanagerver(), defaultDisplayManagerVer);
154+
155+
return imp.toBuilder()
156+
.tagid(StringUtils.isNotEmpty(invCode) ? invCode : imp.getTagid())
157+
.banner(banner != null ? updateBanner(banner, extImp) : null)
158+
.displaymanagerver(displayManagerVer)
159+
.ext(updateImpExt(imp, extImp))
160+
.build();
169161
}
170162

171163
private Banner updateBanner(Banner banner, ExtImpMsft extImp) {
172-
final Banner.BannerBuilder bannerBuilder = banner.toBuilder();
173-
174164
final List<Format> bannerFormat = banner.getFormat();
165+
166+
final Banner.BannerBuilder bannerBuilder = banner.toBuilder();
175167
if (banner.getW() == null && banner.getH() == null && CollectionUtils.isNotEmpty(bannerFormat)) {
176168
final Format firstFormat = bannerFormat.getFirst();
177169
bannerBuilder.w(firstFormat.getW());
178170
bannerBuilder.h(firstFormat.getH());
179171
}
180172

181-
if (banner.getApi() == null) {
182-
bannerBuilder.api(extImp.getBannerFrameworks());
183-
}
184-
185-
return bannerBuilder.build();
173+
return bannerBuilder
174+
.api(ObjectUtils.defaultIfNull(banner.getApi(), extImp.getBannerFrameworks()))
175+
.build();
186176
}
187177

188178
private ObjectNode updateImpExt(Imp imp, ExtImpMsft extImp) {
179+
final MsftExtImpOutgoing impExtOutgoing = MsftExtImpOutgoing.builder()
180+
.placementId(extImp.getPlacementId())
181+
.allowSmallerSizes(extImp.getAllowSmallerSizes())
182+
.usePmtRule(extImp.getUsePmtRule())
183+
.keywords(extImp.getKeywords())
184+
.trafficSourceCode(extImp.getTrafficSourceCode())
185+
.pubClick(extImp.getPubclick())
186+
.extInvCode(extImp.getExtInvCode())
187+
.extImpId(extImp.getExtImpId())
188+
.build();
189+
final String gpid = imp.getExt().at("/gpid").textValue();
190+
189191
final ObjectNode updatedImpExt = mapper.mapper().createObjectNode()
190-
.set("appnexus", mapper.mapper().valueToTree(
191-
MsftExtImpOutgoing.builder()
192-
.placementId(extImp.getPlacementId())
193-
.allowSmallerSizes(extImp.getAllowSmallerSizes())
194-
.usePmtRule(extImp.getUsePmtRule())
195-
.keywords(extImp.getKeywords())
196-
.trafficSourceCode(extImp.getTrafficSourceCode())
197-
.pubClick(extImp.getPubclick())
198-
.extInvCode(extImp.getExtInvCode())
199-
.extImpId(extImp.getExtImpId())
200-
.build()));
201-
202-
final String gpid = ObjectUtil.getIfNotNull(imp.getExt().get("gpid"), JsonNode::textValue);
192+
.set("appnexus", mapper.mapper().valueToTree(impExtOutgoing));
193+
203194
if (StringUtils.isNotEmpty(gpid)) {
204195
updatedImpExt.put("gpid", gpid);
205196
}
@@ -250,7 +241,7 @@ private ExtRequestMsft parseRequestExtMsft(JsonNode extRequestMsftRaw) {
250241
try {
251242
return mapper.mapper().treeToValue(extRequestMsftRaw, ExtRequestMsft.class);
252243
} catch (IllegalArgumentException | JsonProcessingException e) {
253-
throw new PreBidException("Failed to deserialize Microsoft bid request extension: " + e.getMessage());
244+
throw new PreBidException("malformed request ext.appnexus");
254245
}
255246
}
256247

@@ -286,6 +277,7 @@ private String extractEndpointUrl(ExtRequest requestExt) {
286277
private List<HttpRequest<BidRequest>> splitHttpRequests(BidRequest bidRequest,
287278
List<Imp> imps,
288279
String requestUrl) {
280+
289281
return ListUtils.partition(imps, MAX_IMPS_PER_REQUEST)
290282
.stream()
291283
.map(impsForRequest -> makeHttpRequest(bidRequest, impsForRequest, requestUrl))

src/test/java/org/prebid/server/bidder/msft/MsftBidderTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ public void makeHttpRequestsShouldReturnErrorIfThereAreImpsWithDuplicateMemberId
178178

179179
// then
180180
assertThat(result.getValue()).isEmpty();
181-
assertThat(result.getErrors())
182-
.containsExactly(BidderError.badInput("Member id mismatch: "
183-
+ "all impressions must use the same member id but found two different ids: 1 and 2"));
181+
assertThat(result.getErrors()).containsExactly(
182+
BidderError.badInput("member id mismatch: all impressions must use the same member id"));
184183
}
185184

186185
@Test
@@ -447,10 +446,7 @@ public void makeHttpRequestsShouldReturnErrorIfMicrosoftBidRequestExtensionIsInv
447446

448447
// then
449448
assertThat(result.getValue()).hasSize(0);
450-
assertThat(result.getErrors()).hasSize(1).allSatisfy(error -> {
451-
assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input);
452-
assertThat(error.getMessage()).startsWith("Failed to deserialize Microsoft bid request extension: ");
453-
});
449+
assertThat(result.getErrors()).containsExactly(BidderError.badInput("malformed request ext.appnexus"));
454450
}
455451

456452
@Test

0 commit comments

Comments
 (0)