-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Improve alerting user interface; add admin features; (#317)
- Refactor JSONRPC-Requests/-Responses - JsonUtils: refactor tests with exception; new method: generateJsonArray() - Improve OdooUtils NOTE: requires Backend + UI update Co-authored-by: Maximilian Lang <maximilian.lang@fenecon.de> Co-authored-by: Lukas Rieger <lukas.rieger@fenecon.de> Co-authored-by: Stefan Feilmeier <stefan.feilmeier@fenecon.de> Reviewed-on: https://git.intranet.fenecon.de/FENECON/fems/pulls/317 Reviewed-by: Lukas Rieger <lukas.rieger@fenecon.de> Reviewed-by: Stefan Feilmeier <stefan.feilmeier@fenecon.de> Co-authored-by: Kai Jeschek <kai.jeschek@fenecon.de> Co-committed-by: Kai Jeschek <kai.jeschek@fenecon.de>
- Loading branch information
1 parent
d5c0c7b
commit 831b307
Showing
38 changed files
with
1,469 additions
and
963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
...ackend.common/src/io/openems/backend/common/jsonrpc/request/SetAlertingConfigRequest.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...d.common/src/io/openems/backend/common/jsonrpc/request/SetUserAlertingConfigsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.openems.backend.common.jsonrpc.request; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
|
||
import io.openems.backend.common.metadata.AlertingSetting; | ||
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'. | ||
* | ||
* <pre> | ||
* { | ||
* "jsonrpc": "2.0", | ||
* "id": "UUID", | ||
* "method": "setUserAlertingConfigs", | ||
* "params": { | ||
* "edgeId": string, | ||
* "userSettings": [ | ||
* { | ||
* userId: string, | ||
* delayTime": number | ||
* } | ||
* ] | ||
* } | ||
* </pre> | ||
*/ | ||
public class SetUserAlertingConfigsRequest extends JsonrpcRequest { | ||
|
||
public static final String METHOD = "setUserAlertingConfigs"; | ||
|
||
/** | ||
* Create {@link SetUserAlertingConfigsRequest} from a template | ||
* {@link JsonrpcRequest}. | ||
* | ||
* @param request the template {@link JsonrpcRequest} | ||
* @return the {@link SetUserAlertingConfigsRequest} | ||
* @throws OpenemsNamedException on parse error | ||
*/ | ||
public static SetUserAlertingConfigsRequest from(JsonrpcRequest request) throws OpenemsNamedException { | ||
return new SetUserAlertingConfigsRequest(request); | ||
} | ||
|
||
private final String edgeId; | ||
private final List<AlertingSetting> userSettings = new ArrayList<>(); | ||
|
||
private SetUserAlertingConfigsRequest(JsonrpcRequest request) throws OpenemsNamedException { | ||
super(request, SetUserAlertingConfigsRequest.METHOD); | ||
var params = request.getParams(); | ||
|
||
this.edgeId = JsonUtils.getAsString(params, "edgeId"); | ||
JsonUtils.getAsJsonArray(params, "userSettings").forEach(user -> { | ||
var userJsonObject = user.getAsJsonObject(); | ||
try { | ||
var userId = JsonUtils.getAsString(userJsonObject, "userId"); | ||
var timeToWait = JsonUtils.getAsInt(userJsonObject, "delayTime"); | ||
|
||
this.userSettings.add(new AlertingSetting(userId, null, null, timeToWait)); | ||
} catch (OpenemsNamedException e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the Edge-ID. | ||
* | ||
* @return the Edge-ID | ||
*/ | ||
public String getEdgeId() { | ||
return this.edgeId; | ||
} | ||
|
||
/** | ||
* Get list of {@link UserAlertingSetting}. | ||
* | ||
* @return list of {@link UserAlertingSetting} | ||
*/ | ||
public List<AlertingSetting> getUserSettings() { | ||
return this.userSettings; | ||
} | ||
|
||
@Override | ||
public JsonObject getParams() { | ||
return JsonUtils.buildJsonObject() // | ||
.addProperty("edgeId", this.edgeId) // | ||
.add("userSettings", JsonUtils.generateJsonArray(this.userSettings, this::toJson)) // | ||
.build(); | ||
} | ||
|
||
private JsonElement toJson(AlertingSetting setting) { | ||
return JsonUtils.buildJsonObject() // | ||
.addProperty("userId", setting.getUserId()) // | ||
.addProperty("delayTime", setting.getDelayTime()) // | ||
.build(); | ||
} | ||
|
||
} |
43 changes: 0 additions & 43 deletions
43
...kend.common/src/io/openems/backend/common/jsonrpc/response/GetAlertingConfigResponse.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
...common/src/io/openems/backend/common/jsonrpc/response/GetUserAlertingConfigsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.openems.backend.common.jsonrpc.response; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
|
||
import io.openems.backend.common.metadata.AlertingSetting; | ||
import io.openems.common.jsonrpc.base.JsonrpcResponseSuccess; | ||
import io.openems.common.session.Role; | ||
import io.openems.common.utils.JsonUtils; | ||
|
||
/** | ||
* Represents a JSON-RPC Response for 'getAlertingConfig'. | ||
* | ||
* <pre> | ||
* { | ||
* "jsonrpc": "2.0", | ||
* "id": "UUID", | ||
* "result": { | ||
* userSettings: [ | ||
* { | ||
* userId: string, | ||
* role: {@link Role}, | ||
* delayTime": number | ||
* } | ||
* ] | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public class GetUserAlertingConfigsResponse extends JsonrpcResponseSuccess { | ||
|
||
private final List<AlertingSetting> settings; | ||
|
||
public GetUserAlertingConfigsResponse(UUID id, List<AlertingSetting> settings) { | ||
super(id); | ||
this.settings = settings; | ||
} | ||
|
||
@Override | ||
public JsonObject getResult() { | ||
return JsonUtils.buildJsonObject() // | ||
.add("userSettings", JsonUtils.generateJsonArray(this.settings, this::toJson)) // | ||
.build(); | ||
} | ||
|
||
private JsonElement toJson(AlertingSetting setting) { | ||
return JsonUtils.buildJsonObject() // | ||
.addProperty("userId", setting.getUserId()) // | ||
.add("role", setting.getUserRole().asJson()) // | ||
.addProperty("delayTime", setting.getDelayTime()) // | ||
.build(); // | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
io.openems.backend.common/src/io/openems/backend/common/metadata/AlertingSetting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.openems.backend.common.metadata; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import io.openems.common.session.Role; | ||
|
||
public class AlertingSetting { | ||
private final String userId; | ||
private final Role userRole; | ||
private final ZonedDateTime lastNotification; | ||
private final int delayTime; | ||
|
||
public AlertingSetting(String userId, Role userRole, ZonedDateTime lastNotification, int delayTime) { | ||
this.userId = userId; | ||
this.userRole = userRole; | ||
this.lastNotification = lastNotification; | ||
this.delayTime = delayTime; | ||
} | ||
|
||
public String getUserId() { | ||
return this.userId; | ||
} | ||
|
||
public Role getUserRole() { | ||
return this.userRole; | ||
} | ||
|
||
public ZonedDateTime getLastNotification() { | ||
return this.lastNotification; | ||
} | ||
|
||
public int getDelayTime() { | ||
return this.delayTime; | ||
} | ||
} |
Oops, something went wrong.