diff --git a/extra/modules/fiftyone-devicedetection/pom.xml b/extra/modules/fiftyone-devicedetection/pom.xml index 55259e11268..1f2fe9b7e85 100644 --- a/extra/modules/fiftyone-devicedetection/pom.xml +++ b/extra/modules/fiftyone-devicedetection/pom.xml @@ -14,7 +14,7 @@ 51Degrees Device Detection module - 4.4.226 + 4.5.51 diff --git a/extra/modules/fiftyone-devicedetection/src/main/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricher.java b/extra/modules/fiftyone-devicedetection/src/main/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricher.java index 72b1e04cee2..1eb1afa7b5b 100644 --- a/extra/modules/fiftyone-devicedetection/src/main/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricher.java +++ b/extra/modules/fiftyone-devicedetection/src/main/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricher.java @@ -97,6 +97,12 @@ private EnrichmentResult patchDevice(Device device, DeviceData deviceData) { updatedFields.add("model"); } + final UpdateResult resolvedHwv = resolveDeviceHwv(device, deviceData); + if (resolvedHwv.isUpdated()) { + deviceBuilder.hwv(resolvedHwv.getValue()); + updatedFields.add("hwv"); + } + final UpdateResult resolvedOs = resolveOs(device, deviceData); if (resolvedOs.isUpdated()) { deviceBuilder.os(resolvedOs.getValue()); @@ -184,6 +190,11 @@ private UpdateResult resolveModel(Device device, DeviceData deviceData) return UpdateResult.unaltered(currentModel); } + final String hardwareNamePrefix = getSafe(deviceData, DeviceData::getHardwareNamePrefix); + if (StringUtils.isNotBlank(hardwareNamePrefix)) { + return UpdateResult.updated(hardwareNamePrefix); + } + final String model = getSafe(deviceData, DeviceData::getHardwareModel); if (StringUtils.isNotBlank(model)) { return UpdateResult.updated(model); @@ -284,6 +295,18 @@ private UpdateResult resolveDeviceId(Device device, DeviceData deviceDat : UpdateResult.unaltered(currentDeviceId); } + private UpdateResult resolveDeviceHwv(Device device, DeviceData deviceData) { + final String currentDeviceHwv = device.getHwv(); + if (StringUtils.isNotEmpty(currentDeviceHwv)) { + return UpdateResult.unaltered(currentDeviceHwv); + } + + final String deviceHwv = getSafe(deviceData, DeviceData::getHardwareNameVersion); + return StringUtils.isNotEmpty(deviceHwv) + ? UpdateResult.updated(deviceHwv) + : UpdateResult.unaltered(currentDeviceHwv); + } + private static boolean isPositive(Integer value) { return value != null && value > 0; } diff --git a/extra/modules/fiftyone-devicedetection/src/test/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricherTest.java b/extra/modules/fiftyone-devicedetection/src/test/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricherTest.java index 0aa2610f62c..ad7208e1237 100644 --- a/extra/modules/fiftyone-devicedetection/src/test/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricherTest.java +++ b/extra/modules/fiftyone-devicedetection/src/test/java/org/prebid/server/hooks/modules/fiftyone/devicedetection/v1/core/DeviceEnricherTest.java @@ -273,6 +273,7 @@ public void populateDeviceInfoShouldEnrichAllPropertiesWhenDeviceIsEmpty() throw "devicetype", "make", "model", + "hwv", "os", "osv", "h", @@ -335,6 +336,28 @@ public void populateDeviceInfoShouldEnrichMakeWhenItIsMissing() throws Exception assertThat(result.enrichedDevice().getMake()).isEqualTo(buildCompleteDevice().getMake()); } + @Test + public void populateDeviceInfoShouldEnrichModelWithHardwareNamePrefixWhenItIsMissing() throws Exception { + // given + final Device testDevice = buildCompleteDevice().toBuilder() + .model(null) + .build(); + final String expectedModel = "NinjaTech"; + when(deviceData.getHardwareNamePrefix()) + .thenReturn(aspectPropertyValueWith(expectedModel)); + when(deviceData.getHardwareModel()).thenThrow(new RuntimeException()); + + // when + final CollectedEvidence collectedEvidence = CollectedEvidence.builder() + .deviceUA("fake-UserAgent") + .build(); + final EnrichmentResult result = target.populateDeviceInfo(testDevice, collectedEvidence); + + // then + assertThat(result.enrichedFields()).hasSize(1); + assertThat(result.enrichedDevice().getModel()).isEqualTo(expectedModel); + } + @Test public void populateDeviceInfoShouldEnrichModelWithHWNameWhenHWModelIsMissing() throws Exception { // given @@ -366,6 +389,7 @@ public void populateDeviceInfoShouldEnrichModelWhenItIsMissing() throws Exceptio // when buildCompleteDeviceData(); + when(deviceData.getHardwareNamePrefix()).thenReturn(null); final CollectedEvidence collectedEvidence = CollectedEvidence.builder() .deviceUA("fake-UserAgent") .build(); @@ -376,6 +400,28 @@ public void populateDeviceInfoShouldEnrichModelWhenItIsMissing() throws Exceptio assertThat(result.enrichedDevice().getModel()).isEqualTo(buildCompleteDevice().getModel()); } + @Test + public void populateDeviceInfoShouldEnrichHwvWithHardwareNameVersionWhenItIsMissing() throws Exception { + // given + final Device testDevice = buildCompleteDevice().toBuilder() + .hwv(null) + .build(); + final String expectedHwv = "NinjaTech"; + when(deviceData.getHardwareNameVersion()) + .thenReturn(aspectPropertyValueWith(expectedHwv)); + when(deviceData.getHardwareModel()).thenReturn(null); + + // when + final CollectedEvidence collectedEvidence = CollectedEvidence.builder() + .deviceUA("fake-UserAgent") + .build(); + final EnrichmentResult result = target.populateDeviceInfo(testDevice, collectedEvidence); + + // then + assertThat(result.enrichedFields()).hasSize(1); + assertThat(result.enrichedDevice().getHwv()).isEqualTo(expectedHwv); + } + @Test public void populateDeviceInfoShouldEnrichOsWhenItIsMissing() throws Exception { // given @@ -534,6 +580,7 @@ private static Device buildCompleteDevice() { .devicetype(1) .make("StarFleet") .model("communicator") + .hwv("hmv") .os("NeutronAI") .osv("X-502") .h(5051) @@ -551,6 +598,8 @@ private void buildCompleteDeviceData() { when(deviceData.getHardwareVendor()).thenReturn(aspectPropertyValueWith("StarFleet")); when(deviceData.getHardwareModel()).thenReturn(aspectPropertyValueWith("communicator")); when(deviceData.getPlatformName()).thenReturn(aspectPropertyValueWith("NeutronAI")); + when(deviceData.getHardwareNamePrefix()).thenReturn(aspectPropertyValueWith("Prefix")); + when(deviceData.getHardwareNameVersion()).thenReturn(aspectPropertyValueWith("Version")); when(deviceData.getPlatformVersion()).thenReturn(aspectPropertyValueWith("X-502")); when(deviceData.getScreenPixelsHeight()).thenReturn(aspectPropertyValueWith(5051)); when(deviceData.getScreenPixelsWidth()).thenReturn(aspectPropertyValueWith(3001));