refactor code, update logic callback

This commit is contained in:
Yuriy Lytvynchuk 2022-11-22 14:58:46 +02:00
parent 29d3efa205
commit e77c939b67
2 changed files with 12 additions and 12 deletions

View File

@ -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)
);
}

View File

@ -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)
);
}
}
}