use of com.baremaps.osm.domain.Header 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;
}
}
use of com.baremaps.osm.domain.Header in project baremaps by baremaps.
the class UpdateService method call.
@Override
public Void call() throws Exception {
Header header = headerRepository.selectLatest();
String replicationUrl = header.getReplicationUrl();
Long sequenceNumber = header.getReplicationSequenceNumber() + 1;
Consumer<Entity> createGeometry = new CreateGeometryConsumer(coordinates, references);
Consumer<Entity> reprojectGeometry = new ReprojectEntityConsumer(4326, srid);
Consumer<Change> prepareGeometries = new ChangeEntityConsumer(createGeometry.andThen(reprojectGeometry));
Function<Change, Change> prepareChange = consumeThenReturn(prepareGeometries);
Consumer<Change> saveChange = new SaveChangeConsumer(nodeRepository, wayRepository, relationRepository);
URI changeUri = resolve(replicationUrl, sequenceNumber, "osc.gz");
Blob changeBlob = blobStore.get(changeUri);
ProgressLogger progressLogger = new ProgressLogger(changeBlob.getContentLength(), 5000);
try (InputStream blobInputStream = changeBlob.getInputStream();
InputStream progressInputStream = new InputStreamProgress(blobInputStream, progressLogger);
InputStream gzipInputStream = new GZIPInputStream(progressInputStream)) {
new OsmChangeParser().changes(gzipInputStream).map(prepareChange).forEach(saveChange);
}
URI stateUri = resolve(replicationUrl, sequenceNumber, "state.txt");
Blob stateBlob = blobStore.get(stateUri);
try (InputStream stateInputStream = stateBlob.getInputStream()) {
State state = new OsmStateParser().state(stateInputStream);
headerRepository.put(new Header(state.getSequenceNumber(), state.getTimestamp(), header.getReplicationUrl(), header.getSource(), header.getWritingProgram()));
}
return null;
}
use of com.baremaps.osm.domain.Header 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));
}
use of com.baremaps.osm.domain.Header in project baremaps by baremaps.
the class PostgresHeaderRepository method selectAll.
/**
* {@inheritDoc}
*/
@Override
public List<Header> selectAll() throws RepositoryException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(selectLatest)) {
try (ResultSet result = statement.executeQuery()) {
List<Header> values = new ArrayList<>();
while (result.next()) {
Header value = getValue(result);
values.add(value);
}
return values;
}
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.domain.Header in project baremaps by baremaps.
the class PostgresHeaderRepository method get.
/**
* {@inheritDoc}
*/
@Override
public List<Header> get(List<Long> keys) throws RepositoryException {
if (keys.isEmpty()) {
return List.of();
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(selectIn)) {
statement.setArray(1, connection.createArrayOf("int8", keys.toArray()));
try (ResultSet result = statement.executeQuery()) {
Map<Long, Header> values = new HashMap<>();
while (result.next()) {
Header value = getValue(result);
values.put(value.getReplicationSequenceNumber(), value);
}
return keys.stream().map(values::get).collect(Collectors.toList());
}
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
Aggregations