Refactoring and backward-compatiblity improvements
This commit is contained in:
parent
416c3fd10e
commit
436d37ff42
@ -69,6 +69,7 @@ import org.thingsboard.server.service.rpc.FromDeviceRpcResponse;
|
|||||||
import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg;
|
import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg;
|
||||||
import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg;
|
import org.thingsboard.server.service.rpc.ToServerRpcResponseActorMsg;
|
||||||
import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper;
|
import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper;
|
||||||
|
import org.thingsboard.server.utils.JsonUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -102,7 +103,6 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
private final Map<Integer, ToServerRpcRequestMetadata> toServerRpcPendingMap;
|
private final Map<Integer, ToServerRpcRequestMetadata> toServerRpcPendingMap;
|
||||||
|
|
||||||
private final Gson gson = new Gson();
|
private final Gson gson = new Gson();
|
||||||
private final JsonParser jsonParser = new JsonParser();
|
|
||||||
|
|
||||||
private int rpcSeq = 0;
|
private int rpcSeq = 0;
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
@ -327,7 +327,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePostAttributesRequest(ActorContext context, SessionInfoProto sessionInfo, PostAttributeMsg postAttributes) {
|
private void handlePostAttributesRequest(ActorContext context, SessionInfoProto sessionInfo, PostAttributeMsg postAttributes) {
|
||||||
JsonObject json = getJsonObject(postAttributes.getKvList());
|
JsonObject json = JsonUtils.getJsonObject(postAttributes.getKvList());
|
||||||
TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, defaultMetaData.copy(),
|
TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, defaultMetaData.copy(),
|
||||||
TbMsgDataType.JSON, gson.toJson(json), null, null, 0L);
|
TbMsgDataType.JSON, gson.toJson(json), null, null, 0L);
|
||||||
pushToRuleEngine(context, tbMsg);
|
pushToRuleEngine(context, tbMsg);
|
||||||
@ -335,7 +335,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
|
|
||||||
private void handlePostTelemetryRequest(ActorContext context, SessionInfoProto sessionInfo, PostTelemetryMsg postTelemetry) {
|
private void handlePostTelemetryRequest(ActorContext context, SessionInfoProto sessionInfo, PostTelemetryMsg postTelemetry) {
|
||||||
for (TsKvListProto tsKv : postTelemetry.getTsKvListList()) {
|
for (TsKvListProto tsKv : postTelemetry.getTsKvListList()) {
|
||||||
JsonObject json = getJsonObject(tsKv.getKvList());
|
JsonObject json = JsonUtils.getJsonObject(tsKv.getKvList());
|
||||||
TbMsgMetaData metaData = defaultMetaData.copy();
|
TbMsgMetaData metaData = defaultMetaData.copy();
|
||||||
metaData.putValue("ts", tsKv.getTs() + "");
|
metaData.putValue("ts", tsKv.getTs() + "");
|
||||||
TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, metaData, TbMsgDataType.JSON, gson.toJson(json), null, null, 0L);
|
TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, metaData, TbMsgDataType.JSON, gson.toJson(json), null, null, 0L);
|
||||||
@ -347,7 +347,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
UUID sessionId = getSessionId(sessionInfo);
|
UUID sessionId = getSessionId(sessionInfo);
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("method", request.getMethodName());
|
json.addProperty("method", request.getMethodName());
|
||||||
json.add("params", jsonParser.parse(request.getParams()));
|
json.add("params", JsonUtils.parse(request.getParams()));
|
||||||
|
|
||||||
TbMsgMetaData requestMetaData = defaultMetaData.copy();
|
TbMsgMetaData requestMetaData = defaultMetaData.copy();
|
||||||
requestMetaData.putValue("requestId", Integer.toString(request.getRequestId()));
|
requestMetaData.putValue("requestId", Integer.toString(request.getRequestId()));
|
||||||
@ -551,30 +551,6 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
this.defaultMetaData.putValue("deviceType", deviceType);
|
this.defaultMetaData.putValue("deviceType", deviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject getJsonObject(List<KeyValueProto> tsKv) {
|
|
||||||
JsonObject json = new JsonObject();
|
|
||||||
for (KeyValueProto kv : tsKv) {
|
|
||||||
switch (kv.getType()) {
|
|
||||||
case BOOLEAN_V:
|
|
||||||
json.addProperty(kv.getKey(), kv.getBoolV());
|
|
||||||
break;
|
|
||||||
case LONG_V:
|
|
||||||
json.addProperty(kv.getKey(), kv.getLongV());
|
|
||||||
break;
|
|
||||||
case DOUBLE_V:
|
|
||||||
json.addProperty(kv.getKey(), kv.getDoubleV());
|
|
||||||
break;
|
|
||||||
case STRING_V:
|
|
||||||
json.addProperty(kv.getKey(), kv.getStringV());
|
|
||||||
break;
|
|
||||||
case JSON_V:
|
|
||||||
json.add(kv.getKey(), jsonParser.parse(kv.getJsonV()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendToTransport(GetAttributeResponseMsg responseMsg, SessionInfoProto sessionInfo) {
|
private void sendToTransport(GetAttributeResponseMsg responseMsg, SessionInfoProto sessionInfo) {
|
||||||
DeviceActorToTransportMsg msg = DeviceActorToTransportMsg.newBuilder()
|
DeviceActorToTransportMsg msg = DeviceActorToTransportMsg.newBuilder()
|
||||||
.setSessionIdMSB(sessionInfo.getSessionIdMSB())
|
.setSessionIdMSB(sessionInfo.getSessionIdMSB())
|
||||||
|
|||||||
@ -103,7 +103,14 @@ public class DefaultMailService implements MailService {
|
|||||||
javaMailProperties.put(MAIL_PROP + protocol + ".port", jsonConfig.get("smtpPort").asText());
|
javaMailProperties.put(MAIL_PROP + protocol + ".port", jsonConfig.get("smtpPort").asText());
|
||||||
javaMailProperties.put(MAIL_PROP + protocol + ".timeout", jsonConfig.get("timeout").asText());
|
javaMailProperties.put(MAIL_PROP + protocol + ".timeout", jsonConfig.get("timeout").asText());
|
||||||
javaMailProperties.put(MAIL_PROP + protocol + ".auth", String.valueOf(StringUtils.isNotEmpty(jsonConfig.get("username").asText())));
|
javaMailProperties.put(MAIL_PROP + protocol + ".auth", String.valueOf(StringUtils.isNotEmpty(jsonConfig.get("username").asText())));
|
||||||
boolean enableTls = jsonConfig.has("enableTls") && jsonConfig.get("enableTls").booleanValue();
|
boolean enableTls = false;
|
||||||
|
if (jsonConfig.has("enableTls")) {
|
||||||
|
if (jsonConfig.get("enableTls").isBoolean() && jsonConfig.get("enableTls").booleanValue()) {
|
||||||
|
enableTls = true;
|
||||||
|
} else if (jsonConfig.get("enableTls").isTextual()) {
|
||||||
|
enableTls = "true".equalsIgnoreCase(jsonConfig.get("enableTls").asText());
|
||||||
|
}
|
||||||
|
}
|
||||||
javaMailProperties.put(MAIL_PROP + protocol + ".starttls.enable", enableTls);
|
javaMailProperties.put(MAIL_PROP + protocol + ".starttls.enable", enableTls);
|
||||||
if (enableTls && jsonConfig.has("tlsVersion") && StringUtils.isNoneEmpty(jsonConfig.get("tlsVersion").asText())) {
|
if (enableTls && jsonConfig.has("tlsVersion") && StringUtils.isNoneEmpty(jsonConfig.get("tlsVersion").asText())) {
|
||||||
javaMailProperties.put(MAIL_PROP + protocol + ".ssl.protocols", jsonConfig.get("tlsVersion").asText());
|
javaMailProperties.put(MAIL_PROP + protocol + ".ssl.protocols", jsonConfig.get("tlsVersion").asText());
|
||||||
|
|||||||
@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2020 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.utils;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos.KeyValueProto;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JsonUtils {
|
||||||
|
|
||||||
|
private static final JsonParser jsonParser = new JsonParser();
|
||||||
|
|
||||||
|
public static JsonObject getJsonObject(List<KeyValueProto> tsKv) {
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
for (KeyValueProto kv : tsKv) {
|
||||||
|
switch (kv.getType()) {
|
||||||
|
case BOOLEAN_V:
|
||||||
|
json.addProperty(kv.getKey(), kv.getBoolV());
|
||||||
|
break;
|
||||||
|
case LONG_V:
|
||||||
|
json.addProperty(kv.getKey(), kv.getLongV());
|
||||||
|
break;
|
||||||
|
case DOUBLE_V:
|
||||||
|
json.addProperty(kv.getKey(), kv.getDoubleV());
|
||||||
|
break;
|
||||||
|
case STRING_V:
|
||||||
|
json.addProperty(kv.getKey(), kv.getStringV());
|
||||||
|
break;
|
||||||
|
case JSON_V:
|
||||||
|
json.add(kv.getKey(), jsonParser.parse(kv.getJsonV()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonElement parse(String params) {
|
||||||
|
return jsonParser.parse(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user