From 614f935f2f55661935ea508dec8181184dbed5ef Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 10:28:22 +0000 Subject: [PATCH 1/2] Test that the IP Intelligence API example says what the Enterprise file adds The service answers in JSON, so what it writes when it starts is the only place the person running it reads what the Enterprise data file adds and where to find out more. On the Lite file it must give the offer with the contact link, then the Find out more section. --- .../web/GettingStartedApiNotesTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 examples/ip-intelligence/web/getting-started.api/src/test/java/fiftyone/ipintelligence/examples/web/GettingStartedApiNotesTest.java diff --git a/examples/ip-intelligence/web/getting-started.api/src/test/java/fiftyone/ipintelligence/examples/web/GettingStartedApiNotesTest.java b/examples/ip-intelligence/web/getting-started.api/src/test/java/fiftyone/ipintelligence/examples/web/GettingStartedApiNotesTest.java new file mode 100644 index 000000000..897d74f93 --- /dev/null +++ b/examples/ip-intelligence/web/getting-started.api/src/test/java/fiftyone/ipintelligence/examples/web/GettingStartedApiNotesTest.java @@ -0,0 +1,80 @@ +/* ********************************************************************* + * 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.examples.web; + +import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngine; +import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngineBuilder; +import fiftyone.ipintelligence.examples.shared.DataFileHelper; +import fiftyone.ipintelligence.examples.shared.FindOutMore; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.Assert.assertTrue; + +/** + * The service answers in JSON, so what it writes when it starts is the only + * place the person running it reads what the Enterprise data file adds and + * where to find out more. + */ +public class GettingStartedApiNotesTest { + + private static final String CONTACT_US = "https://51degrees.com/contact-us?"; + + /** + * On the free Lite data file, the service says what the Enterprise data + * file adds with the link to the contact page, then writes the "Find out + * more" section, closed by its rule. + */ + @Test + public void startupNotes_FreeDataFile() throws Exception { + String lite = DataFileHelper.getDataFileLocation( + DataFileHelper.LITE_DATA_FILE_REL_PATH); + try (IPIntelligenceOnPremiseEngine engine = + new IPIntelligenceOnPremiseEngineBuilder( + LoggerFactory.getILoggerFactory()) + .setAutoUpdate(false) + .build(lite, false)) { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + GettingStartedApi.writeStartupNotes( + new PrintStream(buffer, true, "UTF-8"), engine); + String output = buffer.toString("UTF-8"); + + assertTrue("The output should say what the Enterprise data " + + "file adds:\n" + output, + output.contains("This example used a free data file.")); + assertTrue("The output should link the contact page:\n" + output, + output.contains(CONTACT_US)); + int heading = output.lastIndexOf(FindOutMore.HEADING); + assertTrue("The output should have the '" + FindOutMore.HEADING + + "' section after the link to the contact " + + "page:\n" + output, + heading > output.lastIndexOf(CONTACT_US)); + assertTrue("The '" + FindOutMore.HEADING + + "' section should end with its rule:\n" + output, + output.indexOf(FindOutMore.RULE, heading) > heading); + } + } +} From 1b4c73df6f9939d6c67077a4b87de10c582393a2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sat, 14 Nov 2026 10:29:29 +0000 Subject: [PATCH 2/2] Say at start-up what the Enterprise file adds, and where to find out more The IP Intelligence API example answers in JSON, so on the Lite file a caller saw the three registration properties and nothing about what the Enterprise data file adds. When the service starts it now writes the Enterprise offer with the tagged contact link, when the file in use is a free one, then the Find out more section. The class Javadoc no longer says the Enterprise file is looked for when no argument is given, as the example has used the Lite file since the free file defaults changed. --- .../examples/web/GettingStartedApi.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/examples/ip-intelligence/web/getting-started.api/src/main/java/fiftyone/ipintelligence/examples/web/GettingStartedApi.java b/examples/ip-intelligence/web/getting-started.api/src/main/java/fiftyone/ipintelligence/examples/web/GettingStartedApi.java index 34b00b036..3ecc63b86 100644 --- a/examples/ip-intelligence/web/getting-started.api/src/main/java/fiftyone/ipintelligence/examples/web/GettingStartedApi.java +++ b/examples/ip-intelligence/web/getting-started.api/src/main/java/fiftyone/ipintelligence/examples/web/GettingStartedApi.java @@ -50,6 +50,7 @@ import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngine; import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngineBuilder; import fiftyone.ipintelligence.examples.shared.DataFileHelper; +import fiftyone.ipintelligence.examples.shared.FindOutMore; import fiftyone.pipeline.core.data.EvidenceKeyFilterWhitelist; import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.flowelements.FlowElement; @@ -74,6 +75,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.security.MessageDigest; @@ -94,7 +97,10 @@ * and a JSON builder element which serialises the results. *

* The data file can be supplied as a command line argument. When no argument is given - * the enterprise data file is looked for in the cxx/data/ip-intelligence directory. + * the free Lite data file is used, and downloaded when it is missing. + *

+ * The service answers in JSON, so when it starts it writes what the Enterprise data file + * adds, when the file in use is a free one, and the "Find out more" section. *

* Note that the .NET version of this example also includes a device detection engine * in the same pipeline. This Java version is IP Intelligence only. @@ -105,6 +111,14 @@ public class GettingStartedApi extends HttpServlet { public static final String DATA_FILE_INIT_PARAM = "dataFile"; public static Logger logger = LoggerFactory.getLogger(GettingStartedApi.class); + /** + * This example's tag in the links of its "Find out more" section. + */ + private static final String EXAMPLE_TAG = + "web-getting-started.api-src-main-java-fiftyone-ipintelligence-examples-web-gettingstartedapi.java"; + + private static final String CONTACT_US = "https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=web-getting-started.api-src-main-java-fiftyone-ipintelligence-examples-web-gettingstartedapi.java&utm_term=enterprise-data-file"; + private Pipeline pipeline; private IPIntelligenceOnPremiseEngine engine; @@ -153,6 +167,25 @@ public void init() throws ServletException { throw new ServletException("Failed to create pipeline from data file '" + dataFileLocation + "'", e); } + writeStartupNotes(System.out, engine); + } + + /** + * Writes what the Enterprise data file adds, with the link to the + * contact page, when the engine uses a free data file, then the "Find + * out more" section. + * @param output where to write + * @param engine the engine the service uses + */ + static void writeStartupNotes( + PrintStream output, + IPIntelligenceOnPremiseEngine engine) { + if (DataFileHelper.isFreeDataFile(engine)) { + DataFileHelper.writeEnterpriseOffer( + new PrintWriter(output), CONTACT_US); + } + FindOutMore.write(output, EXAMPLE_TAG, + FindOutMore.ON_PREMISE_REPOSITORIES); } @Override