Skip to content

Commit

Permalink
format + checkstyle;
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai J committed Jul 20, 2023
1 parent a21cc74 commit 0bf6e3e
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand All @@ -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<String, List<OfflineEdgeAlertingSetting>> settings = Map.of(//
"1", List.of( //
"1", List.of(//
new OfflineEdgeAlertingSetting(1, 1, 1, Utility.now.minusDays(1))), //
"2", List.of(), //
"3", List.of(//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -323,16 +333,6 @@ public static String activeStateChannelsToString(
*/
public List<SumStateAlertingSetting> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ public Collection<Edge> getAllOfflineEdges() {
}

@Override
public List<UserAlertingSettings> getUserAlertingSettings(String edgeId) {
public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

@Override
public List<OfflineEdgeAlertingSetting> getEdgeOfflineAlertingSettings(String edgeId) throws OpenemsException {
public List<UserAlertingSettings> getUserAlertingSettings(String edgeId) {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

@Override
public List<SumStateAlertingSetting> getSumStateAlertingSettings(String edgeId) throws OpenemsException {
public List<OfflineEdgeAlertingSetting> getEdgeOfflineAlertingSettings(String edgeId) throws OpenemsException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

@Override
public UserAlertingSettings getUserAlertingSettings(String edgeId, String userId) throws OpenemsException {
public List<SumStateAlertingSetting> getSumStateAlertingSettings(String edgeId) throws OpenemsException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public EdgeHandler edge() {
public Optional<String> 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<UserAlertingSettings> getUserAlertingSettings(String edgeId) {
Expand All @@ -268,11 +273,6 @@ public List<SumStateAlertingSetting> 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<UserAlertingSettings> settings) {
throw new UnsupportedOperationException("DummyMetadata.setUserAlertingSettings() is not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public Optional<String> 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<UserAlertingSettings> getUserAlertingSettings(String edgeId) {
throw new UnsupportedOperationException("FileMetadata.getUserAlertingSettings() is not implemented");
Expand All @@ -311,11 +316,6 @@ public List<SumStateAlertingSetting> 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<UserAlertingSettings> users) {
throw new UnsupportedOperationException("FileMetadata.setUserAlertingSettings() is not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface Field {
*/
public boolean isQuery();

private static <T extends Enum<? extends Field>> Stream<Field> getSqlQueryFieldsOf(Class<T> field){
private static <T extends Enum<? extends Field>> Stream<Field> getSqlQueryFieldsOf(Class<T> field) {
return Stream.of(field.getEnumConstants()).map(v -> {
if (v instanceof Field f) {
return f;
Expand All @@ -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 <T> enum implementing field
* @param field class of enum
* @return list of fields
*/
public static <T extends Enum<? extends Field>> Field[] getSqlQueryFields(Class<T> 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 <T> enum implementing field
* @param field class of enum
* @param foreign additional fields
* @return list of fields
*/
public static <T extends Enum<? extends Field>> Field[] getSqlQueryFields(Class<T> field, Field... foreign) {
var querryStream = Field.getSqlQueryFieldsOf(field);
var foreignStream = Stream.of(foreign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserAlertingSettings> getUserAlertingSettings(String edgeId) throws OpenemsException {
return this.odooHandler.getUserAlertingSettings(edgeId);
Expand All @@ -421,11 +426,6 @@ public List<SumStateAlertingSetting> 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<UserAlertingSettings> settings) throws OpenemsException {
this.odooHandler.setUserAlertingSettings((MyUser) user, edgeId, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,13 @@ private List<UserAlertingSettings> 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<OfflineEdgeAlertingSetting> getOfflineAlertingSettings(String edgeName) throws OpenemsException {
final var edgeNameField = new GenericField(AlertingSetting.DEVICE_ODOO_ID, EdgeDevice.NAME);

Expand Down Expand Up @@ -1029,6 +1036,13 @@ public List<OfflineEdgeAlertingSetting> 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<SumStateAlertingSetting> getSumStateAlertingSettings(String edgeName) throws OpenemsException {
final var edgeNameField = new GenericField(AlertingSetting.DEVICE_ODOO_ID, EdgeDevice.NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public static <T> T getAsOrElse(Field field, Map<String, ?> values, Class<T> typ
}

try {
if(type.equals(ZonedDateTime.class)) {
if (type.equals(ZonedDateTime.class)) {
return type.cast(OdooUtils.DateTime.stringToDateTime(entry.toString()));
}
return type.cast(entry);
Expand Down
13 changes: 0 additions & 13 deletions io.openems.common/src/io/openems/common/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonPrimitive> getAsOptionalPrimitive(JsonElement jElement, String memberName) {
return Optional.ofNullable(toPrimitive(toSubElement(jElement, memberName)));
}

/**
* Gets the member of the {@link JsonElement} as {@link JsonElement}.
*
Expand Down

0 comments on commit 0bf6e3e

Please sign in to comment.