Merge pull request #7370 from devaskim/relation_to_user
[3.4.2] Rule Engine: Added support of creating relation to USER entity.
This commit is contained in:
commit
d0179c4cd3
@ -32,6 +32,7 @@ import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentType;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
||||
@ -143,6 +144,8 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
||||
return processEdge(ctx, entityContainer, sdId, relationType);
|
||||
case TENANT:
|
||||
return processTenant(ctx, entityContainer, sdId, relationType);
|
||||
case USER:
|
||||
return processUser(ctx, entityContainer, sdId, relationType);
|
||||
}
|
||||
return Futures.immediateFuture(true);
|
||||
}
|
||||
@ -217,6 +220,16 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
|
||||
}, ctx.getDbCallbackExecutor());
|
||||
}
|
||||
|
||||
private ListenableFuture<Boolean> processUser(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
|
||||
return Futures.transformAsync(ctx.getUserService().findUserByIdAsync(ctx.getTenantId(), new UserId(entityContainer.getEntityId().getId())), user -> {
|
||||
if (user != null) {
|
||||
return processSave(ctx, sdId, relationType);
|
||||
} else {
|
||||
return Futures.immediateFuture(true);
|
||||
}
|
||||
}, ctx.getDbCallbackExecutor());
|
||||
}
|
||||
|
||||
private ListenableFuture<Boolean> processSave(TbContext ctx, SearchDirectionIds sdId, String relationType) {
|
||||
return ctx.getRelationService().saveRelationAsync(ctx.getTenantId(), new EntityRelation(sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user