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

Add translation for Excel Export #1778

Merged
merged 1 commit into from
Apr 1, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.UpdateUserLanguageRequest.Language;
import io.openems.common.session.Language;
import io.openems.common.types.ChannelAddress;
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfig.Component.Channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.response.AuthenticateResponse.EdgeMetadata;
import io.openems.common.session.AbstractUser;
import io.openems.common.session.Language;
import io.openems.common.session.Role;

/**
Expand All @@ -21,13 +22,10 @@ public class User extends AbstractUser {
*/
private final String token;

private final String language;

public User(String id, String name, String token, Role globalRole, NavigableMap<String, Role> roles,
String language) {
super(id, name, globalRole, roles);
public User(String id, String name, String token, Language language, Role globalRole,
NavigableMap<String, Role> roles) {
super(id, name, language, globalRole, roles);
this.token = token;
this.language = language;
}

/**
Expand All @@ -39,15 +37,6 @@ public String getToken() {
return this.token;
}

/**
* Gets the user language.
*
* @return the language
*/
public String getLanguage() {
return this.language;
}

/**
* Gets the information whether the Users Role for the given Edge is equal or
* more privileged than the given Role.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ protected CompletableFuture<EdgeRpcResponse> handleRequest(User user, UUID messa
*/
private CompletableFuture<JsonrpcResponseSuccess> handleQueryHistoricDataRequest(String edgeId, User user,
QueryHistoricTimeseriesDataRequest request) throws OpenemsNamedException {
var historicData = this.parent.timeData
.queryHistoricData(edgeId, request);
var historicData = this.parent.timeData.queryHistoricData(edgeId, request);

// JSON-RPC response
return CompletableFuture
Expand Down Expand Up @@ -169,10 +168,8 @@ private CompletableFuture<JsonrpcResponseSuccess> handleQueryHistoricEnergyReque
*/
private CompletableFuture<JsonrpcResponseSuccess> handleQueryHistoricEnergyPerPeriodRequest(String edgeId,
User user, QueryHistoricTimeseriesEnergyPerPeriodRequest request) throws OpenemsNamedException {
var data = this.parent.timeData
.queryHistoricEnergyPerPeriod(//
edgeId, request.getFromDate(), request.getToDate(), request.getChannels(),
request.getResolution());
var data = this.parent.timeData.queryHistoricEnergyPerPeriod(//
edgeId, request.getFromDate(), request.getToDate(), request.getChannels(), request.getResolution());

// JSON-RPC response
return CompletableFuture
Expand All @@ -190,8 +187,8 @@ private CompletableFuture<JsonrpcResponseSuccess> handleQueryHistoricEnergyPerPe
*/
private CompletableFuture<JsonrpcResponseSuccess> handleQueryHistoricTimeseriesExportXlxsRequest(String edgeId,
User user, QueryHistoricTimeseriesExportXlxsRequest request) throws OpenemsNamedException {
return CompletableFuture
.completedFuture(this.parent.timeData.handleQueryHistoricTimeseriesExportXlxsRequest(edgeId, request));
return CompletableFuture.completedFuture(this.parent.timeData
.handleQueryHistoricTimeseriesExportXlxsRequest(edgeId, request, user.getLanguage()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.openems.common.exceptions.NotImplementedException;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.request.UpdateUserLanguageRequest.Language;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.EdgeConfig;
import io.openems.common.types.EdgeConfigDiff;
Expand Down Expand Up @@ -77,7 +77,7 @@ public User authenticate(String username, String password) throws OpenemsNamedEx
for (String edgeId : this.edges.keySet()) {
roles.put(edgeId, Role.ADMIN);
}
var user = new User(username, name, token, Role.ADMIN, roles, this.defaultLanguage.name());
var user = new User(username, name, token, this.defaultLanguage, Role.ADMIN, roles);
this.users.put(user.getId(), user);
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.openems.common.exceptions.NotImplementedException;
import io.openems.common.exceptions.OpenemsError;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.jsonrpc.request.UpdateUserLanguageRequest.Language;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.EdgeConfig;
import io.openems.common.utils.JsonUtils;
Expand Down Expand Up @@ -70,12 +70,13 @@ public class FileMetadata extends AbstractMetadata implements Metadata {
private static final String USER_NAME = "Administrator";
private static final Role USER_GLOBAL_ROLE = Role.ADMIN;

private static Language LANGUAGE = Language.DE;

private final Logger log = LoggerFactory.getLogger(FileMetadata.class);
private final Map<String, MyEdge> edges = new HashMap<>();

private User user;
private String path = "";
private static Language LANGUAGE = Language.DE;

public FileMetadata() {
super("Metadata.File");
Expand Down Expand Up @@ -209,7 +210,7 @@ private synchronized void refreshData() {

private static User generateUser() {
return new User(FileMetadata.USER_ID, FileMetadata.USER_NAME, UUID.randomUUID().toString(),
FileMetadata.USER_GLOBAL_ROLE, new TreeMap<>(), FileMetadata.LANGUAGE.name());
FileMetadata.LANGUAGE, FileMetadata.USER_GLOBAL_ROLE, new TreeMap<>());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import java.util.NavigableMap;

import io.openems.backend.common.metadata.User;
import io.openems.common.session.Language;
import io.openems.common.session.Role;

public class MyUser extends User {

private final int odooId;

public MyUser(int odooId, String login, String name, String token, Role globalRole,
NavigableMap<String, Role> roles, String language) {
super(login, name, token, globalRole, roles, language);
public MyUser(int odooId, String login, String name, String token, Language language, Role globalRole,
NavigableMap<String, Role> roles) {
super(login, name, token, language, globalRole, roles);
this.odooId = odooId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.openems.backend.metadata.odoo.postgres.PostgresHandler;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.UpdateUserLanguageRequest.Language;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.utils.JsonUtils;

Expand Down Expand Up @@ -111,9 +111,9 @@ public User authenticate(String sessionId) throws OpenemsNamedException {
JsonUtils.getAsString(jUser, "login"), //
JsonUtils.getAsString(jUser, "name"), //
sessionId, //
Language.from(JsonUtils.getAsString(jUser, "language")), //
Role.getRole(JsonUtils.getAsString(jUser, "global_role")), //
roles, //
JsonUtils.getAsString(jUser, "language"));
roles);

this.users.put(user.getId(), user);
return user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.openems.backend.metadata.odoo.OdooMetadata;
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.request.UpdateUserLanguageRequest.Language;
import io.openems.common.session.Language;
import io.openems.common.utils.JsonUtils;
import io.openems.common.utils.ObjectUtils;
import io.openems.common.utils.PasswordUtils;
Expand Down Expand Up @@ -789,6 +789,7 @@ public void updateUserLanguage(MyUser user, Language language) throws OpenemsExc
try {
OdooUtils.write(this.credentials, Field.User.ODOO_MODEL, new Integer[] { user.getOdooId() }, //
new FieldValue<>(Field.User.OPENEMS_LANGUAGE, language.name()));
user.setLanguage(language);
} catch (OpenemsNamedException ex) {
throw new OpenemsException("Unable to set language [" + language.name() + "] for current user", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.exceptions.OpenemsException;
import io.openems.common.jsonrpc.base.JsonrpcRequest;
import io.openems.common.session.Language;
import io.openems.common.utils.JsonUtils;

/**
Expand All @@ -23,33 +24,6 @@
*/
public class UpdateUserLanguageRequest extends JsonrpcRequest {

public static enum Language {
EN, //
DE, //
CZ, //
NL, //
ES, //
FR;

/**
* Get {@link Language} for given key of the language or throws an exception.
* The given key is removed all leading and trailing whitespaces and converts
* all characters to upper case.
*
* @param languageKey to get the {@link Language}
* @return the founded {@link Language} or throws an exception
* @throws OpenemsException on error
*/
public static Language from(String languageKey) throws OpenemsException {
try {
return Language.valueOf(languageKey.trim().toUpperCase());
} catch (IllegalArgumentException ex) {
throw new OpenemsException("Language [" + languageKey + "] not supported");
}
}

}

public static final String METHOD = "updateUserLanguage";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.openems.common.jsonrpc.request.AuthenticateWithPasswordRequest;
import io.openems.common.jsonrpc.request.AuthenticateWithTokenRequest;
import io.openems.common.session.AbstractUser;
import io.openems.common.session.Language;
import io.openems.common.session.Role;
import io.openems.common.types.SemanticVersion;
import io.openems.common.utils.JsonUtils;
Expand Down Expand Up @@ -42,10 +43,10 @@ public static class EdgeMetadata {
* [{
* "id": String,
* "comment": String,
* "producttype: String,
* "version: String,
* "role: "admin" | "installer" | "owner" | "guest",
* "isOnline: boolean
* "producttype": String,
* "version": String,
* "role": "admin" | "installer" | "owner" | "guest",
* "isOnline": boolean
* }]
* </pre>
*
Expand Down Expand Up @@ -92,13 +93,13 @@ protected JsonObject toJsonObject() {
private final String token;
private final AbstractUser user;
private final List<EdgeMetadata> edges;
private final String language;
private final Language language;

public AuthenticateResponse(UUID id, String token, AbstractUser user, List<EdgeMetadata> edges) {
this(id, token, user, edges, null);
this(id, token, user, edges, null /* TODO */);
}

public AuthenticateResponse(UUID id, String token, AbstractUser user, List<EdgeMetadata> edges, String language) {
public AuthenticateResponse(UUID id, String token, AbstractUser user, List<EdgeMetadata> edges, Language language) {
super(id);
this.token = token;
this.user = user;
Expand All @@ -117,7 +118,7 @@ public JsonObject getResult() {
.add("user", JsonUtils.buildJsonObject() //
.addProperty("id", this.user.getId()) //
.addProperty("name", this.user.getName()) //
.addProperty("language", this.language) //
.addProperty("language", this.language.name()) //
.add("globalRole", this.user.getGlobalRole().asJson()) //
.build()) //
.add("edges", EdgeMetadata.toJson(this.edges)) //
Expand Down
Loading