Showing
7 changed files
with
54 additions
and
2 deletions
... | ... | @@ -27,12 +27,12 @@ public enum Resource { |
27 | 27 | CUSTOMER(EntityType.CUSTOMER), |
28 | 28 | DASHBOARD(EntityType.DASHBOARD), |
29 | 29 | ENTITY_VIEW(EntityType.ENTITY_VIEW), |
30 | + EDGE(EntityType.EDGE), | |
30 | 31 | TENANT(EntityType.TENANT), |
31 | 32 | RULE_CHAIN(EntityType.RULE_CHAIN), |
32 | 33 | USER(EntityType.USER), |
33 | 34 | WIDGETS_BUNDLE(EntityType.WIDGETS_BUNDLE), |
34 | - WIDGET_TYPE(EntityType.WIDGET_TYPE), | |
35 | - EDGE(EntityType.EDGE); | |
35 | + WIDGET_TYPE(EntityType.WIDGET_TYPE); | |
36 | 36 | |
37 | 37 | private final EntityType entityType; |
38 | 38 | ... | ... |
... | ... | @@ -36,6 +36,7 @@ import org.thingsboard.server.common.data.Device; |
36 | 36 | import org.thingsboard.server.common.data.EntityType; |
37 | 37 | import org.thingsboard.server.common.data.EntityView; |
38 | 38 | import org.thingsboard.server.common.data.asset.Asset; |
39 | +import org.thingsboard.server.common.data.edge.Edge; | |
39 | 40 | import org.thingsboard.server.common.data.id.EntityId; |
40 | 41 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
41 | 42 | import org.thingsboard.server.common.data.page.TextPageData; |
... | ... | @@ -48,6 +49,7 @@ import org.thingsboard.server.dao.asset.AssetService; |
48 | 49 | import org.thingsboard.server.dao.customer.CustomerService; |
49 | 50 | import org.thingsboard.server.dao.dashboard.DashboardService; |
50 | 51 | import org.thingsboard.server.dao.device.DeviceService; |
52 | +import org.thingsboard.server.dao.edge.EdgeService; | |
51 | 53 | import org.thingsboard.server.dao.entityview.EntityViewService; |
52 | 54 | |
53 | 55 | import java.util.List; |
... | ... | @@ -236,6 +238,13 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA |
236 | 238 | targetEntity.setEntityId(entityView.getId()); |
237 | 239 | } |
238 | 240 | break; |
241 | + case EDGE: | |
242 | + EdgeService edgeService = ctx.getEdgeService(); | |
243 | + Edge edge = edgeService.findEdgeByTenantIdAndName(ctx.getTenantId(), entitykey.getEntityName()); | |
244 | + if (edge != null) { | |
245 | + targetEntity.setEntityId(edge.getId()); | |
246 | + } | |
247 | + break; | |
239 | 248 | case DASHBOARD: |
240 | 249 | DashboardService dashboardService = ctx.getDashboardService(); |
241 | 250 | TextPageData<DashboardInfo> dashboardInfoTextPageData = dashboardService.findDashboardsByTenantId(ctx.getTenantId(), new TextPageLink(200, entitykey.getEntityName())); | ... | ... |
... | ... | @@ -69,6 +69,9 @@ public class TbAssignToCustomerNode extends TbAbstractCustomerActionNode<TbAssig |
69 | 69 | case ENTITY_VIEW: |
70 | 70 | processAssignEntityView(ctx, msg, customerId); |
71 | 71 | break; |
72 | + case EDGE: | |
73 | + processAssignEdge(ctx, msg, customerId); | |
74 | + break; | |
72 | 75 | case DASHBOARD: |
73 | 76 | processAssignDashboard(ctx, msg, customerId); |
74 | 77 | break; |
... | ... | @@ -91,6 +94,10 @@ public class TbAssignToCustomerNode extends TbAbstractCustomerActionNode<TbAssig |
91 | 94 | ctx.getEntityViewService().assignEntityViewToCustomer(ctx.getTenantId(), new EntityViewId(msg.getOriginator().getId()), customerId); |
92 | 95 | } |
93 | 96 | |
97 | + private void processAssignEdge(TbContext ctx, TbMsg msg, CustomerId customerId) { | |
98 | + ctx.getEdgeService().assignEdgeToCustomer(ctx.getTenantId(), new EdgeId(msg.getOriginator().getId()), customerId); | |
99 | + } | |
100 | + | |
94 | 101 | private void processAssignDashboard(TbContext ctx, TbMsg msg, CustomerId customerId) { |
95 | 102 | ctx.getDashboardService().assignDashboardToCustomer(ctx.getTenantId(), new DashboardId(msg.getOriginator().getId()), customerId); |
96 | 103 | } | ... | ... |
... | ... | @@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.id.AssetId; |
28 | 28 | import org.thingsboard.server.common.data.id.CustomerId; |
29 | 29 | import org.thingsboard.server.common.data.id.DashboardId; |
30 | 30 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | +import org.thingsboard.server.common.data.id.EdgeId; | |
31 | 32 | import org.thingsboard.server.common.data.id.EntityViewId; |
32 | 33 | import org.thingsboard.server.common.data.id.TenantId; |
33 | 34 | import org.thingsboard.server.common.data.plugin.ComponentType; |
... | ... | @@ -137,6 +138,8 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR |
137 | 138 | return processDashboard(ctx, entityContainer, sdId, relationType); |
138 | 139 | case ENTITY_VIEW: |
139 | 140 | return processView(ctx, entityContainer, sdId, relationType); |
141 | + case EDGE: | |
142 | + return processEdge(ctx, entityContainer, sdId, relationType); | |
140 | 143 | case TENANT: |
141 | 144 | return processTenant(ctx, entityContainer, sdId, relationType); |
142 | 145 | } |
... | ... | @@ -153,6 +156,16 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR |
153 | 156 | }, ctx.getDbCallbackExecutor()); |
154 | 157 | } |
155 | 158 | |
159 | + private ListenableFuture<Boolean> processEdge(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) { | |
160 | + return Futures.transformAsync(ctx.getEdgeService().findEdgeByIdAsync(ctx.getTenantId(), new EdgeId(entityContainer.getEntityId().getId())), edge -> { | |
161 | + if (edge != null) { | |
162 | + return processSave(ctx, sdId, relationType); | |
163 | + } else { | |
164 | + return Futures.immediateFuture(true); | |
165 | + } | |
166 | + }, ctx.getDbCallbackExecutor()); | |
167 | + } | |
168 | + | |
156 | 169 | private ListenableFuture<Boolean> processDevice(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) { |
157 | 170 | return Futures.transformAsync(ctx.getDeviceService().findDeviceByIdAsync(ctx.getTenantId(), new DeviceId(entityContainer.getEntityId().getId())), device -> { |
158 | 171 | if (device != null) { | ... | ... |
... | ... | @@ -62,6 +62,9 @@ public class TbUnassignFromCustomerNode extends TbAbstractCustomerActionNode<TbU |
62 | 62 | case ENTITY_VIEW: |
63 | 63 | processUnassignEntityView(ctx, msg); |
64 | 64 | break; |
65 | + case EDGE: | |
66 | + processUnassignEdge(ctx, msg); | |
67 | + break; | |
65 | 68 | case DASHBOARD: |
66 | 69 | processUnnasignDashboard(ctx, msg, customerId); |
67 | 70 | break; |
... | ... | @@ -87,4 +90,8 @@ public class TbUnassignFromCustomerNode extends TbAbstractCustomerActionNode<TbU |
87 | 90 | private void processUnassignEntityView(TbContext ctx, TbMsg msg) { |
88 | 91 | ctx.getEntityViewService().unassignEntityViewFromCustomer(ctx.getTenantId(), new EntityViewId(msg.getOriginator().getId())); |
89 | 92 | } |
93 | + | |
94 | + private void processUnassignEdge(TbContext ctx, TbMsg msg) { | |
95 | + ctx.getEdgeService().unassignEdgeFromCustomer(ctx.getTenantId(), new EdgeId(msg.getOriginator().getId())); | |
96 | + } | |
90 | 97 | } | ... | ... |
... | ... | @@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.ContactBased; |
28 | 28 | import org.thingsboard.server.common.data.Customer; |
29 | 29 | import org.thingsboard.server.common.data.id.AssetId; |
30 | 30 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | +import org.thingsboard.server.common.data.id.EdgeId; | |
31 | 32 | import org.thingsboard.server.common.data.id.EntityViewId; |
32 | 33 | import org.thingsboard.server.common.data.plugin.ComponentType; |
33 | 34 | import org.thingsboard.server.common.data.rule.RuleChainType; |
... | ... | @@ -108,6 +109,18 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG |
108 | 109 | return Futures.immediateFuture(null); |
109 | 110 | } |
110 | 111 | }, MoreExecutors.directExecutor()); |
112 | + case EDGE: | |
113 | + return Futures.transformAsync(ctx.getEdgeService().findEdgeByIdAsync(ctx.getTenantId(), new EdgeId(msg.getOriginator().getId())), edge -> { | |
114 | + if (edge != null) { | |
115 | + if (!edge.getCustomerId().isNullUid()) { | |
116 | + return ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), edge.getCustomerId()); | |
117 | + } else { | |
118 | + throw new RuntimeException("Edge with name '" + edge.getName() + "' is not assigned to Customer."); | |
119 | + } | |
120 | + } else { | |
121 | + return Futures.immediateFuture(null); | |
122 | + } | |
123 | + }, MoreExecutors.directExecutor()); | |
111 | 124 | default: |
112 | 125 | throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported."); |
113 | 126 | } | ... | ... |