Browse Source

add comstant

pull/7243/head
Yuriy Lytvynchuk 4 years ago
parent
commit
ff89f85bd1
  1. 4
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbJsonPathNode.java
  2. 3
      rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbJsonPathNodeConfiguration.java

4
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbJsonPathNode.java

@ -57,7 +57,7 @@ public class TbJsonPathNode implements TbNode {
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbJsonPathNodeConfiguration.class); this.config = TbNodeUtils.convert(configuration, TbJsonPathNodeConfiguration.class);
this.jsonPathValue = config.getJsonPath(); this.jsonPathValue = config.getJsonPath();
if (this.jsonPathValue != "$") { if (!TbJsonPathNodeConfiguration.DEFAULT_JSON_PATH.equals(this.jsonPathValue)) {
this.configurationJsonPath = Configuration.builder() this.configurationJsonPath = Configuration.builder()
.jsonProvider(new JacksonJsonNodeJsonProvider()) .jsonProvider(new JacksonJsonNodeJsonProvider())
.build(); .build();
@ -67,7 +67,7 @@ public class TbJsonPathNode implements TbNode {
@Override @Override
public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException { public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException {
if (jsonPathValue != "$") { if (!TbJsonPathNodeConfiguration.DEFAULT_JSON_PATH.equals(this.jsonPathValue)) {
try { try {
JsonNode jsonPathData = jsonPath.read(msg.getData(), this.configurationJsonPath); JsonNode jsonPathData = jsonPath.read(msg.getData(), this.configurationJsonPath);
ctx.tellSuccess(TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), JacksonUtil.toString(jsonPathData))); ctx.tellSuccess(TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), JacksonUtil.toString(jsonPathData)));

3
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/transform/TbJsonPathNodeConfiguration.java

@ -21,12 +21,13 @@ import org.thingsboard.rule.engine.api.NodeConfiguration;
@Data @Data
public class TbJsonPathNodeConfiguration implements NodeConfiguration<TbJsonPathNodeConfiguration> { public class TbJsonPathNodeConfiguration implements NodeConfiguration<TbJsonPathNodeConfiguration> {
static final String DEFAULT_JSON_PATH = "$";
private String jsonPath; private String jsonPath;
@Override @Override
public TbJsonPathNodeConfiguration defaultConfiguration() { public TbJsonPathNodeConfiguration defaultConfiguration() {
TbJsonPathNodeConfiguration configuration = new TbJsonPathNodeConfiguration(); TbJsonPathNodeConfiguration configuration = new TbJsonPathNodeConfiguration();
configuration.setJsonPath("$"); configuration.setJsonPath(DEFAULT_JSON_PATH);
return configuration; return configuration;
} }

Loading…
Cancel
Save