Search in sources :

Example 1 with ImportService

use of com.baremaps.osm.repository.ImportService in project baremaps by baremaps.

the class ImportUpdateMonacoTest method monaco.

@Test
@Tag("integration")
void monaco() throws Exception {
    LongDataMap<Coordinate> coordinates = new LongDataOpenHashMap<>(new DataStore<>(new CoordinateDataType(), new OnHeapMemory()));
    LongDataMap<List<Long>> references = new LongDataOpenHashMap<>(new DataStore<>(new LongListDataType(), new OnHeapMemory()));
    // Import data
    new ImportService(new URI("res://monaco/monaco-210801.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(3047l, headerRepository.selectLatest().getReplicationSequenceNumber());
    // Fix the replicationUrl so that we can update the database with local files
    headerRepository.delete(3047l);
    headerRepository.put(new Header(3047l, LocalDateTime.of(2021, 8, 01, 20, 21, 41, 0), "res://monaco/monaco-updates", "", ""));
    coordinates = new PostgresCoordinateMap(dataSource);
    references = new PostgresReferenceMap(dataSource);
    // Generate the diff and update the database
    long replicationSequenceNumber = headerRepository.selectLatest().getReplicationSequenceNumber();
    while (replicationSequenceNumber < 3075) {
        new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call();
        new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
        long nextReplicationSequenceNumber = headerRepository.selectLatest().getReplicationSequenceNumber();
        assertEquals(replicationSequenceNumber + 1, nextReplicationSequenceNumber);
        replicationSequenceNumber = nextReplicationSequenceNumber;
    }
}
Also used : LongListDataType(com.baremaps.store.type.LongListDataType) DiffService(com.baremaps.osm.repository.DiffService) URI(java.net.URI) ImportService(com.baremaps.osm.repository.ImportService) Header(com.baremaps.osm.domain.Header) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateDataType(com.baremaps.store.type.CoordinateDataType) List(java.util.List) LongDataOpenHashMap(com.baremaps.store.LongDataOpenHashMap) OnHeapMemory(com.baremaps.store.memory.OnHeapMemory) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with ImportService

use of com.baremaps.osm.repository.ImportService in project baremaps by baremaps.

the class Import method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    HeaderRepository headerRepository = new PostgresHeaderRepository(datasource);
    Repository<Long, Node> nodeRepository = new PostgresNodeRepository(datasource);
    Repository<Long, Way> wayRepository = new PostgresWayRepository(datasource);
    Repository<Long, Relation> relationRepository = new PostgresRelationRepository(datasource);
    Path directory = Files.createTempDirectory(Paths.get("."), "baremaps_");
    Path nodes = Files.createDirectories(directory.resolve("nodes"));
    Path referencesKeys = Files.createDirectories(directory.resolve("references_keys"));
    Path referencesValues = Files.createDirectories(directory.resolve("references_values"));
    LongDataMap<Coordinate> coordinates = new LongAlignedDataDenseMap<>(new LonLatDataType(), new OnDiskMemory(nodes));
    LongDataMap<List<Long>> references = new LongDataSortedMap<>(new AlignedDataList<>(new PairDataType<>(new LongDataType(), new LongDataType()), new OnDiskMemory(referencesKeys)), new DataStore<>(new LongListDataType(), new OnDiskMemory(referencesValues)));
    logger.info("Importing data");
    new ImportService(file, blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
    logger.info("Done");
    return 0;
}
Also used : PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) LongListDataType(com.baremaps.store.type.LongListDataType) Node(com.baremaps.osm.domain.Node) Way(com.baremaps.osm.domain.Way) Relation(com.baremaps.osm.domain.Relation) ImportService(com.baremaps.osm.repository.ImportService) LongDataSortedMap(com.baremaps.store.LongDataSortedMap) LongAlignedDataDenseMap(com.baremaps.store.LongAlignedDataDenseMap) AlignedDataList(com.baremaps.store.AlignedDataList) List(java.util.List) BlobStore(com.baremaps.blob.BlobStore) PairDataType(com.baremaps.store.type.PairDataType) Path(java.nio.file.Path) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) OnDiskMemory(com.baremaps.store.memory.OnDiskMemory) LonLatDataType(com.baremaps.store.type.LonLatDataType) DataSource(javax.sql.DataSource) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) LongDataType(com.baremaps.store.type.LongDataType) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository)

Example 3 with ImportService

use of com.baremaps.osm.repository.ImportService in project baremaps by baremaps.

the class ImportUpdateDataTest method data.

@Test
@Tag("integration")
void data() throws Exception {
    LongDataMap<Coordinate> coordinates = new LongDataOpenHashMap<>(new DataStore<>(new CoordinateDataType(), new OnHeapMemory()));
    LongDataMap<List<Long>> references = new LongDataOpenHashMap<>(new DataStore<>(new LongListDataType(), new OnHeapMemory()));
    // Import data
    new ImportService(new URI("res://simple/data.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    headerRepository.put(new Header(0l, LocalDateTime.of(2020, 1, 1, 0, 0, 0, 0), "res://simple", "", ""));
    // Check node importation
    assertNull(nodeRepository.get(0l));
    assertNotNull(nodeRepository.get(1l));
    assertNotNull(nodeRepository.get(2l));
    assertNotNull(nodeRepository.get(3l));
    assertNull(nodeRepository.get(4l));
    // Check way importation
    assertNull(wayRepository.get(0l));
    assertNotNull(wayRepository.get(1l));
    assertNull(wayRepository.get(2l));
    // Check relation importation
    assertNull(relationRepository.get(0l));
    assertNotNull(relationRepository.get(1l));
    assertNull(relationRepository.get(2l));
    // Check node properties
    Node node = nodeRepository.get(1l);
    Assertions.assertEquals(1, node.getLon());
    Assertions.assertEquals(1, node.getLat());
    // Check way properties
    Way way = wayRepository.get(1l);
    assertNotNull(way);
    // Update the database
    new UpdateService(blobStore, new PostgresCoordinateMap(dataSource), new PostgresReferenceMap(dataSource), headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    // Check deletions
    assertNull(nodeRepository.get(0l));
    assertNull(nodeRepository.get(1l));
    // Check insertions
    assertNotNull(nodeRepository.get(2l));
    assertNotNull(nodeRepository.get(3l));
    assertNotNull(nodeRepository.get(4l));
}
Also used : LongListDataType(com.baremaps.store.type.LongListDataType) Node(com.baremaps.osm.domain.Node) URI(java.net.URI) Way(com.baremaps.osm.domain.Way) ImportService(com.baremaps.osm.repository.ImportService) Header(com.baremaps.osm.domain.Header) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateDataType(com.baremaps.store.type.CoordinateDataType) List(java.util.List) LongDataOpenHashMap(com.baremaps.store.LongDataOpenHashMap) OnHeapMemory(com.baremaps.store.memory.OnHeapMemory) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 4 with ImportService

use of com.baremaps.osm.repository.ImportService in project baremaps by baremaps.

the class ImportUpdateLiechtensteinTest method liechtenstein.

@Test
@Tag("integration")
void liechtenstein() throws Exception {
    LongDataMap<Coordinate> coordinates = new LongDataOpenHashMap<>(new DataStore<>(new CoordinateDataType(), new OnHeapMemory()));
    LongDataMap<List<Long>> references = new LongDataOpenHashMap<>(new DataStore<>(new LongListDataType(), new OnHeapMemory()));
    // Import data
    new ImportService(new URI("res://liechtenstein/liechtenstein.osm.pbf"), blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2434l, headerRepository.selectLatest().getReplicationSequenceNumber());
    // Fix the replicationUrl so that we can update the database with local files
    headerRepository.put(new Header(2434l, LocalDateTime.of(2019, 11, 18, 21, 19, 5, 0), "res://liechtenstein", "", ""));
    coordinates = new PostgresCoordinateMap(dataSource);
    references = new PostgresReferenceMap(dataSource);
    assertEquals(0, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    // Update the database
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2435l, headerRepository.selectLatest().getReplicationSequenceNumber());
    assertEquals(2, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2436l, headerRepository.selectLatest().getReplicationSequenceNumber());
    assertEquals(0, new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857, 14).call().size());
    new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, 3857).call();
    assertEquals(2437l, headerRepository.selectLatest().getReplicationSequenceNumber());
}
Also used : LongListDataType(com.baremaps.store.type.LongListDataType) DiffService(com.baremaps.osm.repository.DiffService) URI(java.net.URI) ImportService(com.baremaps.osm.repository.ImportService) Header(com.baremaps.osm.domain.Header) UpdateService(com.baremaps.osm.repository.UpdateService) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateDataType(com.baremaps.store.type.CoordinateDataType) List(java.util.List) LongDataOpenHashMap(com.baremaps.store.LongDataOpenHashMap) OnHeapMemory(com.baremaps.store.memory.OnHeapMemory) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

ImportService (com.baremaps.osm.repository.ImportService)4 LongListDataType (com.baremaps.store.type.LongListDataType)4 List (java.util.List)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 Header (com.baremaps.osm.domain.Header)3 UpdateService (com.baremaps.osm.repository.UpdateService)3 LongDataOpenHashMap (com.baremaps.store.LongDataOpenHashMap)3 OnHeapMemory (com.baremaps.store.memory.OnHeapMemory)3 CoordinateDataType (com.baremaps.store.type.CoordinateDataType)3 URI (java.net.URI)3 Tag (org.junit.jupiter.api.Tag)3 Test (org.junit.jupiter.api.Test)3 Node (com.baremaps.osm.domain.Node)2 Way (com.baremaps.osm.domain.Way)2 DiffService (com.baremaps.osm.repository.DiffService)2 BlobStore (com.baremaps.blob.BlobStore)1 Relation (com.baremaps.osm.domain.Relation)1 PostgresHeaderRepository (com.baremaps.osm.postgres.PostgresHeaderRepository)1 PostgresNodeRepository (com.baremaps.osm.postgres.PostgresNodeRepository)1 PostgresRelationRepository (com.baremaps.osm.postgres.PostgresRelationRepository)1