scope replaced to EntityDataProto

This commit is contained in:
Bohdan Smetaniuk 2020-07-14 19:22:31 +03:00
parent 37cb35c99b
commit d81804ac8d
4 changed files with 13 additions and 13 deletions

View File

@ -16,6 +16,7 @@
package org.thingsboard.server.service.edge.rpc.constructor;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.audit.ActionType;
@ -42,7 +43,13 @@ public class EntityDataMsgConstructor {
break;
case ATTRIBUTES_UPDATED:
try {
builder.setPostAttributesMsg(JsonConverter.convertToAttributesProto(entityData));
JsonObject data = entityData.getAsJsonObject();
if (data.has("scope") && data.has("kv")) {
builder.setPostAttributesMsg(JsonConverter.convertToAttributesProto(data.getAsJsonObject("kv")));
builder.setPostAttributeScope(data.getAsJsonPrimitive("scope").getAsString());
} else {
builder.setPostAttributesMsg(JsonConverter.convertToAttributesProto(data));
}
} catch (Exception e) {
log.warn("Can't convert to attributes proto, entityData [{}]", entityData, e);
}

View File

@ -109,6 +109,7 @@ message EntityDataProto {
string entityType = 3;
transport.PostTelemetryMsg postTelemetryMsg = 4;
transport.PostAttributeMsg postAttributesMsg = 5;
string postAttributeScope = 6;
// transport.ToDeviceRpcRequestMsg ???
}

View File

@ -115,7 +115,6 @@ message PostTelemetryMsg {
message PostAttributeMsg {
repeated KeyValueProto kv = 1;
string scope = 2;
}
message GetAttributeRequestMsg {

View File

@ -133,21 +133,14 @@ public class JsonConverter {
.build();
}
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonElement) throws JsonSyntaxException {
if (jsonElement.isJsonObject()) {
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonObject) throws JsonSyntaxException {
if (jsonObject.isJsonObject()) {
PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder();
List<KeyValueProto> keyValueList = null;
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject.has("kv") && jsonObject.has("scope")) {
keyValueList = parseProtoValues(jsonObject.getAsJsonObject("kv"));
result.setScope(jsonObject.getAsJsonPrimitive("scope").getAsString());
} else {
keyValueList = parseProtoValues(jsonObject);
}
List<KeyValueProto> keyValueList = parseProtoValues(jsonObject.getAsJsonObject());
result.addAllKv(keyValueList);
return result.build();
} else {
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonElement);
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
}
}