From 0a668d0a6f61ec2f46e8f22412886c6e6057c37a Mon Sep 17 00:00:00 2001 From: ShvaykaD Date: Mon, 1 Apr 2019 13:22:33 +0300 Subject: [PATCH] add time-units to ActionNode and UI --- .../rule/engine/geo/AbstractGeofencingNode.java | 2 +- .../engine/geo/TbGpsGeofencingActionNode.java | 7 +++++-- .../TbGpsGeofencingActionNodeConfiguration.java | 15 ++++++++++----- .../engine/geo/TbGpsGeofencingFilterNode.java | 4 +++- .../TbGpsGeofencingFilterNodeConfiguration.java | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/AbstractGeofencingNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/AbstractGeofencingNode.java index 2aec28f08b..55cc53377b 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/AbstractGeofencingNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/AbstractGeofencingNode.java @@ -78,7 +78,7 @@ public abstract class AbstractGeofencingNode getPerimeters(TbMsg msg, JsonObject msgDataObj) throws TbNodeException { - if (config.isFetchPerimeterInfoFromMessage()) { + if (config.isFetchPerimeterInfoFromMessageMetadata()) { //TODO: add fetching perimeters from the message itself, if configuration is empty. if (!StringUtils.isEmpty(msg.getMetaData().getValue("perimeter"))) { Perimeter perimeter = new Perimeter(); diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNode.java index 26a5d55a5f..b5211b7020 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNode.java @@ -49,7 +49,9 @@ import java.util.concurrent.TimeoutException; configClazz = TbGpsGeofencingActionNodeConfiguration.class, relationTypes = {"Entered", "Left", "Inside", "Outside"}, nodeDescription = "Produces incoming messages using GPS based geofencing", - nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters") + nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters", + uiResources = {"static/rulenode/rulenode-core-config.js"}, + configDirective = "tbActionNodeGpsGeofencingConfig") public class TbGpsGeofencingActionNode extends AbstractGeofencingNode { private final Map entityStates = new HashMap<>(); @@ -81,7 +83,8 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode (entityState.isInside() ? config.getMinInsideDuration() : config.getMinOutsideDuration())) { + if (stayTime > (entityState.isInside() ? + TimeUnit.valueOf(config.getMinInsideDurationTimeUnit()).toMillis(config.getMinInsideDuration()) : TimeUnit.valueOf(config.getMinOutsideDurationTimeUnit()).toMillis(config.getMinOutsideDuration()))) { setStaid(ctx, msg.getOriginator(), entityState); ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside"); } diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNodeConfiguration.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNodeConfiguration.java index f6b275e008..ef183b6920 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNodeConfiguration.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingActionNodeConfiguration.java @@ -28,17 +28,22 @@ import java.util.concurrent.TimeUnit; @Data public class TbGpsGeofencingActionNodeConfiguration extends TbGpsGeofencingFilterNodeConfiguration { - private double minInsideDuration; - private double minOutsideDuration; + private int minInsideDuration; + private int minOutsideDuration; + + private String minInsideDurationTimeUnit; + private String minOutsideDurationTimeUnit; @Override public TbGpsGeofencingActionNodeConfiguration defaultConfiguration() { TbGpsGeofencingActionNodeConfiguration configuration = new TbGpsGeofencingActionNodeConfiguration(); configuration.setLatitudeKeyName("latitude"); configuration.setLongitudeKeyName("longitude"); - configuration.setFetchPerimeterInfoFromMessage(true); - configuration.setMinInsideDuration(TimeUnit.MINUTES.toMillis(1)); - configuration.setMinOutsideDuration(TimeUnit.MINUTES.toMillis(1)); + configuration.setFetchPerimeterInfoFromMessageMetadata(true); + configuration.setMinInsideDurationTimeUnit(TimeUnit.MINUTES.name()); + configuration.setMinOutsideDurationTimeUnit(TimeUnit.MINUTES.name()); + configuration.setMinInsideDuration(1); + configuration.setMinOutsideDuration(1); return configuration; } } diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNode.java index e816cb6cdc..ed62022edf 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNode.java @@ -50,7 +50,9 @@ import java.util.List; configClazz = TbGpsGeofencingFilterNodeConfiguration.class, relationTypes = {"True", "False"}, nodeDescription = "Filter incoming messages by GPS based geofencing", - nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.") + nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.", + uiResources = {"static/rulenode/rulenode-core-config.js"}, + configDirective = "tbFilterNodeGpsGeofencingConfig") public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode { @Override diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNodeConfiguration.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNodeConfiguration.java index ca2ac4c8d3..55957c9f1c 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNodeConfiguration.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/geo/TbGpsGeofencingFilterNodeConfiguration.java @@ -32,7 +32,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration private String latitudeKeyName; private String longitudeKeyName; - private boolean fetchPerimeterInfoFromMessage; + private boolean fetchPerimeterInfoFromMessageMetadata; private PerimeterType perimeterType; @@ -50,7 +50,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration TbGpsGeofencingFilterNodeConfiguration configuration = new TbGpsGeofencingFilterNodeConfiguration(); configuration.setLatitudeKeyName("latitude"); configuration.setLongitudeKeyName("longitude"); - configuration.setFetchPerimeterInfoFromMessage(true); + configuration.setFetchPerimeterInfoFromMessageMetadata(true); return configuration; } }