Skip to content

Commit

Permalink
Improvedigital: Remove consented_providers logic (#3534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Compile-Ninja authored Nov 4, 2024
1 parent 4ca292e commit af321ad
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.User;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
Expand All @@ -26,13 +24,10 @@
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.ConsentedProvidersSettings;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.improvedigital.ExtImpImprovedigital;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.BidderUtil;
import org.prebid.server.util.HttpUtil;
import org.prebid.server.util.ObjectUtil;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -50,9 +45,6 @@ public class ImprovedigitalBidder implements Bidder<BidRequest> {
private static final TypeReference<ExtPrebid<?, ExtImpImprovedigital>> IMPROVEDIGITAL_EXT_TYPE_REFERENCE =
new TypeReference<>() {
};
private static final String CONSENT_PROVIDERS_SETTINGS_OUT_KEY = "consented_providers_settings";
private static final String CONSENTED_PROVIDERS_KEY = "consented_providers";
private static final String REGEX_SPLIT_STRING_BY_DOT = "\\.";

private static final String IS_REWARDED_INVENTORY_FIELD = "is_rewarded_inventory";
private static final JsonPointer IS_REWARDED_INVENTORY_POINTER
Expand Down Expand Up @@ -89,46 +81,6 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
return Result.withValues(httpRequests);
}

private ExtUser getAdditionalConsentProvidersUserExt(ExtUser extUser) {
final String consentedProviders = ObjectUtil.getIfNotNull(
ObjectUtil.getIfNotNull(extUser, ExtUser::getConsentedProvidersSettings),
ConsentedProvidersSettings::getConsentedProviders);

if (StringUtils.isBlank(consentedProviders)) {
return extUser;
}

final String[] consentedProvidersParts = StringUtils.split(consentedProviders, "~");
final String consentedProvidersPart = consentedProvidersParts.length > 1 ? consentedProvidersParts[1] : null;
if (StringUtils.isBlank(consentedProvidersPart)) {
return extUser;
}

return fillExtUser(extUser, consentedProvidersPart.split(REGEX_SPLIT_STRING_BY_DOT));
}

private ExtUser fillExtUser(ExtUser extUser, String[] arrayOfSplitString) {
final JsonNode consentProviderSettingJsonNode;
try {
consentProviderSettingJsonNode = customJsonNode(arrayOfSplitString);
} catch (IllegalArgumentException e) {
throw new PreBidException(e.getMessage());
}

return mapper.fillExtension(extUser, consentProviderSettingJsonNode);
}

private JsonNode customJsonNode(String[] arrayOfSplitString) {
final Integer[] integers = mapper.mapper().convertValue(arrayOfSplitString, Integer[].class);
final ArrayNode arrayNode = mapper.mapper().createArrayNode();
for (Integer integer : integers) {
arrayNode.add(integer);
}

return mapper.mapper().createObjectNode().set(CONSENT_PROVIDERS_SETTINGS_OUT_KEY,
mapper.mapper().createObjectNode().set(CONSENTED_PROVIDERS_KEY, arrayNode));
}

private ExtImpImprovedigital parseImpExt(Imp imp) {
try {
return mapper.mapper().convertValue(imp.getExt(), IMPROVEDIGITAL_EXT_TYPE_REFERENCE).getBidder();
Expand All @@ -149,12 +101,8 @@ private static Imp updateImp(Imp imp) {
}

private HttpRequest<BidRequest> resolveRequest(BidRequest bidRequest, Imp imp, Integer publisherId) {
final User user = bidRequest.getUser();
final BidRequest modifiedRequest = bidRequest.toBuilder()
.imp(Collections.singletonList(updateImp(imp)))
.user(user != null
? user.toBuilder().ext(getAdditionalConsentProvidersUserExt(user.getExt())).build()
: null)
.build();

final String pathPrefix = publisherId != null && publisherId > 0
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/static/bidder-params/improvedigital.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
"description": "Placement size"
}
},
"required": ["placementId"]
"required": [
"placementId"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,6 @@ public void makeHttpRequestsShouldReturnUserExtIfConsentedProvidersIsNotProvided
.containsExactly(extUser);
}

@Test
public void makeHttpRequestsShouldReturnErrorIfCannotParseConsentedProviders() {
// given
final ExtUser extUser = ExtUser.builder()
.consentedProvidersSettings(ConsentedProvidersSettings.of("1~a.fv.90"))
.build();

final BidRequest bidRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder
.user(User.builder().ext(extUser).build()).id("request_id"),
identity());

// when
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).allSatisfy(error -> {
assertThat(error.getType()).isEqualTo(BidderError.Type.bad_input);
assertThat(error.getMessage()).startsWith("Cannot deserialize value of type");
});
}

@Test
public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@
"ext": {
"ConsentedProvidersSettings": {
"consented_providers": "1~10.20.90"
},
"consented_providers_settings": {
"consented_providers": [
10,
20,
90
]
}
}
},
Expand Down

0 comments on commit af321ad

Please sign in to comment.