Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergii Chernysh committed Mar 5, 2020
1 parent 90ebb6b commit 6399f6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.commons.lang3.StringUtils;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.exception.InvalidRequestException;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.request.ExtBidRequest;
import org.prebid.server.proto.openrtb.ext.request.ExtCurrency;
Expand Down Expand Up @@ -242,8 +243,8 @@ private Targeting parseTargeting(String jsonTargeting) {
final String decodedJsonTargeting = HttpUtil.decodeUrl(jsonTargeting);
return decodedJsonTargeting == null
? Targeting.empty()
: mapper.mapper().readValue(decodedJsonTargeting, Targeting.class);
} catch (JsonProcessingException | IllegalArgumentException e) {
: mapper.decodeValue(decodedJsonTargeting, Targeting.class);
} catch (DecodeException e) {
throw new InvalidRequestException(String.format("Error decoding targeting from url: %s", e.getMessage()));
}
}
Expand Down
36 changes: 25 additions & 11 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,8 @@ private Future<List<BidderRequest>> makeBidderRequests(
final List<String> firstPartyDataBidders = firstPartyDataBidders(requestExt);
final Map<String, ExtBidderConfigFpd> biddersToConfigs = getBiddersToConfigs(requestExt);

final Map<String, User> bidderToUser = new HashMap<>();
for (String bidder : bidders) {
final ExtBidderConfigFpd fpdConfig = ObjectUtils.firstNonNull(biddersToConfigs.get(ALL_BIDDERS_CONFIG),
biddersToConfigs.get(bidder));
final User fpdUser = fpdConfig != null ? fpdConfig.getUser() : null;

final boolean useFirstPartyData = firstPartyDataBidders == null || firstPartyDataBidders.contains(bidder);
final User preparedUser = prepareUser(bidRequest.getUser(), extUser, bidder, aliases, uidsBody,
context.getUidsCookie(), useFirstPartyData, fpdUser);
bidderToUser.put(bidder, preparedUser);
}
final Map<String, User> bidderToUser = prepareUsers(
bidders, context, aliases, bidRequest, extUser, uidsBody, firstPartyDataBidders, biddersToConfigs);

return privacyEnforcementService
.mask(bidderToUser, extUser, bidders, aliases, bidRequest, isGdprEnforced, context.getTimeout())
Expand Down Expand Up @@ -391,6 +382,29 @@ private static List<String> firstPartyDataBidders(ExtBidRequest requestExt) {
return data == null ? null : data.getBidders();
}

private Map<String, User> prepareUsers(List<String> bidders,
AuctionContext context,
Map<String, String> aliases,
BidRequest bidRequest,
ExtUser extUser,
Map<String, String> uidsBody,
List<String> firstPartyDataBidders,
Map<String, ExtBidderConfigFpd> biddersToConfigs) {

final Map<String, User> bidderToUser = new HashMap<>();
for (String bidder : bidders) {
final ExtBidderConfigFpd fpdConfig = ObjectUtils.firstNonNull(biddersToConfigs.get(ALL_BIDDERS_CONFIG),
biddersToConfigs.get(bidder));
final User fpdUser = fpdConfig != null ? fpdConfig.getUser() : null;

final boolean useFirstPartyData = firstPartyDataBidders == null || firstPartyDataBidders.contains(bidder);
final User preparedUser = prepareUser(bidRequest.getUser(), extUser, bidder, aliases, uidsBody,
context.getUidsCookie(), useFirstPartyData, fpdUser);
bidderToUser.put(bidder, preparedUser);
}
return bidderToUser;
}

/**
* Returns original {@link User} if user.buyeruid already contains uid value for bidder.
* Otherwise, returns new {@link User} containing updated {@link ExtUser} and user.buyeruid.
Expand Down

0 comments on commit 6399f6a

Please sign in to comment.