From 0bf6e3ef4db7b297160e4835ce6e61f5f902aa97 Mon Sep 17 00:00:00 2001 From: Kai J Date: Thu, 20 Jul 2023 15:40:52 +0200 Subject: [PATCH] format + checkstyle; --- .../handler/TestOfflineEdgeHandler.java | 11 +++++----- .../backend/common/metadata/Metadata.java | 20 +++++++++---------- .../backend/common/test/DummyMetadata.java | 10 +++++----- .../backend/metadata/dummy/MetadataDummy.java | 10 +++++----- .../backend/metadata/file/MetadataFile.java | 10 +++++----- .../openems/backend/metadata/odoo/Field.java | 19 +++++++++++++++++- .../backend/metadata/odoo/MetadataOdoo.java | 10 +++++----- .../metadata/odoo/odoo/OdooHandler.java | 14 +++++++++++++ .../backend/metadata/odoo/odoo/OdooUtils.java | 2 +- .../io/openems/common/utils/JsonUtils.java | 13 ------------ 10 files changed, 69 insertions(+), 50 deletions(-) diff --git a/io.openems.backend.alerting/test/io/openems/backend/alerting/handler/TestOfflineEdgeHandler.java b/io.openems.backend.alerting/test/io/openems/backend/alerting/handler/TestOfflineEdgeHandler.java index 4750a4354dd..d5c3ea15a3b 100644 --- a/io.openems.backend.alerting/test/io/openems/backend/alerting/handler/TestOfflineEdgeHandler.java +++ b/io.openems.backend.alerting/test/io/openems/backend/alerting/handler/TestOfflineEdgeHandler.java @@ -15,14 +15,16 @@ import org.junit.Test; +import io.openems.backend.alerting.Dummy.MailerImpl; +import io.openems.backend.alerting.Dummy.MessageSchedulerServiceImpl; +import io.openems.backend.alerting.Dummy.OfflineEdgeMetadataImpl; +import io.openems.backend.alerting.Dummy.SimpleMetadataImpl; import io.openems.backend.alerting.message.OfflineEdgeMessage; import io.openems.backend.common.alerting.OfflineEdgeAlertingSetting; import io.openems.backend.common.metadata.Edge; import io.openems.backend.common.metadata.Metadata; import io.openems.backend.common.test.DummyMetadata; -import static io.openems.backend.alerting.Dummy.*; - public class TestOfflineEdgeHandler { @Test @@ -153,7 +155,7 @@ public void getEventHandlerTest() { assertNull(noHandler); } - private static abstract class Utility { + private static class Utility { private static final ZonedDateTime now = ZonedDateTime.now(); @@ -167,10 +169,9 @@ private static OfflineEdgeMetadataImpl getTestMetadata() { Utility.getTestEdge(metadata, "4", Utility.now, false), Utility.getTestEdge(metadata, "5", Utility.now.minusMonths(1), false), // Utility.getTestEdge(metadata, "6", null, false)); // - final Map> settings = Map.of(// - "1", List.of( // + "1", List.of(// new OfflineEdgeAlertingSetting(1, 1, 1, Utility.now.minusDays(1))), // "2", List.of(), // "3", List.of(// diff --git a/io.openems.backend.common/src/io/openems/backend/common/metadata/Metadata.java b/io.openems.backend.common/src/io/openems/backend/common/metadata/Metadata.java index 28b55fe7dcf..e7441ea3fda 100644 --- a/io.openems.backend.common/src/io/openems/backend/common/metadata/Metadata.java +++ b/io.openems.backend.common/src/io/openems/backend/common/metadata/Metadata.java @@ -293,6 +293,16 @@ public static String activeStateChannelsToString( */ public void updateUserLanguage(User user, Language language) throws OpenemsNamedException; + /** + * Gets the alerting settings for given edge id and userId. + * + * @param edgeId the Edge ID + * @param userId the User ID + * @return List of {@link UserAlertingSettings} + * @throws OpenemsException on error + */ + public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException; + /** * Gets all the alerting settings for given edge id. * @@ -323,16 +333,6 @@ public static String activeStateChannelsToString( */ public List getSumStateAlertingSettings(String edgeId) throws OpenemsException; - /** - * Gets the alerting settings for given edge id and userId. - * - * @param edgeId the Edge ID - * @param userId the User ID - * @return List of {@link UserAlertingSettings} - * @throws OpenemsException on error - */ - public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException; - /** * Sets the alerting settings for the given list of users. * 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 87ccd1a5bb4..e2302fd793e 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 @@ -41,22 +41,22 @@ public Collection getAllOfflineEdges() { } @Override - public List getUserAlertingSettings(String edgeId) { + public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { throw new UnsupportedOperationException("Unsupported by Dummy Class"); } - + @Override - public List getEdgeOfflineAlertingSettings(String edgeId) throws OpenemsException { + public List getUserAlertingSettings(String edgeId) { throw new UnsupportedOperationException("Unsupported by Dummy Class"); } @Override - public List getSumStateAlertingSettings(String edgeId) throws OpenemsException { + public List getEdgeOfflineAlertingSettings(String edgeId) throws OpenemsException { throw new UnsupportedOperationException("Unsupported by Dummy Class"); } @Override - public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { + public List getSumStateAlertingSettings(String edgeId) throws OpenemsException { throw new UnsupportedOperationException("Unsupported by Dummy Class"); } diff --git a/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java b/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java index 1038426d9d2..6249ff0babb 100644 --- a/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java +++ b/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java @@ -252,6 +252,11 @@ public EdgeHandler edge() { public Optional getSerialNumberForEdge(Edge edge) { throw new UnsupportedOperationException("DummyMetadata.getSerialNumberForEdge() is not implemented"); } + + @Override + public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { + throw new UnsupportedOperationException("DummyMetadata.getUserAlertingSettings() is not implemented"); + } @Override public List getUserAlertingSettings(String edgeId) { @@ -268,11 +273,6 @@ public List getSumStateAlertingSettings(String edgeId) throw new UnsupportedOperationException("DummyMetadata.getSumStateAlertingSettings() is not implemented"); } - @Override - public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { - throw new UnsupportedOperationException("DummyMetadata.getUserAlertingSettings() is not implemented"); - } - @Override public void setUserAlertingSettings(User user, String edgeId, List settings) { throw new UnsupportedOperationException("DummyMetadata.setUserAlertingSettings() is not implemented"); diff --git a/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java b/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java index 18fe06e9b1c..123beaecdab 100644 --- a/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java +++ b/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java @@ -296,6 +296,11 @@ public Optional getSerialNumberForEdge(Edge edge) { throw new UnsupportedOperationException("FileMetadata.getSerialNumberForEdge() is not implemented"); } + @Override + public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { + throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented"); + } + @Override public List getUserAlertingSettings(String edgeId) { throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented"); @@ -311,11 +316,6 @@ public List getSumStateAlertingSettings(String edgeId) throw new UnsupportedOperationException("FileMetadata.getSumStateAlertingSettings() is not implemented"); } - @Override - public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { - throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented"); - } - @Override public void setUserAlertingSettings(User user, String edgeId, List users) { throw new UnsupportedOperationException("FileMetadata.setUserAlertingSettings() is not implemented"); 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 5892bf1b297..4de6ed3603c 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 @@ -33,7 +33,7 @@ public interface Field { */ public boolean isQuery(); - private static > Stream getSqlQueryFieldsOf(Class field){ + private static > Stream getSqlQueryFieldsOf(Class field) { return Stream.of(field.getEnumConstants()).map(v -> { if (v instanceof Field f) { return f; @@ -56,10 +56,27 @@ public static String getSqlQueryFields(Field[] fields) { .collect(Collectors.joining(",")); } + /** + * Gets all fields that should be queried as a list of {@link Field} for given + * enum class. + * + * @param enum implementing field + * @param field class of enum + * @return list of fields + */ public static > Field[] getSqlQueryFields(Class field) { return Field.getSqlQueryFieldsOf(field).toArray(Field[]::new); } + /** + * Gets all fields that should be queried as a list of {@link Field} for given + * enum class extended with given foreign fields. + * + * @param enum implementing field + * @param field class of enum + * @param foreign additional fields + * @return list of fields + */ public static > Field[] getSqlQueryFields(Class field, Field... foreign) { var querryStream = Field.getSqlQueryFieldsOf(field); var foreignStream = Stream.of(foreign); 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 4506996acd0..e8f455f5721 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 @@ -406,6 +406,11 @@ public void sendMail(ZonedDateTime sendAt, String template, JsonElement params) } } + @Override + public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { + return this.odooHandler.getUserAlertingSettings(edgeId, userId); + } + @Override public List getUserAlertingSettings(String edgeId) throws OpenemsException { return this.odooHandler.getUserAlertingSettings(edgeId); @@ -421,11 +426,6 @@ public List getSumStateAlertingSettings(String edgeId) return this.odooHandler.getSumStateAlertingSettings(edgeId); } - @Override - public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException { - return this.odooHandler.getUserAlertingSettings(edgeId, userId); - } - @Override public void setUserAlertingSettings(User user, String edgeId, List settings) throws OpenemsException { this.odooHandler.setUserAlertingSettings((MyUser) user, edgeId, 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 617f33b9baa..fb76b83fd32 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 @@ -998,6 +998,13 @@ private List requestUserAlertingSettings(String edgeName, return result; } + /** + * Get all offline-alerting specific settings for edge. + * + * @param edgeName unique name of Edge + * @return List of {@link OfflineEdgeAlertingSetting} or {@link null} if no settings are stored + * @throws OpenemsException on error + */ public List getOfflineAlertingSettings(String edgeName) throws OpenemsException { final var edgeNameField = new GenericField(AlertingSetting.DEVICE_ODOO_ID, EdgeDevice.NAME); @@ -1029,6 +1036,13 @@ public List getOfflineAlertingSettings(String edgeNa return result; } + /** + * Get all sum-state-alerting specific settings for edge. + * + * @param edgeName unique name of Edge + * @return List of {@link SumStateAlertingSetting} or {@link null} if no settings are stored + * @throws OpenemsException on error + */ public List getSumStateAlertingSettings(String edgeName) throws OpenemsException { final var edgeNameField = new GenericField(AlertingSetting.DEVICE_ODOO_ID, EdgeDevice.NAME); 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 08d6fa60dad..af565534d75 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 @@ -658,7 +658,7 @@ public static T getAsOrElse(Field field, Map values, Class typ } try { - if(type.equals(ZonedDateTime.class)) { + if (type.equals(ZonedDateTime.class)) { return type.cast(OdooUtils.DateTime.stringToDateTime(entry.toString())); } return type.cast(entry); diff --git a/io.openems.common/src/io/openems/common/utils/JsonUtils.java b/io.openems.common/src/io/openems/common/utils/JsonUtils.java index 6807ed4579f..ea3d447c476 100644 --- a/io.openems.common/src/io/openems/common/utils/JsonUtils.java +++ b/io.openems.common/src/io/openems/common/utils/JsonUtils.java @@ -521,19 +521,6 @@ public static JsonPrimitive getAsPrimitive(JsonElement jElement, String memberNa throw OpenemsError.JSON_NO_PRIMITIVE_MEMBER.exception(memberName, jElement.toString().replace("%", "%%")); } - /** - * Gets the member of the {@link JsonElement} as {@link Optional} - * {@link JsonPrimitive}. - * - * @param jElement the {@link JsonElement} - * @param memberName the name of the member - * @return the {@link Optional} {@link JsonPrimitive} value - * @throws OpenemsNamedException on error - */ - public static Optional getAsOptionalPrimitive(JsonElement jElement, String memberName) { - return Optional.ofNullable(toPrimitive(toSubElement(jElement, memberName))); - } - /** * Gets the member of the {@link JsonElement} as {@link JsonElement}. *