Skip to content

Commit

Permalink
Add rpsl data store and simplify package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Nov 8, 2024
1 parent 21d67cf commit e35ec06
Show file tree
Hide file tree
Showing 165 changed files with 720 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.apache.baremaps.geoparquet.format.GeoParquetReader;
import org.apache.baremaps.geoparquet.GeoParquetReader;
import org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.apache.baremaps.geoparquet.format.GeoParquetReader;
import org.apache.baremaps.geoparquet.GeoParquetReader;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.concurrent.Callable;
import org.apache.baremaps.maplibre.tileset.Tileset;
import org.apache.baremaps.maplibre.tileset.TilesetLayer;
import org.apache.baremaps.openstreetmap.format.stream.ProgressLogger;
import org.apache.baremaps.openstreetmap.format.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.stream.ProgressLogger;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.apache.baremaps.tasks.ExportVectorTiles;
import org.apache.baremaps.tilestore.TileCoord;
import org.apache.baremaps.tilestore.TileEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@


import java.util.function.Function;
import org.apache.baremaps.openstreetmap.format.model.Element;
import org.apache.baremaps.openstreetmap.format.model.Node;
import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.openstreetmap.model.Node;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.LatLonShape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.baremaps.geocoder.openstreetmap;

import java.util.function.Consumer;
import org.apache.baremaps.openstreetmap.format.model.Element;
import org.apache.baremaps.openstreetmap.format.model.Entity;
import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.openstreetmap.model.Entity;
import org.apache.lucene.index.IndexWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,22 @@ public Optional<IpLocObject> apply(RpslObject nicObject) {
var attributes = nicObject.asMap();

// Use a default name if there is no netname
var network = attributes.getOrDefault("netname", "unknown");
var network = String.join(", ", attributes.getOrDefault("netname", List.of("unknown")));
var geoloc = String.join(", ", attributes.getOrDefault("geoloc", List.of()));
var country = String.join(", ", attributes.getOrDefault("country", List.of()));
var source = String.join(", ", attributes.getOrDefault("source", List.of()));

// If there is a geoloc field, we use the latitude and longitude provided
if (attributes.containsKey("geoloc")) {
var location = stringToCoordinate(attributes.get("geoloc"));
var location = stringToCoordinate(geoloc);
if (location.isPresent()) {
return Optional.of(new IpLocObject(
attributes.get("geoloc"),
geoloc,
inetRange,
location.get(),
network,
attributes.get("country"),
attributes.get("source"),
country,
source,
IpLocPrecision.GEOLOC));
}
}
Expand All @@ -112,36 +115,37 @@ public Optional<IpLocObject> apply(RpslObject nicObject) {
// build a query text string out of the cherry-picked fields
var queryTextBuilder = new StringBuilder();
for (String field : searchedFields) {
if (!Strings.isNullOrEmpty(attributes.get(field))) {
var fieldValue = String.join(", ", attributes.get(field));
if (!Strings.isNullOrEmpty(fieldValue)) {
queryTextBuilder.append(attributes.get(field)).append(" ");
}
}

String queryText = queryTextBuilder.toString();
var location = findLocationInCountry(queryText, attributes.get("country"));
var location = findLocationInCountry(queryText, country);
if (location.isPresent()) {
return Optional.of(new IpLocObject(
queryText,
inetRange,
location.get(),
network,
attributes.get("country"),
attributes.get("source"),
country,
source,
IpLocPrecision.GEOCODER));
}
}

// If there is a country get the location of country
if (attributes.containsKey("country")) {
var location = findCountryLocation(attributes.get("country"));
var location = findCountryLocation(country);
if (location.isPresent()) {
return Optional.of(new IpLocObject(
attributes.get("country"),
country,
inetRange,
location.get(),
network,
attributes.get("country"),
attributes.get("source"),
country,
source,
IpLocPrecision.COUNTRY));
}
}
Expand All @@ -152,7 +156,7 @@ public Optional<IpLocObject> apply(RpslObject nicObject) {
new Coordinate(),
network,
null,
attributes.get("source"),
source,
IpLocPrecision.WORLD));
} catch (Exception e) {
logger.warn("Error while mapping nic object to ip loc object", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;
import java.util.stream.Stream;
import javax.sql.DataSource;
import org.apache.baremaps.openstreetmap.format.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.locationtech.jts.geom.Coordinate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.StringJoiner;
import org.apache.baremaps.geocoder.GeocoderConstants;
import org.apache.baremaps.geocoder.openstreetmap.OpenStreetMapEntityConsumer;
import org.apache.baremaps.openstreetmap.format.pbf.PbfEntityReader;
import org.apache.baremaps.openstreetmap.format.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.pbf.PbfEntityReader;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.lucene.index.IndexWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.StringJoiner;
import org.apache.baremaps.iploc.IpLocReader;
import org.apache.baremaps.iploc.IpLocRepository;
import org.apache.baremaps.openstreetmap.format.stream.StreamException;
import org.apache.baremaps.openstreetmap.stream.StreamException;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.apache.lucene.search.SearcherFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.baremaps.tasks;

import static org.apache.baremaps.openstreetmap.format.stream.ConsumerUtils.consumeThenReturn;
import static org.apache.baremaps.openstreetmap.stream.ConsumerUtils.consumeThenReturn;

import java.io.BufferedInputStream;
import java.net.MalformedURLException;
Expand All @@ -28,12 +28,12 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.GZIPInputStream;
import org.apache.baremaps.openstreetmap.format.function.EntityGeometryBuilder;
import org.apache.baremaps.openstreetmap.format.function.EntityToGeometryMapper;
import org.apache.baremaps.openstreetmap.format.function.ProjectionTransformer;
import org.apache.baremaps.openstreetmap.format.model.*;
import org.apache.baremaps.openstreetmap.format.stream.StreamException;
import org.apache.baremaps.openstreetmap.format.xml.XmlChangeReader;
import org.apache.baremaps.openstreetmap.function.EntityGeometryBuilder;
import org.apache.baremaps.openstreetmap.function.EntityToGeometryMapper;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.apache.baremaps.openstreetmap.model.*;
import org.apache.baremaps.openstreetmap.stream.StreamException;
import org.apache.baremaps.openstreetmap.xml.XmlChangeReader;
import org.apache.baremaps.postgres.openstreetmap.HeaderRepository;
import org.apache.baremaps.postgres.openstreetmap.Repository;
import org.apache.baremaps.tilestore.TileCoord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.apache.baremaps.maplibre.style.Style;
import org.apache.baremaps.maplibre.tileset.Tileset;
import org.apache.baremaps.maplibre.tileset.TilesetQuery;
import org.apache.baremaps.openstreetmap.format.stream.ProgressLogger;
import org.apache.baremaps.openstreetmap.format.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.stream.ProgressLogger;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.apache.baremaps.tilestore.*;
import org.apache.baremaps.tilestore.file.FileTileStore;
import org.apache.baremaps.tilestore.mbtiles.MBTilesStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import org.apache.baremaps.openstreetmap.format.model.Element;
import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.postgres.openstreetmap.*;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import org.apache.baremaps.openstreetmap.format.model.Element;
import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.postgres.openstreetmap.*;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.nio.file.Path;
import java.util.StringJoiner;
import org.apache.baremaps.geopackage.store.GeoPackageDataStore;
import org.apache.baremaps.openstreetmap.format.function.ProjectionTransformer;
import org.apache.baremaps.geopackage.GeoPackageDataStore;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.apache.baremaps.postgres.store.PostgresDataStore;
import org.apache.baremaps.store.DataTableGeometryMapper;
import org.apache.baremaps.store.DataTableMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import java.net.URI;
import java.util.StringJoiner;
import org.apache.baremaps.geoparquet.store.GeoParquetDataStore;
import org.apache.baremaps.geoparquet.store.GeoParquetDataTable;
import org.apache.baremaps.openstreetmap.format.function.ProjectionTransformer;
import org.apache.baremaps.geoparquet.GeoParquetDataStore;
import org.apache.baremaps.geoparquet.GeoParquetDataTable;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.apache.baremaps.postgres.store.PostgresDataStore;
import org.apache.baremaps.store.DataTableGeometryMapper;
import org.apache.baremaps.store.DataTableMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package org.apache.baremaps.tasks;

import static org.apache.baremaps.openstreetmap.format.stream.ConsumerUtils.consumeThenReturn;
import static org.apache.baremaps.openstreetmap.stream.ConsumerUtils.consumeThenReturn;

import java.io.BufferedInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.StringJoiner;
import org.apache.baremaps.openstreetmap.format.function.*;
import org.apache.baremaps.openstreetmap.format.xml.XmlChangeReader;
import org.apache.baremaps.openstreetmap.function.*;
import org.apache.baremaps.openstreetmap.xml.XmlChangeReader;
import org.apache.baremaps.postgres.openstreetmap.CopyChangeImporter;
import org.apache.baremaps.postgres.openstreetmap.NodeRepository;
import org.apache.baremaps.postgres.openstreetmap.RelationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import org.apache.baremaps.openstreetmap.format.model.Node;
import org.apache.baremaps.openstreetmap.format.model.Relation;
import org.apache.baremaps.openstreetmap.format.model.Way;
import org.apache.baremaps.openstreetmap.format.pbf.PbfBlockReader;
import org.apache.baremaps.openstreetmap.format.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.model.Node;
import org.apache.baremaps.openstreetmap.model.Relation;
import org.apache.baremaps.openstreetmap.model.Way;
import org.apache.baremaps.openstreetmap.pbf.PbfBlockReader;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.apache.baremaps.postgres.openstreetmap.*;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import java.nio.file.Path;
import java.util.StringJoiner;
import org.apache.baremaps.openstreetmap.format.function.ProjectionTransformer;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.apache.baremaps.postgres.store.PostgresDataStore;
import org.apache.baremaps.shapefile.store.ShapefileDataTable;
import org.apache.baremaps.shapefile.ShapefileDataTable;
import org.apache.baremaps.store.DataTableGeometryMapper;
import org.apache.baremaps.store.DataTableMapper;
import org.apache.baremaps.workflow.Task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import java.util.Map;
import java.util.StringJoiner;
import java.util.zip.GZIPInputStream;
import org.apache.baremaps.openstreetmap.format.function.*;
import org.apache.baremaps.openstreetmap.format.model.Header;
import org.apache.baremaps.openstreetmap.format.model.Node;
import org.apache.baremaps.openstreetmap.format.model.Relation;
import org.apache.baremaps.openstreetmap.format.model.Way;
import org.apache.baremaps.openstreetmap.format.state.StateReader;
import org.apache.baremaps.openstreetmap.format.xml.XmlChangeReader;
import org.apache.baremaps.openstreetmap.function.*;
import org.apache.baremaps.openstreetmap.model.Header;
import org.apache.baremaps.openstreetmap.model.Node;
import org.apache.baremaps.openstreetmap.model.Relation;
import org.apache.baremaps.openstreetmap.model.Way;
import org.apache.baremaps.openstreetmap.state.StateReader;
import org.apache.baremaps.openstreetmap.xml.XmlChangeReader;
import org.apache.baremaps.postgres.openstreetmap.*;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.baremaps.geoparquet.store.GeoParquetDataTable;
import org.apache.baremaps.geoparquet.GeoParquetDataTable;
import org.apache.baremaps.testing.TestFiles;
import org.apache.baremaps.utils.FileUtils;
import org.apache.lucene.document.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.baremaps.integration;

import org.apache.baremaps.geopackage.store.GeoPackageDataStore;
import org.apache.baremaps.geopackage.GeoPackageDataStore;
import org.apache.baremaps.postgres.store.PostgresDataStore;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.apache.baremaps.testing.TestFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.baremaps.geoparquet.store.GeoParquetDataStore;
import org.apache.baremaps.geoparquet.GeoParquetDataStore;
import org.apache.baremaps.postgres.store.PostgresDataStore;
import org.apache.baremaps.testing.PostgresContainerTest;
import org.apache.baremaps.testing.TestFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.apache.baremaps.data.memory.OnHeapMemory;
import org.apache.baremaps.data.type.CoordinateDataType;
import org.apache.baremaps.data.type.LongListDataType;
import org.apache.baremaps.openstreetmap.format.model.Header;
import org.apache.baremaps.openstreetmap.format.state.StateReader;
import org.apache.baremaps.openstreetmap.model.Header;
import org.apache.baremaps.openstreetmap.state.StateReader;
import org.apache.baremaps.postgres.openstreetmap.*;
import org.apache.baremaps.testing.PostgresRepositoryTest;
import org.apache.baremaps.testing.TestFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.baremaps.openstreetmap.format.function.ProjectionTransformer;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.csv.store;
package org.apache.baremaps.csv;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.baremaps.csv.store;
package org.apache.baremaps.csv;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
Expand Down
Loading

0 comments on commit e35ec06

Please sign in to comment.