Commit f9d1e347981c818d9d232ee576be611a43fb8199
Committed by
Andrew Shvayka
1 parent
3255eb90
Added USER as originator for 'customer details' rule node
Showing
2 changed files
with
21 additions
and
6 deletions
... | ... | @@ -83,11 +83,8 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti |
83 | 83 | |
84 | 84 | protected ListenableFuture<TbMsg> getTbMsgListenableFuture(TbContext ctx, TbMsg msg, MessageData messageData, String prefix) { |
85 | 85 | if (!this.config.getDetailsList().isEmpty()) { |
86 | - ListenableFuture<JsonElement> resultObject = null; | |
87 | 86 | ListenableFuture<ContactBased> contactBasedListenableFuture = getContactBasedListenableFuture(ctx, msg); |
88 | - for (EntityDetails entityDetails : this.config.getDetailsList()) { | |
89 | - resultObject = addContactProperties(messageData.getData(), contactBasedListenableFuture, entityDetails, prefix); | |
90 | - } | |
87 | + ListenableFuture<JsonElement> resultObject = addContactProperties(messageData.getData(), contactBasedListenableFuture, prefix); | |
91 | 88 | return transformMsg(ctx, msg, resultObject, messageData); |
92 | 89 | } else { |
93 | 90 | return Futures.immediateFuture(msg); |
... | ... | @@ -109,10 +106,14 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti |
109 | 106 | }, MoreExecutors.directExecutor()); |
110 | 107 | } |
111 | 108 | |
112 | - private ListenableFuture<JsonElement> addContactProperties(JsonElement data, ListenableFuture<ContactBased> entityFuture, EntityDetails entityDetails, String prefix) { | |
109 | + private ListenableFuture<JsonElement> addContactProperties(JsonElement data, ListenableFuture<ContactBased> entityFuture, String prefix) { | |
113 | 110 | return Futures.transformAsync(entityFuture, contactBased -> { |
114 | 111 | if (contactBased != null) { |
115 | - return Futures.immediateFuture(setProperties(contactBased, data, entityDetails, prefix)); | |
112 | + JsonElement jsonElement = null; | |
113 | + for (EntityDetails entityDetails : this.config.getDetailsList()) { | |
114 | + jsonElement = setProperties(contactBased, data, entityDetails, prefix); | |
115 | + } | |
116 | + return Futures.immediateFuture(jsonElement); | |
116 | 117 | } else { |
117 | 118 | return Futures.immediateFuture(null); |
118 | 119 | } | ... | ... |
... | ... | @@ -27,8 +27,10 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
27 | 27 | 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 | +import org.thingsboard.server.common.data.id.CustomerId; | |
30 | 31 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | 32 | import org.thingsboard.server.common.data.id.EntityViewId; |
33 | +import org.thingsboard.server.common.data.id.UserId; | |
32 | 34 | import org.thingsboard.server.common.data.plugin.ComponentType; |
33 | 35 | import org.thingsboard.server.common.msg.TbMsg; |
34 | 36 | |
... | ... | @@ -105,6 +107,18 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG |
105 | 107 | return Futures.immediateFuture(null); |
106 | 108 | } |
107 | 109 | }, MoreExecutors.directExecutor()); |
110 | + case USER: | |
111 | + return Futures.transformAsync(ctx.getUserService().findUserByIdAsync(ctx.getTenantId(), new UserId(msg.getOriginator().getId())), user -> { | |
112 | + if (user != null) { | |
113 | + if (!user.getCustomerId().isNullUid()) { | |
114 | + return ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), user.getCustomerId()); | |
115 | + } else { | |
116 | + throw new RuntimeException("User with name '" + user.getName() + "' is not assigned to Customer."); | |
117 | + } | |
118 | + } else { | |
119 | + return Futures.immediateFuture(null); | |
120 | + } | |
121 | + }, MoreExecutors.directExecutor()); | |
108 | 122 | default: |
109 | 123 | throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported."); |
110 | 124 | } | ... | ... |