Browse Source

refactor code, update logic callback

pull/7666/head
Yuriy Lytvynchuk 4 years ago
parent
commit
e77c939b67
  1. 8
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java
  2. 16
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributes.java

8
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java

@ -71,10 +71,6 @@ public class TbMsgAttributesNode implements TbNode {
ctx.tellSuccess(msg);
return;
}
FutureCallback<Void> callback = new TelemetryNodeCallback(ctx, msg);
if (config.isSendAttributesUpdatedNotification()) {
callback = new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes);
}
String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice");
ctx.getTelemetryService().saveAndNotify(
ctx.getTenantId(),
@ -82,7 +78,9 @@ public class TbMsgAttributesNode implements TbNode {
config.getScope(),
attributes,
config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr),
callback
config.isSendAttributesUpdatedNotification() ?
new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes) :
new TelemetryNodeCallback(ctx, msg)
);
}

16
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributes.java

@ -50,14 +50,12 @@ public class TbMsgDeleteAttributes implements TbNode {
private TbMsgDeleteAttributesConfiguration config;
private String scope;
private List<String> keys;
private boolean sendAttributesDeletedNotification;
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbMsgDeleteAttributesConfiguration.class);
this.scope = config.getScope();
this.keys = config.getKeys();
this.sendAttributesDeletedNotification = config.isSendAttributesDeletedNotification();
}
@Override
@ -70,11 +68,15 @@ public class TbMsgDeleteAttributes implements TbNode {
if (keysToDelete.isEmpty()) {
ctx.tellSuccess(msg);
} else {
FutureCallback<Void> callback = new TelemetryNodeCallback(ctx, msg);
if (sendAttributesDeletedNotification) {
callback = new AttributesDeleteNodeCallback(ctx, msg, scope, keysToDelete);
}
ctx.getTelemetryService().deleteAndNotify(ctx.getTenantId(), msg.getOriginator(), scope, keysToDelete, callback);
ctx.getTelemetryService().deleteAndNotify(
ctx.getTenantId(),
msg.getOriginator(),
scope,
keysToDelete,
config.isSendAttributesDeletedNotification() ?
new AttributesDeleteNodeCallback(ctx, msg, scope, keysToDelete) :
new TelemetryNodeCallback(ctx, msg)
);
}
}
}

Loading…
Cancel
Save