Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
600b974
Test: a query string parameter is shared by default, as share all que…
jwrosewell Nov 15, 2026
967f921
Fix: turn share all query string parameters on by default, so a query…
jwrosewell Nov 15, 2026
3897134
Test: with all Evidence shared, a cookie whose name does not start 51…
jwrosewell Nov 15, 2026
5d95d33
Fix: never share a cookie whose name does not start 51D_, the session…
jwrosewell Nov 15, 2026
6a0c78b
Test: a failure in a polling or watcher check is caught, logged and r…
jwrosewell Nov 15, 2026
8753aeb
Fix: catch and log a failure in a polling or watcher check, report an…
jwrosewell Nov 15, 2026
fd93b77
Test: data update messages, levels and statuses match the Errors tabl…
jwrosewell Nov 15, 2026
90186a6
Fix: log MD5 mismatch at Error with the table's message, warn and go …
jwrosewell Nov 15, 2026
b9bbebf
Test: Evidence keys are matched without regard to case by the default…
jwrosewell Nov 15, 2026
9797f69
Fix: match whitelisted Evidence keys without regard to case by defaul…
jwrosewell Nov 15, 2026
eb9fafa
Test: performance tests of the minification of the JavaScript Builder…
jwrosewell Nov 15, 2026
47a7ccc
Fix: minify the JavaScript Builder's script by default, with a SetMin…
jwrosewell Nov 15, 2026
6a76df2
Test: a comma-separated property list is read the same whatever white…
jwrosewell Nov 15, 2026
c6d5a3c
Fix: split a property list at each comma and trim each name, so a lis…
jwrosewell Nov 15, 2026
a455269
Test: Element Data keys are compared without regard to case, so data …
jwrosewell Nov 15, 2026
34e00f1
Fix: compare Element Data key names without regard to case in the typ…
jwrosewell Nov 15, 2026
4fe3b94
Test: the IP Intelligence getting started examples read each value wi…
jwrosewell Nov 15, 2026
0014283
Fix: the IP Intelligence getting started examples write each value wi…
jwrosewell Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@
import fiftyone.ipintelligence.shared.IPIntelligenceData;
import fiftyone.ipintelligence.shared.testhelpers.KeyUtils;
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.core.data.IWeightedValue;
import fiftyone.pipeline.core.flowelements.Pipeline;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static fiftyone.common.testhelpers.LogbackHelper.configureLogback;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asFloatProperty;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asIPAddressProperty;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asIntegerProperty;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asStringProperty;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asWktStringProperty;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asWeightedString;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.tryGet;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.weightedValues;
import static fiftyone.pipeline.util.FileFinder.getFilePath;

/**
Expand Down Expand Up @@ -199,24 +199,51 @@ private static void analyzeEvidence(Map<String, String> evidence,
/* Display the results of the lookup, which are called IP Intelligence properties.
See the property dictionary at https://51degrees.com/developers/property-dictionary?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=console-src-main-java-fiftyone-ipintelligence-examples-console-gettingstartedcloud.java&utm_term=property-dictionary
for details of all available properties. */
writer.println("\tRegisteredName: " + asStringProperty(tryGet(ipData::getRegisteredName)));
writer.println("\tRegisteredOwner: " + asStringProperty(tryGet(ipData::getRegisteredOwner)));
writer.println("\tRegisteredCountry: " + asStringProperty(tryGet(ipData::getRegisteredCountry)));
writer.println("\tIpRangeStart: " + asIPAddressProperty(tryGet(ipData::getIpRangeStart)));
writer.println("\tIpRangeEnd: " + asIPAddressProperty(tryGet(ipData::getIpRangeEnd)));
writer.println("\tCountry: " + asStringProperty(tryGet(ipData::getCountry)));
writer.println("\tCountryCode: " + asStringProperty(tryGet(ipData::getCountryCode)));
writer.println("\tCountryCode3: " + asStringProperty(tryGet(ipData::getCountryCode3)));
writer.println("\tRegion: " + asStringProperty(tryGet(ipData::getRegion)));
writer.println("\tState: " + asStringProperty(tryGet(ipData::getState)));
writer.println("\tTown: " + asStringProperty(tryGet(ipData::getTown)));
writer.println("\tLatitude: " + asFloatProperty(tryGet(ipData::getLatitude)));
writer.println("\tLongitude: " + asFloatProperty(tryGet(ipData::getLongitude)));
writer.println("\tAreas: " + asWktStringProperty(tryGet(ipData::getAreas)));
writer.println("\tAccuracyRadiusMin: " + asIntegerProperty(tryGet(ipData::getAccuracyRadiusMin)));
writer.println("\tTimeZoneOffset: " + asIntegerProperty(tryGet(ipData::getTimeZoneOffset)));
writeValue(writer, "RegisteredName", tryGet(ipData::getRegisteredName));
writeValue(writer, "RegisteredOwner", tryGet(ipData::getRegisteredOwner));
writeValue(writer, "RegisteredCountry", tryGet(ipData::getRegisteredCountry));
writeValue(writer, "IpRangeStart", tryGet(ipData::getIpRangeStart));
writeValue(writer, "IpRangeEnd", tryGet(ipData::getIpRangeEnd));
writeValue(writer, "Country", tryGet(ipData::getCountry));
writeValue(writer, "CountryCode", tryGet(ipData::getCountryCode));
writeValue(writer, "CountryCode3", tryGet(ipData::getCountryCode3));
writeValue(writer, "Region", tryGet(ipData::getRegion));
writeValue(writer, "State", tryGet(ipData::getState));
writeValue(writer, "Town", tryGet(ipData::getTown));
writeValue(writer, "Latitude", tryGet(ipData::getLatitude));
writeValue(writer, "Longitude", tryGet(ipData::getLongitude));
writeValue(writer, "Areas", tryGet(ipData::getAreas));
writeValue(writer, "AccuracyRadiusMin", tryGet(ipData::getAccuracyRadiusMin));
writeValue(writer, "TimeZoneOffset", tryGet(ipData::getTimeZoneOffset));
}
writer.println();
writer.flush();
}

/**
* Writes each value of a property with its weighting, or why it has no
* value.
*/
private static void writeValue(PrintWriter writer,
String property,
AspectPropertyValue<?> result) {
if (result.hasValue() == false) {
writer.println("\t" + property + ": " + asWeightedString(result));
return;
}
/* IP Intelligence properties return weighted values. Each value comes
with a weighting between 0 and 1, which says how much of the IP range
the value applies to, and a property with a single answer returns it
with a weighting of 1. */
StringBuilder line = new StringBuilder();
for (IWeightedValue<?> weighted : weightedValues(result)) {
if (line.length() > 0) {
line.append(", ");
}
line.append(weighted.getValue())
.append(String.format(Locale.ROOT, " (weighting %.2f)",
weighted.getWeighting()));
}
writer.println("\t" + property + ": " + line);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Supplier;

import static fiftyone.common.testhelpers.LogbackHelper.configureLogback;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.asString;
import static fiftyone.ipintelligence.examples.shared.PropertyHelper.weightedValues;
import static fiftyone.pipeline.util.FileFinder.getFilePath;
import static fiftyone.ipintelligence.examples.shared.DataFileHelper.LITE_DATA_FILE_REL_PATH;

Expand Down Expand Up @@ -261,7 +263,25 @@ private static boolean writeValue(PrintWriter writer,
String property,
Supplier<AspectPropertyValue<?>> value) {
if (DataFileHelper.hasProperty(engine, property)) {
writer.println("\t" + property + ": " + asString(value.get()));
AspectPropertyValue<?> result = value.get();
if (result.hasValue() == false) {
writer.println("\t" + property + ": " + asString(result));
return false;
}
/* IP Intelligence properties return weighted values. Each value
comes with a weighting between 0 and 1, which says how much of the
IP range the value applies to, and a property with a single answer
returns it with a weighting of 1. */
StringBuilder line = new StringBuilder();
for (IWeightedValue<?> weighted : weightedValues(result)) {
if (line.length() > 0) {
line.append(", ");
}
line.append(weighted.getValue())
.append(String.format(Locale.ROOT, " (weighting %.2f)",
weighted.getWeighting()));
}
writer.println("\t" + property + ": " + line);
return false;
}
writer.println("\t" + property + ": " + DataFileHelper.NEEDS_ENTERPRISE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* *********************************************************************
* 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.console;

import org.junit.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertTrue;

/**
* "Examples MUST demonstrate accessing both the value and its associated
* weighting" (ip-intelligence-specification/required-examples.md line 107).
* The getting started examples are where a developer first reads how to get
* a result, so their own code reads each value with its weighting, rather
* than leaving it to a helper the developer does not see.
*/
public class WeightingShownTest {

private static String source(String name) throws IOException {
Path path = Paths.get("src", "main", "java", "fiftyone",
"ipintelligence", "examples", "console", name + ".java");
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
}

private static void assertShowsWeighting(String name) throws IOException {
String source = source(name);
assertTrue(name + " does not read a weighting",
source.contains(".getWeighting()"));
assertTrue(name + " does not read the weighted value",
source.contains("weightedValues(") &&
source.contains(".getValue()"));
}

@Test
public void gettingStartedOnPrem_ShowsValueAndWeighting()
throws IOException {
assertShowsWeighting("GettingStartedOnPrem");
}

@Test
public void gettingStartedCloud_ShowsValueAndWeighting()
throws IOException {
assertShowsWeighting("GettingStartedCloud");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
package fiftyone.ipintelligence.examples.shared;

import fiftyone.pipeline.core.data.IWeightedValue;
import fiftyone.pipeline.core.data.WeightedValue;
import fiftyone.pipeline.core.data.WktString;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import fiftyone.pipeline.engines.data.AspectPropertyValueDefault;
import fiftyone.pipeline.engines.exceptions.PropertyMissingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -193,6 +196,59 @@ public static <T> String asString(AspectPropertyValue<T> value) {
return "Unknown. " + value.getNoValueMessage();
}

/**
* Get each value of an IP Intelligence property with its weighting. IP
* Intelligence properties return weighted values, and a property with a
* single answer returns it with a weighting of 1. Due to Java generics
* type erasure, the on-premise engine returns
* List&lt;IWeightedValue&lt;T&gt;&gt; even when the declared type is T, so
* a value that is not such a list is given here with a weighting of 1.
* @param property the property value, may be null
* @return the weighted values, or an empty list when there is no value
*/
public static List<IWeightedValue<?>> weightedValues(
AspectPropertyValue<?> property) {
List<IWeightedValue<?>> result = new ArrayList<>();
if (property == null || property.hasValue() == false) {
return result;
}
Object value = property.getValue();
if (value instanceof List) {
for (Object item : (List<?>) value) {
if (item instanceof IWeightedValue) {
result.add((IWeightedValue<?>) item);
} else {
result.add(new WeightedValue<>(FULL_WEIGHTING, item));
}
}
} else {
result.add(new WeightedValue<>(FULL_WEIGHTING, value));
}
return result;
}

/**
* The raw weighting of a value that is the only answer, which is a
* weighting of 1.
*/
private static final int FULL_WEIGHTING = 65535;

/**
* Write each value of an IP Intelligence property with its weighting,
* for example "gb (weighting 1.00)", or why there is no value.
* @param property the property value, may be null
* @return the values with their weightings, joined with ", "
*/
public static String asWeightedString(AspectPropertyValue<?> property) {
if (property == null || property.hasValue() == false) {
return reportNoValue(property);
}
return weightedValues(property).stream()
.map(weighted -> String.format(Locale.ROOT, "%s (weighting %.2f)",
weighted.getValue(), weighted.getWeighting()))
.collect(Collectors.joining(", "));
}

/**
* Helper to get the first raw value of an IP Intelligence property.
* Due to Java generics type erasure, the on-premise engine may return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* *********************************************************************
* 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.shared;

import fiftyone.pipeline.core.data.IWeightedValue;
import fiftyone.pipeline.engines.data.AspectPropertyValue;
import fiftyone.pipeline.engines.data.AspectPropertyValueDefault;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* "Examples MUST demonstrate accessing both the value and its associated
* weighting" (ip-intelligence-specification/required-examples.md line 107).
* The examples read each value of a property with its weighting through
* {@link PropertyHelper#weightedValues}.
*/
public class PropertyHelperWeightingTests {

private static IWeightedValue<Object> weighted(
final int rawWeighting,
final Object value) {
return new IWeightedValue<Object>() {
@Override
public int getRawWeighting() {
return rawWeighting;
}

@Override
public Object getValue() {
return value;
}
};
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void weightedValues_ListOfWeightedValues_KeepsEachWeighting() {
List<IWeightedValue<Object>> list = new ArrayList<>();
list.add(weighted(49151, "gb"));
list.add(weighted(16384, "ie"));
AspectPropertyValue<String> property =
new AspectPropertyValueDefault(list);

List<IWeightedValue<?>> values =
PropertyHelper.weightedValues(property);

assertEquals(2, values.size());
assertEquals("gb", values.get(0).getValue());
assertEquals(49151 / 65535f, values.get(0).getWeighting(), 0.0001);
assertEquals("ie", values.get(1).getValue());
assertEquals(16384 / 65535f, values.get(1).getWeighting(), 0.0001);
}

/**
* "a property with a single answer returns it with a weighting of 1"
* (required-examples.md line 107)
*/
@Test
public void weightedValues_SingleValue_HasWeightingOfOne() {
AspectPropertyValue<String> property =
new AspectPropertyValueDefault<>("gb");

List<IWeightedValue<?>> values =
PropertyHelper.weightedValues(property);

assertEquals(1, values.size());
assertEquals("gb", values.get(0).getValue());
assertEquals(1f, values.get(0).getWeighting(), 0.0001);
}

@Test
public void weightedValues_NoValue_IsEmpty() {
assertTrue(PropertyHelper.weightedValues(
new AspectPropertyValueDefault<String>()).isEmpty());
assertTrue(PropertyHelper.weightedValues(null).isEmpty());
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void asWeightedString_ShowsValueAndWeighting() {
List<IWeightedValue<Object>> list = new ArrayList<>();
list.add(weighted(65535, "gb"));
assertEquals("gb (weighting 1.00)", PropertyHelper.asWeightedString(
new AspectPropertyValueDefault(list)));
}
}
Loading
Loading