Browse Source

refactor code

pull/7238/head
Yuriy Lytvynchuk 4 years ago
parent
commit
996aa0f5c2
  1. 12
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java
  2. 4
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributes.java

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

@ -31,7 +31,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType;
import org.thingsboard.server.common.transport.adaptor.JsonConverter; import org.thingsboard.server.common.transport.adaptor.JsonConverter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.List;
@Slf4j @Slf4j
@RuleNode( @RuleNode(
@ -39,7 +39,9 @@ import java.util.Set;
name = "save attributes", name = "save attributes",
configClazz = TbMsgAttributesNodeConfiguration.class, configClazz = TbMsgAttributesNodeConfiguration.class,
nodeDescription = "Saves attributes data", nodeDescription = "Saves attributes data",
nodeDetails = "Saves entity attributes based on configurable scope parameter. Expects messages with 'POST_ATTRIBUTES_REQUEST' message type", nodeDetails = "Saves entity attributes based on configurable scope parameter. Expects messages with 'POST_ATTRIBUTES_REQUEST' message type. " +
"If upsert(update/insert) operation is completed successfully, rule node will send the \"Attributes Updated\" " +
"event to the root chain of the message originator and send the incoming message via <b>Success</b> chain, otherwise, <b>Failure</b> chain is used.",
uiResources = {"static/rulenode/rulenode-core-config.js"}, uiResources = {"static/rulenode/rulenode-core-config.js"},
configDirective = "tbActionNodeAttributesConfig", configDirective = "tbActionNodeAttributesConfig",
icon = "file_upload" icon = "file_upload"
@ -63,15 +65,15 @@ public class TbMsgAttributesNode implements TbNode {
return; return;
} }
String src = msg.getData(); String src = msg.getData();
Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src)); List<AttributeKvEntry> attributes = new ArrayList<>(JsonConverter.convertToAttributes(new JsonParser().parse(src)));
String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice"); String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice");
ctx.getTelemetryService().saveAndNotify( ctx.getTelemetryService().saveAndNotify(
ctx.getTenantId(), ctx.getTenantId(),
msg.getOriginator(), msg.getOriginator(),
config.getScope(), config.getScope(),
new ArrayList<>(attributes), attributes,
config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr), config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr),
new TelemetryNodeCallback(ctx, msg) new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes)
); );
} }

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

@ -37,7 +37,9 @@ import java.util.stream.Collectors;
configClazz = TbMsgDeleteAttributesConfiguration.class, configClazz = TbMsgDeleteAttributesConfiguration.class,
nodeDescription = "Delete attributes for Message Originator.", nodeDescription = "Delete attributes for Message Originator.",
nodeDetails = "Attempt to remove attributes by selected keys. If msg originator doesn't have an attribute with " + nodeDetails = "Attempt to remove attributes by selected keys. If msg originator doesn't have an attribute with " +
" a key selected in the configuration, it will be ignored.", " a key selected in the configuration, it will be ignored. If delete operation is completed successfully, " +
" rule node will send the \"Attributes Deleted\" event to the root chain of the message originator and " +
" send the incoming message via <b>Success</b> chain, otherwise, <b>Failure</b> chain is used.",
uiResources = {"static/rulenode/rulenode-core-config.js"}, uiResources = {"static/rulenode/rulenode-core-config.js"},
configDirective = "tbActionNodeDeleteAttributesConfig", configDirective = "tbActionNodeDeleteAttributesConfig",
icon = "remove_circle" icon = "remove_circle"

Loading…
Cancel
Save