Search in sources :

Example 6 with Header

use of com.baremaps.osm.domain.Header in project baremaps by baremaps.

the class OsmXmlSpliterator method readHeader.

private Header readHeader() {
    String generator = reader.getAttributeValue(null, ATTRIBUTE_NAME_GENERATOR);
    String source = reader.getAttributeValue(null, ATTRIBUTE_NAME_SOURCE);
    String replicationUrl = reader.getAttributeValue(null, ATTRIBUTE_NAME_OSMOSIS_REPLICATION_URL);
    String replicationSequenceNumberValue = reader.getAttributeValue(null, ATTRIBUTE_NAME_OSMOSIS_REPLICATION_SEQUENCE_NUMBER);
    Long replicationSequenceNumber = replicationSequenceNumberValue != null ? Long.parseLong(replicationSequenceNumberValue) : null;
    String timestampValue = reader.getAttributeValue(null, ATTRIBUTE_NAME_TIMESTAMP);
    LocalDateTime timestamp = timestampValue != null ? LocalDateTime.parse(timestampValue, format) : null;
    String osmosisReplicationTimestampValue = reader.getAttributeValue(null, ATTRIBUTE_NAME_OSMOSIS_REPLICATION_TIMESTAMP);
    timestamp = osmosisReplicationTimestampValue != null ? LocalDateTime.parse(osmosisReplicationTimestampValue, format) : timestamp;
    return new Header(replicationSequenceNumber, timestamp, replicationUrl, source, generator);
}
Also used : LocalDateTime(java.time.LocalDateTime) Header(com.baremaps.osm.domain.Header)

Example 7 with Header

use of com.baremaps.osm.domain.Header in project baremaps by baremaps.

the class OpenStreetMapTest method process.

void process(Stream<Entity> stream, long headerCount, long boundCount, long nodeCount, long wayCount, long relationCount) {
    AtomicLong headers = new AtomicLong(0);
    AtomicLong bounds = new AtomicLong(0);
    AtomicLong nodes = new AtomicLong(0);
    AtomicLong ways = new AtomicLong(0);
    AtomicLong relations = new AtomicLong(0);
    stream.forEach(new EntityConsumer() {

        @Override
        public void match(Header header) {
            assertNotNull(header);
            assertEquals("osmium/1.8.0", header.getWritingProgram());
            headers.incrementAndGet();
        }

        @Override
        public void match(Bound bound) {
            assertNotNull(bound);
            assertEquals(43.75169, bound.getMaxLat(), 0.000001);
            assertEquals(7.448637, bound.getMaxLon(), 0.000001);
            assertEquals(43.72335, bound.getMinLat(), 0.000001);
            assertEquals(7.409205, bound.getMinLon(), 0.000001);
            bounds.incrementAndGet();
        }

        @Override
        public void match(Node node) {
            assertNotNull(node);
            nodes.incrementAndGet();
        }

        @Override
        public void match(Way way) {
            assertNotNull(way);
            ways.incrementAndGet();
        }

        @Override
        public void match(Relation relation) {
            assertNotNull(relation);
            relations.incrementAndGet();
        }
    });
    assertEquals(headerCount, headers.get());
    assertEquals(boundCount, bounds.get());
    assertEquals(nodeCount, nodes.get());
    assertEquals(wayCount, ways.get());
    assertEquals(relationCount, relations.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Relation(com.baremaps.osm.domain.Relation) Header(com.baremaps.osm.domain.Header) Node(com.baremaps.osm.domain.Node) Bound(com.baremaps.osm.domain.Bound) EntityConsumer(com.baremaps.osm.function.EntityConsumer) Way(com.baremaps.osm.domain.Way)

Example 8 with Header

use of com.baremaps.osm.domain.Header 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)

Example 9 with Header

use of com.baremaps.osm.domain.Header in project baremaps by baremaps.

the class PostgresHeaderRepository method put.

/**
 * {@inheritDoc}
 */
@Override
public void put(List<Header> values) throws RepositoryException {
    if (values.isEmpty()) {
        return;
    }
    try (Connection connection = dataSource.getConnection();
        PreparedStatement statement = connection.prepareStatement(insert)) {
        for (Header value : values) {
            statement.clearParameters();
            setValue(statement, value);
            statement.addBatch();
        }
        statement.executeBatch();
    } catch (SQLException e) {
        throw new RepositoryException(e);
    }
}
Also used : Header(com.baremaps.osm.domain.Header) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) PreparedStatement(java.sql.PreparedStatement) RepositoryException(com.baremaps.osm.repository.RepositoryException)

Example 10 with Header

use of com.baremaps.osm.domain.Header in project baremaps by baremaps.

the class PostgresHeaderRepository method copy.

/**
 * {@inheritDoc}
 */
@Override
public void copy(List<Header> values) throws RepositoryException {
    if (values.isEmpty()) {
        return;
    }
    try (Connection connection = dataSource.getConnection()) {
        PGConnection pgConnection = connection.unwrap(PGConnection.class);
        try (CopyWriter writer = new CopyWriter(new PGCopyOutputStream(pgConnection, copy))) {
            writer.writeHeader();
            for (Header value : values) {
                writer.startRow(5);
                writer.writeLong(value.getReplicationSequenceNumber());
                writer.writeLocalDateTime(value.getReplicationTimestamp());
                writer.writeString(value.getReplicationUrl());
                writer.writeString(value.getSource());
                writer.writeString(value.getWritingProgram());
            }
        }
    } catch (IOException | SQLException e) {
        throw new RepositoryException(e);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) Header(com.baremaps.osm.domain.Header) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Aggregations

Header (com.baremaps.osm.domain.Header)13 URI (java.net.URI)5 RepositoryException (com.baremaps.osm.repository.RepositoryException)4 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 PGConnection (org.postgresql.PGConnection)4 ImportService (com.baremaps.osm.repository.ImportService)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 LongListDataType (com.baremaps.store.type.LongListDataType)3 PreparedStatement (java.sql.PreparedStatement)3 LocalDateTime (java.time.LocalDateTime)3 List (java.util.List)3 Tag (org.junit.jupiter.api.Tag)3 Test (org.junit.jupiter.api.Test)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 Blob (com.baremaps.blob.Blob)2 OsmChangeParser (com.baremaps.osm.change.OsmChangeParser)2