Skip to content

Commit

Permalink
addtlconsent parsing logic removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Nurul Islam Shihan committed Jun 4, 2024
1 parent 4626c55 commit 6f37890
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 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,10 +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
= JsonPointer.valueOf("/prebid/" + IS_REWARDED_INVENTORY_FIELD);
Expand Down Expand Up @@ -89,46 +80,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 +100,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
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

0 comments on commit 6f37890

Please sign in to comment.