scope replaced to EntityDataProto
This commit is contained in:
parent
37cb35c99b
commit
d81804ac8d
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.service.edge.rpc.constructor;
|
package org.thingsboard.server.service.edge.rpc.constructor;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.thingsboard.server.common.data.audit.ActionType;
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
@ -42,7 +43,13 @@ public class EntityDataMsgConstructor {
|
|||||||
break;
|
break;
|
||||||
case ATTRIBUTES_UPDATED:
|
case ATTRIBUTES_UPDATED:
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
log.warn("Can't convert to attributes proto, entityData [{}]", entityData, e);
|
log.warn("Can't convert to attributes proto, entityData [{}]", entityData, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,6 +109,7 @@ message EntityDataProto {
|
|||||||
string entityType = 3;
|
string entityType = 3;
|
||||||
transport.PostTelemetryMsg postTelemetryMsg = 4;
|
transport.PostTelemetryMsg postTelemetryMsg = 4;
|
||||||
transport.PostAttributeMsg postAttributesMsg = 5;
|
transport.PostAttributeMsg postAttributesMsg = 5;
|
||||||
|
string postAttributeScope = 6;
|
||||||
// transport.ToDeviceRpcRequestMsg ???
|
// transport.ToDeviceRpcRequestMsg ???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,6 @@ message PostTelemetryMsg {
|
|||||||
|
|
||||||
message PostAttributeMsg {
|
message PostAttributeMsg {
|
||||||
repeated KeyValueProto kv = 1;
|
repeated KeyValueProto kv = 1;
|
||||||
string scope = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetAttributeRequestMsg {
|
message GetAttributeRequestMsg {
|
||||||
|
|||||||
@ -133,21 +133,14 @@ public class JsonConverter {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonElement) throws JsonSyntaxException {
|
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonObject) throws JsonSyntaxException {
|
||||||
if (jsonElement.isJsonObject()) {
|
if (jsonObject.isJsonObject()) {
|
||||||
PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder();
|
PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder();
|
||||||
List<KeyValueProto> keyValueList = null;
|
List<KeyValueProto> keyValueList = parseProtoValues(jsonObject.getAsJsonObject());
|
||||||
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);
|
|
||||||
}
|
|
||||||
result.addAllKv(keyValueList);
|
result.addAllKv(keyValueList);
|
||||||
return result.build();
|
return result.build();
|
||||||
} else {
|
} else {
|
||||||
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonElement);
|
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user