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;
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -109,6 +109,7 @@ message EntityDataProto {
 | 
			
		||||
  string entityType = 3;
 | 
			
		||||
  transport.PostTelemetryMsg postTelemetryMsg = 4;
 | 
			
		||||
  transport.PostAttributeMsg postAttributesMsg = 5;
 | 
			
		||||
  string postAttributeScope = 6;
 | 
			
		||||
  // transport.ToDeviceRpcRequestMsg ???
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -115,7 +115,6 @@ message PostTelemetryMsg {
 | 
			
		||||
 | 
			
		||||
message PostAttributeMsg {
 | 
			
		||||
  repeated KeyValueProto kv = 1;
 | 
			
		||||
  string scope = 2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message GetAttributeRequestMsg {
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user