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; 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);
} }

View File

@ -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 ???
} }

View File

@ -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 {

View File

@ -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);
} }
} }