Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/graphic compare bydate #2988

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk18on -->
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.79</version>
<version>1.80</version>
</dependency>
<dependency>
<!-- Bouncycastle for Eclipse Paho MQTTv5 Client -->
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on -->
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.79</version>
<version>1.80</version>
</dependency>
<dependency>
<groupId>org.dhatim</groupId>
Expand Down Expand Up @@ -403,12 +403,12 @@
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>2.2.7</version>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-log4j2</artifactId>
<version>2.2.7</version>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
Expand All @@ -435,7 +435,7 @@
<!-- Used by io.openems.backend.metadata.odoo -->
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
<version>42.7.5</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb -->
Expand Down
6 changes: 3 additions & 3 deletions io.openems.backend.application/BackendApp.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@
org.apache.felix.webconsole.plugins.ds;version='[2.3.0,2.3.1)',\
org.jetbrains.kotlin.osgi-bundle;version='[2.1.0,2.1.1)',\
org.jsr-305;version='[3.0.2,3.0.3)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.2.7,2.2.8)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.2.7,2.2.8)',\
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
org.ops4j.pax.logging.pax-logging-log4j2;version='[2.2.8,2.2.9)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
org.osgi.service.jdbc;version='[1.1.0,1.1.1)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
org.owasp.encoder;version='[1.3.1,1.3.2)',\
org.postgresql.jdbc;version='[42.7.4,42.7.5)',\
org.postgresql.jdbc;version='[42.7.5,42.7.6)',\
reactive-streams;version='[1.0.4,1.0.5)',\
stax2-api;version='[4.2.2,4.2.3)'
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ private void handleJsonRpc(User user, Request baseRequest, HttpServletRequest ht
}
// parse JSON-RPC Request
var message = JsonrpcMessage.from(json);
if (!(message instanceof JsonrpcRequest)) {
if (!(message instanceof JsonrpcRequest request)) {
throw new OpenemsException("Only JSON-RPC Request is supported here.");
}
var request = (JsonrpcRequest) message;

// handle the request
CompletableFuture<? extends JsonrpcResponseSuccess> responseFuture = this.parent.jsonRpcRequestHandler
.handleRequest(this.parent.getName(), user, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public static String activeStateChannelsToString(
var states = new HashMap<Level, HashMultimap<String, Channel>>();
for (Entry<ChannelAddress, Channel> entry : activeStateChannels.entrySet()) {
var detail = entry.getValue().getDetail();
if (detail instanceof ChannelDetailState) {
var level = ((ChannelDetailState) detail).getLevel();
if (detail instanceof ChannelDetailState cds) {
var level = cds.getLevel();
var channelsByComponent = states.get(level);
if (channelsByComponent == null) {
channelsByComponent = HashMultimap.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,21 @@ private void updateConfig(Config config) {
@Override
public CompletableFuture<? extends JsonrpcResponseSuccess> handleRequest(String context, User user,
JsonrpcRequest request) throws OpenemsNamedException {
switch (request.getMethod()) {

case EdgeRpcRequest.METHOD:
return this.edgeRpcRequestHandler.handleRequest(user, request.getId(), EdgeRpcRequest.from(request));

case GetEdgesStatusRequest.METHOD:
return this.handleGetEdgesStatusRequest(user, request.getId(), GetEdgesStatusRequest.from(request));

case GetEdgesChannelsValuesRequest.METHOD:
return this.handleGetEdgesChannelsValuesRequest(user, request.getId(),
return switch (request.getMethod()) {
case EdgeRpcRequest.METHOD //
-> this.edgeRpcRequestHandler.handleRequest(user, request.getId(), EdgeRpcRequest.from(request));
case GetEdgesStatusRequest.METHOD //
-> this.handleGetEdgesStatusRequest(user, request.getId(), GetEdgesStatusRequest.from(request));
case GetEdgesChannelsValuesRequest.METHOD //
-> this.handleGetEdgesChannelsValuesRequest(user, request.getId(),
GetEdgesChannelsValuesRequest.from(request));

case SetGridConnScheduleRequest.METHOD:
return this.handleSetGridConnScheduleRequest(user, request.getId(),
SetGridConnScheduleRequest.from(request));

default:
case SetGridConnScheduleRequest.METHOD //
-> this.handleSetGridConnScheduleRequest(user, request.getId(), SetGridConnScheduleRequest.from(request));
default -> {
this.logWarn(context, "Unhandled Request: " + request);
throw OpenemsError.JSONRPC_UNHANDLED_METHOD.exception(request.getMethod());
}
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.openems.backend.edgewebsocket;

import static io.openems.common.utils.FunctionUtils.doNothing;

import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -118,14 +120,17 @@ private void handleDataNotification(AbstractDataNotification message, WsData wsD
var edgeId = wsData.assertEdgeId(message);

try {
// TODO java 21 switch case with type
if (message instanceof TimestampedDataNotification timestampNotification) {
switch (message) {
case TimestampedDataNotification timestampNotification -> {
wsData.edgeCache.updateCurrentData(timestampNotification);
this.parent.timedataManager.write(edgeId, timestampNotification);
} else if (message instanceof AggregatedDataNotification aggregatedNotification) {
}
case AggregatedDataNotification aggregatedNotification -> {
wsData.edgeCache.updateAggregatedData(aggregatedNotification);
this.parent.timedataManager.write(edgeId, aggregatedNotification);
}
case ResendDataNotification resendNotification -> doNothing(); // handled in handleResendDataNotification()
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,50 +320,45 @@ public void handleEvent(Event event) {
var reader = new EventReader(event);

switch (event.getTopic()) {
case Edge.Events.ON_SET_ONLINE: {
case Edge.Events.ON_SET_ONLINE -> {
var edgeId = reader.getString(Edge.Events.OnSetOnline.EDGE_ID);
var isOnline = reader.getBoolean(Edge.Events.OnSetOnline.IS_ONLINE);

this.getEdge(edgeId).ifPresent(edge -> {
if (edge instanceof MyEdge) {
if (edge instanceof MyEdge myEdge) {
// Set OpenEMS Is Connected in Odoo/Postgres
this.postgresHandler.getPeriodicWriteWorker().onSetOnline((MyEdge) edge, isOnline);
this.postgresHandler.getPeriodicWriteWorker().onSetOnline(myEdge, isOnline);
}
});
}
break;

case Edge.Events.ON_SET_CONFIG:
this.onSetConfigEvent(reader);
break;
case Edge.Events.ON_SET_CONFIG //
-> this.onSetConfigEvent(reader);

case Edge.Events.ON_SET_VERSION: {
case Edge.Events.ON_SET_VERSION -> {
var edge = (MyEdge) reader.getProperty(Edge.Events.OnSetVersion.EDGE);
var version = (SemanticVersion) reader.getProperty(Edge.Events.OnSetVersion.VERSION);

// Set Version in Odoo
this.odooHandler.writeEdge(edge, new FieldValue<>(Field.EdgeDevice.OPENEMS_VERSION, version.toString()));
}
break;

case Edge.Events.ON_SET_LASTMESSAGE: {
case Edge.Events.ON_SET_LASTMESSAGE -> {
var edge = (MyEdge) reader.getProperty(Edge.Events.OnSetLastmessage.EDGE);
// Set LastMessage timestamp in Odoo/Postgres
this.postgresHandler.getPeriodicWriteWorker().onLastMessage(edge);
}
break;

case Edge.Events.ON_SET_SUM_STATE: {
case Edge.Events.ON_SET_SUM_STATE -> {
var edgeId = reader.getString(Edge.Events.OnSetSumState.EDGE_ID);
var sumState = (Level) reader.getProperty(Edge.Events.OnSetSumState.SUM_STATE);

var edge = this.edgeCache.getEdgeFromEdgeId(edgeId);
// Set Sum-State in Odoo/Postgres
this.postgresHandler.getPeriodicWriteWorker().onSetSumState(edge, sumState);
}
break;

case Edge.Events.ON_SET_PRODUCTTYPE: {
case Edge.Events.ON_SET_PRODUCTTYPE -> {
var edge = (MyEdge) reader.getProperty(Edge.Events.OnSetProducttype.EDGE);
var producttype = reader.getString(Edge.Events.OnSetProducttype.PRODUCTTYPE);
// Set Producttype in Odoo/Postgres
Expand All @@ -376,8 +371,6 @@ public void handleEvent(Event event) {
}
});
}
break;

}
}

Expand Down Expand Up @@ -568,10 +561,11 @@ public List<SumStateAlertingSetting> getSumStateAlertingSettings(String edgeId)
@Override
public void setUserAlertingSettings(User user, String edgeId, List<UserAlertingSettings> settings)
throws OpenemsException {
if (user instanceof MyUser odooUser) {
this.odooHandler.setUserAlertingSettings(odooUser, edgeId, settings);
} else {
throw new OpenemsException("User information is from foreign source!!");
switch (user) {
case MyUser odooUser //
-> this.odooHandler.setUserAlertingSettings(odooUser, edgeId, settings);
default //
-> throw new OpenemsException("User information is from foreign source!!");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.openems.backend.metadata.odoo.odoo;

import static io.openems.common.utils.StringUtils.toShortString;

import com.google.gson.JsonElement;

import io.openems.backend.metadata.odoo.Field;
import io.openems.common.utils.StringUtils;

public class FieldValue<T> {
private final Field field;
Expand All @@ -24,14 +25,14 @@ public T getValue() {

@Override
public String toString() {
String string;
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();
}
var string = switch (this.value) {
case JsonElement je //
-> toShortString(je, 100);
case String s //
-> toShortString(s, 100);
default //
-> this.value.toString();
};
string = string.replace("\n", "");
return this.field.id() + ":" + string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ public Optional<String> getSerialNumberForEdge(Edge edge) {
Field.EdgeDevice.STOCK_PRODUCTION_LOT_ID);

var serialNumber = serialNumberField.get(Field.EdgeDevice.STOCK_PRODUCTION_LOT_ID.id());
if (serialNumber instanceof Object[] && ((Object[]) serialNumber).length > 1) {
return getAsOptional(((Object[]) serialNumber)[1], String.class);
if (serialNumber instanceof Object[] sns && sns.length > 1) {
return getAsOptional(sns[1], String.class);
}
return Optional.empty();
} catch (OpenemsException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ protected static <T extends Object> Optional<T> getAsOptional(Object object, Cla
* @return the odoo reference id or empty {@link Optional}
*/
protected static Optional<Integer> getOdooReferenceId(Object object) {
if (object instanceof Object[] odooReference) {
if (odooReference.length > 0 && odooReference[0] instanceof Integer) {
return Optional.of((Integer) odooReference[0]);
}
if (object instanceof Object[] odooReference //
&& odooReference.length > 0 //
&& odooReference[0] instanceof Integer i) {
return Optional.of(i);
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see <a href="https://www.jsonrpc.org/specification">JSON-RPC
* specification</a>
*/
public abstract class AbstractJsonrpcRequest extends JsonrpcMessage {
public abstract sealed class AbstractJsonrpcRequest extends JsonrpcMessage permits JsonrpcRequest, JsonrpcNotification {

private final String method;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @see <a href="https://www.jsonrpc.org/specification">JSON-RPC
* specification</a>
*/
public abstract class JsonrpcMessage {
public abstract sealed class JsonrpcMessage permits AbstractJsonrpcRequest, JsonrpcResponse {

public static final String JSONRPC_VERSION = "2.0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @see <a href="https://www.jsonrpc.org/specification#notification">JSON-RPC
* specification</a>
*/
public abstract class JsonrpcNotification extends AbstractJsonrpcRequest {
public abstract non-sealed class JsonrpcNotification extends AbstractJsonrpcRequest {

public JsonrpcNotification(String method) {
super(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @see <a href="https://www.jsonrpc.org/specification#request_object">JSON-RPC
* specification</a>
*/
public abstract class JsonrpcRequest extends AbstractJsonrpcRequest {
public abstract non-sealed class JsonrpcRequest extends AbstractJsonrpcRequest {

public static final int DEFAULT_TIMEOUT_SECONDS = 60;
public static final int NO_TIMEOUT = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @see <a href="https://www.jsonrpc.org/specification#response_object">JSON-RPC
* specification</a>
*/
public abstract class JsonrpcResponse extends JsonrpcMessage {
public abstract non-sealed class JsonrpcResponse extends JsonrpcMessage {

/**
* Parses a JSON String to a {@link JsonrpcResponse}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public abstract class JsonrpcResponseSuccess extends JsonrpcResponse {
* @throws OpenemsNamedException if it was not a Success Response
*/
public static JsonrpcResponseSuccess from(JsonObject j) throws OpenemsNamedException {
var response = JsonrpcResponse.from(j);
if (!(response instanceof JsonrpcResponseSuccess)) {
throw OpenemsError.GENERIC.exception("Expected a JSON-RPC Success Response");
}
return (JsonrpcResponseSuccess) response;
return switch (JsonrpcResponse.from(j)) {
case JsonrpcResponseSuccess r -> r;
default -> throw OpenemsError.GENERIC.exception("Expected a JSON-RPC Success Response");
};
}

public JsonrpcResponseSuccess(UUID id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* }
* </pre>
*/
// TODO change to sealed class
public abstract class AbstractDataNotification extends JsonrpcNotification {
public abstract sealed class AbstractDataNotification extends JsonrpcNotification
permits TimestampedDataNotification, AggregatedDataNotification, ResendDataNotification {

private final TreeBasedTable<Long, String, JsonElement> data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* }
* </pre>
*/
public class AggregatedDataNotification extends AbstractDataNotification {
public final class AggregatedDataNotification extends AbstractDataNotification {

public static final String METHOD = "aggregatedData";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* }
* </pre>
*/
public class ResendDataNotification extends AbstractDataNotification {
public final class ResendDataNotification extends AbstractDataNotification {

public static final String METHOD = "resendData";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* }
* </pre>
*/
public class TimestampedDataNotification extends AbstractDataNotification {
public final class TimestampedDataNotification extends AbstractDataNotification {

public static final String METHOD = "timestampedData";

Expand Down
Loading