refactor code

This commit is contained in:
Yuriy Lytvynchuk 2022-09-22 10:29:38 +03:00
parent 3fe6fa99aa
commit c6364cdc2f
3 changed files with 4 additions and 4 deletions

View File

@ -15,11 +15,11 @@
*/ */
package org.thingsboard.rule.engine.metadata; package org.thingsboard.rule.engine.metadata;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.thingsboard.rule.engine.api.RuleNode; import org.thingsboard.rule.engine.api.RuleNode;
import org.thingsboard.rule.engine.api.TbContext; import org.thingsboard.rule.engine.api.TbContext;
import org.thingsboard.rule.engine.util.EntitiesTenantIdAsyncLoader;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.plugin.ComponentType; import org.thingsboard.server.common.data.plugin.ComponentType;
@ -40,7 +40,7 @@ public class TbGetTenantAttributeNode extends TbEntityGetAttrNode<TenantId> {
@Override @Override
protected ListenableFuture<TenantId> findEntityAsync(TbContext ctx, EntityId originator) { protected ListenableFuture<TenantId> findEntityAsync(TbContext ctx, EntityId originator) {
return EntitiesTenantIdAsyncLoader.findEntityIdAsync(ctx, originator); return Futures.immediateFuture(ctx.getTenantId());
} }
} }

View File

@ -85,7 +85,7 @@ public class TbChangeOriginatorNode extends TbAbstractTransformNode {
case CUSTOMER_SOURCE: case CUSTOMER_SOURCE:
return EntitiesCustomerIdAsyncLoader.findEntityIdAsync(ctx, msg.getOriginator()); return EntitiesCustomerIdAsyncLoader.findEntityIdAsync(ctx, msg.getOriginator());
case TENANT_SOURCE: case TENANT_SOURCE:
return EntitiesTenantIdAsyncLoader.findEntityIdAsync(ctx, msg.getOriginator()); return Futures.immediateFuture(ctx.getTenantId());
case RELATED_SOURCE: case RELATED_SOURCE:
return EntitiesRelatedEntityIdAsyncLoader.findEntityAsync(ctx, msg.getOriginator(), config.getRelationsQuery()); return EntitiesRelatedEntityIdAsyncLoader.findEntityAsync(ctx, msg.getOriginator(), config.getRelationsQuery());
case ALARM_ORIGINATOR_SOURCE: case ALARM_ORIGINATOR_SOURCE:

View File

@ -31,7 +31,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.id.UserId;
public class EntitiesTenantIdAsyncLoader { public class EntitiesTenantIdAsyncLoader {
// TODO: consider to remove since tenantId is already defined in the TbContext.
public static ListenableFuture<TenantId> findEntityIdAsync(TbContext ctx, EntityId original) { public static ListenableFuture<TenantId> findEntityIdAsync(TbContext ctx, EntityId original) {
switch (original.getEntityType()) { switch (original.getEntityType()) {