add options send notifications
This commit is contained in:
parent
d8f87c45c8
commit
29d3efa205
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.rule.engine.telemetry;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.gson.JsonParser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
@ -65,11 +66,15 @@ public class TbMsgAttributesNode implements TbNode {
|
||||
return;
|
||||
}
|
||||
String src = msg.getData();
|
||||
List<AttributeKvEntry> attributes = new ArrayList<>(JsonConverter.convertToAttributes(new JsonParser().parse(src)));
|
||||
List<AttributeKvEntry> attributes = new ArrayList<>(JsonConverter.convertToAttributes(JsonParser.parseString(src)));
|
||||
if (attributes.isEmpty()) {
|
||||
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(),
|
||||
@ -77,7 +82,7 @@ public class TbMsgAttributesNode implements TbNode {
|
||||
config.getScope(),
|
||||
attributes,
|
||||
config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr),
|
||||
new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes)
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -25,12 +25,14 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration<TbMsg
|
||||
private String scope;
|
||||
|
||||
private Boolean notifyDevice;
|
||||
private boolean sendAttributesUpdatedNotification;
|
||||
|
||||
@Override
|
||||
public TbMsgAttributesNodeConfiguration defaultConfiguration() {
|
||||
TbMsgAttributesNodeConfiguration configuration = new TbMsgAttributesNodeConfiguration();
|
||||
configuration.setScope(DataConstants.SERVER_SCOPE);
|
||||
configuration.setNotifyDevice(false);
|
||||
configuration.setSendAttributesUpdatedNotification(false);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.rule.engine.telemetry;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.thingsboard.rule.engine.api.RuleNode;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
@ -49,12 +50,14 @@ 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
|
||||
@ -67,7 +70,11 @@ public class TbMsgDeleteAttributes implements TbNode {
|
||||
if (keysToDelete.isEmpty()) {
|
||||
ctx.tellSuccess(msg);
|
||||
} else {
|
||||
ctx.getTelemetryService().deleteAndNotify(ctx.getTenantId(), msg.getOriginator(), scope, keysToDelete, new AttributesDeleteNodeCallback(ctx, msg, scope, keysToDelete));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,12 +27,14 @@ public class TbMsgDeleteAttributesConfiguration implements NodeConfiguration<TbM
|
||||
|
||||
private String scope;
|
||||
private List<String> keys;
|
||||
private boolean sendAttributesDeletedNotification;
|
||||
|
||||
@Override
|
||||
public TbMsgDeleteAttributesConfiguration defaultConfiguration() {
|
||||
TbMsgDeleteAttributesConfiguration configuration = new TbMsgDeleteAttributesConfiguration();
|
||||
configuration.setScope(DataConstants.SERVER_SCOPE);
|
||||
configuration.setKeys(Collections.emptyList());
|
||||
configuration.setSendAttributesDeletedNotification(false);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user