|
|
|
@ -19,12 +19,14 @@ import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.AttributeScope; |
|
|
|
import org.thingsboard.server.common.data.EdgeUtils; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.HasCustomerId; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
|
|
|
@ -37,6 +39,7 @@ import org.thingsboard.server.common.data.id.EdgeId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|
|
|
import org.thingsboard.server.common.data.id.EntityViewId; |
|
|
|
import org.thingsboard.server.common.data.id.HasId; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
|
@ -348,6 +351,29 @@ public abstract class BaseEdgeProcessor implements EdgeProcessor { |
|
|
|
edgeCtx.getRelationService().saveRelation(tenantId, relation); |
|
|
|
} |
|
|
|
|
|
|
|
protected <T extends HasId<? extends EntityId>> void pushEntityEventToRuleEngine(TenantId tenantId, T entity, TbMsgType msgType) { |
|
|
|
pushEntityEventToRuleEngine(tenantId, null, entity, msgType); |
|
|
|
} |
|
|
|
|
|
|
|
protected <T extends HasId<? extends EntityId>> void pushEntityEventToRuleEngine(TenantId tenantId, Edge edge, T entity, TbMsgType msgType) { |
|
|
|
try { |
|
|
|
String entityAsString = JacksonUtil.toString(entity); |
|
|
|
CustomerId customerId = getCustomerId(entity); |
|
|
|
TbMsgMetaData tbMsgMetaData = edge == null ? TbMsgMetaData.EMPTY : getEdgeActionTbMsgMetaData(edge, customerId); |
|
|
|
|
|
|
|
pushEntityEventToRuleEngine(tenantId, entity.getId(), customerId, msgType, entityAsString, tbMsgMetaData); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("[{}][{}] Failed to push entity action for {} to rule engine: {}", tenantId, entity.getId(), entity.getId().getEntityType(), msgType.name(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private <T extends HasId<? extends EntityId>> CustomerId getCustomerId(T entity) { |
|
|
|
if (entity instanceof HasCustomerId hasCustomer) { |
|
|
|
return hasCustomer.getCustomerId(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
protected TbMsgMetaData getEdgeActionTbMsgMetaData(Edge edge, CustomerId customerId) { |
|
|
|
TbMsgMetaData metaData = new TbMsgMetaData(); |
|
|
|
metaData.putValue("edgeId", edge.getId().toString()); |
|
|
|
|