Skip to content

Commit abb8c92

Browse files
Merge pull request #16 from WURFL/PR-3685-pass-4
More refactoring of device update process for exception handling
2 parents 36372d6 + 9a1f2aa commit abb8c92

4 files changed

Lines changed: 59 additions & 48 deletions

File tree

extra/modules/wurfl-devicedetection/src/main/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/config/WURFLDeviceDetectionConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.prebid.server.spring.config.model.FileSyncerProperties;
1414
import org.prebid.server.spring.config.model.HttpClientProperties;
1515
import org.prebid.server.execution.file.FileUtil;
16-
import org.prebid.server.json.ObjectMapperProvider;
1716
import org.prebid.server.json.JacksonMapper;
1817
import org.springframework.boot.context.properties.ConfigurationProperties;
1918

@@ -35,15 +34,16 @@ WURFLDeviceDetectionConfigProperties configProperties() {
3534

3635
@Bean
3736
public WURFLDeviceDetectionModule wurflDeviceDetectionModule(WURFLDeviceDetectionConfigProperties configProperties,
37+
JacksonMapper mapper,
3838
Vertx vertx) {
39+
3940
final WURFLService wurflService = new WURFLService(null, configProperties);
4041
final FileSyncer fileSyncer = createFileSyncer(configProperties, wurflService, vertx);
4142
fileSyncer.sync();
4243

4344
return new WURFLDeviceDetectionModule(List.of(
4445
new WURFLDeviceDetectionEntrypointHook(),
45-
new WURFLDeviceDetectionRawAuctionRequestHook(wurflService, configProperties,
46-
new JacksonMapper(ObjectMapperProvider.mapper()))));
46+
new WURFLDeviceDetectionRawAuctionRequestHook(wurflService, configProperties, mapper)));
4747
}
4848

4949
private FileSyncer createFileSyncer(WURFLDeviceDetectionConfigProperties configProperties,

extra/modules/wurfl-devicedetection/src/main/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/v1/OrtbDeviceUpdater.java

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,55 +103,74 @@ private String getWurflModel() {
103103
}
104104

105105
private Integer getWurflDeviceType() {
106-
if (wurflDevice.getVirtualCapabilityAsBool("is_mobile")) {
107-
// if at least one of these capabilities is not defined, the mobile device type is undefined
108-
try {
106+
107+
try {
108+
if (wurflDevice.getVirtualCapabilityAsBool("is_mobile")) {
109+
// if at least one of these capabilities is not defined, the mobile device type is undefined
109110
final boolean isPhone = wurflDevice.getVirtualCapabilityAsBool("is_phone");
110111
final boolean isTablet = wurflDevice.getCapabilityAsBool("is_tablet");
111112
return isPhone || isTablet ? 1 : 6;
112-
} catch (CapabilityNotDefinedException | VirtualCapabilityNotDefinedException e) {
113-
logger.warn("Failed to determine device type from WURFL device capabilities", e);
114-
return null;
115113
}
116-
}
117114

118-
if (wurflDevice.getVirtualCapabilityAsBool("is_full_desktop")) {
119-
return 2;
120-
}
115+
if (wurflDevice.getVirtualCapabilityAsBool("is_full_desktop")) {
116+
return 2;
117+
}
121118

122-
if (wurflDevice.getCapabilityAsBool("is_connected_tv")) {
123-
return 3;
124-
}
119+
if (wurflDevice.getCapabilityAsBool("is_connected_tv")) {
120+
return 3;
121+
}
125122

126-
if (wurflDevice.getCapabilityAsBool("is_phone")) {
127-
return 4;
128-
}
123+
if (wurflDevice.getCapabilityAsBool("is_phone")) {
124+
return 4;
125+
}
129126

130-
if (wurflDevice.getCapabilityAsBool("is_tablet")) {
131-
return 5;
132-
}
127+
if (wurflDevice.getCapabilityAsBool("is_tablet")) {
128+
return 5;
129+
}
133130

134-
if (wurflDevice.getCapabilityAsBool("is_ott")) {
135-
return 7;
131+
if (wurflDevice.getCapabilityAsBool("is_ott")) {
132+
return 7;
133+
}
134+
} catch (CapabilityNotDefinedException | VirtualCapabilityNotDefinedException | NumberFormatException e) {
135+
logger.warn("Failed to determine device type from WURFL device capabilities", e);
136136
}
137-
138137
return null;
139138
}
140139

141140
private String getWurflOs() {
142-
return wurflDevice.getVirtualCapability("advertised_device_os");
141+
try {
142+
return wurflDevice.getVirtualCapability("advertised_device_os");
143+
} catch (VirtualCapabilityNotDefinedException e) {
144+
logger.warn("Failed to evaluate advertised device OS", e);
145+
return null;
146+
}
143147
}
144148

145149
private String getWurflOsv() {
146-
return wurflDevice.getVirtualCapability("advertised_device_os_version");
150+
try {
151+
return wurflDevice.getVirtualCapability("advertised_device_os_version");
152+
} catch (VirtualCapabilityNotDefinedException e) {
153+
logger.warn("Failed to evaluate advertised device OS version", e);
154+
}
155+
return null;
147156
}
148157

149158
private Integer getWurflH() {
150-
return wurflDevice.getCapabilityAsInt("resolution_height");
159+
try {
160+
return wurflDevice.getCapabilityAsInt("resolution_height");
161+
} catch (NumberFormatException e) {
162+
logger.warn("Failed to get resolution height from WURFL device capabilities", e);
163+
return null;
164+
}
151165
}
152166

153167
private Integer getWurflW() {
154-
return wurflDevice.getCapabilityAsInt("resolution_width");
168+
try {
169+
return wurflDevice.getCapabilityAsInt("resolution_width");
170+
} catch (NumberFormatException e) {
171+
logger.warn("Failed to get resolution width from WURFL device capabilities", e);
172+
return null;
173+
}
155174
}
156175

157176
private Integer getWurflPpi() {
@@ -167,16 +186,21 @@ private BigDecimal getWurflPxRatio() {
167186
try {
168187
final String densityAsString = wurflDevice.getCapability("density_class");
169188
return densityAsString != null
170-
? new BigDecimal(densityAsString)
171-
: null;
172-
} catch (CapabilityNotDefinedException e) {
189+
? new BigDecimal(densityAsString)
190+
: null;
191+
} catch (CapabilityNotDefinedException | NumberFormatException e) {
173192
logger.warn("Failed to get pixel ratio from WURFL device capabilities", e);
174193
return null;
175194
}
176195
}
177196

178-
private int getWurflJs() {
179-
return wurflDevice.getCapabilityAsBool("ajax_support_javascript") ? 1 : 0;
197+
private Integer getWurflJs() {
198+
try {
199+
return wurflDevice.getCapabilityAsBool("ajax_support_javascript") ? 1 : 0;
200+
} catch (CapabilityNotDefinedException | NumberFormatException e) {
201+
logger.warn("Failed to get JS support from WURFL device capabilities", e);
202+
return null;
203+
}
180204
}
181205

182206
private ExtDevice updateExt(ExtDevice ortbExtDevice) {

extra/modules/wurfl-devicedetection/src/main/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/v1/WURFLDeviceDetectionRawAuctionRequestHook.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
5656
}
5757

5858
final BidRequest bidRequest = auctionRequestPayload.bidRequest();
59-
if (bidRequest == null || bidRequest.getDevice() == null) {
59+
if (bidRequest.getDevice() == null) {
6060
logger.warn("BidRequest is null");
6161
return noActionResult();
6262
}

extra/modules/wurfl-devicedetection/src/test/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/v1/WURFLDeviceDetectionRawAuctionRequestHookTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,6 @@ void codeShouldReturnCorrectHookCode() {
7171
assertThat(result).isEqualTo("wurfl-devicedetection-raw-auction-request");
7272
}
7373

74-
@Test
75-
void callShouldReturnNoActionWhenBidRequestIsNull() {
76-
// given
77-
when(payload.bidRequest()).thenReturn(null);
78-
79-
// when
80-
final InvocationResult<AuctionRequestPayload> result = target.call(payload, context).result();
81-
82-
// then
83-
assertThat(result.status()).isEqualTo(InvocationStatus.success);
84-
assertThat(result.action()).isEqualTo(InvocationAction.no_action);
85-
}
86-
8774
@Test
8875
void callShouldReturnNoActionWhenDeviceIsNull() {
8976
// given

0 commit comments

Comments
 (0)