From 6006eaea5f1ab16760fd7f66c400b599f7b930d5 Mon Sep 17 00:00:00 2001 From: Stefan Feilmeier Date: Tue, 20 Feb 2024 11:49:19 +0100 Subject: [PATCH] Review + apply formatting --- .../alerting/handler/SumStateHandler.java | 11 +- .../alerting/SumStateAlertingSetting.java | 13 +- .../common/alerting/UserAlertingSettings.java | 1 + .../SetUserAlertingConfigsRequest.java | 25 +- .../GetUserAlertingConfigsResponse.java | 10 +- .../openems/backend/common/metadata/User.java | 3 +- .../backend/common/test/DummyMetadata.java | 2 +- .../jsonrpc/UserAlertingSettingsJsonRpc.java | 38 ++- .../openems/backend/metadata/odoo/Field.java | 22 +- .../backend/metadata/odoo/MetadataOdoo.java | 1 - .../metadata/odoo/odoo/OdooHandler.java | 273 +++++++++--------- .../backend/uiwebsocket/impl/OnRequest.java | 4 +- 12 files changed, 209 insertions(+), 194 deletions(-) diff --git a/io.openems.backend.alerting/src/io/openems/backend/alerting/handler/SumStateHandler.java b/io.openems.backend.alerting/src/io/openems/backend/alerting/handler/SumStateHandler.java index 6260f740e2a..1250ebd0861 100644 --- a/io.openems.backend.alerting/src/io/openems/backend/alerting/handler/SumStateHandler.java +++ b/io.openems.backend.alerting/src/io/openems/backend/alerting/handler/SumStateHandler.java @@ -182,14 +182,9 @@ private void handleEdgeOnSetSumState(EventReader event) { @Override public Consumer getEventHandler(String eventTopic) { return switch (eventTopic) { - case Edge.Events.ON_SET_ONLINE: - yield this::handleEdgeOnSetOnline; - - case Edge.Events.ON_SET_SUM_STATE: - yield this::handleEdgeOnSetSumState; - - default: - yield null; + case Edge.Events.ON_SET_ONLINE -> this::handleEdgeOnSetOnline; + case Edge.Events.ON_SET_SUM_STATE -> this::handleEdgeOnSetSumState; + default -> null; }; } diff --git a/io.openems.backend.common/src/io/openems/backend/common/alerting/SumStateAlertingSetting.java b/io.openems.backend.common/src/io/openems/backend/common/alerting/SumStateAlertingSetting.java index aadd2723bf4..04dc5e0364a 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/alerting/SumStateAlertingSetting.java +++ b/io.openems.backend.common/src/io/openems/backend/common/alerting/SumStateAlertingSetting.java @@ -14,15 +14,10 @@ public record SumStateAlertingSetting(String edgeId, String userLogin, int fault */ public int getDelay(Level state) { return switch (state) { - case OK: - case INFO: - yield 0; - case FAULT: - yield this.faultDelay; - case WARNING: - yield this.warningDelay; - default: - yield -1; + case OK, INFO -> 0; + case FAULT -> this.faultDelay; + case WARNING -> this.warningDelay; + default -> -1; }; } } diff --git a/io.openems.backend.common/src/io/openems/backend/common/alerting/UserAlertingSettings.java b/io.openems.backend.common/src/io/openems/backend/common/alerting/UserAlertingSettings.java index 8d2f88af6ce..ead84d4eaa4 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/alerting/UserAlertingSettings.java +++ b/io.openems.backend.common/src/io/openems/backend/common/alerting/UserAlertingSettings.java @@ -5,6 +5,7 @@ public record UserAlertingSettings(String deviceId, String userLogin, // int edgeOfflineDelay, int edgeFaultDelay, int edgeWarningDelay, // ZonedDateTime lastEdgeOfflineNotification, ZonedDateTime lastSumStateNotification) { + public UserAlertingSettings(String userLogin, int offlineEdgeDelay, int faultStateDelay, int warningStateDelay) { this(null, userLogin, offlineEdgeDelay, faultStateDelay, warningStateDelay, null, null); } diff --git a/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/request/SetUserAlertingConfigsRequest.java b/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/request/SetUserAlertingConfigsRequest.java index 05a77e3b2a4..660a4927ad3 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/request/SetUserAlertingConfigsRequest.java +++ b/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/request/SetUserAlertingConfigsRequest.java @@ -1,5 +1,11 @@ package io.openems.backend.common.jsonrpc.request; +import static io.openems.common.utils.JsonUtils.buildJsonObject; +import static io.openems.common.utils.JsonUtils.generateJsonArray; +import static io.openems.common.utils.JsonUtils.getAsInt; +import static io.openems.common.utils.JsonUtils.getAsJsonArray; +import static io.openems.common.utils.JsonUtils.getAsString; + import java.util.ArrayList; import java.util.List; @@ -9,7 +15,6 @@ import io.openems.backend.common.alerting.UserAlertingSettings; import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; import io.openems.common.jsonrpc.base.JsonrpcRequest; -import io.openems.common.utils.JsonUtils; /** * Represents a JSON-RPC Request for 'getEdgeConfig'. @@ -55,14 +60,14 @@ private SetUserAlertingConfigsRequest(JsonrpcRequest request) throws OpenemsName super(request, SetUserAlertingConfigsRequest.METHOD); var params = request.getParams(); - this.edgeId = JsonUtils.getAsString(params, "edgeId"); - JsonUtils.getAsJsonArray(params, "userSettings").forEach(user -> { + this.edgeId = getAsString(params, "edgeId"); + getAsJsonArray(params, "userSettings").forEach(user -> { var userJsonObject = user.getAsJsonObject(); try { - var userLogin = JsonUtils.getAsString(userJsonObject, "userLogin"); - var offlineEdgeDelay = JsonUtils.getAsInt(userJsonObject, "offlineEdgeDelay"); - var faultEdgeDelay = JsonUtils.getAsInt(userJsonObject, "faultEdgeDelay"); - var warningEdgeDelay = JsonUtils.getAsInt(userJsonObject, "warningEdgeDelay"); + var userLogin = getAsString(userJsonObject, "userLogin"); + var offlineEdgeDelay = getAsInt(userJsonObject, "offlineEdgeDelay"); + var faultEdgeDelay = getAsInt(userJsonObject, "faultEdgeDelay"); + var warningEdgeDelay = getAsInt(userJsonObject, "warningEdgeDelay"); this.userSettings .add(new UserAlertingSettings(userLogin, offlineEdgeDelay, faultEdgeDelay, warningEdgeDelay)); @@ -92,14 +97,14 @@ public List getUserSettings() { @Override public JsonObject getParams() { - return JsonUtils.buildJsonObject() // + return buildJsonObject() // .addProperty("edgeId", this.edgeId) // - .add("userSettings", JsonUtils.generateJsonArray(this.userSettings, this::toJson)) // + .add("userSettings", generateJsonArray(this.userSettings, this::toJson)) // .build(); } private JsonElement toJson(UserAlertingSettings setting) { - return JsonUtils.buildJsonObject() // + return buildJsonObject() // .addProperty("userLogin", setting.userLogin()) // .addProperty("offlineEdgeDelay", setting.edgeOfflineDelay()) // .addProperty("faultEdgeDelay", setting.edgeFaultDelay()) // diff --git a/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/response/GetUserAlertingConfigsResponse.java b/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/response/GetUserAlertingConfigsResponse.java index a78ec0dbfe7..4bcf9acd189 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/response/GetUserAlertingConfigsResponse.java +++ b/io.openems.backend.common/src/io/openems/backend/common/jsonrpc/response/GetUserAlertingConfigsResponse.java @@ -1,5 +1,8 @@ package io.openems.backend.common.jsonrpc.response; +import static io.openems.common.utils.JsonUtils.buildJsonObject; +import static io.openems.common.utils.JsonUtils.generateJsonArray; + import java.util.List; import java.util.UUID; @@ -8,7 +11,6 @@ import io.openems.backend.common.alerting.UserAlertingSettings; import io.openems.common.jsonrpc.base.JsonrpcResponseSuccess; -import io.openems.common.utils.JsonUtils; /** * Represents a JSON-RPC Response for 'getAlertingConfig'. @@ -50,14 +52,14 @@ public GetUserAlertingConfigsResponse(UUID id, UserAlertingSettings currentUserS @Override public JsonObject getResult() { - return JsonUtils.buildJsonObject() // + return buildJsonObject() // .add("currentUserSettings", this.toJson(this.currentUserSettings)) // - .add("otherUsersSettings", JsonUtils.generateJsonArray(this.otherUsersSettings, this::toJson)) // + .add("otherUsersSettings", generateJsonArray(this.otherUsersSettings, this::toJson)) // .build(); } private JsonElement toJson(UserAlertingSettings setting) { - return JsonUtils.buildJsonObject() // + return buildJsonObject() // .addProperty("userLogin", setting.userLogin()) // .addProperty("offlineEdgeDelay", setting.edgeOfflineDelay()) // .addProperty("faultEdgeDelay", setting.edgeFaultDelay()) // diff --git a/io.openems.backend.common/src/io/openems/backend/common/metadata/User.java b/io.openems.backend.common/src/io/openems/backend/common/metadata/User.java index bf4f6ef2b28..93acdcdd235 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/metadata/User.java +++ b/io.openems.backend.common/src/io/openems/backend/common/metadata/User.java @@ -30,7 +30,8 @@ public class User extends AbstractUser { */ private final boolean hasMultipleEdges; - public User(String id, String name, String token, Language language, Role globalRole, boolean hasMultipleEdges, JsonObject settings) { + public User(String id, String name, String token, Language language, Role globalRole, boolean hasMultipleEdges, + JsonObject settings) { this(id, name, token, language, globalRole, new TreeMap<>(), hasMultipleEdges, settings); } diff --git a/io.openems.backend.common/src/io/openems/backend/common/test/DummyMetadata.java b/io.openems.backend.common/src/io/openems/backend/common/test/DummyMetadata.java index 77d95ac14fb..1d161b9496e 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/test/DummyMetadata.java +++ b/io.openems.backend.common/src/io/openems/backend/common/test/DummyMetadata.java @@ -61,7 +61,7 @@ public Collection getAllOfflineEdges() { public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { throw new UnsupportedOperationException("Unsupported by Dummy Class"); } - + @Override public List getUserAlertingSettings(String edgeId) { throw new UnsupportedOperationException("Unsupported by Dummy Class"); diff --git a/io.openems.backend.common/test/io/openems/backend/common/jsonrpc/UserAlertingSettingsJsonRpc.java b/io.openems.backend.common/test/io/openems/backend/common/jsonrpc/UserAlertingSettingsJsonRpc.java index 55bc5364c59..bbb6e1c169d 100644 --- a/io.openems.backend.common/test/io/openems/backend/common/jsonrpc/UserAlertingSettingsJsonRpc.java +++ b/io.openems.backend.common/test/io/openems/backend/common/jsonrpc/UserAlertingSettingsJsonRpc.java @@ -1,10 +1,12 @@ package io.openems.backend.common.jsonrpc; +import static io.openems.common.utils.JsonUtils.buildJsonArray; +import static io.openems.common.utils.JsonUtils.buildJsonObject; +import static java.util.UUID.randomUUID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.util.List; -import java.util.UUID; import org.junit.Test; @@ -16,7 +18,6 @@ import io.openems.backend.common.jsonrpc.response.GetUserAlertingConfigsResponse; import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; import io.openems.common.jsonrpc.base.JsonrpcRequest; -import io.openems.common.utils.JsonUtils; public class UserAlertingSettingsJsonRpc { @@ -24,9 +25,10 @@ public class UserAlertingSettingsJsonRpc { public void testGetUserAlertingConfigsRequest() { assertEquals("getUserAlertingConfigs", GetUserAlertingConfigsRequest.METHOD); - var id = UUID.randomUUID(); + var id = randomUUID(); var edgeId = "edge4"; - var params = JsonUtils.buildJsonObject().addProperty("edgeId", edgeId).build(); + var params = buildJsonObject() // + .addProperty("edgeId", edgeId).build(); var json = new JsonrpcRequest(id, GetUserAlertingConfigsRequest.METHOD, 0) { @Override @@ -40,6 +42,7 @@ public JsonObject getParams() { assertEquals(id, request.id); assertEquals(edgeId, request.getEdgeId()); assertEquals(params, request.getParams()); + } catch (OpenemsNamedException e) { e.printStackTrace(); fail(e.getMessage()); @@ -50,21 +53,22 @@ public JsonObject getParams() { public void testSetUserAlertingConfigsRequest() { assertEquals("setUserAlertingConfigs", SetUserAlertingConfigsRequest.METHOD); - var userSettingJson = JsonUtils.buildJsonObject() // + var userSettingJson = buildJsonObject() // .addProperty("userLogin", "user1") // .addProperty("offlineEdgeDelay", 15) // .addProperty("faultEdgeDelay", 30) // .addProperty("warningEdgeDelay", 60) // .build(); - var illegalSettingJson = JsonUtils.buildJsonObject() // + var illegalSettingJson = buildJsonObject() // .addProperty("err", "wrong") // .build(); - var id = UUID.randomUUID(); + var id = randomUUID(); var edgeId = "edge4"; - var params = JsonUtils.buildJsonObject() // + var params = buildJsonObject() // .addProperty("edgeId", edgeId) // - .add("userSettings", JsonUtils.buildJsonArray().add(userSettingJson) // + .add("userSettings", buildJsonArray() // + .add(userSettingJson) // .add(illegalSettingJson) // .build()) // .build(); @@ -83,15 +87,17 @@ public JsonObject getParams() { assertEquals(id, request.id); assertEquals(edgeId, request.getEdgeId()); - var expected = JsonUtils.buildJsonObject() // + var expected = buildJsonObject() // .addProperty("edgeId", edgeId) // - .add("userSettings", JsonUtils.buildJsonArray().add(userSettingJson).build()) // + .add("userSettings", buildJsonArray() // + .add(userSettingJson).build()) // .build(); assertEquals(expected, request.getParams()); var settings = request.getUserSettings(); assertEquals(1, settings.size()); assertEquals(userSetting, settings.get(0)); + } catch (OpenemsNamedException e) { e.printStackTrace(); fail(e.getMessage()); @@ -103,25 +109,25 @@ public void testGetUserAlertingConfigsResponse() { var sett1 = new UserAlertingSettings("edge1", "user1", 0, 15, 30, null, null); var sett2 = new UserAlertingSettings("edge2", "user2", 10, 10, 10, null, null); - var id = UUID.randomUUID(); + var id = randomUUID(); var response = new GetUserAlertingConfigsResponse(id, sett1, List.of(sett2)); - var sett1Json = JsonUtils.buildJsonObject() // + var sett1Json = buildJsonObject() // .addProperty("userLogin", sett1.userLogin()) // .addProperty("offlineEdgeDelay", sett1.edgeOfflineDelay()) // .addProperty("faultEdgeDelay", sett1.edgeFaultDelay()) // .addProperty("warningEdgeDelay", sett1.edgeWarningDelay()) // .build(); - var sett2Json = JsonUtils.buildJsonObject() // + var sett2Json = buildJsonObject() // .addProperty("userLogin", sett2.userLogin()) // .addProperty("offlineEdgeDelay", sett2.edgeOfflineDelay()) // .addProperty("faultEdgeDelay", sett2.edgeFaultDelay()) // .addProperty("warningEdgeDelay", sett2.edgeWarningDelay()) // .build(); - var settArrJson = JsonUtils.buildJsonObject() // + var settArrJson = buildJsonObject() // .add("currentUserSettings", sett1Json) - .add("otherUsersSettings", JsonUtils.buildJsonArray().add(sett2Json).build()) // + .add("otherUsersSettings", buildJsonArray().add(sett2Json).build()) // .build(); var jsonObj = response.getResult(); 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 5e4cf2905e4..c0eb9da2aee 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 @@ -1,6 +1,7 @@ package io.openems.backend.metadata.odoo; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.joining; + import java.util.stream.Stream; public interface Field { @@ -34,13 +35,9 @@ public interface Field { public boolean isQuery(); private static > Stream getSqlQueryFieldsOf(Class field) { - return Stream.of(field.getEnumConstants()).map(v -> { - if (v instanceof Field f) { - return f; - } else { - return null; - } - }).filter(Field::isQuery); + return Stream.of(field.getEnumConstants()) // + .map(v -> v instanceof Field f ? f : null) // + .filter(Field::isQuery); } /** @@ -53,7 +50,7 @@ public static String getSqlQueryFields(Field[] fields) { return Stream.of(fields) // .filter(Field::isQuery) // .map(Field::id) // - .collect(Collectors.joining(",")); + .collect(joining(",")); } /** @@ -65,7 +62,8 @@ public static String getSqlQueryFields(Field[] fields) { * @return list of fields */ public static > Field[] getSqlQueryFields(Class field) { - return Field.getSqlQueryFieldsOf(field).toArray(Field[]::new); + return Field.getSqlQueryFieldsOf(field) // + .toArray(Field[]::new); } /** @@ -85,7 +83,9 @@ public static > Field[] getSqlQueryFields(Class< public record GenericField(String id) implements Field { public GenericField(Field... fields) { - this(Stream.of(fields).map(Field::name).collect(Collectors.joining("."))); + this(Stream.of(fields) // + .map(Field::name) // + .collect(joining("."))); } @Override diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MetadataOdoo.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MetadataOdoo.java index b3c3dba35d5..23324b1ab0b 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MetadataOdoo.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MetadataOdoo.java @@ -613,7 +613,6 @@ public Optional getSumState(String edgeId) { } } - @Override public void updateUserSettings(User user, JsonObject settings) throws OpenemsNamedException { this.odooHandler.updateUserSettings(user, settings); diff --git a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooHandler.java b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooHandler.java index bc37632041a..1bcf0477ed5 100644 --- a/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooHandler.java +++ b/io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/odoo/OdooHandler.java @@ -1,5 +1,17 @@ package io.openems.backend.metadata.odoo.odoo; +import static io.openems.backend.metadata.odoo.odoo.OdooUtils.getAs; +import static io.openems.backend.metadata.odoo.odoo.OdooUtils.getAsEnum; +import static io.openems.backend.metadata.odoo.odoo.OdooUtils.getAsOptional; +import static io.openems.backend.metadata.odoo.odoo.OdooUtils.getAsOrElse; +import static io.openems.common.utils.JsonUtils.buildJsonObject; +import static io.openems.common.utils.JsonUtils.getAsJsonElement; +import static io.openems.common.utils.JsonUtils.getAsJsonObject; +import static io.openems.common.utils.JsonUtils.getAsOptionalJsonArray; +import static io.openems.common.utils.JsonUtils.getAsOptionalJsonObject; +import static io.openems.common.utils.JsonUtils.getAsOptionalString; +import static io.openems.common.utils.JsonUtils.getAsString; + import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; @@ -45,7 +57,6 @@ import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions; import io.openems.common.session.Language; import io.openems.common.session.Role; -import io.openems.common.utils.JsonUtils; import io.openems.common.utils.ObjectUtils; import io.openems.common.utils.PasswordUtils; @@ -193,9 +204,8 @@ public String authenticate(String username, String password) throws OpenemsNamed * @throws OpenemsNamedException on error */ public JsonObject authenticateSession(String sessionId) throws OpenemsNamedException { - return JsonUtils - .getAsJsonObject(OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/info", - "session_id=" + sessionId, new JsonObject()).result); + return getAsJsonObject(OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/info", + "session_id=" + sessionId, new JsonObject()).result); } /** @@ -262,13 +272,13 @@ public void setUserInformation(MyUser user, JsonObject userJson) throws OpenemsN var fieldValues = new HashMap<>(this.updateAddress(userJson)); fieldValues.putAll(this.updateCompany(user, userJson)); - JsonUtils.getAsOptionalString(userJson, "firstname") // + getAsOptionalString(userJson, "firstname") // .ifPresent(firstname -> fieldValues.put(Field.Partner.FIRSTNAME.id(), firstname)); - JsonUtils.getAsOptionalString(userJson, "lastname") // + getAsOptionalString(userJson, "lastname") // .ifPresent(lastname -> fieldValues.put(Field.Partner.LASTNAME.id(), lastname)); - JsonUtils.getAsOptionalString(userJson, "email") // + getAsOptionalString(userJson, "email") // .ifPresent(email -> fieldValues.put(Field.Partner.EMAIL.id(), email.toLowerCase())); - JsonUtils.getAsOptionalString(userJson, "phone") // + getAsOptionalString(userJson, "phone") // .ifPresent(phone -> fieldValues.put(Field.Partner.PHONE.id(), phone)); var odooPartnerId = this.getOdooPartnerId(user.getOdooId()); @@ -283,7 +293,7 @@ public void setUserInformation(MyUser user, JsonObject userJson) throws OpenemsN * @throws OpenemsException on error */ private Map updateAddress(JsonObject addressJson) throws OpenemsException { - var addressOpt = JsonUtils.getAsOptionalJsonObject(addressJson, "address"); + var addressOpt = getAsOptionalJsonObject(addressJson, "address"); if (!addressOpt.isPresent()) { return new HashMap<>(); } @@ -291,14 +301,14 @@ private Map updateAddress(JsonObject addressJson) throws Openems Map addressFields = new HashMap<>(); addressFields.put("type", "contact"); - JsonUtils.getAsOptionalString(address, "street") // + getAsOptionalString(address, "street") // .ifPresent(street -> addressFields.put(Field.Partner.STREET.id(), street)); - JsonUtils.getAsOptionalString(address, "zip") // + getAsOptionalString(address, "zip") // .ifPresent(zip -> addressFields.put(Field.Partner.ZIP.id(), zip)); - JsonUtils.getAsOptionalString(address, "city") // + getAsOptionalString(address, "city") // .ifPresent(city -> addressFields.put(Field.Partner.CITY.id(), city)); - var countryCodeOpt = JsonUtils.getAsOptionalString(address, "country"); + var countryCodeOpt = getAsOptionalString(address, "country"); if (countryCodeOpt.isPresent()) { var countryCode = countryCodeOpt.get().toUpperCase(); @@ -339,11 +349,11 @@ private Map updateCompany(JsonObject companyJson) throws Openems * @throws OpenemsException on error */ private Map updateCompany(MyUser user, JsonObject companyJson) throws OpenemsException { - var companyOpt = JsonUtils.getAsOptionalJsonObject(companyJson, "company"); + var companyOpt = getAsOptionalJsonObject(companyJson, "company"); if (!companyOpt.isPresent()) { return new HashMap<>(); } - var companyNameOpt = JsonUtils.getAsOptionalString(companyOpt.get(), "name"); + var companyNameOpt = getAsOptionalString(companyOpt.get(), "name"); if (!companyNameOpt.isPresent()) { return new HashMap<>(); } @@ -401,12 +411,12 @@ public byte[] getOdooSetupProtocolReport(int setupProtocolId) throws OpenemsName * @throws OpenemsNamedException on error */ public int submitSetupProtocol(MyUser user, JsonObject setupProtocolJson) throws OpenemsNamedException { - var userJson = JsonUtils.getAsJsonObject(setupProtocolJson, "customer"); - var edgeJson = JsonUtils.getAsJsonObject(setupProtocolJson, "edge"); - var installerJson = JsonUtils.getAsJsonObject(setupProtocolJson, "installer"); - var oem = JsonUtils.getAsString(setupProtocolJson, "oem").toUpperCase(); + var userJson = getAsJsonObject(setupProtocolJson, "customer"); + var edgeJson = getAsJsonObject(setupProtocolJson, "edge"); + var installerJson = getAsJsonObject(setupProtocolJson, "installer"); + var oem = getAsString(setupProtocolJson, "oem").toUpperCase(); - var edgeId = JsonUtils.getAsString(edgeJson, "id"); + var edgeId = getAsString(edgeJson, "id"); var foundEdge = OdooUtils.search(this.credentials, Field.EdgeDevice.ODOO_MODEL, new Domain(Field.EdgeDevice.NAME, Operator.EQ, edgeId)); if (foundEdge.length != 1) { @@ -429,9 +439,9 @@ public int submitSetupProtocol(MyUser user, JsonObject setupProtocolJson) throws var isCompany = (boolean) installer.get("is_company"); if (!isCompany) { Map fieldsToUpdate = new HashMap<>(); - JsonUtils.getAsOptionalString(installerJson, "firstname") // + getAsOptionalString(installerJson, "firstname") // .ifPresent(firstname -> fieldsToUpdate.put(Field.Partner.FIRSTNAME.id(), firstname)); - JsonUtils.getAsOptionalString(installerJson, "lastname") // + getAsOptionalString(installerJson, "lastname") // .ifPresent(lastname -> fieldsToUpdate.put(Field.Partner.LASTNAME.id(), lastname)); if (!fieldsToUpdate.isEmpty()) { @@ -460,18 +470,18 @@ public int submitSetupProtocol(MyUser user, JsonObject setupProtocolJson) throws private void updateEdgeComment(JsonObject customer, String edgeId, int odooEdgeId) throws OpenemsNamedException { // build comment var builder = new StringBuilder(); - JsonUtils.getAsOptionalString(customer, "firstname") // + getAsOptionalString(customer, "firstname") // .ifPresent(firstname -> builder.append(firstname)); - JsonUtils.getAsOptionalString(customer, "lastname") // + getAsOptionalString(customer, "lastname") // .ifPresent(lastname -> { if (builder.length() > 0) { builder.append(" "); } builder.append(lastname); }); - JsonUtils.getAsOptionalJsonObject(customer, "address") // + getAsOptionalJsonObject(customer, "address") // .ifPresent(address -> { // - JsonUtils.getAsOptionalString(address, "city") // + getAsOptionalString(address, "city") // .ifPresent(city -> { if (builder.length() > 0) { builder.append(", "); @@ -501,13 +511,12 @@ private void updateEdgeComment(JsonObject customer, String edgeId, int odooEdgeI * @throws OpenemsNamedException on error */ private void sendSetupProtocolMail(MyUser user, int protocolId, String edgeId) throws OpenemsNamedException { - OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/sendSetupProtocolEmail", - JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // - .addProperty("setupProtocolId", protocolId) // - .addProperty("edgeId", edgeId) // - .build()) // - .build()); + OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/sendSetupProtocolEmail", buildJsonObject() // + .add("params", buildJsonObject() // + .addProperty("setupProtocolId", protocolId) // + .addProperty("edgeId", edgeId) // + .build()) // + .build()); } /** @@ -524,15 +533,15 @@ private int createOdooUser(JsonObject userJson, String password, String oem) thr var customerFields = new HashMap<>(this.updateAddress(userJson)); customerFields.putAll(this.updateCompany(userJson)); - JsonUtils.getAsOptionalString(userJson, "firstname") // + getAsOptionalString(userJson, "firstname") // .ifPresent(firstname -> customerFields.put(Field.Partner.FIRSTNAME.id(), firstname)); - JsonUtils.getAsOptionalString(userJson, "lastname") // + getAsOptionalString(userJson, "lastname") // .ifPresent(lastname -> customerFields.put(Field.Partner.LASTNAME.id(), lastname)); - var email = JsonUtils.getAsString(userJson, "email").toLowerCase(); + var email = getAsString(userJson, "email").toLowerCase(); customerFields.put(Field.Partner.EMAIL.id(), email); - JsonUtils.getAsOptionalString(userJson, "phone") // + getAsOptionalString(userJson, "phone") // .ifPresent(phone -> customerFields.put(Field.Partner.PHONE.id(), phone)); var userFound = OdooUtils.search(this.credentials, Field.User.ODOO_MODEL, @@ -592,20 +601,20 @@ private int createSetupProtocol(JsonObject jsonObject, int edgeId, int customerI throws OpenemsException { Integer locationId = null; - var jLocationOpt = JsonUtils.getAsOptionalJsonObject(jsonObject, "location"); + var jLocationOpt = getAsOptionalJsonObject(jsonObject, "location"); if (jLocationOpt.isPresent()) { var location = jLocationOpt.get(); var locationFields = new HashMap<>(this.updateAddress(location)); locationFields.putAll(this.updateCompany(location)); - JsonUtils.getAsOptionalString(location, "firstname") // + getAsOptionalString(location, "firstname") // .ifPresent(firstname -> locationFields.put(Field.Partner.FIRSTNAME.id(), firstname)); - JsonUtils.getAsOptionalString(location, "lastname") // + getAsOptionalString(location, "lastname") // .ifPresent(lastname -> locationFields.put(Field.Partner.LASTNAME.id(), lastname)); - JsonUtils.getAsOptionalString(location, "email") // + getAsOptionalString(location, "email") // .ifPresent(mail -> locationFields.put(Field.Partner.EMAIL.id(), mail.toLowerCase())); - JsonUtils.getAsOptionalString(location, "phone") // + getAsOptionalString(location, "phone") // .ifPresent(phone -> locationFields.put(Field.Partner.PHONE.id(), phone)); locationId = OdooUtils.create(this.credentials, Field.Partner.ODOO_MODEL, locationFields); @@ -619,11 +628,11 @@ private int createSetupProtocol(JsonObject jsonObject, int edgeId, int customerI var setupProtocolId = OdooUtils.create(this.credentials, Field.SetupProtocol.ODOO_MODEL, setupProtocolFields); - var lotsOpt = JsonUtils.getAsOptionalJsonArray(jsonObject, "lots"); + var lotsOpt = getAsOptionalJsonArray(jsonObject, "lots"); if (lotsOpt.isPresent()) { this.createSetupProtocolProductionLots(setupProtocolId, lotsOpt.get()); } - var itemsOpt = JsonUtils.getAsOptionalJsonArray(jsonObject, "items"); + var itemsOpt = getAsOptionalJsonArray(jsonObject, "items"); if (itemsOpt.isPresent()) { this.createSetupProtocolItems(setupProtocolId, itemsOpt.get()); } @@ -647,12 +656,12 @@ private void createSetupProtocolProductionLots(int setupProtocolId, JsonArray lo lotFields.put(Field.SetupProtocolProductionLot.SETUP_PROTOCOL.id(), setupProtocolId); lotFields.put(Field.SetupProtocolProductionLot.SEQUENCE.id(), i); - JsonUtils.getAsOptionalString(lot, "category") // + getAsOptionalString(lot, "category") // .ifPresent(category -> lotFields.put("category", category)); - JsonUtils.getAsOptionalString(lot, "name") // + getAsOptionalString(lot, "name") // .ifPresent(name -> lotFields.put("name", name)); - var serialNumberOpt = JsonUtils.getAsOptionalString(lot, "serialNumber"); + var serialNumberOpt = getAsOptionalString(lot, "serialNumber"); if (serialNumberOpt.isPresent()) { var lotId = OdooUtils.search(this.credentials, Field.StockProductionLot.ODOO_MODEL, // new Domain(Field.StockProductionLot.SERIAL_NUMBER, Operator.EQ, serialNumberOpt.get())); @@ -687,9 +696,9 @@ private void createNotFoundSerialNumbers(int setupProtocolId, List setupProtocolItem.put("category", "Seriennummern wurden im System nicht gefunden"); var item = serialNumbers.get(i); - JsonUtils.getAsOptionalString(item, "name") // + getAsOptionalString(item, "name") // .ifPresent(name -> setupProtocolItem.put("name", name)); - JsonUtils.getAsOptionalString(item, "serialNumber") // + getAsOptionalString(item, "serialNumber") // .ifPresent(serialNumber -> setupProtocolItem.put("value", serialNumber)); OdooUtils.create(this.credentials, Field.SetupProtocolItem.ODOO_MODEL, setupProtocolItem); @@ -711,15 +720,15 @@ private void createSetupProtocolItems(int setupProtocolId, JsonArray items) thro setupProtocolItem.put(Field.SetupProtocolItem.SETUP_PROTOCOL.id(), setupProtocolId); setupProtocolItem.put(Field.SetupProtocolItem.SEQUENCE.id(), i); - JsonUtils.getAsOptionalString(item, "category") // + getAsOptionalString(item, "category") // .ifPresent(category -> setupProtocolItem.put("category", category)); - JsonUtils.getAsOptionalString(item, "name") // + getAsOptionalString(item, "name") // .ifPresent(name -> setupProtocolItem.put("name", name)); - JsonUtils.getAsOptionalString(item, "value") // + getAsOptionalString(item, "value") // .ifPresent(value -> setupProtocolItem.put("value", value)); - JsonUtils.getAsOptionalString(item, "view") // + getAsOptionalString(item, "view") // .ifPresent(view -> setupProtocolItem.put("view", view)); - JsonUtils.getAsOptionalString(item, "field") // + getAsOptionalString(item, "field") // .ifPresent(field -> setupProtocolItem.put("field", field)); OdooUtils.create(this.credentials, Field.SetupProtocolItem.ODOO_MODEL, setupProtocolItem); @@ -764,7 +773,7 @@ private int getOdooPartnerId(int odooUserId) throws OpenemsException { * @throws OpenemsNamedException on error */ public void registerUser(JsonObject jsonObject, OdooUserRole role, String oem) throws OpenemsNamedException { - var emailOpt = JsonUtils.getAsOptionalString(jsonObject, "email"); + var emailOpt = getAsOptionalString(jsonObject, "email"); if (!emailOpt.isPresent()) { throw new OpenemsException("No email specified"); } @@ -784,13 +793,13 @@ public void registerUser(JsonObject jsonObject, OdooUserRole role, String oem) t userFields.putAll(this.updateAddress(jsonObject)); userFields.putAll(this.updateCompany(jsonObject)); - JsonUtils.getAsOptionalString(jsonObject, "firstname") // + getAsOptionalString(jsonObject, "firstname") // .ifPresent(firstname -> userFields.put("firstname", firstname)); - JsonUtils.getAsOptionalString(jsonObject, "lastname") // + getAsOptionalString(jsonObject, "lastname") // .ifPresent(lastname -> userFields.put("lastname", lastname)); - JsonUtils.getAsOptionalString(jsonObject, "phone") // + getAsOptionalString(jsonObject, "phone") // .ifPresent(phone -> userFields.put("phone", phone)); - JsonUtils.getAsOptionalString(jsonObject, "password") // + getAsOptionalString(jsonObject, "password") // .ifPresent(password -> userFields.put("password", password)); var createdUserId = OdooUtils.create(this.credentials, Field.User.ODOO_MODEL, userFields); @@ -818,8 +827,8 @@ private void sendRegistrationMail(int odooUserId, String oem) throws OpenemsName private void sendRegistrationMail(int odooUserId, String password, String oem) { try { OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/sendRegistrationEmail", - JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("userId", odooUserId) // .addProperty("password", password) // .addProperty("oem", oem) // @@ -842,8 +851,8 @@ private void sendRegistrationMail(int odooUserId, String password, String oem) { public Future sendNotificationMailAsync(ZonedDateTime sentAt, String template, JsonElement params) throws OpenemsNamedException { return OdooUtils.sendAdminJsonrpcRequestAsync(this.credentials, "/openems_backend/mail/" + template, - JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("sentAt", OdooUtils.DateTime.dateTimeToString(sentAt)) // .add("params", params) // .build()) // @@ -878,14 +887,14 @@ public void updateUserLanguage(MyUser user, Language language) throws OpenemsExc */ public JsonObject getSetupProtocolData(MyUser user, String edgeName) throws OpenemsNamedException { // build request - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edge_name", edgeName) // .build()) // .build(); // call odoo api - return JsonUtils.getAsJsonObject( + return getAsJsonObject( OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/get_latest_setup_protocol", "session_id=" + user.getToken(), request).result); } @@ -909,7 +918,7 @@ public Optional getSerialNumberForEdge(Edge edge) { var serialNumber = serialNumberField.get(Field.EdgeDevice.STOCK_PRODUCTION_LOT_ID.id()); if (serialNumber instanceof Object[] && ((Object[]) serialNumber).length > 1) { - return OdooUtils.getAsOptional(((Object[]) serialNumber)[1], String.class); + return getAsOptional(((Object[]) serialNumber)[1], String.class); } return Optional.empty(); } catch (OpenemsException ex) { @@ -929,15 +938,15 @@ public Optional getSerialNumberForEdge(Edge edge) { * @throws OpenemsNamedException on error */ public JsonObject getIsKeyApplicable(String key, String edgeId, String appId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("key", key) // .addProperty("edgeId", edgeId) // .addPropertyIfNotNull("appId", appId) // .build()) // .build(); - var result = JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + var result = getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/is_key_applicable", request).result); return result; } @@ -955,8 +964,8 @@ public JsonObject getIsKeyApplicable(String key, String edgeId, String appId) th */ public JsonObject getAddInstallAppInstanceHistory(String key, String edgeId, String appId, UUID instanceId, String userId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("key", key) // .addProperty("edgeId", edgeId) // .addProperty("appId", appId) // @@ -965,7 +974,7 @@ public JsonObject getAddInstallAppInstanceHistory(String key, String edgeId, Str .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/add_install_app_instance_history", request).result); } @@ -981,15 +990,15 @@ public JsonObject getAddInstallAppInstanceHistory(String key, String edgeId, Str */ public JsonObject getAddDeinstallAppInstanceHistory(String edgeId, String appId, UUID instanceId, String userId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .addProperty("appId", appId) // .addProperty("instanceId", instanceId.toString()) // .addPropertyIfNotNull("userId", userId) // .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/add_deinstall_app_instance_history", request).result); } @@ -1005,15 +1014,15 @@ public JsonObject getAddDeinstallAppInstanceHistory(String edgeId, String appId, */ public JsonObject getAddRegisterKeyHistory(String edgeId, String appId, String key, MyUser user) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .addProperty("key", key) // .addPropertyIfNotNull("appId", appId) // .addProperty("userId", user.getId()) // .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/add_register_key_history", request).result); } @@ -1030,8 +1039,8 @@ public JsonObject getAddRegisterKeyHistory(String edgeId, String appId, String k */ public JsonObject getAddUnregisterKeyHistory(String edgeId, String appId, String key, MyUser user) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .addProperty("key", key) // .addPropertyIfNotNull("appId", appId) // @@ -1039,7 +1048,7 @@ public JsonObject getAddUnregisterKeyHistory(String edgeId, String appId, String .build()) .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/add_deregister_key_history", request).result); } @@ -1052,13 +1061,13 @@ public JsonObject getAddUnregisterKeyHistory(String edgeId, String appId, String * @throws OpenemsNamedException on error */ public JsonObject getRegisteredKeys(String edgeId, String appId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .addPropertyIfNotNull("appId", appId) // .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/get_registered_key", request).result); } @@ -1071,13 +1080,13 @@ public JsonObject getRegisteredKeys(String edgeId, String appId) throws OpenemsN * @throws OpenemsNamedException on error */ public JsonObject getPossibleApps(String key, String edgeId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .addProperty("key", key) // .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/get_possible_apps", request).result); } @@ -1089,12 +1098,12 @@ public JsonObject getPossibleApps(String key, String edgeId) throws OpenemsNamed * @throws OpenemsNamedException on error */ public JsonObject getInstalledApps(String edgeId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edgeId", edgeId) // .build()) // .build(); - return JsonUtils.getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, + return getAsJsonObject(OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_app_center/get_installed_apps", request).result); } @@ -1114,7 +1123,8 @@ public List getUserAlertingSettings(String edgeId) throws * * @param edgeId ID of Edge * @param userId ID of User - * @return {@link UserAlertingSettings} or {@link null} if no settings are stored + * @return {@link UserAlertingSettings} or {@link null} if no settings are + * stored * @throws OpenemsException on error */ public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { @@ -1140,20 +1150,20 @@ private List requestUserAlertingSettings(String edgeName, // create result list; var result = new ArrayList(alertingSettings.length); for (var setting : alertingSettings) { - var login = OdooUtils.getAs(AlertingSetting.USER_LOGIN, setting, String.class); - var deviceName = OdooUtils.getAs(AlertingSetting.DEVICE_NAME, setting, String.class); + var login = getAs(AlertingSetting.USER_LOGIN, setting, String.class); + var deviceName = getAs(AlertingSetting.DEVICE_NAME, setting, String.class); - var edgeOfflineDelay = OdooUtils.getAs(AlertingSetting.OFFLINE_DELAY, setting, Integer.class); - var edgeOfflineNotification = OdooUtils.getAsOrElse(AlertingSetting.OFFLINE_LAST_NOTIFICATION, setting, + var edgeOfflineDelay = getAs(AlertingSetting.OFFLINE_DELAY, setting, Integer.class); + var edgeOfflineNotification = getAsOrElse(AlertingSetting.OFFLINE_LAST_NOTIFICATION, setting, ZonedDateTime.class, null); - var edgeFaultDelay = OdooUtils.getAs(AlertingSetting.FAULT_DELAY, setting, Integer.class); - var edgeWarningDelay = OdooUtils.getAs(AlertingSetting.WARNING_DELAY, setting, Integer.class); - var sumStateNotification = OdooUtils.getAsOrElse(AlertingSetting.SUM_STATE_LAST_NOTIFICATION, setting, + var edgeFaultDelay = getAs(AlertingSetting.FAULT_DELAY, setting, Integer.class); + var edgeWarningDelay = getAs(AlertingSetting.WARNING_DELAY, setting, Integer.class); + var sumStateNotification = getAsOrElse(AlertingSetting.SUM_STATE_LAST_NOTIFICATION, setting, ZonedDateTime.class, null); - result.add(new UserAlertingSettings(deviceName, login, edgeOfflineDelay, edgeFaultDelay, - edgeWarningDelay, edgeOfflineNotification, sumStateNotification)); + result.add(new UserAlertingSettings(deviceName, login, edgeOfflineDelay, edgeFaultDelay, edgeWarningDelay, + edgeOfflineNotification, sumStateNotification)); } return result; @@ -1168,9 +1178,10 @@ private List requestUserAlertingSettings(String edgeName, * @throws OpenemsException on error */ public List getOfflineAlertingSettings(String edgeName) throws OpenemsException { - final var fields = new Field[] { AlertingSetting.DEVICE_ODOO_ID, AlertingSetting.USER_ODOO_ID, - AlertingSetting.OFFLINE_DELAY, AlertingSetting.OFFLINE_LAST_NOTIFICATION, AlertingSetting.DEVICE_NAME, - AlertingSetting.USER_LOGIN }; + final var fields = new Field[] { // + AlertingSetting.DEVICE_ODOO_ID, AlertingSetting.USER_ODOO_ID, AlertingSetting.OFFLINE_DELAY, // + AlertingSetting.OFFLINE_LAST_NOTIFICATION, AlertingSetting.DEVICE_NAME, AlertingSetting.USER_LOGIN // + }; final var filter = new Domain[] { // new Domain(AlertingSetting.DEVICE_NAME, Operator.EQ_I_LIKE, edgeName) }; @@ -1180,12 +1191,12 @@ public List getOfflineAlertingSettings(String edgeNa var result = new ArrayList(alertingSettings.length); for (var setting : alertingSettings) { - var delay = OdooUtils.getAs(AlertingSetting.OFFLINE_DELAY, setting, Integer.class); - var lastNotification = OdooUtils.getAsOrElse(AlertingSetting.OFFLINE_LAST_NOTIFICATION, setting, - ZonedDateTime.class, null); + var delay = getAs(AlertingSetting.OFFLINE_DELAY, setting, Integer.class); + var lastNotification = getAsOrElse(AlertingSetting.OFFLINE_LAST_NOTIFICATION, setting, ZonedDateTime.class, + null); - var deviceName = OdooUtils.getAs(AlertingSetting.DEVICE_NAME, setting, String.class); - var userLogin = OdooUtils.getAs(AlertingSetting.USER_LOGIN, setting, String.class); + var deviceName = getAs(AlertingSetting.DEVICE_NAME, setting, String.class); + var userLogin = getAs(AlertingSetting.USER_LOGIN, setting, String.class); if (deviceName == null || userLogin == null) { this.log.error( @@ -1219,13 +1230,13 @@ public List getSumStateAlertingSettings(String edgeName var result = new ArrayList(alertingSettings.length); for (var setting : alertingSettings) { - var faultDelay = OdooUtils.getAs(AlertingSetting.FAULT_DELAY, setting, Integer.class); - var warningDelay = OdooUtils.getAs(AlertingSetting.WARNING_DELAY, setting, Integer.class); - var lastNotification = OdooUtils.getAsOrElse(AlertingSetting.SUM_STATE_LAST_NOTIFICATION, setting, + var faultDelay = getAs(AlertingSetting.FAULT_DELAY, setting, Integer.class); + var warningDelay = getAs(AlertingSetting.WARNING_DELAY, setting, Integer.class); + var lastNotification = getAsOrElse(AlertingSetting.SUM_STATE_LAST_NOTIFICATION, setting, ZonedDateTime.class, null); - var deviceName = OdooUtils.getAs(AlertingSetting.DEVICE_NAME, setting, String.class); - var userLogin = OdooUtils.getAs(AlertingSetting.USER_LOGIN, setting, String.class); + var deviceName = getAs(AlertingSetting.DEVICE_NAME, setting, String.class); + var userLogin = getAs(AlertingSetting.USER_LOGIN, setting, String.class); result.add(new SumStateAlertingSetting(deviceName, userLogin, faultDelay, warningDelay, lastNotification)); } @@ -1287,19 +1298,18 @@ public void setUserAlertingSettings(MyUser user, String edgeId, List b.add("searchParams", paginationOptions.getSearchParams().toJson()))// .build()) // .build(); - return JsonUtils - .getAsJsonObject(OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/get_edges", - "session_id=" + user.getToken(), request).result); + return getAsJsonObject(OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/get_edges", + "session_id=" + user.getToken(), request).result); } /** @@ -1311,13 +1321,13 @@ public JsonObject getEdges(MyUser user, PaginationOptions paginationOptions) thr * @throws OpenemsNamedException on error */ public JsonObject getEdgeWithRole(User user, String edgeId) throws OpenemsNamedException { - var request = JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // + var request = buildJsonObject() // + .add("params", buildJsonObject() // .addProperty("edge_id", edgeId) // .build()) // .build(); - return JsonUtils.getAsJsonObject( + return getAsJsonObject( OdooUtils.sendJsonrpcRequest(this.credentials.getUrl() + "/openems_backend/get_edge_with_role", "session_id=" + user.getToken(), request).result); } @@ -1338,11 +1348,11 @@ public Level getSumState(String edgeId) throws OpenemsException { fields, filter); if (edgeLevel.length == 1) { - return OdooUtils.getAsEnum(EdgeDevice.OPENEMS_SUM_STATE, edgeLevel[0], Level.class, Level.OK); + return getAsEnum(EdgeDevice.OPENEMS_SUM_STATE, edgeLevel[0], Level.class, Level.OK); } throw new OpenemsException("Expected 1 Edge as response, got: " + edgeLevel.length); } - + /** * Updates the settings of a user. * @@ -1350,13 +1360,12 @@ public Level getSumState(String edgeId) throws OpenemsException { * @param settings the settings of the user */ public void updateUserSettings(User user, JsonObject settings) throws OpenemsNamedException { - OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/set_user_settings", - JsonUtils.buildJsonObject() // - .add("params", JsonUtils.buildJsonObject() // - .add("settings", settings)// - .addProperty("userId", user.getId()) // - .build()) // - .build()); + OdooUtils.sendAdminJsonrpcRequest(this.credentials, "/openems_backend/set_user_settings", buildJsonObject() // + .add("params", buildJsonObject() // + .add("settings", settings)// + .addProperty("userId", user.getId()) // + .build()) // + .build()); } } diff --git a/io.openems.backend.uiwebsocket/src/io/openems/backend/uiwebsocket/impl/OnRequest.java b/io.openems.backend.uiwebsocket/src/io/openems/backend/uiwebsocket/impl/OnRequest.java index 271fc6933b7..b35e84f4225 100644 --- a/io.openems.backend.uiwebsocket/src/io/openems/backend/uiwebsocket/impl/OnRequest.java +++ b/io.openems.backend.uiwebsocket/src/io/openems/backend/uiwebsocket/impl/OnRequest.java @@ -500,7 +500,9 @@ private CompletableFuture handleGetUserAlertin if (userIsAdmin(user, edgeId)) { var allSettings = this.parent.metadata.getUserAlertingSettings(edgeId); - var userOpt = allSettings.stream().filter(s -> s.userLogin().equals(user.getId())).findAny(); + var userOpt = allSettings.stream() // + .filter(s -> s.userLogin().equals(user.getId())) // + .findAny(); if (userOpt.isPresent()) { allSettings.remove(userOpt.get()); currentUser = userOpt.get();