From 742af2dc2a511d6992dfe139da9fc827f418cca7 Mon Sep 17 00:00:00 2001 From: Stefan Feilmeier Date: Wed, 22 Dec 2021 13:49:18 +0100 Subject: [PATCH] Backend Odoo: apply Checkstyle, fix taking database name from configuration --- .../openems/backend/metadata/odoo/Field.java | 27 +++++++++++++++++++ .../openems/backend/metadata/odoo/MyEdge.java | 2 +- .../metadata/odoo/odoo/Credentials.java | 14 +++++++--- .../metadata/odoo/odoo/FieldValue.java | 12 ++++----- .../backend/metadata/odoo/odoo/OdooUtils.java | 2 +- .../metadata/odoo/postgres/Credentials.java | 6 +++++ .../odoo/postgres/PostgresHandler.java | 3 +++ .../postgres/task/InsertEdgeConfigUpdate.java | 1 + .../task/InsertOrUpdateDeviceStates.java | 1 + .../odoo/postgres/task/UpdateEdgeConfig.java | 1 + .../postgres/task/UpdateEdgeProducttype.java | 1 + .../postgres/task/UpdateEdgeStateActive.java | 1 + .../odoo/postgres/task/UpdateSumState.java | 3 ++- 13 files changed, 61 insertions(+), 13 deletions(-) diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/Field.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/Field.java index b3fc898f9b5..cf1a4be5d8e 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/Field.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/Field.java @@ -5,17 +5,38 @@ public interface Field { + /** + * Gets the Field ID. + * + * @return the ID + */ public String id(); + /** + * Gets the Field index. + * + * @return the index + */ public int index(); + /** + * Gets the Field name. + * + * @return the name + */ public String name(); + /** + * Should this Field be queried?. + * + * @return true if yes + */ public boolean isQuery(); /** * Gets all fields that should be queried as a comma separated string. * + * @param fields an array of {@link Field}s * @return the String */ public static String getSqlQueryFields(Field[] fields) { @@ -68,10 +89,12 @@ private EdgeDevice(String id, boolean query) { } } + @Override public String id() { return this.id; } + @Override public int index() { return this.queryIndex; } @@ -120,10 +143,12 @@ private EdgeDeviceStatus(String id, boolean query) { } } + @Override public String id() { return this.id; } + @Override public int index() { return this.queryIndex; } @@ -167,10 +192,12 @@ private EdgeConfigUpdate(String id, boolean query) { } } + @Override public String id() { return this.id; } + @Override public int index() { return this.queryIndex; } diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MyEdge.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MyEdge.java index 3f32bdad306..a84efdd6dd8 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MyEdge.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MyEdge.java @@ -21,7 +21,7 @@ public int getOdooId() { } public String getApikey() { - return apikey; + return this.apikey; } } diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/Credentials.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/Credentials.java index a59b3a53489..969469cce57 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/Credentials.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/Credentials.java @@ -7,6 +7,12 @@ */ public class Credentials { + /** + * Creates {@link Credentials} from a {@link Config}uration. + * + * @param config the configuration + * @return a new {@link Credentials} object + */ public static Credentials fromConfig(Config config) { return new Credentials(// config.odooProtocol(), config.odooHost(), config.odooPort(), config.odooUid(), config.odooPassword(), @@ -32,15 +38,15 @@ public Credentials(Protocol protocol, String host, int port, int uid, String pas } public Protocol getProtocol() { - return protocol; + return this.protocol; } public String getHost() { - return host; + return this.host; } public int getPort() { - return port; + return this.port; } public int getUid() { @@ -52,7 +58,7 @@ public String getUrl() { } public String getPassword() { - return password; + return this.password; } public String getDatabase() { diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/FieldValue.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/FieldValue.java index b830f6cef03..3bddbb1804d 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/FieldValue.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/FieldValue.java @@ -15,20 +15,20 @@ public FieldValue(Field field, T value) { } public Field getField() { - return field; + return this.field; } public T getValue() { - return value; + return this.value; } @Override public String toString() { String string; - if (value instanceof JsonElement) { - string = StringUtils.toShortString((JsonElement) value, 100); - } else if (value instanceof String) { - string = StringUtils.toShortString((String) value, 100); + if (this.value instanceof JsonElement) { + string = StringUtils.toShortString((JsonElement) this.value, 100); + } else if (this.value instanceof String) { + string = StringUtils.toShortString((String) this.value, 100); } else { string = this.value.toString(); } diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooUtils.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooUtils.java index 00c2c8c38af..0507bd8449d 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooUtils.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooUtils.java @@ -194,7 +194,7 @@ protected static String login(Credentials credentials, String username, String p .addProperty("jsonrpc", "2.0") // .addProperty("method", "call") // .add("params", JsonUtils.buildJsonObject() // - .addProperty("db", "v12") // + .addProperty("db", credentials.getDatabase()) // .addProperty("login", username) // .addProperty("password", password) // .build()) // diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/Credentials.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/Credentials.java index d099e9e3cf2..fbd179c493b 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/Credentials.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/Credentials.java @@ -7,6 +7,12 @@ */ public class Credentials { + /** + * Creates {@link Credentials} from a {@link Config}uration. + * + * @param config the configuration + * @return a new {@link Credentials} object + */ public static Credentials fromConfig(Config config) { return new Credentials(// config.pgHost(), config.pgPort(), config.pgUser(), config.pgPassword(), config.database()); diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/PostgresHandler.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/PostgresHandler.java index 7f566aac2d8..ed0e6e6b417 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/PostgresHandler.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/PostgresHandler.java @@ -39,6 +39,9 @@ public PostgresHandler(OdooMetadata parent, EdgeCache edgeCache, Config config, this.queueWriteWorker.start(); } + /** + * Deactivates the {@link PostgresHandler}. + */ public void deactivate() { this.initializeEdgesWorker.stop(); this.periodicWriteWorker.stop(); diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertEdgeConfigUpdate.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertEdgeConfigUpdate.java index b2ca740984d..b6988c55065 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertEdgeConfigUpdate.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertEdgeConfigUpdate.java @@ -38,6 +38,7 @@ protected void _execute(Connection connection) throws SQLException { * UPDATE {} SET openems_config = {}, openems_config_components = {} WHERE id = * {};. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */ diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertOrUpdateDeviceStates.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertOrUpdateDeviceStates.java index b858d103d3c..951b5a024de 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertOrUpdateDeviceStates.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/InsertOrUpdateDeviceStates.java @@ -63,6 +63,7 @@ protected void _execute(Connection connection) throws SQLException { *

* Be careful to synchronize access to the resulting PreparedStatement. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */ diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeConfig.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeConfig.java index 1a9f457981e..5ea5e46bc34 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeConfig.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeConfig.java @@ -37,6 +37,7 @@ protected void _execute(Connection connection) throws SQLException { * UPDATE {} SET openems_config = {}, openems_config_components = {} WHERE id = * {};. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */ diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeProducttype.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeProducttype.java index 16ae72b85ea..52f00285088 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeProducttype.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeProducttype.java @@ -27,6 +27,7 @@ protected void _execute(Connection connection) throws SQLException { /** * UPDATE {} SET version = {} WHERE id = {};. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */ diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeStateActive.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeStateActive.java index ef5626e647e..beec53d2307 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeStateActive.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateEdgeStateActive.java @@ -24,6 +24,7 @@ protected void _execute(Connection connection) throws SQLException { /** * UPDATE {} SET state = 'active' WHERE id = {};. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */ diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateSumState.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateSumState.java index 8b38827a36b..f2ef1487f40 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateSumState.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/postgres/task/UpdateSumState.java @@ -22,7 +22,7 @@ protected void _execute(Connection connection) throws SQLException { PreparedStatement ps = this.psUpdateSumState(connection); final String sumStateString; if (this.sumState != null) { - sumStateString = sumState.getName().toLowerCase(); + sumStateString = this.sumState.getName().toLowerCase(); } else { sumStateString = ""; } @@ -34,6 +34,7 @@ protected void _execute(Connection connection) throws SQLException { /** * UPDATE {} SET openems_sum_state_level = {} WHERE id = {};. * + * @param connection the {@link Connection} * @return the PreparedStatement * @throws SQLException on error */