Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extra/modules/fiftyone-devicedetection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<description>51Degrees Device Detection module</description>

<properties>
<fiftyone-device-detection.version>4.4.226</fiftyone-device-detection.version>
<fiftyone-device-detection.version>4.5.51</fiftyone-device-detection.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ private EnrichmentResult patchDevice(Device device, DeviceData deviceData) {
updatedFields.add("model");
}

final UpdateResult<String> resolvedHwv = resolveDeviceHwv(device, deviceData);
if (resolvedHwv.isUpdated()) {
deviceBuilder.hwv(resolvedHwv.getValue());
updatedFields.add("hwv");
}

final UpdateResult<String> resolvedOs = resolveOs(device, deviceData);
if (resolvedOs.isUpdated()) {
deviceBuilder.os(resolvedOs.getValue());
Expand Down Expand Up @@ -184,6 +190,11 @@ private UpdateResult<String> 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);
Expand Down Expand Up @@ -284,6 +295,18 @@ private UpdateResult<String> resolveDeviceId(Device device, DeviceData deviceDat
: UpdateResult.unaltered(currentDeviceId);
}

private UpdateResult<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public void populateDeviceInfoShouldEnrichAllPropertiesWhenDeviceIsEmpty() throw
"devicetype",
"make",
"model",
"hwv",
"os",
"osv",
"h",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -534,6 +580,7 @@ private static Device buildCompleteDevice() {
.devicetype(1)
.make("StarFleet")
.model("communicator")
.hwv("hmv")
.os("NeutronAI")
.osv("X-502")
.h(5051)
Expand All @@ -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));
Expand Down
Loading