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);
}
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());
}
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());
}
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);
}
}
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);
}
}
Aggregations