fixed bug with saving server attributes in client scope
This commit is contained in:
parent
2fffa660ab
commit
2b14fa3634
@ -71,7 +71,9 @@ import org.thingsboard.server.gen.edge.UserCredentialsRequestMsg;
|
||||
import org.thingsboard.server.service.executors.DbCallbackExecutorService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@ -289,25 +291,29 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
|
||||
public void onSuccess(@Nullable List<AttributeKvEntry> ssAttributes) {
|
||||
if (ssAttributes != null && !ssAttributes.isEmpty()) {
|
||||
try {
|
||||
ObjectNode entityNode = mapper.createObjectNode();
|
||||
Map<String, Object> entityData = new HashMap<>();
|
||||
ObjectNode attributes = mapper.createObjectNode();
|
||||
for (AttributeKvEntry attr : ssAttributes) {
|
||||
if (attr.getDataType() == DataType.BOOLEAN && attr.getBooleanValue().isPresent()) {
|
||||
entityNode.put(attr.getKey(), attr.getBooleanValue().get());
|
||||
attributes.put(attr.getKey(), attr.getBooleanValue().get());
|
||||
} else if (attr.getDataType() == DataType.DOUBLE && attr.getDoubleValue().isPresent()) {
|
||||
entityNode.put(attr.getKey(), attr.getDoubleValue().get());
|
||||
attributes.put(attr.getKey(), attr.getDoubleValue().get());
|
||||
} else if (attr.getDataType() == DataType.LONG && attr.getLongValue().isPresent()) {
|
||||
entityNode.put(attr.getKey(), attr.getLongValue().get());
|
||||
attributes.put(attr.getKey(), attr.getLongValue().get());
|
||||
} else {
|
||||
entityNode.put(attr.getKey(), attr.getValueAsString());
|
||||
attributes.put(attr.getKey(), attr.getValueAsString());
|
||||
}
|
||||
}
|
||||
log.debug("Sending attributes data msg, entityId [{}], attributes [{}]", entityId, entityNode);
|
||||
entityData.put("kv", attributes);
|
||||
entityData.put("scope", DataConstants.SERVER_SCOPE);
|
||||
JsonNode entityBody = mapper.valueToTree(entityData);
|
||||
log.debug("Sending attributes data msg, entityId [{}], attributes [{}]", entityId, entityBody);
|
||||
saveEdgeEvent(edge.getTenantId(),
|
||||
edge.getId(),
|
||||
edgeEventType,
|
||||
ActionType.ATTRIBUTES_UPDATED,
|
||||
entityId,
|
||||
entityNode);
|
||||
entityBody);
|
||||
} catch (Exception e) {
|
||||
log.error("[{}] Failed to send attribute updates to the edge", edge.getName(), e);
|
||||
}
|
||||
|
||||
@ -115,6 +115,7 @@ message PostTelemetryMsg {
|
||||
|
||||
message PostAttributeMsg {
|
||||
repeated KeyValueProto kv = 1;
|
||||
string scope = 2;
|
||||
}
|
||||
|
||||
message GetAttributeRequestMsg {
|
||||
|
||||
@ -136,8 +136,9 @@ public class JsonConverter {
|
||||
public static PostAttributeMsg convertToAttributesProto(JsonElement jsonObject) throws JsonSyntaxException {
|
||||
if (jsonObject.isJsonObject()) {
|
||||
PostAttributeMsg.Builder result = PostAttributeMsg.newBuilder();
|
||||
List<KeyValueProto> keyValueList = parseProtoValues(jsonObject.getAsJsonObject());
|
||||
List<KeyValueProto> keyValueList = parseProtoValues(jsonObject.getAsJsonObject().getAsJsonObject("kv"));
|
||||
result.addAllKv(keyValueList);
|
||||
result.setScope(jsonObject.getAsJsonObject().getAsJsonPrimitive("scope").getAsString());
|
||||
return result.build();
|
||||
} else {
|
||||
throw new JsonSyntaxException(CAN_T_PARSE_VALUE + jsonObject);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user