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); ctx.tellSuccess(msg);
return; 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"); String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice");
ctx.getTelemetryService().saveAndNotify( ctx.getTelemetryService().saveAndNotify(
ctx.getTenantId(), ctx.getTenantId(),
@ -82,7 +78,9 @@ public class TbMsgAttributesNode implements TbNode {
config.getScope(), config.getScope(),
attributes, attributes,
config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr), 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 TbMsgDeleteAttributesConfiguration config;
private String scope; private String scope;
private List<String> keys; private List<String> keys;
private boolean sendAttributesDeletedNotification;
@Override @Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbMsgDeleteAttributesConfiguration.class); this.config = TbNodeUtils.convert(configuration, TbMsgDeleteAttributesConfiguration.class);
this.scope = config.getScope(); this.scope = config.getScope();
this.keys = config.getKeys(); this.keys = config.getKeys();
this.sendAttributesDeletedNotification = config.isSendAttributesDeletedNotification();
} }
@Override @Override
@ -70,11 +68,15 @@ public class TbMsgDeleteAttributes implements TbNode {
if (keysToDelete.isEmpty()) { if (keysToDelete.isEmpty()) {
ctx.tellSuccess(msg); ctx.tellSuccess(msg);
} else { } else {
FutureCallback<Void> callback = new TelemetryNodeCallback(ctx, msg); ctx.getTelemetryService().deleteAndNotify(
if (sendAttributesDeletedNotification) { ctx.getTenantId(),
callback = new AttributesDeleteNodeCallback(ctx, msg, scope, keysToDelete); msg.getOriginator(),
} scope,
ctx.getTelemetryService().deleteAndNotify(ctx.getTenantId(), msg.getOriginator(), scope, keysToDelete, callback); keysToDelete,
config.isSendAttributesDeletedNotification() ?
new AttributesDeleteNodeCallback(ctx, msg, scope, keysToDelete) :
new TelemetryNodeCallback(ctx, msg)
);
} }
} }
} }