Search in sources :

Example 1 with Blob

use of com.baremaps.blob.Blob in project baremaps by baremaps.

the class EditorResources method getTile.

@GET
@javax.ws.rs.Path("/tiles/{z}/{x}/{y}.mvt")
public Response getTile(@PathParam("z") int z, @PathParam("x") int x, @PathParam("y") int y) {
    try {
        List<PostgresQuery> queries = asPostgresQuery(getTileset());
        TileStore tileStore = new PostgresTileStore(dataSource, queries);
        Tile tile = new Tile(x, y, z);
        Blob blob = tileStore.read(tile);
        if (blob != null) {
            return Response.status(200).header(CONTENT_TYPE, blob.getContentType()).header(CONTENT_ENCODING, blob.getContentEncoding()).entity(blob.getInputStream()).build();
        } else {
            return Response.status(204).build();
        }
    } catch (Exception ex) {
        logger.error("Tile error", ex);
        return Response.status(404).build();
    }
}
Also used : TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Blob(com.baremaps.blob.Blob) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Tile(com.baremaps.tile.Tile) BlobStoreException(com.baremaps.blob.BlobStoreException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) GET(javax.ws.rs.GET)

Example 2 with Blob

use of com.baremaps.blob.Blob 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;
}
Also used : Entity(com.baremaps.osm.domain.Entity) CreateGeometryConsumer(com.baremaps.osm.geometry.CreateGeometryConsumer) Blob(com.baremaps.blob.Blob) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) InputStreamProgress(com.baremaps.osm.progress.InputStreamProgress) ProgressLogger(com.baremaps.osm.progress.ProgressLogger) Change(com.baremaps.osm.domain.Change) URI(java.net.URI) GZIPInputStream(java.util.zip.GZIPInputStream) ChangeEntityConsumer(com.baremaps.osm.function.ChangeEntityConsumer) Header(com.baremaps.osm.domain.Header) State(com.baremaps.osm.domain.State) ReprojectEntityConsumer(com.baremaps.osm.geometry.ReprojectEntityConsumer) OsmChangeParser(com.baremaps.osm.change.OsmChangeParser) OsmStateParser(com.baremaps.osm.state.OsmStateParser)

Example 3 with Blob

use of com.baremaps.blob.Blob in project baremaps by baremaps.

the class JavaScriptConfig method read.

/**
 * {@inheritDoc} *
 */
@Override
public byte[] read() throws ConfigException {
    try {
        Blob blob = store.get(uri);
        try (Reader reader = new InputStreamReader(blob.getInputStream())) {
            Source source = Source.newBuilder("js", reader, "config.js").mimeType("application/javascript+module").build();
            Value value = context.eval(source);
            return value.getMember("default").toString().getBytes(StandardCharsets.UTF_8);
        }
    } catch (Exception e) {
        throw new ConfigException(e);
    }
}
Also used : Blob(com.baremaps.blob.Blob) InputStreamReader(java.io.InputStreamReader) Value(org.graalvm.polyglot.Value) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Source(org.graalvm.polyglot.Source)

Example 4 with Blob

use of com.baremaps.blob.Blob in project baremaps by baremaps.

the class TileStoreTest method readWriteDeleteTile.

@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
    TileStore tileStore = createTileStore();
    Tile tile = new Tile(1, 2, 3);
    byte[] bytes = "tile_content".getBytes();
    Blob blob = Blob.builder().withByteArray(bytes).build();
    // Write data
    tileStore.write(tile, blob);
    // Read the data
    try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
        assertArrayEquals(bytes, inputStream.readAllBytes());
    }
    // Delete the data
    tileStore.delete(tile);
    assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
Also used : TileStore(com.baremaps.tile.TileStore) Blob(com.baremaps.blob.Blob) InputStream(java.io.InputStream) Tile(com.baremaps.tile.Tile) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 5 with Blob

use of com.baremaps.blob.Blob in project baremaps by baremaps.

the class TileStoreTest method readWriteDeleteTile.

// TODO: try to move this in the testing module
@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
    TileStore tileStore = createTileStore();
    Tile tile = new Tile(1, 2, 3);
    byte[] bytes = "tile_content".getBytes();
    Blob blob = Blob.builder().withByteArray(bytes).build();
    // Write data
    tileStore.write(tile, blob);
    // Read the data
    try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
        assertArrayEquals(bytes, inputStream.readAllBytes());
    }
    // Delete the data
    tileStore.delete(tile);
    assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
Also used : Blob(com.baremaps.blob.Blob) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

Blob (com.baremaps.blob.Blob)7 InputStream (java.io.InputStream)5 InputStreamProgress (com.baremaps.osm.progress.InputStreamProgress)3 ProgressLogger (com.baremaps.osm.progress.ProgressLogger)3 OsmChangeParser (com.baremaps.osm.change.OsmChangeParser)2 Entity (com.baremaps.osm.domain.Entity)2 Header (com.baremaps.osm.domain.Header)2 CreateGeometryConsumer (com.baremaps.osm.geometry.CreateGeometryConsumer)2 ReprojectEntityConsumer (com.baremaps.osm.geometry.ReprojectEntityConsumer)2 Tile (com.baremaps.tile.Tile)2 TileStore (com.baremaps.tile.TileStore)2 URI (java.net.URI)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 Tag (org.junit.jupiter.api.Tag)2 Test (org.junit.jupiter.api.Test)2 BlobStoreException (com.baremaps.blob.BlobStoreException)1 Block (com.baremaps.osm.domain.Block)1 Change (com.baremaps.osm.domain.Change)1 State (com.baremaps.osm.domain.State)1 BlockEntityConsumer (com.baremaps.osm.function.BlockEntityConsumer)1