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 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); + } + } +}