Skip to content

Commit 17d7b1e

Browse files
committed
Fix iplocmapper
1 parent 08b8be7 commit 17d7b1e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,15 @@ public Optional<IpLocObject> apply(RpslObject nicObject) {
8686

8787
// Use a default name if there is no netname
8888
var network = String.join(", ", attributes.getOrDefault("netname", List.of("unknown")));
89-
var geoloc = String.join(", ", attributes.getOrDefault("geoloc", List.of()));
90-
var country = String.join(", ", attributes.getOrDefault("country", List.of()));
91-
var source = String.join(", ", attributes.getOrDefault("source", List.of()));
89+
var geoloc = attributes.containsKey("geoloc")
90+
? String.join(", ", attributes.getOrDefault("geoloc", List.of()))
91+
: null;
92+
var country = attributes.containsKey("country")
93+
? String.join(", ", attributes.getOrDefault("country", List.of()))
94+
: null;
95+
var source = attributes.containsKey("source")
96+
? String.join(", ", attributes.getOrDefault("source", List.of()))
97+
: null;
9298

9399
// If there is a geoloc field, we use the latitude and longitude provided
94100
if (attributes.containsKey("geoloc")) {
@@ -115,8 +121,10 @@ public Optional<IpLocObject> apply(RpslObject nicObject) {
115121
// build a query text string out of the cherry-picked fields
116122
var queryTextBuilder = new StringBuilder();
117123
for (String field : searchedFields) {
118-
var fieldValue = String.join(", ", attributes.get(field));
119-
if (!Strings.isNullOrEmpty(fieldValue)) {
124+
var value = attributes.containsKey(field)
125+
? String.join(", ", attributes.getOrDefault(field, List.of()))
126+
: null;
127+
if (!Strings.isNullOrEmpty(value)) {
120128
queryTextBuilder.append(attributes.get(field)).append(" ");
121129
}
122130
}

baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
class IpLocObjectTest {
5353

54-
private static List<RpslObject> nicObjects;
54+
private static List<RpslObject> rpslObjects;
5555
private static IpLocMapper ipLocMapper;
5656
private static List<IpLocObject> ipLocObjects;
5757
private static IpLocRepository iplocRepository;
@@ -63,7 +63,7 @@ public static void beforeAll() throws Exception {
6363
// Load the NIC sample objects
6464
var file = TestFiles.resolve("baremaps-testing/data/ripe/sample.txt");
6565
try (var input = Files.newInputStream(file)) {
66-
nicObjects = new RpslReader().read(input).toList();
66+
rpslObjects = new RpslReader().read(input).toList();
6767
}
6868

6969
// Init the geocoder service
@@ -78,7 +78,7 @@ public static void beforeAll() throws Exception {
7878
var dir = FSDirectory.open(directory);
7979
var searcherManager = new SearcherManager(dir, new SearcherFactory());
8080
ipLocMapper = new IpLocMapper(searcherManager);
81-
ipLocObjects = nicObjects.stream()
81+
ipLocObjects = rpslObjects.stream()
8282
.map(ipLocMapper)
8383
.filter(Optional::isPresent)
8484
.map(Optional::get)

0 commit comments

Comments
 (0)