diff --git a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java index 6fe4f6d762..f45028a70e 100644 --- a/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java @@ -44,6 +44,7 @@ import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.event.EventService; import org.thingsboard.server.dao.plugin.PluginService; +import org.thingsboard.server.dao.relation.RelationService; import org.thingsboard.server.dao.rule.RuleService; import org.thingsboard.server.dao.tenant.TenantService; import org.thingsboard.server.dao.timeseries.TimeseriesService; @@ -109,6 +110,9 @@ public class ActorSystemContext { @Autowired @Getter private AlarmService alarmService; + @Autowired + @Getter private RelationService relationService; + @Autowired @Getter @Setter private PluginWebSocketMsgEndpoint wsMsgEndpoint; diff --git a/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java b/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java index 0e2ffcb792..8f65fc687d 100644 --- a/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/plugin/PluginProcessingContext.java @@ -33,6 +33,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; import org.thingsboard.server.common.data.kv.TsKvQuery; import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.common.data.plugin.PluginMetaData; +import org.thingsboard.server.common.data.relation.EntityRelation; +import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.rule.RuleMetaData; import org.thingsboard.server.common.msg.cluster.ServerAddress; import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; @@ -394,6 +396,16 @@ public final class PluginProcessingContext implements PluginContext { } } + @Override + public ListenableFuture> findByFromAndType(EntityId from, String relationType) { + return this.pluginCtx.relationService.findByFromAndType(from, relationType, RelationTypeGroup.COMMON); + } + + @Override + public ListenableFuture> findByToAndType(EntityId from, String relationType) { + return this.pluginCtx.relationService.findByToAndType(from, relationType, RelationTypeGroup.COMMON); + } + @Override public Optional resolve(EntityId entityId) { return pluginCtx.routingService.resolveById(entityId); diff --git a/application/src/main/java/org/thingsboard/server/actors/plugin/SharedPluginProcessingContext.java b/application/src/main/java/org/thingsboard/server/actors/plugin/SharedPluginProcessingContext.java index 43ddce6105..de859a205e 100644 --- a/application/src/main/java/org/thingsboard/server/actors/plugin/SharedPluginProcessingContext.java +++ b/application/src/main/java/org/thingsboard/server/actors/plugin/SharedPluginProcessingContext.java @@ -30,6 +30,7 @@ import org.thingsboard.server.dao.attributes.AttributesService; import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.plugin.PluginService; +import org.thingsboard.server.dao.relation.RelationService; import org.thingsboard.server.dao.rule.RuleService; import org.thingsboard.server.dao.tenant.TenantService; import org.thingsboard.server.dao.timeseries.TimeseriesService; @@ -61,6 +62,7 @@ public final class SharedPluginProcessingContext { final AttributesService attributesService; final ClusterRpcService rpcService; final ClusterRoutingService routingService; + final RelationService relationService; final PluginId pluginId; final TenantId tenantId; @@ -83,6 +85,7 @@ public final class SharedPluginProcessingContext { this.pluginService = sysContext.getPluginService(); this.customerService = sysContext.getCustomerService(); this.tenantService = sysContext.getTenantService(); + this.relationService = sysContext.getRelationService(); } public PluginId getPluginId() { diff --git a/extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/PluginContext.java b/extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/PluginContext.java index 2d346e7724..c825594ec5 100644 --- a/extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/PluginContext.java +++ b/extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/PluginContext.java @@ -15,11 +15,14 @@ */ package org.thingsboard.server.extensions.api.plugins; +import com.google.common.util.concurrent.ListenableFuture; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.id.*; import org.thingsboard.server.common.data.kv.AttributeKvEntry; import org.thingsboard.server.common.data.kv.TsKvEntry; import org.thingsboard.server.common.data.kv.TsKvQuery; +import org.thingsboard.server.common.data.relation.EntityRelation; +import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.msg.cluster.ServerAddress; import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; @@ -109,4 +112,12 @@ public interface PluginContext { void getCustomerDevices(TenantId tenantId, CustomerId customerId, int limit, PluginCallback> callback); + + /* + * Relations API + * */ + + ListenableFuture> findByFromAndType(EntityId from, String relationType); + + ListenableFuture> findByToAndType(EntityId from, String relationType); } diff --git a/extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/ServerSideRpcCallAction.java b/extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/ServerSideRpcCallAction.java index 679c87b0e6..5279eb1d28 100644 --- a/extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/ServerSideRpcCallAction.java +++ b/extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/ServerSideRpcCallAction.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2017 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.extensions.core.action.rpc; import lombok.extern.slf4j.Slf4j; @@ -28,7 +43,8 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem private ServerSideRpcCallActionConfiguration configuration; private Optional