This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/main by this push:
new 47b39228 Fix some issues detected by sonar (#870)
47b39228 is described below
commit 47b39228195c43e07ae1c35f03b043e595cd752b
Author: Bertil Chapuis <[email protected]>
AuthorDate: Wed Jun 12 00:47:12 2024 +0200
Fix some issues detected by sonar (#870)
* Correctly skip bytes
* Suppress warning on controlled input
* Improve exception handling
* Fix issues reported by sonar
* Format code with spotless
* Suppress some warnings
* Fix sonar issues and clean code
---
.../org/apache/baremaps/cli/BaremapsException.java | 54 ++++++++
.../main/java/org/apache/baremaps/cli/map/Dev.java | 5 +-
.../org/apache/baremaps/database/DiffService.java | 7 +-
.../apache/baremaps/database/copy/CopyWriter.java | 147 +++++++++------------
.../baremaps/database/copy/JsonbValueHandler.java | 14 +-
.../database/function/ChangeElementsImporter.java | 1 -
.../database/metadata/DatabaseMetadata.java | 61 ++++-----
.../baremaps/database/postgres/NodeRepository.java | 33 ++++-
.../database/postgres/RelationRepository.java | 38 ++++--
.../baremaps/database/postgres/WayRepository.java | 26 +++-
.../flatgeobuf/FlatGeoBufTypeConversion.java | 11 +-
.../storage/geoparquet/GeoParquetDataTable.java | 6 +-
.../storage/postgres/PostgresDataStore.java | 6 +-
.../storage/postgres/PostgresTypeConversion.java | 6 +-
.../shapefile/internal/ShapefileByteReader.java | 61 ++++-----
.../baremaps/tilestore/mbtiles/MBTilesStore.java | 24 ++--
.../baremaps/workflow/tasks/DecompressFile.java | 50 +++----
.../baremaps/workflow/tasks/ExportVectorTiles.java | 29 ++--
.../baremaps/workflow/tasks/ImportOsmPbf.java | 6 +-
.../baremaps/workflow/tasks/UpdateOsmDatabase.java | 6 +-
.../org/apache/baremaps/calcite/CalciteTest.java | 5 +-
.../baremaps/database/PostgresContainerTest.java | 4 +-
.../database/postgres/HeaderRepositoryTest.java | 13 +-
.../database/postgres/NodeRepositoryTest.java | 10 +-
.../database/postgres/RelationRepositoryTest.java | 14 +-
.../database/postgres/WayRepositoryTest.java | 14 +-
.../flatgeobuf/FlatGeoBufDataTableTest.java | 4 +-
.../geopackage/GeoPackageDataStoreTest.java | 4 +-
.../baremaps/data/algorithm/ExternalMergeSort.java | 3 +-
.../apache/baremaps/data/calcite/SqlDataTable.java | 6 +-
.../baremaps/data/calcite/SqlTypeConversion.java | 4 +
.../maplibre/vectortile/VectorTileDecoder.java | 7 +-
32 files changed, 379 insertions(+), 300 deletions(-)
diff --git
a/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java
b/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java
new file mode 100644
index 00000000..20413592
--- /dev/null
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/BaremapsException.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.cli;
+
+
+/** Signals that an exception occurred in the {@link Baremaps} CLI. */
+public class BaremapsException extends RuntimeException {
+
+ /** Constructs a {@link BaremapsException} with {@code null} as its error
detail message. */
+ public BaremapsException() {}
+
+ /**
+ * Constructs an {@link BaremapsException} with the specified detail message.
+ *
+ * @param message the message
+ */
+ public BaremapsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a {@link BaremapsException} with the specified cause.
+ *
+ * @param cause the cause
+ */
+ public BaremapsException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a {@link BaremapsException} with the specified detail message
and cause.
+ *
+ * @param message the message
+ * @param cause the cause
+ */
+ public BaremapsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
index b3794699..2ba6c766 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
@@ -30,6 +30,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
+import org.apache.baremaps.cli.BaremapsException;
import org.apache.baremaps.cli.Options;
import org.apache.baremaps.config.ConfigReader;
import org.apache.baremaps.maplibre.style.Style;
@@ -88,7 +89,7 @@ public class Dev implements Callable<Integer> {
var config = configReader.read(tilesetPath);
return objectMapper.readValue(config, Tileset.class);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new BaremapsException(e);
}
};
@@ -102,7 +103,7 @@ public class Dev implements Callable<Integer> {
var config = configReader.read(stylePath);
return objectMapper.readValue(config, Style.class);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new BaremapsException(e);
}
};
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
index 49c51d4f..07a7b890 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/database/DiffService.java
@@ -58,8 +58,11 @@ public class DiffService implements
Callable<List<TileCoord>> {
public DiffService(
Map<Long, Coordinate> coordinateMap,
Map<Long, List<Long>> referenceMap,
- HeaderRepository headerRepository, Repository<Long, Node> nodeRepository,
- Repository<Long, Way> wayRepository, Repository<Long, Relation>
relationRepository, int srid,
+ HeaderRepository headerRepository,
+ Repository<Long, Node> nodeRepository,
+ Repository<Long, Way> wayRepository,
+ Repository<Long, Relation> relationRepository,
+ int srid,
int zoom) {
this.coordinateMap = coordinateMap;
this.referenceMap = referenceMap;
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
index c71b752f..41c8d573 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/CopyWriter.java
@@ -144,12 +144,13 @@ public class CopyWriter implements AutoCloseable {
}
/**
- * Writes a null value.
+ * Writes the number of columns affected by the query.
*
+ * @param columns
* @throws IOException
*/
- public void writeNull() throws IOException {
- data.writeInt(-1);
+ public void startRow(int columns) throws IOException {
+ data.writeShort(columns);
}
/**
@@ -157,261 +158,241 @@ public class CopyWriter implements AutoCloseable {
*
* @throws IOException
*/
- public <T> void write(BaseValueHandler<T> handler, T value) throws
IOException {
- handler.handle(data, value);
+ public void writeNull() throws IOException {
+ data.writeInt(-1);
}
/**
- * Writes the number of columns affected by the query.
+ * Writes a null value.
*
- * @param columns
- * @throws IOException
+ * @param handler the value handler
+ * @param value the value
*/
- public void startRow(int columns) throws IOException {
- data.writeShort(columns);
+ public <T> void write(BaseValueHandler<T> handler, T value) {
+ handler.handle(data, value);
}
/**
* Writes a string value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void write(String value) throws IOException {
+ public void write(String value) {
STRING_HANDLER.handle(data, value);
}
/**
* Writes a list of string values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void write(List<String> value) throws IOException {
+ public void write(List<String> value) {
STRING_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a boolean value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeBoolean(Boolean value) throws IOException {
+ public void writeBoolean(Boolean value) {
BOOLEAN_HANDLER.handle(data, value);
}
/**
* Writes a list of boolean values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeBooleanList(List<Boolean> value) throws IOException {
+ public void writeBooleanList(List<Boolean> value) {
BOOLEAN_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a byte value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeByte(Byte value) throws IOException {
+ public void writeByte(Byte value) {
BYTE_HANDLER.handle(data, value);
}
/**
* Writes a byte array value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeByteArray(byte[] value) throws IOException {
+ public void writeByteArray(byte[] value) {
BYTE_ARRAY_HANDLER.handle(data, value);
}
/**
* Writes a short value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeShort(Short value) throws IOException {
+ public void writeShort(Short value) {
SHORT_HANDLER.handle(data, value);
}
/**
* Writes a list of short values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeShortList(List<Short> value) throws IOException {
+ public void writeShortList(List<Short> value) {
SHORT_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes an integer value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeInteger(Integer value) throws IOException {
+ public void writeInteger(Integer value) {
INTEGER_HANDLER.handle(data, value);
}
/**
* Writes a list of integer values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeIntegerList(List<Integer> value) throws IOException {
+ public void writeIntegerList(List<Integer> value) {
INTEGER_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a long value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeLong(Long value) throws IOException {
+ public void writeLong(Long value) {
LONG_HANDLER.handle(data, value);
}
/**
* Writes a list of long values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeLongList(List<Long> value) throws IOException {
+ public void writeLongList(List<Long> value) {
LONG_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a float value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeFloat(Float value) throws IOException {
+ public void writeFloat(Float value) {
FLOAT_HANDLER.handle(data, value);
}
/**
* Writes a list of float values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeFloatList(List<Float> value) throws IOException {
+ public void writeFloatList(List<Float> value) {
FLOAT_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a double value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeDouble(Double value) throws IOException {
+ public void writeDouble(Double value) {
DOUBLE_HANDLER.handle(data, value);
}
/**
* Writes a list of double values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeDoubleArray(List<Double> value) throws IOException {
+ public void writeDoubleArray(List<Double> value) {
DOUBLE_COLLECTION_HANDLER.handle(data, value);
}
/**
* Writes a date value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeLocalDate(LocalDate value) throws IOException {
+ public void writeLocalDate(LocalDate value) {
LOCAL_DATE_HANDLER.handle(data, value);
}
/**
* Writes a list of date values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeLocalDateTime(LocalDateTime value) throws IOException {
+ public void writeLocalDateTime(LocalDateTime value) {
LOCAL_DATE_TIME_HANDLER.handle(data, value);
}
/**
* Writes an inet adress value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeInet4Adress(Inet4Address value) throws IOException {
+ public void writeInet4Adress(Inet4Address value) {
INET_4_ADDRESS_HANDLER.handle(data, value);
}
/**
* Writes a list of inet adress values.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeInet6Adress(Inet6Address value) throws IOException {
+ public void writeInet6Adress(Inet6Address value) {
INET_6_ADDRESS_HANDLER.handle(data, value);
}
/**
* Writes a map value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeHstore(Map<String, String> value) throws IOException {
+ public void writeHstore(Map<String, String> value) {
HSTORE_HANDLER.handle(data, value);
}
/**
* Writes a jsonb array
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeJsonb(String value) throws IOException {
+ public void writeJsonb(String value) {
JSONB_HANDLER.handle(data, value);
}
/**
* Writes a geometry value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeGeometry(Geometry value) throws IOException {
+ public void writeGeometry(Geometry value) {
GEOMETRY_HANDLER.handle(data, value);
}
/**
* Writes an envelope value.
*
- * @param value
- * @throws IOException
+ * @param value the value
*/
- public void writeEnvelope(Envelope value) throws IOException {
+ public void writeEnvelope(Envelope value) {
ENVELOPE_HANDLER.handle(data, value);
}
- /** Close the writer. */
+ /**
+ * Writes the end of the row.
+ *
+ * @throws IOException
+ */
@Override
public void close() throws IOException {
data.writeShort(-1);
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/JsonbValueHandler.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/JsonbValueHandler.java
index 7a101e95..82a07243 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/copy/JsonbValueHandler.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/copy/JsonbValueHandler.java
@@ -55,17 +55,17 @@ public class JsonbValueHandler extends
BaseValueHandler<Object> {
this.jsonbProtocolVersion = jsonbProtocolVersion;
}
- private static byte[] asJson(Object object) {
+ private static byte[] asJson(Object object) throws IOException {
try {
String value = objectMapper.writeValueAsString(object);
return value.getBytes("UTF-8");
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new IOException(e);
}
}
@Override
- protected void internalHandle(DataOutputStream buffer, Object value) throws
Exception {
+ protected void internalHandle(DataOutputStream buffer, Object value) throws
IOException {
byte[] utf8Bytes = asJson(value);
buffer.writeInt(utf8Bytes.length + 1);
buffer.writeByte(jsonbProtocolVersion);
@@ -74,7 +74,11 @@ public class JsonbValueHandler extends
BaseValueHandler<Object> {
@Override
public int getLength(Object value) {
- byte[] utf8Bytes = asJson(value);
- return utf8Bytes.length;
+ try {
+ byte[] utf8Bytes = asJson(value);
+ return utf8Bytes.length;
+ } catch (IOException e) {
+ return 0;
+ }
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/function/ChangeElementsImporter.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/function/ChangeElementsImporter.java
index e12f1a6a..200a8bfe 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/function/ChangeElementsImporter.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/function/ChangeElementsImporter.java
@@ -17,7 +17,6 @@
package org.apache.baremaps.database.function;
-
import java.util.function.Consumer;
import org.apache.baremaps.database.postgres.Repository;
import org.apache.baremaps.database.postgres.RepositoryException;
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/metadata/DatabaseMetadata.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/metadata/DatabaseMetadata.java
index dcddb4a5..1c0a180c 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/metadata/DatabaseMetadata.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/metadata/DatabaseMetadata.java
@@ -29,36 +29,37 @@ import javax.sql.DataSource;
public class DatabaseMetadata {
- public static final String TABLE_CAT = "TABLE_CAT";
- public static final String TABLE_SCHEM = "TABLE_SCHEM";
- public static final String TABLE_NAME = "TABLE_NAME";
- public static final String TABLE_TYPE = "TABLE_TYPE";
- public static final String REMARKS = "REMARKS";
- public static final String TYPE_CAT = "TYPE_CAT";
- public static final String TYPE_SCHEM = "TYPE_SCHEM";
- public static final String TYPE_NAME = "TYPE_NAME";
- public static final String SELF_REFERENCING_COL_NAME =
"SELF_REFERENCING_COL_NAME";
- public static final String REF_GENERATION = "REF_GENERATION";
- public static final String COLUMN_NAME = "COLUMN_NAME";
- public static final String DATA_TYPE = "DATA_TYPE";
- public static final String COLUMN_SIZE = "COLUMN_SIZE";
- public static final String DECIMAL_DIGITS = "DECIMAL_DIGITS";
- public static final String NUM_PREC_RADIX = "NUM_PREC_RADIX";
- public static final String NULLABLE = "NULLABLE";
- public static final String COLUMN_DEF = "COLUMN_DEF";
- public static final String KEY_SEQ = "KEY_SEQ";
- public static final String PK_NAME = "PK_NAME";
- public static final String SQL_DATA_TYPE = "SQL_DATA_TYPE";
- public static final String SQL_DATETIME_SUB = "SQL_DATETIME_SUB";
- public static final String CHAR_OCTET_LENGTH = "CHAR_OCTET_LENGTH";
- public static final String ORDINAL_POSITION = "ORDINAL_POSITION";
- public static final String IS_NULLABLE = "IS_NULLABLE";
- public static final String SCOPE_CATALOG = "SCOPE_CATALOG";
- public static final String SCOPE_SCHEMA = "SCOPE_SCHEMA";
- public static final String SCOPE_TABLE = "SCOPE_TABLE";
- public static final String SOURCE_DATA_TYPE = "SOURCE_DATA_TYPE";
- public static final String IS_AUTOINCREMENT = "IS_AUTOINCREMENT";
- public static final String IS_GENERATEDCOLUMN = "IS_GENERATEDCOLUMN";
+ private static final String TABLE_CAT = "TABLE_CAT";
+ private static final String TABLE_SCHEM = "TABLE_SCHEM";
+ private static final String TABLE_NAME = "TABLE_NAME";
+ private static final String TABLE_TYPE = "TABLE_TYPE";
+ private static final String REMARKS = "REMARKS";
+ private static final String TYPE_CAT = "TYPE_CAT";
+ private static final String TYPE_SCHEM = "TYPE_SCHEM";
+ private static final String TYPE_NAME = "TYPE_NAME";
+ private static final String SELF_REFERENCING_COL_NAME =
"SELF_REFERENCING_COL_NAME";
+ private static final String REF_GENERATION = "REF_GENERATION";
+ private static final String COLUMN_NAME = "COLUMN_NAME";
+ private static final String DATA_TYPE = "DATA_TYPE";
+ private static final String COLUMN_SIZE = "COLUMN_SIZE";
+ private static final String DECIMAL_DIGITS = "DECIMAL_DIGITS";
+ private static final String NUM_PREC_RADIX = "NUM_PREC_RADIX";
+ private static final String NULLABLE = "NULLABLE";
+ private static final String COLUMN_DEF = "COLUMN_DEF";
+ private static final String KEY_SEQ = "KEY_SEQ";
+ private static final String PK_NAME = "PK_NAME";
+ private static final String SQL_DATA_TYPE = "SQL_DATA_TYPE";
+ private static final String SQL_DATETIME_SUB = "SQL_DATETIME_SUB";
+ private static final String CHAR_OCTET_LENGTH = "CHAR_OCTET_LENGTH";
+ private static final String ORDINAL_POSITION = "ORDINAL_POSITION";
+ private static final String IS_NULLABLE = "IS_NULLABLE";
+ private static final String SCOPE_CATALOG = "SCOPE_CATALOG";
+ private static final String SCOPE_SCHEMA = "SCOPE_SCHEMA";
+ private static final String SCOPE_TABLE = "SCOPE_TABLE";
+ private static final String SOURCE_DATA_TYPE = "SOURCE_DATA_TYPE";
+ private static final String IS_AUTOINCREMENT = "IS_AUTOINCREMENT";
+ private static final String IS_GENERATEDCOLUMN = "IS_GENERATEDCOLUMN";
+
private final DataSource dataSource;
public DatabaseMetadata(DataSource dataSource) {
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/NodeRepository.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/NodeRepository.java
index 16c9bbd1..326ae9d9 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/NodeRepository.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/NodeRepository.java
@@ -71,9 +71,19 @@ public class NodeRepository implements Repository<Long,
Node> {
* @param dataSource
*/
public NodeRepository(DataSource dataSource) {
- this(dataSource, "public", "osm_nodes", "id", "version", "uid",
"timestamp", "changeset",
- "tags", "lon",
- "lat", "geom");
+ this(
+ dataSource,
+ "public",
+ "osm_nodes",
+ "id",
+ "version",
+ "uid",
+ "timestamp",
+ "changeset",
+ "tags",
+ "lon",
+ "lat",
+ "geom");
}
/**
@@ -92,9 +102,20 @@ public class NodeRepository implements Repository<Long,
Node> {
* @param latitudeColumn
* @param geometryColumn
*/
- public NodeRepository(DataSource dataSource, String schema, String table,
String idColumn,
- String versionColumn, String uidColumn, String timestampColumn, String
changesetColumn,
- String tagsColumn, String longitudeColumn, String latitudeColumn, String
geometryColumn) {
+ @SuppressWarnings("squid:S107")
+ public NodeRepository(
+ DataSource dataSource,
+ String schema,
+ String table,
+ String idColumn,
+ String versionColumn,
+ String uidColumn,
+ String timestampColumn,
+ String changesetColumn,
+ String tagsColumn,
+ String longitudeColumn,
+ String latitudeColumn,
+ String geometryColumn) {
var fullTableName = String.format("%1$s.%2$s", schema, table);
this.dataSource = dataSource;
this.createTable = String.format("""
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/RelationRepository.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/RelationRepository.java
index 3f3cfa03..6a0a9622 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/RelationRepository.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/RelationRepository.java
@@ -25,7 +25,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.*;
-import java.util.stream.Collectors;
import javax.sql.DataSource;
import org.apache.baremaps.database.copy.CopyWriter;
import org.apache.baremaps.openstreetmap.model.Info;
@@ -66,9 +65,20 @@ public class RelationRepository implements Repository<Long,
Relation> {
* @param dataSource
*/
public RelationRepository(DataSource dataSource) {
- this(dataSource, "public", "osm_relations", "id", "version", "uid",
"timestamp", "changeset",
+ this(
+ dataSource,
+ "public",
+ "osm_relations",
+ "id",
+ "version",
+ "uid",
+ "timestamp",
+ "changeset",
"tags",
- "member_refs", "member_types", "member_roles", "geom");
+ "member_refs",
+ "member_types",
+ "member_roles",
+ "geom");
}
/**
@@ -88,10 +98,20 @@ public class RelationRepository implements Repository<Long,
Relation> {
* @param memberRoles
* @param geometryColumn
*/
- public RelationRepository(DataSource dataSource, String schema, String table,
+ @SuppressWarnings("squid:S107")
+ public RelationRepository(
+ DataSource dataSource,
+ String schema,
+ String table,
String idColumn,
- String versionColumn, String uidColumn, String timestampColumn, String
changesetColumn,
- String tagsColumn, String memberRefs, String memberTypes, String
memberRoles,
+ String versionColumn,
+ String uidColumn,
+ String timestampColumn,
+ String changesetColumn,
+ String tagsColumn,
+ String memberRefs,
+ String memberTypes,
+ String memberRoles,
String geometryColumn) {
var fullTableName = String.format("%1$s.%2$s", schema, table);
this.dataSource = dataSource;
@@ -295,11 +315,11 @@ public class RelationRepository implements
Repository<Long, Relation> {
writer.writeLong(value.getInfo().getChangeset());
writer.writeJsonb(JsonbMapper.toJson(value.getTags()));
writer.writeLongList(
-
value.getMembers().stream().map(Member::getRef).collect(Collectors.toList()));
+ value.getMembers().stream().map(Member::getRef).toList());
writer.writeIntegerList(value.getMembers().stream().map(Member::getType)
- .map(MemberType::ordinal).collect(Collectors.toList()));
+ .map(MemberType::ordinal).toList());
writer
-
.write(value.getMembers().stream().map(Member::getRole).collect(Collectors.toList()));
+
.write(value.getMembers().stream().map(Member::getRole).toList());
writer.writeGeometry(value.getGeometry());
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/WayRepository.java
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/WayRepository.java
index f884a430..63fd1426 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/WayRepository.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/database/postgres/WayRepository.java
@@ -74,7 +74,15 @@ public class WayRepository implements Repository<Long, Way> {
* @param dataSource the datasource
*/
public WayRepository(DataSource dataSource) {
- this(dataSource, "public", "osm_ways", "id", "version", "uid",
"timestamp", "changeset", "tags",
+ this(dataSource,
+ "public",
+ "osm_ways",
+ "id",
+ "version",
+ "uid",
+ "timestamp",
+ "changeset",
+ "tags",
"nodes",
"geom");
}
@@ -94,9 +102,19 @@ public class WayRepository implements Repository<Long, Way>
{
* @param nodesColumn
* @param geometryColumn
*/
- public WayRepository(DataSource dataSource, String schema, String table,
String idColumn,
- String versionColumn, String uidColumn, String timestampColumn, String
changesetColumn,
- String tagsColumn, String nodesColumn, String geometryColumn) {
+ @SuppressWarnings("squid:S107")
+ public WayRepository(
+ DataSource dataSource,
+ String schema,
+ String table,
+ String idColumn,
+ String versionColumn,
+ String uidColumn,
+ String timestampColumn,
+ String changesetColumn,
+ String tagsColumn,
+ String nodesColumn,
+ String geometryColumn) {
var fullTableName = String.format("%1$s.%2$s", schema, table);
this.dataSource = dataSource;
this.createTable = String.format("""
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
index 1a42148c..6c46a913 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufTypeConversion.java
@@ -24,7 +24,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.*;
-import java.util.stream.Collectors;
import org.apache.baremaps.data.storage.*;
import org.apache.baremaps.data.storage.DataColumn.Cardinality;
import org.apache.baremaps.data.storage.DataColumn.Type;
@@ -38,7 +37,7 @@ import org.wololo.flatgeobuf.generated.Header;
public class FlatGeoBufTypeConversion {
- public static final EnumMap<Type, Integer> types = new EnumMap<>(Type.class);
+ private static final Map<Type, Integer> types = new EnumMap<>(Type.class);
static {
types.put(Type.BYTE, ColumnType.Byte);
@@ -51,6 +50,10 @@ public class FlatGeoBufTypeConversion {
types.put(Type.STRING, ColumnType.String);
}
+ private FlatGeoBufTypeConversion() {
+ // Prevent instantiation
+ }
+
public static DataSchema asSchema(HeaderMeta headerMeta) {
var name = headerMeta.name;
var columns = headerMeta.columns.stream()
@@ -199,13 +202,11 @@ public class FlatGeoBufTypeConversion {
throw new UnsupportedOperationException();
}
-
-
public static List<ColumnMeta> asColumns(List<DataColumn> columns) {
return columns.stream()
.map(FlatGeoBufTypeConversion::asColumn)
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toList();
}
public static ColumnMeta asColumn(DataColumn column) {
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
index 205003d1..225ce61c 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/geoparquet/GeoParquetDataTable.java
@@ -24,7 +24,6 @@ import java.util.stream.Stream;
import org.apache.baremaps.data.storage.*;
import org.apache.baremaps.geoparquet.GeoParquetException;
import org.apache.baremaps.geoparquet.GeoParquetReader;
-import org.apache.baremaps.geoparquet.data.GeoParquetGroup.Schema;
public class GeoParquetDataTable implements DataTable {
@@ -86,8 +85,9 @@ public class GeoParquetDataTable implements DataTable {
@Override
public DataSchema schema() {
if (schema == null) {
- Schema schema = reader().getGeoParquetSchema();
- this.schema = GeoParquetTypeConversion.asSchema(path.toString(), schema);
+ this.schema = GeoParquetTypeConversion.asSchema(
+ path.toString(),
+ reader().getGeoParquetSchema());
return this.schema;
}
return schema;
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
index 3168d21f..e767b0d1 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresDataStore.java
@@ -68,7 +68,7 @@ public class PostgresDataStore implements DataStore {
DatabaseMetadata metadata = new DatabaseMetadata(dataSource);
return metadata.getTableMetaData(null, "public", null, TYPES).stream()
.map(table -> table.table().tableName())
- .collect(Collectors.toList());
+ .toList();
}
/**
@@ -252,7 +252,7 @@ public class PostgresDataStore implements DataStore {
protected List<DataColumn> getColumns(DataSchema schema) {
return schema.columns().stream()
.filter(this::isSupported)
- .collect(Collectors.toList());
+ .toList();
}
/**
@@ -264,7 +264,7 @@ public class PostgresDataStore implements DataStore {
protected List<BaseValueHandler> getHandlers(DataSchema schema) {
return getColumns(schema).stream()
.map(column -> getHandler(column.type()))
- .collect(Collectors.toList());
+ .toList();
}
/**
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
index fb428e73..14166163 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/postgres/PostgresTypeConversion.java
@@ -24,7 +24,11 @@ import org.apache.baremaps.data.storage.DataColumn.Type;
@SuppressWarnings("squid:S1192")
public class PostgresTypeConversion {
- public static final EnumMap<Type, String> typeToName = new
EnumMap<>(Type.class);
+ private PostgresTypeConversion() {
+ // Prevent instantiation
+ }
+
+ protected static final Map<Type, String> typeToName = new
EnumMap<>(Type.class);
static {
typeToName.put(Type.STRING, "varchar");
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
index 0a88c19a..86cc3ccd 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java
@@ -176,30 +176,22 @@ public class ShapefileByteReader extends CommonByteReader
{
try (FileInputStream fis = new FileInputStream(this.shapeFileIndex);
FileChannel fc = fis.getChannel()) {
- try {
- int fsize = (int) fc.size();
- MappedByteBuffer indexesByteBuffer =
fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
-
- // Indexes entries follow.
- this.indexes = new ArrayList<>();
- this.recordsLengths = new ArrayList<>();
- indexesByteBuffer.position(100);
- indexesByteBuffer.order(ByteOrder.BIG_ENDIAN);
-
- while (indexesByteBuffer.hasRemaining()) {
- this.indexes.add(indexesByteBuffer.getInt()); // Data offset : the
position of the record
- // in the main
shapefile,
- // expressed in words (16 bits).
- this.recordsLengths.add(indexesByteBuffer.getInt()); // Length of
this shapefile record.
- }
- return true;
- } catch (IOException e) {
- this.shapeFileIndex = null;
- return false;
+ int fsize = (int) fc.size();
+ MappedByteBuffer indexesByteBuffer =
fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
+
+ // Indexes entries follow.
+ this.indexes = new ArrayList<>();
+ this.recordsLengths = new ArrayList<>();
+ indexesByteBuffer.position(100);
+ indexesByteBuffer.order(ByteOrder.BIG_ENDIAN);
+
+ while (indexesByteBuffer.hasRemaining()) {
+ this.indexes.add(indexesByteBuffer.getInt()); // Data offset : the
position of the record
+ // in the main shapefile,
+ // expressed in words (16 bits).
+ this.recordsLengths.add(indexesByteBuffer.getInt()); // Length of this
shapefile record.
}
- } catch (FileNotFoundException e) {
- this.shapeFileIndex = null;
- return false;
+ return true;
} catch (IOException e) {
this.shapeFileIndex = null;
return false;
@@ -264,8 +256,8 @@ public class ShapefileByteReader extends CommonByteReader {
*/
public void completeRow(DataRow row) throws ShapefileException {
// insert points into some type of list
- int RecordNumber = getByteBuffer().getInt();
- int ContentLength = getByteBuffer().getInt();
+ getByteBuffer().getInt(); // record number
+ getByteBuffer().getInt(); // content length
getByteBuffer().order(ByteOrder.LITTLE_ENDIAN);
int shapeTypeId = getByteBuffer().getInt();
@@ -409,26 +401,27 @@ public class ShapefileByteReader extends CommonByteReader
{
/* double xmax = */ getByteBuffer().getDouble();
/* double ymax = */ getByteBuffer().getDouble();
- int NumParts = getByteBuffer().getInt();
- int NumPoints = getByteBuffer().getInt();
+ int numParts = getByteBuffer().getInt();
+ int numPoints = getByteBuffer().getInt();
- int[] NumPartArr = new int[NumParts + 1];
+ int[] numPartArr = new int[numParts + 1];
- for (int n = 0; n < NumParts; n++) {
+ for (int n = 0; n < numParts; n++) {
int idx = getByteBuffer().getInt();
- NumPartArr[n] = idx;
+ numPartArr[n] = idx;
}
- NumPartArr[NumParts] = NumPoints;
+ numPartArr[numParts] = numPoints;
- double xpnt, ypnt;
+ double xpnt;
+ double ypnt;
var coordinates = new CoordinateList();
- for (int m = 0; m < NumParts; m++) {
+ for (int m = 0; m < numParts; m++) {
xpnt = getByteBuffer().getDouble();
ypnt = getByteBuffer().getDouble();
coordinates.add(new Coordinate(xpnt, ypnt));
- for (int j = NumPartArr[m]; j < NumPartArr[m + 1] - 1; j++) {
+ for (int j = numPartArr[m]; j < numPartArr[m + 1] - 1; j++) {
xpnt = getByteBuffer().getDouble();
ypnt = getByteBuffer().getDouble();
coordinates.add(new Coordinate(xpnt, ypnt));
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStore.java
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStore.java
index 9787cbeb..755739b6 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStore.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/mbtiles/MBTilesStore.java
@@ -120,20 +120,18 @@ public class MBTilesStore implements TileStore {
*/
@Override
public void write(List<TileEntry> tileEntries) throws TileStoreException {
- try (Connection connection = dataSource.getConnection()) {
- // connection.setAutoCommit(false);
- try (PreparedStatement statement =
connection.prepareStatement(INSERT_TILE)) {
- for (TileEntry tileEntry : tileEntries) {
- TileCoord tileCoord = tileEntry.getTileCoord();
- ByteBuffer byteBuffer = tileEntry.getByteBuffer();
- statement.setInt(1, tileCoord.z());
- statement.setInt(2, tileCoord.x());
- statement.setInt(3, reverseY(tileCoord.y(), tileCoord.z()));
- statement.setBytes(4, byteBuffer.array());
- statement.execute();
- }
+ try (
+ Connection connection = dataSource.getConnection();
+ PreparedStatement statement =
connection.prepareStatement(INSERT_TILE)) {
+ for (TileEntry tileEntry : tileEntries) {
+ TileCoord tileCoord = tileEntry.getTileCoord();
+ ByteBuffer byteBuffer = tileEntry.getByteBuffer();
+ statement.setInt(1, tileCoord.z());
+ statement.setInt(2, tileCoord.x());
+ statement.setInt(3, reverseY(tileCoord.y(), tileCoord.z()));
+ statement.setBytes(4, byteBuffer.array());
+ statement.execute();
}
- // connection.commit();
} catch (SQLException e) {
throw new TileStoreException(e);
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/DecompressFile.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/DecompressFile.java
index d3d0d65b..6fca8f46 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/DecompressFile.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/DecompressFile.java
@@ -134,22 +134,7 @@ public class DecompressFile implements Task {
try (var bufferedInputStream = new
BufferedInputStream(Files.newInputStream(source));
var gzipInputStream = new GZIPInputStream(bufferedInputStream);
var tarInputStream = new TarArchiveInputStream(gzipInputStream)) {
- TarArchiveEntry entry;
- while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) !=
null) {
- var path = target.resolve(entry.getName());
- if (entry.isDirectory()) {
- Files.createDirectories(path);
- } else {
- Files.createDirectories(path.getParent());
- Files.write(path, new byte[] {},
- StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING);
- try (BufferedOutputStream outputStream =
- new BufferedOutputStream(Files.newOutputStream(path))) {
- tarInputStream.transferTo(outputStream);
- }
- }
- }
+ decompressTar(target, tarInputStream);
}
}
@@ -165,20 +150,25 @@ public class DecompressFile implements Task {
try (var bufferedInputStream = new
BufferedInputStream(Files.newInputStream(source));
var bzip2InputStream = new
BZip2CompressorInputStream(bufferedInputStream);
var tarInputStream = new TarArchiveInputStream(bzip2InputStream)) {
- TarArchiveEntry entry;
- while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) !=
null) {
- var path = target.resolve(entry.getName());
- if (entry.isDirectory()) {
- Files.createDirectories(path);
- } else {
- Files.createDirectories(path.getParent());
- Files.write(path, new byte[] {},
- StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING);
- try (BufferedOutputStream outputStream =
- new BufferedOutputStream(Files.newOutputStream(path))) {
- tarInputStream.transferTo(outputStream);
- }
+ decompressTar(target, tarInputStream);
+ }
+ }
+
+ private static void decompressTar(Path target, TarArchiveInputStream
tarInputStream)
+ throws IOException {
+ TarArchiveEntry entry;
+ while ((entry = tarInputStream.getNextEntry()) != null) {
+ var path = target.resolve(entry.getName());
+ if (entry.isDirectory()) {
+ Files.createDirectories(path);
+ } else {
+ Files.createDirectories(path.getParent());
+ Files.write(path, new byte[] {},
+ StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING);
+ try (BufferedOutputStream outputStream =
+ new BufferedOutputStream(Files.newOutputStream(path))) {
+ tarInputStream.transferTo(outputStream);
}
}
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
index 0a1b9f0c..646b15a1 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
@@ -42,6 +42,7 @@ import
org.apache.baremaps.tilestore.postgres.PostgresTileStore;
import org.apache.baremaps.utils.SqliteUtils;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
+import org.apache.baremaps.workflow.WorkflowException;
import org.locationtech.jts.geom.Envelope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,8 +97,8 @@ public class ExportVectorTiles implements Task {
var configReader = new ConfigReader();
var objectMapper = objectMapper();
- var tileset = objectMapper.readValue(configReader.read(this.tileset),
Tileset.class);
- var style = objectMapper.readValue(configReader.read(this.style),
Style.class);
+ var tilesetObject =
objectMapper.readValue(configReader.read(this.tileset), Tileset.class);
+ var styleObject = objectMapper.readValue(configReader.read(this.style),
Style.class);
// Write the static files
var directory = switch (format) {
@@ -115,31 +116,31 @@ public class ExportVectorTiles implements Task {
}
Files.write(
directory.resolve("tiles.json"),
- objectMapper.writeValueAsBytes(tileset),
+ objectMapper.writeValueAsBytes(tilesetObject),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
Files.write(
directory.resolve("style.json"),
- objectMapper.writeValueAsBytes(style),
+ objectMapper.writeValueAsBytes(styleObject),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
- var datasource = context.getDataSource(tileset.getDatabase());
+ var datasource = context.getDataSource(tilesetObject.getDatabase());
- try (var sourceTileStore = sourceTileStore(tileset, datasource);
- var targetTileStore = targetTileStore(tileset)) {
+ try (var sourceTileStore = sourceTileStore(tilesetObject, datasource);
+ var targetTileStore = targetTileStore(tilesetObject)) {
- var envelope = tileset.getBounds().size() == 4
+ var envelope = tilesetObject.getBounds().size() == 4
? new Envelope(
- tileset.getBounds().get(0), tileset.getBounds().get(2),
- tileset.getBounds().get(1), tileset.getBounds().get(3))
+ tilesetObject.getBounds().get(0),
tilesetObject.getBounds().get(2),
+ tilesetObject.getBounds().get(1),
tilesetObject.getBounds().get(3))
: new Envelope(-180, 180, -85.0511, 85.0511);
- var count = TileCoord.count(envelope, tileset.getMinzoom(),
tileset.getMaxzoom());
+ var count = TileCoord.count(envelope, tilesetObject.getMinzoom(),
tilesetObject.getMaxzoom());
var start = System.currentTimeMillis();
var tileCoordIterator =
- TileCoord.iterator(envelope, tileset.getMinzoom(),
tileset.getMaxzoom());
+ TileCoord.iterator(envelope, tilesetObject.getMinzoom(),
tilesetObject.getMaxzoom());
var tileCoordStream =
StreamUtils.stream(tileCoordIterator).peek(new
ProgressLogger<>(count, 5000));
@@ -147,7 +148,7 @@ public class ExportVectorTiles implements Task {
try {
return new TileEntry(tile, sourceTileStore.read(tile));
} catch (TileStoreException e) {
- throw new RuntimeException(e);
+ throw new WorkflowException(e);
}
}, 1000);
@@ -156,7 +157,7 @@ public class ExportVectorTiles implements Task {
try {
targetTileStore.write(batch);
} catch (TileStoreException e) {
- throw new RuntimeException(e);
+ throw new WorkflowException(e);
}
});
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java
index 002cf307..cf3809b6 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ImportOsmPbf.java
@@ -33,16 +33,12 @@ import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.apache.baremaps.workflow.Task;
import org.apache.baremaps.workflow.WorkflowContext;
import org.locationtech.jts.geom.Coordinate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Import an OSM PBF file into a database.
*/
public class ImportOsmPbf implements Task {
- private static final Logger logger =
LoggerFactory.getLogger(ImportOsmPbf.class);
-
private Path file;
private Object database;
private Integer databaseSrid;
@@ -52,7 +48,7 @@ public class ImportOsmPbf implements Task {
* Constructs a {@code ImportOsmPbf}.
*/
public ImportOsmPbf() {
-
+ // Default constructor
}
/**
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UpdateOsmDatabase.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UpdateOsmDatabase.java
index deaf4e83..52d847fb 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UpdateOsmDatabase.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/UpdateOsmDatabase.java
@@ -105,8 +105,10 @@ public class UpdateOsmDatabase implements Task {
public static void execute(
Map<Long, Coordinate> coordinateMap,
Map<Long, List<Long>> referenceMap,
- HeaderRepository headerRepository, Repository<Long, Node> nodeRepository,
- Repository<Long, Way> wayRepository, Repository<Long, Relation>
relationRepository,
+ HeaderRepository headerRepository,
+ Repository<Long, Node> nodeRepository,
+ Repository<Long, Way> wayRepository,
+ Repository<Long, Relation> relationRepository,
Integer databaseSrid,
String replicationUrl) throws Exception {
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
index 13cf44d0..d56ce6c9 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/calcite/CalciteTest.java
@@ -43,11 +43,10 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.*;
-public class CalciteTest {
-
+class CalciteTest {
@Test
- public void test() throws SQLException {
+ void test() throws SQLException {
GeometryFactory geometryFactory = new GeometryFactory();
Properties info = new Properties();
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/database/PostgresContainerTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/database/PostgresContainerTest.java
index 3c2f2e43..17f76c21 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/database/PostgresContainerTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/database/PostgresContainerTest.java
@@ -21,8 +21,6 @@ package org.apache.baremaps.database;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
-import java.io.IOException;
-import java.sql.SQLException;
import javax.sql.DataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -36,7 +34,7 @@ public abstract class PostgresContainerTest {
private DataSource dataSource;
@BeforeEach
- public void startContainer() throws SQLException, IOException {
+ public void startContainer() {
// start the container
var postgis =
DockerImageName.parse("ghcr.io/baosystems/postgis:14-3.3")
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/HeaderRepositoryTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/HeaderRepositoryTest.java
index a9786ad9..3897b5f5 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/HeaderRepositoryTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/HeaderRepositoryTest.java
@@ -24,11 +24,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
-import java.io.IOException;
-import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.apache.baremaps.openstreetmap.model.Header;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -39,7 +36,7 @@ class HeaderRepositoryTest extends PostgresRepositoryTest {
HeaderRepository headerRepository;
@BeforeEach
- void init() throws SQLException, IOException {
+ void init() {
headerRepository = new HeaderRepository(dataSource());
}
@@ -72,7 +69,7 @@ class HeaderRepositoryTest extends PostgresRepositoryTest {
List<Header> headers = Arrays.asList(HEADER_0, HEADER_1, HEADER_2);
headerRepository.put(headers);
assertIterableEquals(headers, headerRepository.get(
- headers.stream().map(e ->
e.getReplicationSequenceNumber()).collect(Collectors.toList())));
+ headers.stream().map(Header::getReplicationSequenceNumber).toList()));
}
@Test
@@ -89,9 +86,9 @@ class HeaderRepositoryTest extends PostgresRepositoryTest {
List<Header> headers = Arrays.asList(HEADER_0, HEADER_1, HEADER_2);
headerRepository.put(headers);
headerRepository.delete(
- headers.stream().map(e ->
e.getReplicationSequenceNumber()).collect(Collectors.toList()));
+ headers.stream().map(Header::getReplicationSequenceNumber).toList());
assertIterableEquals(Arrays.asList(null, null, null), headerRepository.get(
- headers.stream().map(e ->
e.getReplicationSequenceNumber()).collect(Collectors.toList())));
+ headers.stream().map(Header::getReplicationSequenceNumber).toList()));
}
@Test
@@ -100,6 +97,6 @@ class HeaderRepositoryTest extends PostgresRepositoryTest {
List<Header> headers = Arrays.asList(HEADER_0, HEADER_1, HEADER_2);
headerRepository.copy(headers);
assertIterableEquals(headers, headerRepository.get(
- headers.stream().map(e ->
e.getReplicationSequenceNumber()).collect(Collectors.toList())));
+ headers.stream().map(Header::getReplicationSequenceNumber).toList()));
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/NodeRepositoryTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/NodeRepositoryTest.java
index ef42773d..1c34b362 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/NodeRepositoryTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/NodeRepositoryTest.java
@@ -23,8 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.apache.baremaps.database.repository.Constants;
+import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.openstreetmap.model.Node;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -52,7 +52,7 @@ class NodeRepositoryTest extends PostgresRepositoryTest {
List<Node> nodes = Arrays.asList(Constants.NODE_0, Constants.NODE_1,
Constants.NODE_2);
nodeRepository.put(nodes);
assertIterableEquals(nodes,
- nodeRepository.get(nodes.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ nodeRepository.get(nodes.stream().map(Element::getId).toList()));
}
@Test
@@ -68,9 +68,9 @@ class NodeRepositoryTest extends PostgresRepositoryTest {
void deleteAll() throws RepositoryException {
List<Node> nodes = Arrays.asList(Constants.NODE_0, Constants.NODE_1,
Constants.NODE_2);
nodeRepository.put(nodes);
- nodeRepository.delete(nodes.stream().map(e ->
e.getId()).collect(Collectors.toList()));
+ nodeRepository.delete(nodes.stream().map(Element::getId).toList());
assertIterableEquals(Arrays.asList(null, null, null),
- nodeRepository.get(nodes.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ nodeRepository.get(nodes.stream().map(Element::getId).toList()));
}
@Test
@@ -79,6 +79,6 @@ class NodeRepositoryTest extends PostgresRepositoryTest {
List<Node> nodes = Arrays.asList(Constants.NODE_0, Constants.NODE_1,
Constants.NODE_2);
nodeRepository.copy(nodes);
assertIterableEquals(nodes,
- nodeRepository.get(nodes.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ nodeRepository.get(nodes.stream().map(Element::getId).toList()));
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/RelationRepositoryTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/RelationRepositoryTest.java
index da5243db..4c3be761 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/RelationRepositoryTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/RelationRepositoryTest.java
@@ -21,12 +21,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
-import java.io.IOException;
-import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.apache.baremaps.database.repository.Constants;
+import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.openstreetmap.model.Relation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -37,7 +35,7 @@ class RelationRepositoryTest extends PostgresRepositoryTest {
RelationRepository relationRepository;
@BeforeEach
- void init() throws SQLException, IOException {
+ void init() {
relationRepository = new RelationRepository(dataSource());
}
@@ -55,7 +53,7 @@ class RelationRepositoryTest extends PostgresRepositoryTest {
Arrays.asList(Constants.RELATION_2, Constants.RELATION_3,
Constants.RELATION_4);
relationRepository.put(relations);
assertIterableEquals(relations, relationRepository
- .get(relations.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ .get(relations.stream().map(Element::getId).toList()));
}
@Test
@@ -72,9 +70,9 @@ class RelationRepositoryTest extends PostgresRepositoryTest {
List<Relation> relations =
Arrays.asList(Constants.RELATION_2, Constants.RELATION_3,
Constants.RELATION_4);
relationRepository.put(relations);
- relationRepository.delete(relations.stream().map(e ->
e.getId()).collect(Collectors.toList()));
+ relationRepository.delete(relations.stream().map(Element::getId).toList());
assertIterableEquals(Arrays.asList(null, null, null), relationRepository
- .get(relations.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ .get(relations.stream().map(Element::getId).toList()));
}
@Test
@@ -84,6 +82,6 @@ class RelationRepositoryTest extends PostgresRepositoryTest {
Arrays.asList(Constants.RELATION_2, Constants.RELATION_3,
Constants.RELATION_4);
relationRepository.copy(relations);
assertIterableEquals(relations, relationRepository
- .get(relations.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ .get(relations.stream().map(Element::getId).toList()));
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/WayRepositoryTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/WayRepositoryTest.java
index 4906b88d..bd996295 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/WayRepositoryTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/database/postgres/WayRepositoryTest.java
@@ -21,12 +21,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
-import java.io.IOException;
-import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import org.apache.baremaps.database.repository.Constants;
+import org.apache.baremaps.openstreetmap.model.Element;
import org.apache.baremaps.openstreetmap.model.Way;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
@@ -37,7 +35,7 @@ class WayRepositoryTest extends PostgresRepositoryTest {
WayRepository wayRepository;
@BeforeEach
- void init() throws SQLException, IOException {
+ void init() {
wayRepository = new WayRepository(dataSource());
}
@@ -54,7 +52,7 @@ class WayRepositoryTest extends PostgresRepositoryTest {
List<Way> ways = Arrays.asList(Constants.WAY_0, Constants.WAY_1,
Constants.WAY_2);
wayRepository.put(ways);
assertIterableEquals(ways,
- wayRepository.get(ways.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ wayRepository.get(ways.stream().map(Element::getId).toList()));
}
@Test
@@ -70,9 +68,9 @@ class WayRepositoryTest extends PostgresRepositoryTest {
void deleteAll() throws RepositoryException {
List<Way> ways = Arrays.asList(Constants.WAY_0, Constants.WAY_1,
Constants.WAY_2);
wayRepository.put(ways);
- wayRepository.delete(ways.stream().map(e ->
e.getId()).collect(Collectors.toList()));
+ wayRepository.delete(ways.stream().map(Element::getId).toList());
assertIterableEquals(Arrays.asList(null, null, null),
- wayRepository.get(ways.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ wayRepository.get(ways.stream().map(Element::getId).toList()));
}
@Test
@@ -81,6 +79,6 @@ class WayRepositoryTest extends PostgresRepositoryTest {
List<Way> ways = Arrays.asList(Constants.WAY_0, Constants.WAY_1,
Constants.WAY_2);
wayRepository.copy(ways);
assertIterableEquals(ways,
- wayRepository.get(ways.stream().map(e ->
e.getId()).collect(Collectors.toList())));
+ wayRepository.get(ways.stream().map(Element::getId).toList()));
}
}
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
index bcf450f1..d277e10f 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/flatgeobuf/FlatGeoBufDataTableTest.java
@@ -31,8 +31,8 @@ class FlatGeoBufDataTableTest {
var file =
TestFiles.resolve("baremaps-testing/data/samples/countries.fgb");
var table = new FlatGeoBufDataTable(file);
var rowType = table.schema();
- assertEquals(rowType.name(), null);
- assertEquals(rowType.columns().size(), 2);
+ assertEquals(null, rowType.name());
+ assertEquals(2, rowType.columns().size());
}
@Test
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
index 12785b83..11b2cf7d 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/storage/geopackage/GeoPackageDataStoreTest.java
@@ -30,8 +30,8 @@ class GeoPackageDataStoreTest {
var geoPackageStore = new GeoPackageDataStore(file);
var table = geoPackageStore.get("countries");
var rowType = table.schema();
- assertEquals(rowType.name(), "countries");
- assertEquals(rowType.columns().size(), 4);
+ assertEquals("countries", rowType.name());
+ assertEquals(4, rowType.columns().size());
}
@Test
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/algorithm/ExternalMergeSort.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/algorithm/ExternalMergeSort.java
index 040886ff..1e520979 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/algorithm/ExternalMergeSort.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/algorithm/ExternalMergeSort.java
@@ -67,13 +67,12 @@ public class ExternalMergeSort {
* @param comparator The comparator that tells how to sort the lines
* @param distinct The flag indicating if duplicates should be discarded
* @return the number of data sorted
- * @throws IOException
*/
private static <T> long mergeSortedBatches(
List<DataList<T>> batches,
DataList<T> output,
Comparator<T> comparator,
- boolean distinct) throws IOException {
+ boolean distinct) {
PriorityQueue<DataStack<T>> queue =
new PriorityQueue<>(batches.size(), (i, j) ->
comparator.compare(i.peek(), j.peek()));
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
index b2db254a..80349aa4 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlDataTable.java
@@ -58,10 +58,10 @@ public class SqlDataTable extends AbstractTable implements
ScannableTable {
}
private RelDataType createRowType(RelDataTypeFactory typeFactory) {
- var rowType = new RelDataTypeFactory.Builder(typeFactory);
+ var rowTypeBuilder = new RelDataTypeFactory.Builder(typeFactory);
for (DataColumn column : table.schema().columns()) {
- rowType.add(column.name(), SqlTypeConversion.types.get(column.type()));
+ rowTypeBuilder.add(column.name(),
SqlTypeConversion.types.get(column.type()));
}
- return rowType.build();
+ return rowTypeBuilder.build();
}
}
diff --git
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
index 78a6ee25..a973ed8d 100644
---
a/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
+++
b/baremaps-data/src/main/java/org/apache/baremaps/data/calcite/SqlTypeConversion.java
@@ -62,4 +62,8 @@ public class SqlTypeConversion {
types.put(Type.GEOMETRYCOLLECTION, new JavaTypeFactoryImpl()
.createJavaType(GeometryCollection.class));
}
+
+ private SqlTypeConversion() {
+ // Prevent instantiation
+ }
}
diff --git
a/baremaps-maplibre/src/main/java/org/apache/baremaps/maplibre/vectortile/VectorTileDecoder.java
b/baremaps-maplibre/src/main/java/org/apache/baremaps/maplibre/vectortile/VectorTileDecoder.java
index b37abc6c..7f7839e9 100644
---
a/baremaps-maplibre/src/main/java/org/apache/baremaps/maplibre/vectortile/VectorTileDecoder.java
+++
b/baremaps-maplibre/src/main/java/org/apache/baremaps/maplibre/vectortile/VectorTileDecoder.java
@@ -23,7 +23,6 @@ import com.google.protobuf.InvalidProtocolBufferException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
-import java.util.stream.Collectors;
import org.apache.baremaps.maplibre.binary.VectorTile;
import org.apache.baremaps.maplibre.binary.VectorTile.Tile.GeomType;
import org.apache.baremaps.maplibre.binary.VectorTile.Tile.Value;
@@ -77,7 +76,7 @@ public class VectorTileDecoder {
public Tile decodeTile(VectorTile.Tile tile) {
List<Layer> layers = tile.getLayersList().stream()
.map(this::decodeLayer)
- .collect(Collectors.toList());
+ .toList();
return new Tile(layers);
}
@@ -113,11 +112,11 @@ public class VectorTileDecoder {
keys = layer.getKeysList();
values = layer.getValuesList().stream()
.map(this::decodeValue)
- .collect(Collectors.toList());
+ .toList();
List<Feature> features = layer.getFeaturesList().stream()
.map(this::decodeFeature)
- .collect(Collectors.toList());
+ .toList();
return new Layer(name, extent, features);
}