Skip to content

Commit 4fdbb8f

Browse files
sfeilmeiersebastianasenmichaelgrillvenu-sagarlukasrgr
authored
FEMS Backports 2023-06 (#2664)
- Hardy Barth: correct Phase URL mapping - Wrong mapping of Phase 3 current - BridgeHttp: added support for http code & message - added support for http code & message - changed DelayTimeProvider to also be able to handle errors and success responses - improved testing - added common class HttpStatus with all official Http status codes as constants - added lazy endpoint construction to define unique params for each call - UI: Added metric field in 'Network configuration' - UI: fix tab title - setting web-app tab title to ```environment.edgeShortName``` - Backend: Remove edges from authenticate -Removed Edges from Authenticate response - UI: Split user and company related information - Splitting user and company related data, only user data is editable, non company assigned users are still seeing the same and are able to change all userInformation - EdgeConfig: remove Channels - Normal EdgeConfig does not contain Channels anymore - Added separate Requests to get channels for: - [x] Component Status View - [x] Component Channels View - [x] Subscribe only needed Channels in Soltaro ServiceAssistent - [x] Get Channel Units for variable channel for singlethreshold history & live - [x] Get DigitalInputChannels with separate request and fixed subscription - Time-of-Use Tariff Stadtwerk Haßfurt implementation - Time-of-Use Tariff Groupe-E implementation - Added new provider Groupe-E. - Added new currency CHF (Swiss francs) to the list of currencies in core meta. - Moved the exchangerate API to Utils so it is common for both ENTSO-E and Groupe-E providers. - UI: set secure=https property in Cookie -This fixes an issue where a token value could be exposed when redirecting from http to https - Update EdgeApp.bndrun --------- Co-authored-by: Sebastian Asen <[email protected]> Co-authored-by: Michael Grill <[email protected]> Co-authored-by: Sagar Venu <[email protected]> Co-authored-by: Lukas Rieger <[email protected]> Co-authored-by: Katsuya Oda <[email protected]> Co-authored-by: Hiromasa Ihara <[email protected]>
1 parent a946ba0 commit 4fdbb8f

File tree

126 files changed

+5576
-1084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+5576
-1084
lines changed

io.openems.backend.common/src/io/openems/backend/common/metadata/User.java

-36
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package io.openems.backend.common.metadata;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
import java.util.Map.Entry;
63
import java.util.NavigableMap;
74
import java.util.TreeMap;
85

96
import com.google.gson.JsonObject;
107

11-
import io.openems.common.channel.Level;
128
import io.openems.common.exceptions.OpenemsError;
139
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
14-
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
1510
import io.openems.common.session.AbstractUser;
1611
import io.openems.common.session.Language;
1712
import io.openems.common.session.Role;
@@ -74,37 +69,6 @@ public Role assertEdgeRoleIsAtLeast(String resource, String edgeId, Role role) t
7469
return thisRole;
7570
}
7671

77-
/**
78-
* Gets the Metadata information of the accessible Edges.
79-
*
80-
* @param user the {@link User}
81-
* @param metadataService a {@link Metadata} provider
82-
* @return a list of {@link EdgeMetadata}
83-
*/
84-
public static List<EdgeMetadata> generateEdgeMetadatas(User user, Metadata metadataService) {
85-
List<EdgeMetadata> metadatas = new ArrayList<>();
86-
for (Entry<String, Role> edgeRole : user.getEdgeRoles().entrySet()) {
87-
var edgeId = edgeRole.getKey();
88-
var role = edgeRole.getValue();
89-
var edgeOpt = metadataService.getEdge(edgeId);
90-
if (edgeOpt.isPresent()) {
91-
var edge = edgeOpt.get();
92-
metadatas.add(new EdgeMetadata(//
93-
edge.getId(), // Edge-ID
94-
edge.getComment(), // Comment
95-
edge.getProducttype(), // Product-Type
96-
edge.getVersion(), // Version
97-
role, // Role
98-
edge.isOnline(), // Online-State
99-
edge.getLastmessage(), // Last-Message Timestamp
100-
null, //
101-
Level.OK //
102-
));
103-
}
104-
}
105-
return metadatas;
106-
}
107-
10872
@Override
10973
public boolean hasMultipleEdges() {
11074
return this.hasMultipleEdges;

io.openems.backend.metadata.odoo/src/io/openems/backend/metadata/odoo/MetadataOdoo.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.HashMap;
1010
import java.util.List;
1111
import java.util.Map;
12-
import java.util.NavigableMap;
1312
import java.util.Optional;
1413
import java.util.TreeMap;
1514
import java.util.UUID;
@@ -176,16 +175,8 @@ public User authenticate(String sessionId) throws OpenemsNamedException {
176175
.flatMap(JsonUtils::getAsOptionalJsonObject) //
177176
.orElse(new JsonObject());
178177

179-
var jDevices = JsonUtils.getAsJsonArray(result, "devices");
180-
NavigableMap<String, Role> roles = new TreeMap<>();
181-
for (JsonElement device : jDevices) {
182-
var edgeId = JsonUtils.getAsString(device, "name");
183-
var role = Role.getRole(JsonUtils.getAsString(device, "role"));
184-
roles.put(edgeId, role);
185-
}
186-
187-
var user = new MyUser(odooUserId, login, name, sessionId, language, globalRole, roles, hasMultipleEdges,
188-
settings);
178+
var user = new MyUser(odooUserId, login, name, sessionId, language, globalRole, new TreeMap<>(),
179+
hasMultipleEdges, settings);
189180
var oldUser = this.users.put(login, user);
190181
if (oldUser != null) {
191182
oldUser.getEdgeRoles().forEach((edgeId, role) -> {

io.openems.backend.uiwebsocket/src/io/openems/backend/uiwebsocket/impl/OnRequest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ private CompletableFuture<JsonrpcResponseSuccess> handleAuthentication(WsData ws
170170
throws OpenemsNamedException {
171171
wsData.setUserId(user.getId());
172172
wsData.setToken(user.getToken());
173-
return CompletableFuture.completedFuture(new AuthenticateResponse(requestId, user.getToken(), user,
174-
User.generateEdgeMetadatas(user, this.parent.metadata), user.getLanguage()));
173+
return CompletableFuture
174+
.completedFuture(new AuthenticateResponse(requestId, user.getToken(), user, user.getLanguage()));
175175
}
176176

177177
/**
@@ -225,9 +225,8 @@ private CompletableFuture<EdgeRpcResponse> handleEdgeRpcRequest(WsData wsData, U
225225
this.handleSubscribeChannelsRequest(wsData, edgeId, user, SubscribeChannelsRequest.from(request));
226226
case SubscribeSystemLogRequest.METHOD ->
227227
this.handleSubscribeSystemLogRequest(wsData, edgeId, user, SubscribeSystemLogRequest.from(request));
228-
case SimulationRequest.METHOD ->
229-
this.handleSimulationRequest(edgeId, user, SimulationRequest.from(request));
230-
228+
case SimulationRequest.METHOD -> this.handleSimulationRequest(edgeId, user, SimulationRequest.from(request));
229+
231230
case ComponentJsonApiRequest.METHOD -> {
232231
final var componentRequest = ComponentJsonApiRequest.from(request);
233232
if (!"_host".equals(componentRequest.getComponentId())) {
@@ -287,19 +286,20 @@ private CompletableFuture<EdgeRpcResponse> handleEdgeRpcRequest(WsData wsData, U
287286
/**
288287
* Handles a {@link GetSimulationRequest}.
289288
*
290-
* @param edgeId the Edge-ID
291-
* @param user the {@link User} - no specific level required
289+
* @param edgeId the Edge-ID
290+
* @param user the {@link User} - no specific level required
292291
* @param request the {@link GetSimulationRequest}
293292
* @return the JSON-RPC Success Response Future
294293
* @throws OpenemsNamedException on error
295294
*/
296-
private CompletableFuture<JsonrpcResponseSuccess> handleSimulationRequest(String edgeId, User user, SimulationRequest request) throws OpenemsNamedException {
297-
295+
private CompletableFuture<JsonrpcResponseSuccess> handleSimulationRequest(String edgeId, User user,
296+
SimulationRequest request) throws OpenemsNamedException {
297+
298298
final var simulation = this.parent.simulation;
299299
if (simulation == null) {
300300
throw new OpenemsException("simulation unavailable");
301301
}
302-
302+
303303
return simulation.handleRequest(edgeId, user, request);
304304
}
305305

io.openems.common/src/io/openems/common/jsonrpc/response/AuthenticateResponse.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package io.openems.common.jsonrpc.response;
22

3-
import java.util.Collections;
4-
import java.util.List;
53
import java.util.UUID;
64

5+
import com.google.gson.JsonArray;
76
import com.google.gson.JsonObject;
87

98
import io.openems.common.jsonrpc.base.JsonrpcResponseSuccess;
109
import io.openems.common.jsonrpc.request.AuthenticateWithPasswordRequest;
1110
import io.openems.common.jsonrpc.request.AuthenticateWithTokenRequest;
12-
import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata;
1311
import io.openems.common.session.AbstractUser;
1412
import io.openems.common.session.Language;
1513
import io.openems.common.utils.JsonUtils;
@@ -33,19 +31,12 @@ public class AuthenticateResponse extends JsonrpcResponseSuccess {
3331

3432
private final String token;
3533
private final AbstractUser user;
36-
private final List<EdgeMetadata> edges;
3734
private final Language language;
3835

3936
public AuthenticateResponse(UUID id, String token, AbstractUser user, Language language) {
40-
this(id, token, user, Collections.emptyList(), language);
41-
}
42-
43-
// TODO: remove after UI is updated to new version
44-
public AuthenticateResponse(UUID id, String token, AbstractUser user, List<EdgeMetadata> edges, Language language) {
4537
super(id);
4638
this.token = token;
4739
this.user = user;
48-
this.edges = edges;
4940
this.language = language;
5041
}
5142

@@ -65,7 +56,8 @@ public JsonObject getResult() {
6556
.add("settings", this.user.getSettings()) //
6657
.add("globalRole", this.user.getGlobalRole().asJson()) //
6758
.build()) //
68-
.add("edges", EdgeMetadata.toJson(this.edges)) //
59+
// still kept to avoid NPE in UI for older versions
60+
.add("edges", new JsonArray()) //
6961
.build();
7062
}
7163

io.openems.common/src/io/openems/common/jsonrpc/serialization/JsonObjectPath.java

+17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ public default StringPath getStringPath(String member) {
2727
return this.getJsonElementPath(member).getAsStringPath();
2828
}
2929

30+
/**
31+
* Gets the enum value of the element associated with the member name of this
32+
* object.
33+
*
34+
* @param <T> the type of the enum
35+
* @param member the name of the member
36+
* @param enumClass the class of the enum
37+
* @return the enum value
38+
*/
39+
public default <T extends Enum<T>> T getEnum(String member, Class<T> enumClass) {
40+
try {
41+
return Enum.valueOf(enumClass, this.getString(member));
42+
} catch (Exception e) {
43+
return enumClass.getEnumConstants()[0];
44+
}
45+
}
46+
3047
/**
3148
* Gets the element associated with the member name from this object as a
3249
* {@link String}.

io.openems.common/src/io/openems/common/jsonrpc/serialization/JsonSerializer.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.openems.common.jsonrpc.serialization;
22

3+
import static io.openems.common.jsonrpc.serialization.JsonSerializerUtil.jsonSerializer;
4+
import static io.openems.common.utils.JsonUtils.toJsonArray;
5+
6+
import java.util.List;
7+
38
import com.google.gson.JsonElement;
49

510
public interface JsonSerializer<T> {
@@ -38,4 +43,18 @@ public default T deserialize(JsonElement json) {
3843
return this.deserializePath(new JsonElementPathActual(json));
3944
}
4045

46+
/**
47+
* Creates a new {@link JsonSerializer} which is able to serialize {@link List
48+
* Lists} with their generic type of the current {@link JsonSerializer}.
49+
*
50+
* @return the new {@link JsonSerializer} of a {@link List}
51+
*/
52+
public default JsonSerializer<List<T>> toListSerializer() {
53+
return jsonSerializer(//
54+
json -> json.getAsJsonArrayPath().getAsList(this), //
55+
obj -> obj.stream() //
56+
.map(this::serialize) //
57+
.collect(toJsonArray()));
58+
}
59+
4160
}

io.openems.common/src/io/openems/common/oem/DummyOpenemsEdgeOem.java

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public SystemUpdateParams getSystemUpdateParams() {
6565
.put("App.FENECON.Industrial.S.ISK011", "https://fenecon.de/fenecon-industrial-s/") //
6666
.put("App.TimeOfUseTariff.Awattar", "") //
6767
.put("App.TimeOfUseTariff.ENTSO-E", "") //
68+
.put("App.TimeOfUseTariff.GroupeE", "") //
69+
.put("App.TimeOfUseTariff.Hassfurt", "") //
6870
.put("App.TimeOfUseTariff.RabotCharge", "") //
6971
.put("App.TimeOfUseTariff.Stromdao", "") //
7072
.put("App.TimeOfUseTariff.Tibber", "") //

io.openems.common/src/io/openems/common/types/EdgeConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
public class EdgeConfig {
4242

43-
private static Logger LOG = LoggerFactory.getLogger(EdgeConfig.class);
43+
private static final Logger LOG = LoggerFactory.getLogger(EdgeConfig.class);
4444

4545
/**
4646
* Represents an instance of an OpenEMS Component.
@@ -1388,7 +1388,7 @@ public List<Component> getComponentsByFactory(String factoryId) {
13881388
public synchronized JsonObject toJson() {
13891389
if (this._json == null) {
13901390
this._json = JsonUtils.buildJsonObject() //
1391-
.add("components", this.componentsToJson(JsonFormat.COMPLETE)) //
1391+
.add("components", this.componentsToJson(JsonFormat.WITHOUT_CHANNELS)) //
13921392
.add("factories", this.factoriesToJson()) //
13931393
.build();
13941394
}

0 commit comments

Comments
 (0)