From 9d0a379ff43784053a7e2dfef3496d6fa199c4b2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Fri, 12 Jun 2026 10:42:21 +0100 Subject: [PATCH 1/3] Merged Pull Request '#121 feature/align-environment-variables->main: Align resource key and data file environment variables' Test helpers now check the aligned 51DEGREES_RESOURCE_KEY name (environment variable or system property) before the legacy TestResourceKey, and the aligned 51DEGREES_IPI_PATH name before searching the project space for a data file. Developer-facing messages and the README now reference the aligned names. Co-authored-by: Claude Fable 5 --- README.md | 14 +++++++++ .../ipintelligence/cloud/WrapperCloud.java | 2 +- .../shared/testhelpers/FileUtils.java | 31 +++++++++++++++++++ .../shared/testhelpers/KeyUtils.java | 23 ++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4233d898..e13aac4b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,13 @@ data file. [ip-intelligence-data](https://github.com/51Degrees/ip-intelligence-data/) repository instructs how to obtain a 'Lite' data file, otherwise [contact us](https://51degrees.com/contact-us) to obtain an 'Enterprise' data file. +For tests, the data file can be supplied explicitly by setting the +`51DEGREES_IPI_PATH` environment variable or system property to the path of +the .ipi file. When it is not set, the project space is searched for the +expected file name, with the free 'Lite' file expected in the +[ip-intelligence-data](https://github.com/51Degrees/ip-intelligence-data/) +location. + ## Installation Our latest release is available as compiled JARs on Maven - or you can compile from source as described below. @@ -105,6 +112,13 @@ repository. You will need [resource keys](https://51degrees.com/documentation/_info__resource_keys.html) (see above) to complete the tests and run examples which include exercising the cloud API. +The tests look for a resource key in the following order: + +1. The aligned `51DEGREES_RESOURCE_KEY` name, set as an environment variable + or as a system property. +2. The legacy `TestResourceKey` name, which is still supported and is checked + after the aligned name. + To verify the code: ``` diff --git a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/WrapperCloud.java b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/WrapperCloud.java index 892d5cb1..d4c68b57 100644 --- a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/WrapperCloud.java +++ b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/WrapperCloud.java @@ -47,7 +47,7 @@ public class WrapperCloud implements Closeable { public WrapperCloud() throws Exception { cloudRequestEngine = new CloudRequestEngineBuilder(loggerFactory) - .setResourceKey(KeyUtils.getNamedKey("TestResourceKey")) + .setResourceKey(KeyUtils.getResourceKey("TestResourceKey")) .build(); IPIntelligenceCloudEngine = new IPIntelligenceCloudEngineBuilder(loggerFactory) .build(); diff --git a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java index 41cd5794..b15109d0 100644 --- a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java +++ b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java @@ -38,6 +38,13 @@ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class FileUtils { + /** + * Name of the aligned environment variable or system property which can + * supply an explicit path to the IPI data file. When set and the file + * exists it is used in preference to searching the project space. + */ + public static final String IPI_PATH_ENV_VAR = "51DEGREES_IPI_PATH"; + public static final String ENTERPRISE_IPI_DATA_FILE_NAME = "Enterprise-IpIntelligenceV41.ipi"; public static final String ENTERPRISE_IPI_V41_DATA_FILE_NAME = "51Degrees-EnterpriseIpiV41.ipi"; @@ -63,6 +70,10 @@ public static String getHashFileName() { * @return a file or empty if not found */ public static File getHashFile() { + File explicitFile = getExplicitHashFile(); + if (Objects.nonNull(explicitFile)) { + return explicitFile; + } try { if (Objects.nonNull(IPI_DATA_FILE)){ return IPI_DATA_FILE.orElse(null); @@ -88,6 +99,26 @@ public static File getHashFile() { } } + /** + * Check the aligned {@link #IPI_PATH_ENV_VAR} environment variable and + * system property for an explicit path to the IPI data file. + * + * @return a file if the path is set and the file exists, otherwise null + */ + private static File getExplicitHashFile() { + String explicitPath = System.getenv(IPI_PATH_ENV_VAR); + if (Objects.isNull(explicitPath)) { + explicitPath = System.getProperty(IPI_PATH_ENV_VAR); + } + if (Objects.nonNull(explicitPath)) { + File explicitFile = new File(explicitPath); + if (explicitFile.exists()) { + return explicitFile; + } + } + return null; + } + public static File getEvidenceFile() { if (Objects.nonNull(EVIDENCE_FILE)) { return EVIDENCE_FILE.orElse(null); diff --git a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/KeyUtils.java b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/KeyUtils.java index df2d1ac6..cabb6648 100644 --- a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/KeyUtils.java +++ b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/KeyUtils.java @@ -29,6 +29,29 @@ * Helpers to obtain keys from the environment */ public class KeyUtils { + /** + * Name of the aligned environment variable or system property which + * supplies the resource key. This name is checked before any legacy name. + */ + public static final String RESOURCE_KEY_ENV_VAR = "51DEGREES_RESOURCE_KEY"; + + /** + * Obtain a resource key from an environment variable or a system property. + *

+ * The aligned name {@link #RESOURCE_KEY_ENV_VAR} is checked first and the + * supplied legacy name is checked second. Each name is looked up using + * {@link #getNamedKey(String)}. + * @param legacyKeyName legacy name to try when the aligned name is not set + * @return the resource key, or null if neither name is set + */ + public static String getResourceKey(String legacyKeyName) { + String resourceKey = getNamedKey(RESOURCE_KEY_ENV_VAR); + if (Objects.isNull(resourceKey)) { + resourceKey = getNamedKey(legacyKeyName); + } + return resourceKey; + } + /** * Obtain a key either from environment variable or from a property. *

From 1e6951c5b745c01f0b13bd0406b35834a4cf41b6 Mon Sep 17 00:00:00 2001 From: James Rogers Date: Fri, 12 Jun 2026 13:03:38 +0100 Subject: [PATCH 2/3] FEAT/CLEANUP: Several identifiers, class names, test utilities, comments, and constants were ported verbatim from device-detection-java and still reference device-detection-specific concepts (Hash algorithm, User-Agent, Client Hints, TAC) that have no relevance to IP Intelligence. Change where appropriate and deprecate items that aren't relevenat to ipi and aren't core to the solution. --- .github/workflows/data-file-change.yml | 2 +- .github/workflows/nightly-pipeline.yml | 2 +- ci/README.md | 8 +- .../cloud/data/MultiIPIDataCloud.java | 15 +- .../HardwareProfileCloudEngine.java | 4 + .../HardwareProfileCloudEngineBuilder.java | 7 + .../ipintelligence/cloud/TestsBase.java | 10 +- .../cloud/data/ValueCloudTests.java | 3 - .../engine/onpremise/Enums.java | 12 +- .../data/IPIntelligenceDataHash.java | 23 +- .../data/IPIntelligenceDataOnPremise.java | 27 +- .../IPIntelligenceDataHashDefault.java | 370 +---------------- .../IPIntelligenceDataOnPremiseDefault.java | 393 ++++++++++++++++++ .../IPIntelligenceOnPremiseEngine.java | 20 +- .../IPIntelligenceOnPremiseEngineBuilder.java | 25 +- .../engine/onpremise/AutoCloseable.java | 4 +- .../engine/onpremise/TestsBase.java | 18 +- ...WrapperHash.java => WrapperOnPremise.java} | 4 +- ...rHash.java => DataValidatorOnPremise.java} | 4 +- ...Hash.java => MetaDataHasherOnPremise.java} | 2 +- ...Tests.java => MetaDataOnPremiseTests.java} | 14 +- ...ashTests.java => ValueOnPremiseTests.java} | 10 +- .../onpremise/flowelements/EngineTests.java | 4 +- .../flowelements/EvidenceKeysTests.java | 8 +- .../flowelements/IPIntelligenceDataTests.java | 28 +- .../flowelements/TestProcessTests.java | 22 +- .../ipintelligence/shared/Constants.java | 14 + .../shared/testhelpers/FileUtils.java | 31 +- .../ClientHintsExampleTestBase.java | 80 ---- ...Generator.java => IpAddressGenerator.java} | 24 +- .../flowelements/ProcessTests.java | 2 +- ...PIntelligenceOnPremisePipelineBuilder.java | 8 +- .../CloudRequestOriginTests.java | 6 +- ...elligenceOnPremisePipelineBuilderTest.java | 2 +- .../ipintelligence/IPIntelligenceTests.java | 24 +- 35 files changed, 624 insertions(+), 606 deletions(-) rename ip-intelligence/src/main/java/fiftyone/ipintelligence/Enums.java => ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataOnPremise.java (56%) create mode 100644 ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataOnPremiseDefault.java rename ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/{WrapperHash.java => WrapperOnPremise.java} (95%) rename ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/{DataValidatorHash.java => DataValidatorOnPremise.java} (95%) rename ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/{MetaDataHasherHash.java => MetaDataHasherOnPremise.java} (98%) rename ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/{MetaDataHashTests.java => MetaDataOnPremiseTests.java} (90%) rename ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/{ValueHashTests.java => ValueOnPremiseTests.java} (85%) delete mode 100644 ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/ClientHintsExampleTestBase.java rename ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/{UserAgentGenerator.java => IpAddressGenerator.java} (81%) diff --git a/.github/workflows/data-file-change.yml b/.github/workflows/data-file-change.yml index 313460ba..70cf63c9 100644 --- a/.github/workflows/data-file-change.yml +++ b/.github/workflows/data-file-change.yml @@ -17,5 +17,5 @@ jobs: data-filename: "51Degrees-EnterpriseV4.ipi.gz" secrets: token: ${{ secrets.ACCESS_TOKEN }} - data-key: ${{ secrets.DEVICE_DETECTION_KEY }} + data-key: ${{ secrets.IP_INTELLIGENCE_KEY }} data-url: ${{ secrets.IPI_DATA_FILE_URL }} diff --git a/.github/workflows/nightly-pipeline.yml b/.github/workflows/nightly-pipeline.yml index 672eaf19..568e77dd 100644 --- a/.github/workflows/nightly-pipeline.yml +++ b/.github/workflows/nightly-pipeline.yml @@ -22,7 +22,7 @@ jobs: data-filename: "51Degrees-EnterpriseV4.ipi.gz" secrets: token: ${{ secrets.ACCESS_TOKEN }} - data-key: ${{ secrets.DEVICE_DETECTION_KEY }} + data-key: ${{ secrets.IP_INTELLIGENCE_KEY }} data-url: ${{ secrets.IPI_DATA_FILE_URL }} PackageUpdate: diff --git a/ci/README.md b/ci/README.md index f9800088..1e698aa3 100644 --- a/ci/README.md +++ b/ci/README.md @@ -6,7 +6,7 @@ The following secrets are required: * Example: `github_pat_l0ng_r4nd0m_s7r1ng` The following secrets are required to run on-premise tests: -* `DEVICE_DETECTION_KEY` - [license key](https://51degrees.com/pricing) for downloading assets (enterprise IPI data file) +* `IP_INTELLIGENCE_KEY` - [license key](https://51degrees.com/pricing) for downloading assets (enterprise IPI data file) * Example: `V3RYL0NGR4ND0M57R1NG` The following secrets are requred to run cloud tests: @@ -22,8 +22,8 @@ The following secrets are required for publishing releases (this should only be * `CODE_SIGNING_CERT_PASSWORD` - Password for the `CODE_SIGNING_CERT` The following secrets are optional: -* `DEVICE_DETECTION_URL` - URL for downloading the enterprise TAC hash file - * Default: `https://distributor.51degrees.com/api/v2/download?LicenseKeys=DEVICE_DETECTION_KEY&Type=HashV41&Download=True&Product=V4TAC` +* `IPI_DATA_FILE_URL` - URL for downloading the enterprise IP Intelligence data file + * Default: `https://distributor.51degrees.com/api/v2/download?LicenseKeys=IP_INTELLIGENCE_KEY&Type=IPIV41&Download=True&Product=IPIV4Enterprise` ## Integration Tests @@ -48,7 +48,7 @@ graph TD It performs the following steps: 1. Clone Examples Repo: Clone the "ip-intelligence-java-examples" repository into the common-ci directory. -3. Set up test files: Move the 51Degrees-EnterpriseIpiV41.ipi file to the ip-intelligence-java-examples/ip-intelligence-data directory and download Evidence and User-Agent files into ip-intelligence-data directory. +3. Set up test files: Move the 51Degrees-EnterpriseIpiV41.ipi file to the ip-intelligence-java-examples/ip-intelligence-data directory and download evidence files into ip-intelligence-data directory. 4. Enter ip-intelligence-examples directory: Changes the current working directory to the ip-intelligence-java-examples folder. 5. Set package dependency version: Sets the version of the ip-intelligence package dependency for the examples to the specified Version parameter. This will be the version installed in the local repository found in the .m2 folder. 6. Test Examples: Runs the Maven clean test command, passing the TestResourceKey, SuperResourceKey, and LicenseKey as parameters. diff --git a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/data/MultiIPIDataCloud.java b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/data/MultiIPIDataCloud.java index cf0dba4c..c143de4b 100644 --- a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/data/MultiIPIDataCloud.java +++ b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/data/MultiIPIDataCloud.java @@ -38,12 +38,17 @@ /** * Encapsulates a list of {@link IPIntelligenceData} instances which can be returned - * by the 51Degrees Cloud service when certain evidence is provided (e.g. TAC) + * by the 51Degrees Cloud service when the evidence provided matches more than + * one profile. + * @deprecated multi-profile responses (e.g. hardware profile lookup) are a + * device detection feature and have no equivalent in IP Intelligence. This + * class will be removed in a future version. */ +@Deprecated public class MultiIPIDataCloud extends AspectDataBase implements MultiProfileData { - private static final String DEVICE_LIST_KEY = "profiles"; + private static final String PROFILE_LIST_KEY = "profiles"; /** * Constructs a new instance with a non-thread-safe, case-insensitive @@ -58,7 +63,7 @@ public MultiIPIDataCloud( FlowData flowData, AspectEngine engine) { super(logger, flowData, engine); - this.put(DEVICE_LIST_KEY, new ArrayList()); + this.put(PROFILE_LIST_KEY, new ArrayList()); } /** @@ -77,7 +82,7 @@ public MultiIPIDataCloud( AspectEngine engine, MissingPropertyService missingPropertyService) { super(logger, flowData, engine, missingPropertyService); - this.put(DEVICE_LIST_KEY, new ArrayList()); + this.put(PROFILE_LIST_KEY, new ArrayList()); } @Override @@ -96,6 +101,6 @@ public void addProfile(IPIntelligenceData profile) { */ @SuppressWarnings("unchecked") private List getDeviceList() { - return (List)this.get(DEVICE_LIST_KEY); + return (List)this.get(PROFILE_LIST_KEY); } } diff --git a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngine.java b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngine.java index 35d7a581..6f383329 100644 --- a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngine.java +++ b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngine.java @@ -35,7 +35,11 @@ * Engine that takes the JSON response from the {@link CloudRequestEngine} and * uses it populate a {@link MultiIPIDataCloud} instance for easier consumption. * @see Specification + * @deprecated hardware profile lookup is a device detection feature and has + * no equivalent in IP Intelligence. This engine will be removed in a future + * version. */ +@Deprecated public class HardwareProfileCloudEngine extends PropertyKeyedCloudEngineBase { diff --git a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngineBuilder.java b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngineBuilder.java index eaf1fabe..18ec6a3c 100644 --- a/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngineBuilder.java +++ b/ip-intelligence.cloud/src/main/java/fiftyone/ipintelligence/cloud/flowelements/HardwareProfileCloudEngineBuilder.java @@ -35,6 +35,13 @@ import java.util.List; +/** + * Builder for the {@link HardwareProfileCloudEngine}. + * @deprecated hardware profile lookup is a device detection feature and has + * no equivalent in IP Intelligence. This builder will be removed in a future + * version. + */ +@Deprecated @ElementBuilder public class HardwareProfileCloudEngineBuilder extends AspectEngineBuilderBase< HardwareProfileCloudEngineBuilder, diff --git a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/TestsBase.java b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/TestsBase.java index 2887e503..3bda7e26 100644 --- a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/TestsBase.java +++ b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/TestsBase.java @@ -22,7 +22,7 @@ package fiftyone.ipintelligence.cloud; -import fiftyone.ipintelligence.shared.testhelpers.UserAgentGenerator; +import fiftyone.ipintelligence.shared.testhelpers.IpAddressGenerator; import fiftyone.pipeline.util.FileFinder; import static fiftyone.ipintelligence.shared.testhelpers.FileUtils.IP_ADDRESSES_FILE_NAME; @@ -30,19 +30,19 @@ public class TestsBase { private WrapperCloud wrapper = null; - private UserAgentGenerator userAgents; + private IpAddressGenerator ipAddresses; protected WrapperCloud getWrapper() { return wrapper; } - protected UserAgentGenerator getUserAgents() { - return userAgents; + protected IpAddressGenerator getIpAddresses() { + return ipAddresses; } protected void testInitialize() throws Exception { wrapper = new WrapperCloud(); - userAgents = new UserAgentGenerator( + ipAddresses = new IpAddressGenerator( FileFinder.getFilePath(IP_ADDRESSES_FILE_NAME)); } diff --git a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/data/ValueCloudTests.java b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/data/ValueCloudTests.java index 3c70c65f..d7b969b4 100644 --- a/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/data/ValueCloudTests.java +++ b/ip-intelligence.cloud/src/test/java/fiftyone/ipintelligence/cloud/data/ValueCloudTests.java @@ -24,7 +24,6 @@ import fiftyone.ipintelligence.cloud.TestsBase; import fiftyone.ipintelligence.cloud.ValueTests; -import fiftyone.ipintelligence.shared.testhelpers.UserAgentGenerator; import org.junit.After; import org.junit.Before; @@ -34,8 +33,6 @@ @Ignore public class ValueCloudTests extends TestsBase { - private UserAgentGenerator userAgents; - @Before public void init() throws Exception { testInitialize(); diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/Enums.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/Enums.java index 4acf48bd..805e0596 100644 --- a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/Enums.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/Enums.java @@ -22,10 +22,20 @@ package fiftyone.ipintelligence.engine.onpremise; +/** + * @deprecated match methods are a device detection (Hash algorithm) concept + * and are not used by IP Intelligence. This class will be removed in a + * future version. + */ +@Deprecated public class Enums { /** - * Enumeration of possible match methods used by the Hash engine. + * Enumeration of possible match methods used by the device detection + * Hash engine. + * @deprecated not used by IP Intelligence; will be removed in a future + * version. */ + @Deprecated public enum MatchMethods { NONE, PERFORMANCE, diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataHash.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataHash.java index a28d0fbe..14796052 100644 --- a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataHash.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataHash.java @@ -23,23 +23,14 @@ package fiftyone.ipintelligence.engine.onpremise.data; import fiftyone.ipintelligence.shared.IPIntelligenceData; -import fiftyone.pipeline.engines.data.AspectPropertyValue; - -import java.util.List; /** * On-premise specific interface for {@link IPIntelligenceData}. - * @see Specification + * @deprecated "Hash" refers to the device detection algorithm and has no + * meaning for IP Intelligence. Use {@link IPIntelligenceDataOnPremise} + * instead; this interface only remains for backward compatibility and will + * be removed in a future version. */ -public interface IPIntelligenceDataHash extends IPIntelligenceData { - - /** - * Get the values for the specified property as a List<>. - * @param propertyName name of the property to get values for - * @param parametrizedTypes types parametrizing {@link AspectPropertyValue} starting with {@link List} - * @return values as a list - */ - AspectPropertyValue> getValues( - String propertyName, - Class[] parametrizedTypes); -} \ No newline at end of file +@Deprecated +public interface IPIntelligenceDataHash extends IPIntelligenceDataOnPremise { +} diff --git a/ip-intelligence/src/main/java/fiftyone/ipintelligence/Enums.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataOnPremise.java similarity index 56% rename from ip-intelligence/src/main/java/fiftyone/ipintelligence/Enums.java rename to ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataOnPremise.java index 72201630..0d25fdb8 100644 --- a/ip-intelligence/src/main/java/fiftyone/ipintelligence/Enums.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/data/IPIntelligenceDataOnPremise.java @@ -20,15 +20,26 @@ * such notice(s) shall fulfill the requirements of that article. * ********************************************************************* */ -package fiftyone.ipintelligence; +package fiftyone.ipintelligence.engine.onpremise.data; + +import fiftyone.ipintelligence.shared.IPIntelligenceData; +import fiftyone.pipeline.engines.data.AspectPropertyValue; + +import java.util.List; /** - * @deprecated no longer needed since IP Intelligence uses a different algorithm than device detection + * On-premise specific interface for {@link IPIntelligenceData}. + * @see Specification */ -@Deprecated -public class Enums { - public enum IPIntelligenceAlgorithm { - Hash, - Pattern - } +public interface IPIntelligenceDataOnPremise extends IPIntelligenceData { + + /** + * Get the values for the specified property as a List<>. + * @param propertyName name of the property to get values for + * @param parametrizedTypes types parametrizing {@link AspectPropertyValue} starting with {@link List} + * @return values as a list + */ + AspectPropertyValue> getValues( + String propertyName, + Class[] parametrizedTypes); } diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataHashDefault.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataHashDefault.java index 572d174d..4745a6a7 100644 --- a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataHashDefault.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataHashDefault.java @@ -22,69 +22,21 @@ package fiftyone.ipintelligence.engine.onpremise.flowelements; -import fiftyone.ipintelligence.engine.onpremise.Enums; -import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataHash; -import fiftyone.ipintelligence.engine.onpremise.interop.swig.*; -import fiftyone.ipintelligence.shared.IPIntelligenceDataBaseOnPremise; import fiftyone.pipeline.core.data.FlowData; -import fiftyone.pipeline.core.data.IWeightedValue; -import fiftyone.pipeline.core.data.TryGetResult; -import fiftyone.pipeline.core.data.WeightedValue; -import fiftyone.pipeline.core.data.types.JavaScript; -import fiftyone.pipeline.engines.data.AspectPropertyValue; -import fiftyone.pipeline.engines.data.AspectPropertyValueDefault; import fiftyone.pipeline.engines.services.MissingPropertyService; import org.slf4j.Logger; -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Collectors; - /** - * Internal implementation of the {@link IPIntelligenceDataHash} interface. This can - * only be constructed by the {@link IPIntelligenceOnPremiseEngine}. - * @see Specification + * Internal implementation of the on-premise element data. This can only be + * constructed by the {@link IPIntelligenceOnPremiseEngine}. + * @deprecated "Hash" refers to the device detection algorithm and has no + * meaning for IP Intelligence. Use {@link IPIntelligenceDataOnPremiseDefault} + * instead; this class only remains for backward compatibility and will be + * removed in a future version. */ -public class IPIntelligenceDataHashDefault - extends IPIntelligenceDataBaseOnPremise - implements IPIntelligenceDataHash, AutoCloseable { - - /** - * True if the {@link #close()} method has been called. - */ - private boolean closed = false; - - /** - * Pre-populated list of match methods. This to avoid calling the - * '.values()' method every time. - */ - private static final Enums.MatchMethods[] matchMethods = - Enums.MatchMethods.values(); - - /** - * List of native results which make up this result instance. Usually, this - * will only be one. - */ - private final List resultsList = new ArrayList<>(); +@Deprecated +public class IPIntelligenceDataHashDefault extends IPIntelligenceDataOnPremiseDefault { - /** - * Constructs a new instance. - * @param logger used for logging - * @param flowData the {@link FlowData} instance this element data will be - * associated with - * @param engine the engine which created the instance - * @param missingPropertyService service used to determine the reason for - * a property value being missing - */ IPIntelligenceDataHashDefault( Logger logger, FlowData flowData, @@ -92,308 +44,4 @@ public class IPIntelligenceDataHashDefault MissingPropertyService missingPropertyService) { super(logger, flowData, engine, missingPropertyService); } - - /** - * Add the native results to the list of results contained in this instance. - * @param results the results to add - */ - void setResults(ResultsIpiSwig results) { - checkState(); - resultsList.add(results); - } - - /** - * Get a single native results instance. If there is only one available, - * that is what is returned. If there are more, then the first one which - * contains values for the requested property is returned. - * @param propertyName used to select results from list - * @return single native results instance - */ - private ResultsIpiSwig getSingleResults(String propertyName) { - return resultsList.size() == 1 ? - resultsList.get(0) : getResultsContainingProperty(propertyName); - } - - /** - * Get the first native results in {@link #resultsList} which contains - * values for the requested property. - * @param propertyName name of the requested property - * @return native results containing values, or null if none were found - */ - private ResultsIpiSwig getResultsContainingProperty(String propertyName) { - for (ResultsIpiSwig results : resultsList) { - if (results.containsProperty(propertyName)) { - return results; - } - } - return null; - } - - @Override - protected boolean propertyIsAvailable(String propertyName) { - checkState(); - for (ResultsIpiSwig results : resultsList) { - if (results.containsProperty(propertyName)) { - return true; - } - } - return false; - } - - private static < - TListValueSwig extends AutoCloseable, - TListSwig extends AutoCloseable & List, - TWeightedValueSwig, - TElement> - void populateWeightedValues( - AspectPropertyValue> result, - Supplier listValueSwigSupplier, - Predicate listValueSwigHasValue, - Function listValueSwigGetNoValueMessage, - Function listSwigExtractor, - Function elementConverter) { - try (TListValueSwig listValueSwig = listValueSwigSupplier.get()) - { - if (listValueSwigHasValue.test(listValueSwig)) { - try (TListSwig listSwig = listSwigExtractor.apply(listValueSwig)) { - List convertedWeightedElements = listSwig.stream() - .map(elementConverter) - .collect(Collectors.toList()); - result.setValue(Collections.unmodifiableList(convertedWeightedElements)); - } - } - else { - result.setNoValueMessage(listValueSwigGetNoValueMessage.apply(listValueSwig)); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public AspectPropertyValue> getValues(String propertyName, - Class[] parametrizedTypes) { - checkState(); - AspectPropertyValue> result = - new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results == null) { - return result; - } - if (parametrizedTypes.length < 2) { - return null; - } - Class listedType = parametrizedTypes[1]; - boolean isWeighted = listedType.equals(IWeightedValue.class) || listedType.equals(WeightedValue.class); - if (!isWeighted) { - return null; - } - if (parametrizedTypes.length < 3) { - return null; - } - Class valueType = parametrizedTypes[2]; - if (valueType.equals(Boolean.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedBoolList(propertyName), - WeightedBoolListValueSwig::hasValue, - WeightedBoolListValueSwig::getNoValueMessage, - WeightedBoolListValueSwig::getValue, - x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) - ); - } else if (valueType.equals(Double.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedDoubleList(propertyName), - WeightedDoubleListValueSwig::hasValue, - WeightedDoubleListValueSwig::getNoValueMessage, - WeightedDoubleListValueSwig::getValue, - x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) - ); - } else if (valueType.equals(Float.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedDoubleList(propertyName), - WeightedDoubleListValueSwig::hasValue, - WeightedDoubleListValueSwig::getNoValueMessage, - WeightedDoubleListValueSwig::getValue, - x -> new WeightedValue<>(x.getShortRawWeight(), (float)x.getValue()) - ); - } else if (valueType.equals(Integer.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedIntegerList(propertyName), - WeightedIntListValueSwig::hasValue, - WeightedIntListValueSwig::getNoValueMessage, - WeightedIntListValueSwig::getValue, - x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) - ); - } else if (valueType.equals(InetAddress.class) - || valueType.equals(Inet4Address.class) - || valueType.equals(Inet6Address.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedStringList(propertyName), - WeightedStringListValueSwig::hasValue, - WeightedStringListValueSwig::getNoValueMessage, - WeightedStringListValueSwig::getValue, - x -> { - try { - return new WeightedValue<>(x.getShortRawWeight(), InetAddress.getByName(x.getValue())); - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } - } - ); - } else if (valueType.equals(String.class)) { - populateWeightedValues( - result, - () -> results.getValuesAsWeightedUTF8StringList(propertyName), - WeightedUTF8StringListValueSwig::hasValue, - WeightedUTF8StringListValueSwig::getNoValueMessage, - WeightedUTF8StringListValueSwig::getValue, - x -> { - String theString; - try (UTF8StringSwig stringSwig = x.getValue()) { - byte[] bytes = new byte[stringSwig.size()]; - for (int i = 0; i < stringSwig.size(); i++) { - bytes[i] = (byte)(short)stringSwig.get(i); - } - theString = new String(bytes, StandardCharsets.UTF_8); - } - return new WeightedValue<>(x.getShortRawWeight(), theString); - } - ); - } else { - throw new IllegalArgumentException("Unsupported value type: " + valueType.getName()); - } - return result; - } - - @Override - protected AspectPropertyValue getValueAsString(String propertyName) { - AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results != null) { - - try (StringValueSwig value = results.getValueAsString( - propertyName)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); - } - } - } - return result; - } - - @Override - protected AspectPropertyValue getValueAsJavaScript( - String propertyName) { - AspectPropertyValue result = - new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results != null) { - try (StringValueSwig value = results.getValueAsString( - propertyName)) { - if (value.hasValue()) { - result.setValue(new JavaScript(value.getValue())); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); - } - } - } - return result; - } - - @Override - protected AspectPropertyValue getValueAsInteger( - String propertyName) { - AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results != null) { - try (IntegerValueSwig value = results.getValueAsInteger( - propertyName)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); - } - } - } - return result; - } - - @Override - protected AspectPropertyValue getValueAsBool(String propertyName) { - AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results != null) { - try (BoolValueSwig value = results.getValueAsBool( - propertyName)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); - } - } - } - return result; - } - - @Override - protected AspectPropertyValue getValueAsDouble(String propertyName) { - AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsIpiSwig results = getSingleResults(propertyName); - if (results != null) { - try (DoubleValueSwig value = results.getValueAsDouble( - propertyName)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); - } - } - } - return result; - } - - @Override - protected TryGetResult tryGetValue( - String key, - Class type, - Class... parameterisedTypes) { - checkState(); - return super.tryGetValue(key, type, parameterisedTypes); - } - - private void checkState() { - if (closed) { - throw new IllegalStateException("The IPIntelligenceDataHash instance has " + - "been closed, and cannot be used. Any result processing should " + - "be carried out within a 'try-with-resource' block which " + - "closes the FlowData and any AutoCloseable elements."); - } - } - - @Override - public void close() { - closed = true; - for (ResultsIpiSwig result : resultsList) { - try { - result.close(); - } catch (Exception e) { - logger.error("Failed to close native results instance. " + - "A IPIntelligenceDataHash instance contains native unmanaged " + - "memory which needs to be closed. Failing to close " + - "could lead to memory leaks.", e); - } - } - } -} \ No newline at end of file +} diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataOnPremiseDefault.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataOnPremiseDefault.java new file mode 100644 index 00000000..238da0e0 --- /dev/null +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataOnPremiseDefault.java @@ -0,0 +1,393 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.ipintelligence.engine.onpremise.flowelements; + +import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataHash; +import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataOnPremise; +import fiftyone.ipintelligence.engine.onpremise.interop.swig.*; +import fiftyone.ipintelligence.shared.IPIntelligenceDataBaseOnPremise; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.core.data.IWeightedValue; +import fiftyone.pipeline.core.data.TryGetResult; +import fiftyone.pipeline.core.data.WeightedValue; +import fiftyone.pipeline.core.data.types.JavaScript; +import fiftyone.pipeline.engines.data.AspectPropertyValue; +import fiftyone.pipeline.engines.data.AspectPropertyValueDefault; +import fiftyone.pipeline.engines.services.MissingPropertyService; +import org.slf4j.Logger; + +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Internal implementation of the {@link IPIntelligenceDataOnPremise} interface. + * This can only be constructed by the {@link IPIntelligenceOnPremiseEngine}. + * @see Specification + */ +@SuppressWarnings("deprecation") +public class IPIntelligenceDataOnPremiseDefault + extends IPIntelligenceDataBaseOnPremise + implements IPIntelligenceDataHash, AutoCloseable { + + /** + * True if the {@link #close()} method has been called. + */ + private boolean closed = false; + + /** + * List of native results which make up this result instance. Usually, this + * will only be one. + */ + private final List resultsList = new ArrayList<>(); + + /** + * Constructs a new instance. + * @param logger used for logging + * @param flowData the {@link FlowData} instance this element data will be + * associated with + * @param engine the engine which created the instance + * @param missingPropertyService service used to determine the reason for + * a property value being missing + */ + IPIntelligenceDataOnPremiseDefault( + Logger logger, + FlowData flowData, + IPIntelligenceOnPremiseEngine engine, + MissingPropertyService missingPropertyService) { + super(logger, flowData, engine, missingPropertyService); + } + + /** + * Add the native results to the list of results contained in this instance. + * @param results the results to add + */ + void setResults(ResultsIpiSwig results) { + checkState(); + resultsList.add(results); + } + + /** + * Get a single native results instance. If there is only one available, + * that is what is returned. If there are more, then the first one which + * contains values for the requested property is returned. + * @param propertyName used to select results from list + * @return single native results instance + */ + private ResultsIpiSwig getSingleResults(String propertyName) { + return resultsList.size() == 1 ? + resultsList.get(0) : getResultsContainingProperty(propertyName); + } + + /** + * Get the first native results in {@link #resultsList} which contains + * values for the requested property. + * @param propertyName name of the requested property + * @return native results containing values, or null if none were found + */ + private ResultsIpiSwig getResultsContainingProperty(String propertyName) { + for (ResultsIpiSwig results : resultsList) { + if (results.containsProperty(propertyName)) { + return results; + } + } + return null; + } + + @Override + protected boolean propertyIsAvailable(String propertyName) { + checkState(); + for (ResultsIpiSwig results : resultsList) { + if (results.containsProperty(propertyName)) { + return true; + } + } + return false; + } + + private static < + TListValueSwig extends AutoCloseable, + TListSwig extends AutoCloseable & List, + TWeightedValueSwig, + TElement> + void populateWeightedValues( + AspectPropertyValue> result, + Supplier listValueSwigSupplier, + Predicate listValueSwigHasValue, + Function listValueSwigGetNoValueMessage, + Function listSwigExtractor, + Function elementConverter) { + try (TListValueSwig listValueSwig = listValueSwigSupplier.get()) + { + if (listValueSwigHasValue.test(listValueSwig)) { + try (TListSwig listSwig = listSwigExtractor.apply(listValueSwig)) { + List convertedWeightedElements = listSwig.stream() + .map(elementConverter) + .collect(Collectors.toList()); + result.setValue(Collections.unmodifiableList(convertedWeightedElements)); + } + } + else { + result.setNoValueMessage(listValueSwigGetNoValueMessage.apply(listValueSwig)); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public AspectPropertyValue> getValues(String propertyName, + Class[] parametrizedTypes) { + checkState(); + AspectPropertyValue> result = + new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results == null) { + return result; + } + if (parametrizedTypes.length < 2) { + return null; + } + Class listedType = parametrizedTypes[1]; + boolean isWeighted = listedType.equals(IWeightedValue.class) || listedType.equals(WeightedValue.class); + if (!isWeighted) { + return null; + } + if (parametrizedTypes.length < 3) { + return null; + } + Class valueType = parametrizedTypes[2]; + if (valueType.equals(Boolean.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedBoolList(propertyName), + WeightedBoolListValueSwig::hasValue, + WeightedBoolListValueSwig::getNoValueMessage, + WeightedBoolListValueSwig::getValue, + x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) + ); + } else if (valueType.equals(Double.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedDoubleList(propertyName), + WeightedDoubleListValueSwig::hasValue, + WeightedDoubleListValueSwig::getNoValueMessage, + WeightedDoubleListValueSwig::getValue, + x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) + ); + } else if (valueType.equals(Float.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedDoubleList(propertyName), + WeightedDoubleListValueSwig::hasValue, + WeightedDoubleListValueSwig::getNoValueMessage, + WeightedDoubleListValueSwig::getValue, + x -> new WeightedValue<>(x.getShortRawWeight(), (float)x.getValue()) + ); + } else if (valueType.equals(Integer.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedIntegerList(propertyName), + WeightedIntListValueSwig::hasValue, + WeightedIntListValueSwig::getNoValueMessage, + WeightedIntListValueSwig::getValue, + x -> new WeightedValue<>(x.getShortRawWeight(), x.getValue()) + ); + } else if (valueType.equals(InetAddress.class) + || valueType.equals(Inet4Address.class) + || valueType.equals(Inet6Address.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedStringList(propertyName), + WeightedStringListValueSwig::hasValue, + WeightedStringListValueSwig::getNoValueMessage, + WeightedStringListValueSwig::getValue, + x -> { + try { + return new WeightedValue<>(x.getShortRawWeight(), InetAddress.getByName(x.getValue())); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + ); + } else if (valueType.equals(String.class)) { + populateWeightedValues( + result, + () -> results.getValuesAsWeightedUTF8StringList(propertyName), + WeightedUTF8StringListValueSwig::hasValue, + WeightedUTF8StringListValueSwig::getNoValueMessage, + WeightedUTF8StringListValueSwig::getValue, + x -> { + String theString; + try (UTF8StringSwig stringSwig = x.getValue()) { + byte[] bytes = new byte[stringSwig.size()]; + for (int i = 0; i < stringSwig.size(); i++) { + bytes[i] = (byte)(short)stringSwig.get(i); + } + theString = new String(bytes, StandardCharsets.UTF_8); + } + return new WeightedValue<>(x.getShortRawWeight(), theString); + } + ); + } else { + throw new IllegalArgumentException("Unsupported value type: " + valueType.getName()); + } + return result; + } + + @Override + protected AspectPropertyValue getValueAsString(String propertyName) { + AspectPropertyValue result = new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results != null) { + + try (StringValueSwig value = results.getValueAsString( + propertyName)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } + } + } + return result; + } + + @Override + protected AspectPropertyValue getValueAsJavaScript( + String propertyName) { + AspectPropertyValue result = + new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results != null) { + try (StringValueSwig value = results.getValueAsString( + propertyName)) { + if (value.hasValue()) { + result.setValue(new JavaScript(value.getValue())); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } + } + } + return result; + } + + @Override + protected AspectPropertyValue getValueAsInteger( + String propertyName) { + AspectPropertyValue result = new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results != null) { + try (IntegerValueSwig value = results.getValueAsInteger( + propertyName)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } + } + } + return result; + } + + @Override + protected AspectPropertyValue getValueAsBool(String propertyName) { + AspectPropertyValue result = new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results != null) { + try (BoolValueSwig value = results.getValueAsBool( + propertyName)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } + } + } + return result; + } + + @Override + protected AspectPropertyValue getValueAsDouble(String propertyName) { + AspectPropertyValue result = new AspectPropertyValueDefault<>(); + ResultsIpiSwig results = getSingleResults(propertyName); + if (results != null) { + try (DoubleValueSwig value = results.getValueAsDouble( + propertyName)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } + } + } + return result; + } + + @Override + protected TryGetResult tryGetValue( + String key, + Class type, + Class... parameterisedTypes) { + checkState(); + return super.tryGetValue(key, type, parameterisedTypes); + } + + private void checkState() { + if (closed) { + throw new IllegalStateException("The IPIntelligenceDataOnPremise instance has " + + "been closed, and cannot be used. Any result processing should " + + "be carried out within a 'try-with-resource' block which " + + "closes the FlowData and any AutoCloseable elements."); + } + } + + @Override + public void close() { + closed = true; + for (ResultsIpiSwig result : resultsList) { + try { + result.close(); + } catch (Exception e) { + logger.error("Failed to close native results instance. " + + "An IPIntelligenceDataOnPremise instance contains native unmanaged " + + "memory which needs to be closed. Failing to close " + + "could lead to memory leaks.", e); + } + } + } +} \ No newline at end of file diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngine.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngine.java index 284749b5..46c27ab7 100644 --- a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngine.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngine.java @@ -22,7 +22,7 @@ package fiftyone.ipintelligence.engine.onpremise.flowelements; -import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataHash; +import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataOnPremise; import fiftyone.ipintelligence.engine.onpremise.data.ProfileMetaDataIPI; import fiftyone.ipintelligence.engine.onpremise.data.PropertyMetaDataIPI; import fiftyone.ipintelligence.engine.onpremise.data.ValueMetaDataIPI; @@ -45,13 +45,13 @@ import static org.apache.commons.lang3.BooleanUtils.isFalse; /** - * On-premise IP Intelligence engine. This engine takes User-Agents and other - * relevant HTTP headers and returns properties about the device which produced - * them e.g. DeviceType or ReleaseDate. + * On-premise IP Intelligence engine. This engine takes IP addresses and + * other relevant HTTP headers and returns properties about the IP range + * that the IP address falls within. * @see Specification */ public class IPIntelligenceOnPremiseEngine - extends FiftyOneOnPremiseAspectEngineBase { private EngineIpiSwig engine = null; private final List properties = new ArrayList<>(); @@ -71,7 +71,7 @@ public class IPIntelligenceOnPremiseEngine * the properties which the engine should be initialised * with * @param IPIDataFactory the factory to use when creating a - * {@link IPIntelligenceDataHash} instance + * {@link IPIntelligenceDataOnPremise} instance * @param tempDataFileDir the file where a temporary data file copy * will be stored if one is created */ @@ -80,7 +80,7 @@ public class IPIntelligenceOnPremiseEngine AspectEngineDataFile dataFile, ConfigIpiSwig config, RequiredPropertiesConfigSwig properties, - ElementDataFactory IPIDataFactory, + ElementDataFactory IPIDataFactory, String tempDataFileDir) { super(logger, IPIDataFactory, tempDataFileDir); this.config = config; @@ -293,7 +293,7 @@ public void refreshData(String dataFileIdentifier, byte[] data) { } @Override - protected void processEngine(FlowData flowData, IPIntelligenceDataHash IPIData) { + protected void processEngine(FlowData flowData, IPIntelligenceDataOnPremise IPIData) { try (EvidenceIpiSwig relevantEvidence = new EvidenceIpiSwig()) { List keys = evidenceKeys; @@ -313,7 +313,7 @@ protected void processEngine(FlowData flowData, IPIntelligenceDataHash IPIData) evidenceItem.getValue().toString()); } } - ((IPIntelligenceDataHashDefault) IPIData).setResults( + ((IPIntelligenceDataOnPremiseDefault) IPIData).setResults( engine.process(relevantEvidence)); } } @@ -366,7 +366,7 @@ public void addDataFile(AspectEngineDataFile dataFile) { super.addDataFile(dataFile); if (dataFile instanceof FiftyOneDataFile) { FiftyOneDataFile fiftyOneDataFile = (FiftyOneDataFile)dataFile; - fiftyOneDataFile.setDataUpdateDownloadType("HashV41"); + fiftyOneDataFile.setDataUpdateDownloadType("IPIV41"); } } diff --git a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngineBuilder.java b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngineBuilder.java index 5dd86d47..ac25fc30 100644 --- a/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngineBuilder.java +++ b/ip-intelligence.engine.on-premise/src/main/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceOnPremiseEngineBuilder.java @@ -22,7 +22,7 @@ package fiftyone.ipintelligence.engine.onpremise.flowelements; -import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataHash; +import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataOnPremise; import fiftyone.ipintelligence.engine.onpremise.interop.swig.ConfigIpiSwig; import fiftyone.ipintelligence.engine.onpremise.interop.swig.RequiredPropertiesConfigSwig; import fiftyone.ipintelligence.engine.onpremise.interop.swig.VectorStringSwig; @@ -51,15 +51,15 @@ * Builder for the {@link IPIntelligenceOnPremiseEngine}. All options for the engine * should be set here. *

- * Default values are taken from ip-intelligence-cxx/src/hash/hash.c + * Default values are taken from the ip-intelligence-cxx engine configuration */ -@ElementBuilder(alternateName = "HashIPIntelligence") +@ElementBuilder(alternateName = "IPIntelligenceOnPremise") public class IPIntelligenceOnPremiseEngineBuilder extends OnPremiseIPIntelligenceEngineBuilderBase< IPIntelligenceOnPremiseEngineBuilder, IPIntelligenceOnPremiseEngine> { - private final String dataDownloadType = "HashV41"; + private final String dataDownloadType = "IPIV41"; /** * Native configuration instance for this engine. @@ -172,7 +172,6 @@ public IPIntelligenceOnPremiseEngineBuilder setPerformanceProfile( * Provide a hint as to how many threads will access the pipeline simultaneously *

* Default is the result of {@link Runtime#getRuntime()#getAvailableProcessors()} - * @see Concurrent processing * @param concurrency expected concurrent accesses * @return this builder */ @@ -239,25 +238,25 @@ protected IPIntelligenceOnPremiseEngine newEngine(List properties) { dataFile, config, requiredProperties, - new HashDataFactory(loggerFactory), + new OnPremiseDataFactory(loggerFactory), tempDir); } - private static class HashDataFactory implements - ElementDataFactory { + private static class OnPremiseDataFactory implements + ElementDataFactory { private final ILoggerFactory loggerFactory; - public HashDataFactory(ILoggerFactory loggerFactory) { + public OnPremiseDataFactory(ILoggerFactory loggerFactory) { this.loggerFactory = loggerFactory; } @Override - public IPIntelligenceDataHash create( + public IPIntelligenceDataOnPremise create( FlowData flowData, - FlowElement engine) { - return new IPIntelligenceDataHashDefault( - loggerFactory.getLogger(IPIntelligenceDataHash.class.getName()), + FlowElement engine) { + return new IPIntelligenceDataOnPremiseDefault( + loggerFactory.getLogger(IPIntelligenceDataOnPremise.class.getName()), flowData, (IPIntelligenceOnPremiseEngine) engine, MissingPropertyServiceDefault.getInstance()); diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/AutoCloseable.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/AutoCloseable.java index e08a3206..a0d8a63a 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/AutoCloseable.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/AutoCloseable.java @@ -22,7 +22,7 @@ package fiftyone.ipintelligence.engine.onpremise; -import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataHash; +import fiftyone.ipintelligence.engine.onpremise.data.IPIntelligenceDataOnPremise; import fiftyone.ipintelligence.engine.onpremise.interop.swig.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,7 +56,7 @@ public static Collection data() { {VectorStringSwig.class, true}, // Classes which should not be AutoCloseable. {Date.class, false}, - {IPIntelligenceDataHash.class, false}, + {IPIntelligenceDataOnPremise.class, false}, {MetaDataSwig.class, false}, {CollectionConfigSwig.class, false}, {RequiredPropertiesConfigSwig.class, false}, diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/TestsBase.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/TestsBase.java index aa3dbf19..ed7cc67a 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/TestsBase.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/TestsBase.java @@ -22,7 +22,7 @@ package fiftyone.ipintelligence.engine.onpremise; -import fiftyone.ipintelligence.shared.testhelpers.UserAgentGenerator; +import fiftyone.ipintelligence.shared.testhelpers.IpAddressGenerator; import fiftyone.ipintelligence.shared.testhelpers.FileUtils; import fiftyone.pipeline.engines.Constants; @@ -31,22 +31,22 @@ public class TestsBase { - private WrapperHash wrapper = null; - private UserAgentGenerator userAgents; + private WrapperOnPremise wrapper = null; + private IpAddressGenerator ipAddresses; - protected WrapperHash getWrapper() { + protected WrapperOnPremise getWrapper() { return wrapper; } - protected UserAgentGenerator getUserAgents() { - return userAgents; + protected IpAddressGenerator getIpAddresses() { + return ipAddresses; } protected void testInitialize(Constants.PerformanceProfiles profile) throws Exception { - wrapper = new WrapperHash( - FileUtils.getHashFile(), + wrapper = new WrapperOnPremise( + FileUtils.getIpiFile(), profile); - userAgents = new UserAgentGenerator( + ipAddresses = new IpAddressGenerator( getFilePath(IP_ADDRESSES_FILE_NAME)); } diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperHash.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperOnPremise.java similarity index 95% rename from ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperHash.java rename to ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperOnPremise.java index d9e861c0..b36a7bf2 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperHash.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/WrapperOnPremise.java @@ -37,13 +37,13 @@ import java.io.File; -public class WrapperHash implements Wrapper { +public class WrapperOnPremise implements Wrapper { protected static final ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); private Pipeline pipeline; private IPIntelligenceOnPremiseEngine engine; - public WrapperHash(File dataFile, Constants.PerformanceProfiles profile) throws Exception { + public WrapperOnPremise(File dataFile, Constants.PerformanceProfiles profile) throws Exception { engine = new IPIntelligenceOnPremiseEngineBuilder(loggerFactory, null) .setPerformanceProfile(profile) .setAutoUpdate(false) diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorHash.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorOnPremise.java similarity index 95% rename from ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorHash.java rename to ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorOnPremise.java index 017ee631..5086fb2e 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorHash.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/DataValidatorOnPremise.java @@ -37,11 +37,11 @@ import static org.junit.Assert.*; -public class DataValidatorHash implements DataValidator { +public class DataValidatorOnPremise implements DataValidator { private IPIntelligenceOnPremiseEngine engine; - public DataValidatorHash(IPIntelligenceOnPremiseEngine engine) { + public DataValidatorOnPremise(IPIntelligenceOnPremiseEngine engine) { this.engine = engine; } diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherHash.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherOnPremise.java similarity index 98% rename from ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherHash.java rename to ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherOnPremise.java index 4683157a..ab58307d 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherHash.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHasherOnPremise.java @@ -30,7 +30,7 @@ import fiftyone.pipeline.engines.fiftyone.data.ValueMetaData; -public class MetaDataHasherHash implements MetaDataHasher { +public class MetaDataHasherOnPremise implements MetaDataHasher { @Override public int hashProperties(int hash, Wrapper wrapper) { diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHashTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataOnPremiseTests.java similarity index 90% rename from ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHashTests.java rename to ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataOnPremiseTests.java index d229af08..a68d6013 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataHashTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/MetaDataOnPremiseTests.java @@ -36,7 +36,7 @@ import static org.junit.Assume.assumeTrue; @Ignore -public class MetaDataHashTests extends TestsBase { +public class MetaDataOnPremiseTests extends TestsBase { private static final double expectedPropertiesSeconds = 300.1; private static final double expectedValuesSeconds = 300.1; private static final double expectedComponentsSeconds = 300.01; @@ -57,8 +57,8 @@ public void cleanup() { } @Test - public void MetaData_Hash_Reload() throws ExecutionException, InterruptedException { - fiftyone.ipintelligence.shared.testhelpers.data.MetaDataTests.reload(getWrapper(), new MetaDataHasherHash(), executorService); + public void MetaData_OnPremise_Reload() throws ExecutionException, InterruptedException { + fiftyone.ipintelligence.shared.testhelpers.data.MetaDataTests.reload(getWrapper(), new MetaDataHasherOnPremise(), executorService); } /** @@ -68,7 +68,7 @@ public void MetaData_Hash_Reload() throws ExecutionException, InterruptedExcepti */ @Test public void MetaData_Performance_Properties() { - MetaDataHasherHash hasher = new MetaDataHasherHash(); + MetaDataHasherOnPremise hasher = new MetaDataHasherOnPremise(); long start = System.currentTimeMillis(); hasher.hashProperties(0, getWrapper()); double time = ((double)System.currentTimeMillis() - (double)start) / @@ -86,7 +86,7 @@ public void MetaData_Performance_Properties() { */ @Test public void MetaData_Performance_Components() { - MetaDataHasherHash hasher = new MetaDataHasherHash(); + MetaDataHasherOnPremise hasher = new MetaDataHasherOnPremise(); long start = System.currentTimeMillis(); hasher.hashComponents(0, getWrapper()); double time = ((double)System.currentTimeMillis() - (double)start) / @@ -104,7 +104,7 @@ public void MetaData_Performance_Components() { */ @Test public void MetaData_Performance_Values() { - MetaDataHasherHash hasher = new MetaDataHasherHash(); + MetaDataHasherOnPremise hasher = new MetaDataHasherOnPremise(); long start = System.currentTimeMillis(); hasher.hashValues(0, getWrapper()); double time = ((double)System.currentTimeMillis() - (double)start) / @@ -122,7 +122,7 @@ public void MetaData_Performance_Values() { */ @Test public void MetaData_Performance_Profiles() { - MetaDataHasherHash hasher = new MetaDataHasherHash(); + MetaDataHasherOnPremise hasher = new MetaDataHasherOnPremise(); long start = System.currentTimeMillis(); hasher.hashProfiles(0, getWrapper()); double time = ((double)System.currentTimeMillis() - (double)start) / diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueHashTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueOnPremiseTests.java similarity index 85% rename from ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueHashTests.java rename to ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueOnPremiseTests.java index cb15f026..f47fcbbb 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueHashTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/data/ValueOnPremiseTests.java @@ -30,7 +30,7 @@ import org.junit.Before; import org.junit.Test; -public class ValueHashTests extends TestsBase { +public class ValueOnPremiseTests extends TestsBase { @Before public void init() throws Exception { @@ -43,22 +43,22 @@ public void cleanup() { } @Test - public void Values_Hash_ValueTypes() throws Exception { + public void Values_OnPremise_ValueTypes() throws Exception { ValueTests.valueTypes(getWrapper()); } @Test - public void Values_Hash_AvailableProperties() throws Exception { + public void Values_OnPremise_AvailableProperties() throws Exception { ValueTests.availableProperties(getWrapper()); } @Test - public void Values_Hash_TypedGetters() throws Exception { + public void Values_OnPremise_TypedGetters() throws Exception { ValueTests.typedGetters(getWrapper()); } @Test - public void Values_Hash_DeviceId() throws Exception { + public void Values_OnPremise_DeviceId() throws Exception { ValueTests.deviceId(getWrapper()); } } diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java index 3edf1706..6d1b134a 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java @@ -81,7 +81,7 @@ private void testDataSourceTier(String fileName) throws Exception { * @throws Exception */ @Test - public void Engine_Hash_GetDataSourceTier_Lite() throws Exception { + public void Engine_OnPremise_GetDataSourceTier_Lite() throws Exception { testDataSourceTier(LITE_IPI_DATA_FILE_NAME); } @@ -91,7 +91,7 @@ public void Engine_Hash_GetDataSourceTier_Lite() throws Exception { * @throws Exception */ @Test - public void Engine_Hash_GetDataSourceTier_Enterprise() throws Exception { + public void Engine_OnPremise_GetDataSourceTier_Enterprise() throws Exception { testDataSourceTier(ENTERPRISE_IPI_V41_DATA_FILE_NAME); } diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EvidenceKeysTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EvidenceKeysTests.java index 94a0b805..1abffd31 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EvidenceKeysTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EvidenceKeysTests.java @@ -44,24 +44,24 @@ public void cleanup() { } @Test - public void EvidenceKeys_Hash_ContainsClientIP() { + public void EvidenceKeys_OnPremise_ContainsClientIP() { EvidenceKeyTests.containsClientIP(getWrapper()); } @Test - public void EvidenceKeys_Hash_ContainsQueryParams() { + public void EvidenceKeys_OnPremise_ContainsQueryParams() { EvidenceKeyTests.containsQueryParams(getWrapper()); } @Test - public void EvidenceKeys_Hash_ContainsOverrides() { + public void EvidenceKeys_OnPremise_ContainsOverrides() { assumeFalse("Need to run test with Enterprise data", getWrapper().getEngine().getDataSourceTier().equals("Lite")); EvidenceKeyTests.containsOverrides(getWrapper()); } @Test - public void EvidenceKeys_Hash_CaseInsensitiveKeys() { + public void EvidenceKeys_OnPremise_CaseInsensitiveKeys() { EvidenceKeyTests.caseInsensitiveKeys(getWrapper()); } } diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataTests.java index 161a3ce1..df916089 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/IPIntelligenceDataTests.java @@ -71,7 +71,7 @@ public void cleanup() { @Test public void IPIData_ResultsClose() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), @@ -90,7 +90,7 @@ public void IPIData_ResultsClose() throws Exception { /** * Verify that the {@link ResultsIpiSwig#containsProperty(String)} method * is called the expected number of times when the target method is called - * on the {@link IPIntelligenceDataHashDefault} instance. + * on the {@link IPIntelligenceDataOnPremiseDefault} instance. * @param data instance to call method on * @param results to be checked * @param getMethod to call on the data @@ -99,7 +99,7 @@ public void IPIData_ResultsClose() throws Exception { * @throws IllegalAccessException exception */ private void verifyCallsToContainsProperty( - IPIntelligenceDataHashDefault data, + IPIntelligenceDataOnPremiseDefault data, ResultsIpiSwig results, Method getMethod, int expectedCount) @@ -144,7 +144,7 @@ private void configureNativeGettersNoValue(ResultsIpiSwig results) { public void IPIData_ContainsProperty_SingleResult() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), @@ -178,7 +178,7 @@ public void IPIData_ContainsProperty_SingleResult() public void IPIData_ContainsProperty_MultipleResults() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), @@ -222,7 +222,7 @@ public void IPIData_ContainsProperty_MultipleResults() @Test public void IPIData_MissingProperty_SingleResult() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), @@ -254,7 +254,7 @@ results, times(1)) @Test public void IPIData_MissingProperty_MultipleResults() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), @@ -286,10 +286,10 @@ results2, times(1)) /** * Interface used for lambda in - * {@link #checkThrowsIllegalState(IPIntelligenceDataHashDefault, IPIDataHashCall)}. + * {@link #checkThrowsIllegalState(IPIntelligenceDataOnPremiseDefault, IPIDataMethodCall)}. */ - private interface IPIDataHashCall { - void call(IPIntelligenceDataHashDefault instance); + private interface IPIDataMethodCall { + void call(IPIntelligenceDataOnPremiseDefault instance); } /** @@ -299,8 +299,8 @@ private interface IPIDataHashCall { * @throws Exception exception */ private void checkThrowsIllegalState( - IPIntelligenceDataHashDefault instance, - IPIDataHashCall methodCall) throws Exception { + IPIntelligenceDataOnPremiseDefault instance, + IPIDataMethodCall methodCall) throws Exception { try { methodCall.call(instance); fail("An exception was not thrown by even though the instance " + @@ -316,14 +316,14 @@ private void checkThrowsIllegalState( } /** - * Check that once a {@link IPIntelligenceDataHashDefault} instance has been closed, + * Check that once a {@link IPIntelligenceDataOnPremiseDefault} instance has been closed, * an {@link IllegalStateException} is throw when calling get methods. * @throws Exception exception */ @Test public void IPIData_Closed() throws Exception { try (FlowData flowData = getWrapper().getPipeline().createFlowData()) { - IPIntelligenceDataHashDefault data = new IPIntelligenceDataHashDefault( + IPIntelligenceDataOnPremiseDefault data = new IPIntelligenceDataOnPremiseDefault( logger, flowData, getWrapper().getEngine(), diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/TestProcessTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/TestProcessTests.java index e234c9ec..07863e96 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/TestProcessTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/TestProcessTests.java @@ -23,7 +23,7 @@ package fiftyone.ipintelligence.engine.onpremise.flowelements; import fiftyone.ipintelligence.engine.onpremise.TestsBase; -import fiftyone.ipintelligence.engine.onpremise.data.DataValidatorHash; +import fiftyone.ipintelligence.engine.onpremise.data.DataValidatorOnPremise; import fiftyone.ipintelligence.shared.testhelpers.flowelements.ProcessTests; import fiftyone.pipeline.engines.Constants; import org.junit.After; @@ -43,27 +43,27 @@ public void cleanup() { } @Test - public void Process_Hash_NoEvidence() throws Exception { - ProcessTests.noEvidence(getWrapper(), new DataValidatorHash(getWrapper().getEngine())); + public void Process_OnPremise_NoEvidence() throws Exception { + ProcessTests.noEvidence(getWrapper(), new DataValidatorOnPremise(getWrapper().getEngine())); } @Test - public void Process_Hash_EmptyUserAgent() throws Exception { - ProcessTests.emptyUserAgent(getWrapper(), new DataValidatorHash(getWrapper().getEngine())); + public void Process_OnPremise_EmptyIpAddress() throws Exception { + ProcessTests.emptyIpAddress(getWrapper(), new DataValidatorOnPremise(getWrapper().getEngine())); } @Test - public void Process_Hash_NoHeaders() throws Exception { - ProcessTests.noHeaders(getWrapper(), new DataValidatorHash(getWrapper().getEngine())); + public void Process_OnPremise_NoHeaders() throws Exception { + ProcessTests.noHeaders(getWrapper(), new DataValidatorOnPremise(getWrapper().getEngine())); } @Test - public void Process_Hash_NoUsefulHeaders() throws Exception { - ProcessTests.noUsefulHeaders(getWrapper(), new DataValidatorHash(getWrapper().getEngine())); + public void Process_OnPremise_NoUsefulHeaders() throws Exception { + ProcessTests.noUsefulHeaders(getWrapper(), new DataValidatorOnPremise(getWrapper().getEngine())); } @Test - public void Process_Hash_CaseInsensitiveKeys() throws Exception { - ProcessTests.caseInsensitiveEvidenceKeys(getWrapper(), new DataValidatorHash(getWrapper().getEngine())); + public void Process_OnPremise_CaseInsensitiveKeys() throws Exception { + ProcessTests.caseInsensitiveEvidenceKeys(getWrapper(), new DataValidatorOnPremise(getWrapper().getEngine())); } } diff --git a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/Constants.java b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/Constants.java index 22e7ee9a..ef69bd76 100644 --- a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/Constants.java +++ b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/Constants.java @@ -30,12 +30,18 @@ public class Constants { /** * The suffix that is used to identify a TAC in evidence. * https://en.wikipedia.org/wiki/Type_Allocation_Code + * @deprecated TAC is a device detection concept and is not used by + * IP Intelligence. This constant will be removed in a future version. */ + @Deprecated public static final String EVIDENCE_TAC_SUFFIX = "tac"; /** * The complete key for supplying a TAC as evidence. + * @deprecated TAC is a device detection concept and is not used by + * IP Intelligence. This constant will be removed in a future version. */ + @Deprecated public static final String EVIDENCE_QUERY_TAC_KEY = EVIDENCE_QUERY_PREFIX + EVIDENCE_SEPERATOR + @@ -48,12 +54,20 @@ public class Constants { * for Android devices and by * https://gist.github.com/soapyigu/c99e1f45553070726f14c1bb0a54053b#file-machinename-swift * for iOS devices. + * @deprecated the native model name is a device detection concept and is + * not used by IP Intelligence. This constant will be removed in a future + * version. */ + @Deprecated public static final String EVIDENCE_NATIVE_MODEL_SUFFIX = "nativemodel"; /** * The complete key for supplying a native model name as evidence. + * @deprecated the native model name is a device detection concept and is + * not used by IP Intelligence. This constant will be removed in a future + * version. */ + @Deprecated public static final String EVIDENCE_QUERY_NATIVE_MODEL_KEY = EVIDENCE_QUERY_PREFIX + EVIDENCE_SEPERATOR + diff --git a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java index 41cd5794..a49ff95a 100644 --- a/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java +++ b/ip-intelligence.shared/src/main/java/fiftyone/ipintelligence/shared/testhelpers/FileUtils.java @@ -44,7 +44,6 @@ public class FileUtils { public static final String LITE_IPI_DATA_FILE_NAME = "51Degrees-LiteV41.ipi"; private static Optional IPI_DATA_FILE; public static final String IP_ADDRESSES_FILE_NAME = "evidence.csv"; - private static File UA_FILE; public static final String EVIDENCE_FILE_NAME = "evidence.yml"; private static Optional EVIDENCE_FILE; @@ -53,16 +52,40 @@ public class FileUtils { * * @return a file or null if not found */ + public static String getIpiFileName() { + return Objects.isNull(getIpiFile()) ? null : getIpiFile().getPath(); + } + + /** + * Helper to find the location of an Enterprise or Lite IPI file in the default search scope + * + * @return a file or null if not found + * @deprecated "Hash" refers to the device detection algorithm and has no + * meaning for IP Intelligence. Use {@link #getIpiFileName()} instead. + */ + @Deprecated public static String getHashFileName() { - return Objects.isNull(getHashFile()) ? null : getHashFile().getPath(); + return getIpiFileName(); } /** * Helper to find the location of an Enterprise or Lite IPI file in the default search scope * - * @return a file or empty if not found + * @return a file or null if not found + * @deprecated "Hash" refers to the device detection algorithm and has no + * meaning for IP Intelligence. Use {@link #getIpiFile()} instead. */ + @Deprecated public static File getHashFile() { + return getIpiFile(); + } + + /** + * Helper to find the location of an Enterprise or Lite IPI file in the default search scope + * + * @return a file or empty if not found + */ + public static File getIpiFile() { try { if (Objects.nonNull(IPI_DATA_FILE)){ return IPI_DATA_FILE.orElse(null); @@ -104,7 +127,7 @@ public static File getEvidenceFile() { /** * Prefix for temp files that are created by {@link #jarFileHelper(String)} **/ - public static String TEMP_FILE_PREFIX = "DDTempFile"; + public static String TEMP_FILE_PREFIX = "IPITempFile"; /** * Search the classpath for a resource. If it doesn't exist throw an exception. diff --git a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/ClientHintsExampleTestBase.java b/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/ClientHintsExampleTestBase.java deleted file mode 100644 index d027cb23..00000000 --- a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/ClientHintsExampleTestBase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ********************************************************************* - * This Original Work is copyright of 51 Degrees Mobile Experts Limited. - * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, - * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. - * - * This Original Work is licensed under the European Union Public Licence - * (EUPL) v.1.2 and is subject to its terms as set out below. - * - * If a copy of the EUPL was not distributed with this file, You can obtain - * one at https://opensource.org/licenses/EUPL-1.2. - * - * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be - * amended by the European Commission) shall be deemed incompatible for - * the purposes of the Work and the provisions of the compatibility - * clause in Article 5 of the EUPL shall not apply. - * - * If using the Work as, or as part of, a network application, by - * including the attribution notice(s) required under Article 5 of the EUPL - * in the end user terms of the application under an appropriate heading, - * such notice(s) shall fulfill the requirements of that article. - * ********************************************************************* */ - -package fiftyone.ipintelligence.shared.testhelpers; - -import static fiftyone.ipintelligence.shared.testhelpers.Constants.*; -import static org.junit.Assert.fail; - -public class ClientHintsExampleTestBase { - - public static String ALL_PROPERTIES = null; - public static String BASE_PROPERTIES = "HardwareVendor,HardwareName,DeviceType,PlatformVendor,PlatformName,PlatformVersion,BrowserVendor,BrowserName,BrowserVersion"; - public static String PLATFORM_PROPERTIES = BASE_PROPERTIES + ",SetHeaderPlatformAccept-CH"; - public static String HARDWARE_PROPERTIES = BASE_PROPERTIES + ",SetHeaderHardwareAccept-CH"; - public static String BROWSER_PROPERTIES = BASE_PROPERTIES + ",SetHeaderBrowserAccept-CH"; - - public static String CHROME_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"; - public static String EDGE_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 " - + "Edg/95.0.1020.44"; - public static String FIREFOX_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64;" - + " rv:94.0) Gecko/20100101 Firefox/94.0"; - public static String SAFARI_UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 " - + "like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 " - + "Mobile/15E148 Safari/604.1"; - public static String CURL_UA = "curl/7.80.0"; - - public static String SUPER_ACCEPT_CH = "SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version,SEC-CH-UA-Model," - + "SEC-CH-UA-Mobile,SEC-CH-UA-Arch,SEC-CH-UA,SEC-CH-UA-Full-Version"; - public static String PLATFORM_ACCEPT_CH = "SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version"; - public static String HARDWARE_ACCEPT_CH = "SEC-CH-UA-Model,SEC-CH-UA-Mobile,SEC-CH-UA-Arch"; - public static String BROWSER_ACCEPT_CH = "SEC-CH-UA,SEC-CH-UA-Full-Version"; - - public static int TEST_PORT_NUMBER = 8080; - public static String BASE_URL = "http://localhost:"+ TEST_PORT_NUMBER + "/"; - public static String CLOUD_URL = BASE_URL + "pipeline.uachmanual.cloud.examples.servlet"; - public static String HASH_URL = BASE_URL + "pipeline.uachmanual.examples.servlet"; - - - /* - * Function to get environment variable value. - */ - private static String getEnvVar(String name, String description) { - String resourceKey = null; - String envResourceKey = System.getenv(name); - String propertyResourceKey = System.getProperty(name); - - if(envResourceKey == null || envResourceKey.isEmpty()) { - if (propertyResourceKey == null || propertyResourceKey.isEmpty()) - fail(description + " needs to be set in " + name + " environment variable to run Cloud tests."); - else { - resourceKey = propertyResourceKey; - } - } - else { - resourceKey = envResourceKey; - } - return resourceKey; - } -} diff --git a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/UserAgentGenerator.java b/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/IpAddressGenerator.java similarity index 81% rename from ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/UserAgentGenerator.java rename to ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/IpAddressGenerator.java index d57d8e05..3ff14e37 100644 --- a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/UserAgentGenerator.java +++ b/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/IpAddressGenerator.java @@ -32,20 +32,20 @@ import java.util.Random; import java.util.regex.Pattern; -public class UserAgentGenerator { +public class IpAddressGenerator { - private final List userAgents; + private final List ipAddresses; private Random random = new Random(); - public UserAgentGenerator(File userAgentFile) throws IOException { - userAgents = Files.readAllLines( - userAgentFile.toPath(), + public IpAddressGenerator(File ipAddressFile) throws IOException { + ipAddresses = Files.readAllLines( + ipAddressFile.toPath(), Charset.defaultCharset()); } - public String getRandomUserAgent(int randomness) { - String value = userAgents.get(random.nextInt(userAgents.size())); + public String getRandomIpAddress(int randomness) { + String value = ipAddresses.get(random.nextInt(ipAddresses.size())); if (randomness > 0) { byte[] bytes = value.getBytes(StandardCharsets.US_ASCII); for (int i = 0; i < randomness; i++) { @@ -63,7 +63,7 @@ public String getRandomUserAgent(int randomness) { public Iterable getIterable(int count, int randomness) { List result = new ArrayList<>(count); for (int i = 0; i < count; i++) { - result.add(getRandomUserAgent(randomness)); + result.add(getRandomIpAddress(randomness)); } return result; } @@ -73,9 +73,9 @@ public Iterable getIterable(int count, String pattern) { int index = 0; List result = new ArrayList<>(); Pattern regex = Pattern.compile(pattern); - while (counter < count && index < userAgents.size()) { - if (regex.matcher(userAgents.get(index)).matches()) { - result.add(userAgents.get(index)); + while (counter < count && index < ipAddresses.size()) { + if (regex.matcher(ipAddresses.get(index)).matches()) { + result.add(ipAddresses.get(index)); counter++; } index++; @@ -87,7 +87,7 @@ public Iterable getIterable(int count) { return getIterable(count, "(.*?)"); } - public Iterable getRandomUserAgents(int count) { + public Iterable getRandomIpAddresses(int count) { return getIterable(count); } } diff --git a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/flowelements/ProcessTests.java b/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/flowelements/ProcessTests.java index 95ea6446..c2d0fbb7 100644 --- a/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/flowelements/ProcessTests.java +++ b/ip-intelligence.shared/src/test/java/fiftyone/ipintelligence/shared/testhelpers/flowelements/ProcessTests.java @@ -43,7 +43,7 @@ public static void noEvidence( } } - public static void emptyUserAgent( + public static void emptyIpAddress( Wrapper wrapper, DataValidator validator) throws Exception { try (FlowData data = wrapper.getPipeline().createFlowData()) { diff --git a/ip-intelligence/src/main/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilder.java b/ip-intelligence/src/main/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilder.java index cbf715c6..19e0e9e8 100644 --- a/ip-intelligence/src/main/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilder.java +++ b/ip-intelligence/src/main/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilder.java @@ -325,9 +325,9 @@ public IPIntelligenceOnPremisePipelineBuilder setDataUpdateUrlFormatter(DataUpda public Pipeline build() throws Exception { AspectEngine IPIntelligenceEngine; - IPIntelligenceOnPremiseEngineBuilder hashBuilder = + IPIntelligenceOnPremiseEngineBuilder engineBuilder = new IPIntelligenceOnPremiseEngineBuilder(loggerFactory, dataUpdateService); - IPIntelligenceEngine = configureAndBuild(hashBuilder); + IPIntelligenceEngine = configureAndBuild(engineBuilder); if (IPIntelligenceEngine != null) { // Add the share usage element to the list if enabled @@ -348,8 +348,8 @@ public Pipeline build() throws Exception { } /** - * Private method used to set configuration options common to - * both hash and pattern engines and build the engine. + * Private method used to set configuration options on + * the on-premise engine builder and build the engine. * @param builder The builder to configure. * @return A new IP Intelligence engine instance. * @throws Exception diff --git a/ip-intelligence/src/test/java/fiftyone/ipintelligence/CloudRequestOriginTests.java b/ip-intelligence/src/test/java/fiftyone/ipintelligence/CloudRequestOriginTests.java index aaabebd8..55b56121 100644 --- a/ip-intelligence/src/test/java/fiftyone/ipintelligence/CloudRequestOriginTests.java +++ b/ip-intelligence/src/test/java/fiftyone/ipintelligence/CloudRequestOriginTests.java @@ -94,11 +94,7 @@ public void ResourceKeyWithOrigin() throws Exception { .build(); try(FlowData data = pipeline.createFlowData()) { - data.addEvidence("query.client-ip", - "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL " + - "Build/OPD1.170816.004) AppleWebKit/537.36 " + - "(KHTML, like Gecko) Chrome/80.0.3987.106 " + - "Mobile Safari/537.36") + data.addEvidence("query.client-ip", "50.154.29.201") .process(); } } diff --git a/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilderTest.java b/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilderTest.java index 0d4b4c31..deac8d33 100644 --- a/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilderTest.java +++ b/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceOnPremisePipelineBuilderTest.java @@ -53,7 +53,7 @@ @SuppressWarnings({"rawtypes", "deprecation"}) public class IPIntelligenceOnPremisePipelineBuilderTest { - private static final String IPI_DATA_FILE_NAME = FileUtils.getHashFileName(); + private static final String IPI_DATA_FILE_NAME = FileUtils.getIpiFileName(); private IPIntelligenceOnPremisePipelineBuilder builder; private File datafile = FileFinder.getFilePath(IPI_DATA_FILE_NAME); private ILoggerFactory loggerFactory; diff --git a/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceTests.java b/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceTests.java index 132ddaab..e8bc123a 100644 --- a/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceTests.java +++ b/ip-intelligence/src/test/java/fiftyone/ipintelligence/IPIntelligenceTests.java @@ -24,7 +24,7 @@ import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngine; import fiftyone.ipintelligence.shared.IPIntelligenceData; -import fiftyone.ipintelligence.shared.testhelpers.UserAgentGenerator; +import fiftyone.ipintelligence.shared.testhelpers.IpAddressGenerator; import fiftyone.ipintelligence.shared.testhelpers.FileUtils; import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.data.FlowError; @@ -54,7 +54,7 @@ import java.util.concurrent.Future; import static fiftyone.ipintelligence.shared.testhelpers.FileUtils.IP_ADDRESSES_FILE_NAME; -import static fiftyone.pipeline.core.Constants.EVIDENCE_HTTPHEADER_PREFIX; +import static fiftyone.pipeline.core.Constants.EVIDENCE_QUERY_PREFIX; import static fiftyone.pipeline.core.Constants.EVIDENCE_SEPERATOR; import static fiftyone.pipeline.engines.Constants.PerformanceProfiles.*; import static org.junit.Assert.assertEquals; @@ -69,9 +69,9 @@ public class IPIntelligenceTests { private static final Logger logger = LoggerFactory.getLogger(IPIntelligenceTests.class); - private static final String IPI_DATA_FILE_NAME = FileUtils.getHashFileName(); + private static final String IPI_DATA_FILE_NAME = FileUtils.getIpiFileName(); - private static UserAgentGenerator userAgents; + private static IpAddressGenerator ipAddresses; TestConfig[] ipiConfigs = { // ******** IPI with a single thread ********* new TestConfig(IPI_DATA_FILE_NAME, MaxPerformance, false, false, "IPI-MaxPerformance-NoCache-SingleThread"), @@ -103,7 +103,7 @@ public class IPIntelligenceTests { @BeforeClass public static void initClass() throws IOException { - userAgents = new UserAgentGenerator( + ipAddresses = new IpAddressGenerator( FileFinder.getFilePath(IP_ADDRESSES_FILE_NAME)); } @@ -136,10 +136,10 @@ private static void AddToMessage(StringBuilder message, String textToAdd, int de } @Test - public void IPI_AllConfigurations_100_UserAgents() throws Exception { + public void IPI_AllConfigurations_100_IpAddresses() throws Exception { for (TestConfig config : ipiConfigs) { logger.info("Testing '" + config.name + "'"); - TestOnPremise_AllConfigurations_100_UserAgents( + TestOnPremise_AllConfigurations_100_IpAddresses( config.dataFileName, config.performanceProfile, config.useCache, @@ -147,7 +147,7 @@ public void IPI_AllConfigurations_100_UserAgents() throws Exception { } } - public void TestOnPremise_AllConfigurations_100_UserAgents( + public void TestOnPremise_AllConfigurations_100_IpAddresses( String datafileName, Constants.PerformanceProfiles performanceProfile, boolean useCache, @@ -177,12 +177,12 @@ public void TestOnPremise_AllConfigurations_100_UserAgents( callables.add(new Callable() { @Override public Void call() throws Exception { - for (String userAgent : userAgents.getRandomUserAgents(100)) { + for (String ipAddress : ipAddresses.getRandomIpAddresses(100)) { try (FlowData flowData = pipeline.createFlowData()) { flowData.addEvidence( - EVIDENCE_HTTPHEADER_PREFIX + - EVIDENCE_SEPERATOR + "User-Agent", - userAgent) + EVIDENCE_QUERY_PREFIX + + EVIDENCE_SEPERATOR + "client-ip", + ipAddress) .process(); if (flowData.getErrors() != null) { assertEquals( From 0c86e6aa652f3a5efe7d0fbbb688201384c866a4 Mon Sep 17 00:00:00 2001 From: James Rogers Date: Fri, 12 Jun 2026 14:20:20 +0100 Subject: [PATCH 3/3] BUG: USe correct ipi file names in engine tests --- .../engine/onpremise/flowelements/EngineTests.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java index 6d1b134a..fc7a914c 100644 --- a/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java +++ b/ip-intelligence.engine.on-premise/src/test/java/fiftyone/ipintelligence/engine/onpremise/flowelements/EngineTests.java @@ -66,13 +66,17 @@ private void testDataSourceTier(String fileName) throws Exception { IPIntelligenceOnPremiseEngine engine = createEngine(dataFile); String tier = engine.getDataSourceTier(); engine.close(); - + + // getDataSourceTier() returns the data set name embedded in the .ipi + // file header, which is the common-metadata product name. The values + // below were confirmed by loading the actual data files: IPIV4Lite, + // IPIV4Enterprise and IPIV4Asn. (The device detection "TAC" tier has + // no equivalent for IP Intelligence.) if (fileName.equals(LITE_IPI_DATA_FILE_NAME)) { - assertEquals("Lite", tier); + assertEquals("IPIV4Lite", tier); } else { - assertTrue(tier.equalsIgnoreCase("Enterprise") || - tier.equalsIgnoreCase("TAC")); + assertEquals("IPIV4Enterprise", tier); } }