Skip to content

Commit

Permalink
Move RPSL classes in a dedicated module
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Nov 8, 2024
1 parent 03d217a commit 21d67cf
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 279 deletions.
8 changes: 4 additions & 4 deletions baremaps-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ limitations under the License.
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
<dependency>
<groupId>net.ripe.ipresource</groupId>
<artifactId>ipresource</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-csv</artifactId>
Expand Down Expand Up @@ -90,6 +86,10 @@ limitations under the License.
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-postgres</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-rpsl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-shapefile</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.regex.Pattern;
import net.ripe.ipresource.IpResourceRange;
import org.apache.baremaps.geocoder.geonames.GeonamesQueryBuilder;
import org.apache.baremaps.rpsl.RpslObject;
import org.apache.baremaps.rpsl.RpslUtils;
import org.apache.baremaps.utils.IsoCountriesUtils;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SearcherManager;
Expand All @@ -36,7 +38,7 @@
import org.slf4j.LoggerFactory;

/** Generating pairs of IP address ranges and their locations into an SQLite database */
public class IpLocMapper implements Function<NicObject, Optional<IpLocObject>> {
public class IpLocMapper implements Function<RpslObject, Optional<IpLocObject>> {

private static final Logger logger = LoggerFactory.getLogger(IpLocMapper.class);

Expand Down Expand Up @@ -64,13 +66,13 @@ public IpLocMapper(SearcherManager searcherManager) {
*/
@Override
@SuppressWarnings({"squid:S3776", "squid:S1192"})
public Optional<IpLocObject> apply(NicObject nicObject) {
public Optional<IpLocObject> apply(RpslObject nicObject) {
try {
if (nicObject.attributes().isEmpty()) {
return Optional.empty();
}

if (!NicUtils.isInetnum(nicObject)) {
if (!RpslUtils.isInetnum(nicObject)) {
return Optional.empty();
}

Expand All @@ -80,7 +82,7 @@ public Optional<IpLocObject> apply(NicObject nicObject) {
var end = InetAddresses.forString(ipRange.getEnd().toString());
var inetRange = new InetRange(start, end);

var attributes = nicObject.toMap();
var attributes = nicObject.asMap();

// Use a default name if there is no netname
var network = attributes.getOrDefault("netname", "unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public record IpLocObject(
Coordinate coordinate,
String network,
String country,

String source,

IpLocPrecision precision) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStream;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.baremaps.rpsl.RpslReader;
import org.apache.lucene.search.SearcherManager;

/** A reader for IP location data. */
Expand All @@ -44,7 +45,7 @@ public IpLocReader(SearcherManager searcherManager) {
* @return a {@link Stream} of IP location objects
*/
public Stream<IpLocObject> read(InputStream inputStream) {
var nicReader = new NicReader();
var nicReader = new RpslReader();
return nicReader.read(inputStream)
.map(new IpLocMapper(searcherManager))
.filter(Optional::isPresent)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;
import java.util.Optional;
import net.ripe.ipresource.IpResourceRange;
import org.apache.baremaps.rpsl.RpslObject;
import org.apache.baremaps.rpsl.RpslReader;
import org.apache.baremaps.tasks.CreateGeonamesIndex;
import org.apache.baremaps.testing.TestFiles;
import org.apache.baremaps.utils.FileUtils;
Expand All @@ -49,7 +51,7 @@
*/
class IpLocObjectTest {

private static List<NicObject> nicObjects;
private static List<RpslObject> nicObjects;
private static IpLocMapper ipLocMapper;
private static List<IpLocObject> ipLocObjects;
private static IpLocRepository iplocRepository;
Expand All @@ -59,7 +61,10 @@ class IpLocObjectTest {
@BeforeAll
public static void beforeAll() throws Exception {
// Load the NIC sample objects
nicObjects = NicData.sample("baremaps-testing/data/ripe/sample.txt");
var file = TestFiles.resolve("baremaps-testing/data/ripe/sample.txt");
try (var input = Files.newInputStream(file)) {
nicObjects = new RpslReader().read(input).toList();
}

// Init the geocoder service
directory = Files.createTempDirectory(Paths.get("."), "geocoder_");
Expand Down
24 changes: 24 additions & 0 deletions baremaps-rpsl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps</artifactId>
<version>0.7.4-SNAPSHOT</version>
</parent>

<artifactId>baremaps-rpsl</artifactId>

<dependencies>
<dependency>
<groupId>net.ripe.ipresource</groupId>
<artifactId>ipresource</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,11 @@
* limitations under the License.
*/

package org.apache.baremaps.iploc;
package org.apache.baremaps.rpsl;

/**
* Represents a RPSL attribute.
*/
public record RpslAttribute(String name, String value) {


import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
import org.apache.baremaps.testing.TestFiles;

public class NicData {

private static final String SAMPLE = "sample.txt";

public static List<NicObject> sample(String resource) throws IOException {
try (InputStream input = Files.newInputStream(TestFiles.resolve(resource))) {
return new NicReader().read(input).toList();
}
}
}
Loading

0 comments on commit 21d67cf

Please sign in to comment.