Skip to content

Commit c8d5cef

Browse files
committed
51Degrees module: extend device detection module with new fields
1 parent 5926c92 commit c8d5cef

3 files changed

Lines changed: 73 additions & 1 deletion

File tree

extra/modules/fiftyone-devicedetection/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<description>51Degrees Device Detection module</description>
1515

1616
<properties>
17-
<fiftyone-device-detection.version>4.4.226</fiftyone-device-detection.version>
17+
<fiftyone-device-detection.version>4.5.51</fiftyone-device-detection.version>
1818
</properties>
1919

2020
<dependencies>

extra/modules/fiftyone-devicedetection/src/main/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricher.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ private EnrichmentResult patchDevice(Device device, DeviceData deviceData) {
9797
updatedFields.add("model");
9898
}
9999

100+
final UpdateResult<String> resolvedHwv = resolveDeviceHwv(device, deviceData);
101+
if (resolvedHwv.isUpdated()) {
102+
deviceBuilder.hwv(resolvedHwv.getValue());
103+
updatedFields.add("hwv");
104+
}
105+
100106
final UpdateResult<String> resolvedOs = resolveOs(device, deviceData);
101107
if (resolvedOs.isUpdated()) {
102108
deviceBuilder.os(resolvedOs.getValue());
@@ -184,6 +190,11 @@ private UpdateResult<String> resolveModel(Device device, DeviceData deviceData)
184190
return UpdateResult.unaltered(currentModel);
185191
}
186192

193+
final String hardwareNamePrefix = getSafe(deviceData, DeviceData::getHardwareNamePrefix);
194+
if (StringUtils.isNotBlank(hardwareNamePrefix)) {
195+
return UpdateResult.updated(hardwareNamePrefix);
196+
}
197+
187198
final String model = getSafe(deviceData, DeviceData::getHardwareModel);
188199
if (StringUtils.isNotBlank(model)) {
189200
return UpdateResult.updated(model);
@@ -284,6 +295,18 @@ private UpdateResult<String> resolveDeviceId(Device device, DeviceData deviceDat
284295
: UpdateResult.unaltered(currentDeviceId);
285296
}
286297

298+
private UpdateResult<String> resolveDeviceHwv(Device device, DeviceData deviceData) {
299+
final String currentDeviceHwv = device.getHwv();
300+
if (StringUtils.isNotEmpty(currentDeviceHwv)) {
301+
return UpdateResult.unaltered(currentDeviceHwv);
302+
}
303+
304+
final String deviceHwv = getSafe(deviceData, DeviceData::getHardwareNameVersion);
305+
return StringUtils.isNotEmpty(deviceHwv)
306+
? UpdateResult.updated(deviceHwv)
307+
: UpdateResult.unaltered(currentDeviceHwv);
308+
}
309+
287310
private static boolean isPositive(Integer value) {
288311
return value != null && value > 0;
289312
}

extra/modules/fiftyone-devicedetection/src/test/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricherTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public void populateDeviceInfoShouldEnrichAllPropertiesWhenDeviceIsEmpty() throw
273273
"devicetype",
274274
"make",
275275
"model",
276+
"hwv",
276277
"os",
277278
"osv",
278279
"h",
@@ -335,6 +336,28 @@ public void populateDeviceInfoShouldEnrichMakeWhenItIsMissing() throws Exception
335336
assertThat(result.enrichedDevice().getMake()).isEqualTo(buildCompleteDevice().getMake());
336337
}
337338

339+
@Test
340+
public void populateDeviceInfoShouldEnrichModelWithHardwareNamePrefixWhenItIsMissing() throws Exception {
341+
// given
342+
final Device testDevice = buildCompleteDevice().toBuilder()
343+
.model(null)
344+
.build();
345+
final String expectedModel = "NinjaTech";
346+
when(deviceData.getHardwareNamePrefix())
347+
.thenReturn(aspectPropertyValueWith(expectedModel));
348+
when(deviceData.getHardwareModel()).thenThrow(new RuntimeException());
349+
350+
// when
351+
final CollectedEvidence collectedEvidence = CollectedEvidence.builder()
352+
.deviceUA("fake-UserAgent")
353+
.build();
354+
final EnrichmentResult result = target.populateDeviceInfo(testDevice, collectedEvidence);
355+
356+
// then
357+
assertThat(result.enrichedFields()).hasSize(1);
358+
assertThat(result.enrichedDevice().getModel()).isEqualTo(expectedModel);
359+
}
360+
338361
@Test
339362
public void populateDeviceInfoShouldEnrichModelWithHWNameWhenHWModelIsMissing() throws Exception {
340363
// given
@@ -366,6 +389,7 @@ public void populateDeviceInfoShouldEnrichModelWhenItIsMissing() throws Exceptio
366389

367390
// when
368391
buildCompleteDeviceData();
392+
when(deviceData.getHardwareNamePrefix()).thenReturn(null);
369393
final CollectedEvidence collectedEvidence = CollectedEvidence.builder()
370394
.deviceUA("fake-UserAgent")
371395
.build();
@@ -376,6 +400,28 @@ public void populateDeviceInfoShouldEnrichModelWhenItIsMissing() throws Exceptio
376400
assertThat(result.enrichedDevice().getModel()).isEqualTo(buildCompleteDevice().getModel());
377401
}
378402

403+
@Test
404+
public void populateDeviceInfoShouldEnrichHwvWithHardwareNameVersionWhenItIsMissing() throws Exception {
405+
// given
406+
final Device testDevice = buildCompleteDevice().toBuilder()
407+
.hwv(null)
408+
.build();
409+
final String expectedHwv = "NinjaTech";
410+
when(deviceData.getHardwareNameVersion())
411+
.thenReturn(aspectPropertyValueWith(expectedHwv));
412+
when(deviceData.getHardwareModel()).thenReturn(null);
413+
414+
// when
415+
final CollectedEvidence collectedEvidence = CollectedEvidence.builder()
416+
.deviceUA("fake-UserAgent")
417+
.build();
418+
final EnrichmentResult result = target.populateDeviceInfo(testDevice, collectedEvidence);
419+
420+
// then
421+
assertThat(result.enrichedFields()).hasSize(1);
422+
assertThat(result.enrichedDevice().getHwv()).isEqualTo(expectedHwv);
423+
}
424+
379425
@Test
380426
public void populateDeviceInfoShouldEnrichOsWhenItIsMissing() throws Exception {
381427
// given
@@ -534,6 +580,7 @@ private static Device buildCompleteDevice() {
534580
.devicetype(1)
535581
.make("StarFleet")
536582
.model("communicator")
583+
.hwv("hmv")
537584
.os("NeutronAI")
538585
.osv("X-502")
539586
.h(5051)
@@ -551,6 +598,8 @@ private void buildCompleteDeviceData() {
551598
when(deviceData.getHardwareVendor()).thenReturn(aspectPropertyValueWith("StarFleet"));
552599
when(deviceData.getHardwareModel()).thenReturn(aspectPropertyValueWith("communicator"));
553600
when(deviceData.getPlatformName()).thenReturn(aspectPropertyValueWith("NeutronAI"));
601+
when(deviceData.getHardwareNamePrefix()).thenReturn(aspectPropertyValueWith("Prefix"));
602+
when(deviceData.getHardwareNameVersion()).thenReturn(aspectPropertyValueWith("Version"));
554603
when(deviceData.getPlatformVersion()).thenReturn(aspectPropertyValueWith("X-502"));
555604
when(deviceData.getScreenPixelsHeight()).thenReturn(aspectPropertyValueWith(5051));
556605
when(deviceData.getScreenPixelsWidth()).thenReturn(aspectPropertyValueWith(3001));

0 commit comments

Comments
 (0)