Skip to content

Commit

Permalink
Backend Odoo: apply Checkstyle, fix taking database name from configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
sfeilmeier committed Dec 22, 2021
1 parent 0f43c0a commit 742af2d
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -68,10 +89,12 @@ private EdgeDevice(String id, boolean query) {
}
}

@Override
public String id() {
return this.id;
}

@Override
public int index() {
return this.queryIndex;
}
Expand Down Expand Up @@ -120,10 +143,12 @@ private EdgeDeviceStatus(String id, boolean query) {
}
}

@Override
public String id() {
return this.id;
}

@Override
public int index() {
return this.queryIndex;
}
Expand Down Expand Up @@ -167,10 +192,12 @@ private EdgeConfigUpdate(String id, boolean query) {
}
}

@Override
public String id() {
return this.id;
}

@Override
public int index() {
return this.queryIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public int getOdooId() {
}

public String getApikey() {
return apikey;
return this.apikey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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() {
Expand All @@ -52,7 +58,7 @@ public String getUrl() {
}

public String getPassword() {
return password;
return this.password;
}

public String getDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected void _execute(Connection connection) throws SQLException {
* <p>
* Be careful to synchronize access to the resulting PreparedStatement.
*
* @param connection the {@link Connection}
* @return the PreparedStatement
* @throws SQLException on error
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
Expand All @@ -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
*/
Expand Down

0 comments on commit 742af2d

Please sign in to comment.