Commit a4d651eb4bc9ddea7e5b6a44792bc8d6a1c92751
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
2 changed files
with
20 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 | } | ... | ... |
... | ... | @@ -29,6 +29,7 @@ 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 | 31 | import org.thingsboard.server.common.data.id.EntityViewId; |
32 | +import org.thingsboard.server.common.data.id.UserId; | |
32 | 33 | import org.thingsboard.server.common.data.plugin.ComponentType; |
33 | 34 | import org.thingsboard.server.common.msg.TbMsg; |
34 | 35 | |
... | ... | @@ -105,6 +106,18 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG |
105 | 106 | return Futures.immediateFuture(null); |
106 | 107 | } |
107 | 108 | }, MoreExecutors.directExecutor()); |
109 | + case USER: | |
110 | + return Futures.transformAsync(ctx.getUserService().findUserByIdAsync(ctx.getTenantId(), new UserId(msg.getOriginator().getId())), user -> { | |
111 | + if (user != null) { | |
112 | + if (!user.getCustomerId().isNullUid()) { | |
113 | + return ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), user.getCustomerId()); | |
114 | + } else { | |
115 | + throw new RuntimeException("User with name '" + user.getName() + "' is not assigned to Customer."); | |
116 | + } | |
117 | + } else { | |
118 | + return Futures.immediateFuture(null); | |
119 | + } | |
120 | + }, MoreExecutors.directExecutor()); | |
108 | 121 | default: |
109 | 122 | throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported."); |
110 | 123 | } | ... | ... |