Commit f9d1e347981c818d9d232ee576be611a43fb8199

Authored by Alexander Yurov
Committed by Andrew Shvayka
1 parent 3255eb90

Added USER as originator for 'customer details' rule node

@@ -83,11 +83,8 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti @@ -83,11 +83,8 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti
83 83
84 protected ListenableFuture<TbMsg> getTbMsgListenableFuture(TbContext ctx, TbMsg msg, MessageData messageData, String prefix) { 84 protected ListenableFuture<TbMsg> getTbMsgListenableFuture(TbContext ctx, TbMsg msg, MessageData messageData, String prefix) {
85 if (!this.config.getDetailsList().isEmpty()) { 85 if (!this.config.getDetailsList().isEmpty()) {
86 - ListenableFuture<JsonElement> resultObject = null;  
87 ListenableFuture<ContactBased> contactBasedListenableFuture = getContactBasedListenableFuture(ctx, msg); 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 return transformMsg(ctx, msg, resultObject, messageData); 88 return transformMsg(ctx, msg, resultObject, messageData);
92 } else { 89 } else {
93 return Futures.immediateFuture(msg); 90 return Futures.immediateFuture(msg);
@@ -109,10 +106,14 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti @@ -109,10 +106,14 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti
109 }, MoreExecutors.directExecutor()); 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 return Futures.transformAsync(entityFuture, contactBased -> { 110 return Futures.transformAsync(entityFuture, contactBased -> {
114 if (contactBased != null) { 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 } else { 117 } else {
117 return Futures.immediateFuture(null); 118 return Futures.immediateFuture(null);
118 } 119 }
@@ -27,8 +27,10 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils; @@ -27,8 +27,10 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils;
27 import org.thingsboard.server.common.data.ContactBased; 27 import org.thingsboard.server.common.data.ContactBased;
28 import org.thingsboard.server.common.data.Customer; 28 import org.thingsboard.server.common.data.Customer;
29 import org.thingsboard.server.common.data.id.AssetId; 29 import org.thingsboard.server.common.data.id.AssetId;
  30 +import org.thingsboard.server.common.data.id.CustomerId;
30 import org.thingsboard.server.common.data.id.DeviceId; 31 import org.thingsboard.server.common.data.id.DeviceId;
31 import org.thingsboard.server.common.data.id.EntityViewId; 32 import org.thingsboard.server.common.data.id.EntityViewId;
  33 +import org.thingsboard.server.common.data.id.UserId;
32 import org.thingsboard.server.common.data.plugin.ComponentType; 34 import org.thingsboard.server.common.data.plugin.ComponentType;
33 import org.thingsboard.server.common.msg.TbMsg; 35 import org.thingsboard.server.common.msg.TbMsg;
34 36
@@ -105,6 +107,18 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG @@ -105,6 +107,18 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG
105 return Futures.immediateFuture(null); 107 return Futures.immediateFuture(null);
106 } 108 }
107 }, MoreExecutors.directExecutor()); 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 default: 122 default:
109 throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported."); 123 throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported.");
110 } 124 }