Commit 0a668d0a6f61ec2f46e8f22412886c6e6057c37a

Authored by ShvaykaD
Committed by Andrew Shvayka
1 parent 42d2f0be

add time-units to ActionNode and UI

@@ -78,7 +78,7 @@ public abstract class AbstractGeofencingNode<T extends TbGpsGeofencingFilterNode @@ -78,7 +78,7 @@ public abstract class AbstractGeofencingNode<T extends TbGpsGeofencingFilterNode
78 } 78 }
79 79
80 protected List<Perimeter> getPerimeters(TbMsg msg, JsonObject msgDataObj) throws TbNodeException { 80 protected List<Perimeter> getPerimeters(TbMsg msg, JsonObject msgDataObj) throws TbNodeException {
81 - if (config.isFetchPerimeterInfoFromMessage()) { 81 + if (config.isFetchPerimeterInfoFromMessageMetadata()) {
82 //TODO: add fetching perimeters from the message itself, if configuration is empty. 82 //TODO: add fetching perimeters from the message itself, if configuration is empty.
83 if (!StringUtils.isEmpty(msg.getMetaData().getValue("perimeter"))) { 83 if (!StringUtils.isEmpty(msg.getMetaData().getValue("perimeter"))) {
84 Perimeter perimeter = new Perimeter(); 84 Perimeter perimeter = new Perimeter();
@@ -49,7 +49,9 @@ import java.util.concurrent.TimeoutException; @@ -49,7 +49,9 @@ import java.util.concurrent.TimeoutException;
49 configClazz = TbGpsGeofencingActionNodeConfiguration.class, 49 configClazz = TbGpsGeofencingActionNodeConfiguration.class,
50 relationTypes = {"Entered", "Left", "Inside", "Outside"}, 50 relationTypes = {"Entered", "Left", "Inside", "Outside"},
51 nodeDescription = "Produces incoming messages using GPS based geofencing", 51 nodeDescription = "Produces incoming messages using GPS based geofencing",
52 - nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters") 52 + nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters",
  53 + uiResources = {"static/rulenode/rulenode-core-config.js"},
  54 + configDirective = "tbActionNodeGpsGeofencingConfig")
53 public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofencingActionNodeConfiguration> { 55 public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofencingActionNodeConfiguration> {
54 56
55 private final Map<EntityId, EntityGeofencingState> entityStates = new HashMap<>(); 57 private final Map<EntityId, EntityGeofencingState> entityStates = new HashMap<>();
@@ -81,7 +83,8 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe @@ -81,7 +83,8 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe
81 ctx.tellNext(msg, matches ? "Entered" : "Left"); 83 ctx.tellNext(msg, matches ? "Entered" : "Left");
82 } else if (!entityState.isStayed()) { 84 } else if (!entityState.isStayed()) {
83 long stayTime = ts - entityState.getStateSwitchTime(); 85 long stayTime = ts - entityState.getStateSwitchTime();
84 - if (stayTime > (entityState.isInside() ? config.getMinInsideDuration() : config.getMinOutsideDuration())) { 86 + if (stayTime > (entityState.isInside() ?
  87 + TimeUnit.valueOf(config.getMinInsideDurationTimeUnit()).toMillis(config.getMinInsideDuration()) : TimeUnit.valueOf(config.getMinOutsideDurationTimeUnit()).toMillis(config.getMinOutsideDuration()))) {
85 setStaid(ctx, msg.getOriginator(), entityState); 88 setStaid(ctx, msg.getOriginator(), entityState);
86 ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside"); 89 ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside");
87 } 90 }
@@ -28,17 +28,22 @@ import java.util.concurrent.TimeUnit; @@ -28,17 +28,22 @@ import java.util.concurrent.TimeUnit;
28 @Data 28 @Data
29 public class TbGpsGeofencingActionNodeConfiguration extends TbGpsGeofencingFilterNodeConfiguration { 29 public class TbGpsGeofencingActionNodeConfiguration extends TbGpsGeofencingFilterNodeConfiguration {
30 30
31 - private double minInsideDuration;  
32 - private double minOutsideDuration; 31 + private int minInsideDuration;
  32 + private int minOutsideDuration;
  33 +
  34 + private String minInsideDurationTimeUnit;
  35 + private String minOutsideDurationTimeUnit;
33 36
34 @Override 37 @Override
35 public TbGpsGeofencingActionNodeConfiguration defaultConfiguration() { 38 public TbGpsGeofencingActionNodeConfiguration defaultConfiguration() {
36 TbGpsGeofencingActionNodeConfiguration configuration = new TbGpsGeofencingActionNodeConfiguration(); 39 TbGpsGeofencingActionNodeConfiguration configuration = new TbGpsGeofencingActionNodeConfiguration();
37 configuration.setLatitudeKeyName("latitude"); 40 configuration.setLatitudeKeyName("latitude");
38 configuration.setLongitudeKeyName("longitude"); 41 configuration.setLongitudeKeyName("longitude");
39 - configuration.setFetchPerimeterInfoFromMessage(true);  
40 - configuration.setMinInsideDuration(TimeUnit.MINUTES.toMillis(1));  
41 - configuration.setMinOutsideDuration(TimeUnit.MINUTES.toMillis(1)); 42 + configuration.setFetchPerimeterInfoFromMessageMetadata(true);
  43 + configuration.setMinInsideDurationTimeUnit(TimeUnit.MINUTES.name());
  44 + configuration.setMinOutsideDurationTimeUnit(TimeUnit.MINUTES.name());
  45 + configuration.setMinInsideDuration(1);
  46 + configuration.setMinOutsideDuration(1);
42 return configuration; 47 return configuration;
43 } 48 }
44 } 49 }
@@ -50,7 +50,9 @@ import java.util.List; @@ -50,7 +50,9 @@ import java.util.List;
50 configClazz = TbGpsGeofencingFilterNodeConfiguration.class, 50 configClazz = TbGpsGeofencingFilterNodeConfiguration.class,
51 relationTypes = {"True", "False"}, 51 relationTypes = {"True", "False"},
52 nodeDescription = "Filter incoming messages by GPS based geofencing", 52 nodeDescription = "Filter incoming messages by GPS based geofencing",
53 - nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.") 53 + nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.",
  54 + uiResources = {"static/rulenode/rulenode-core-config.js"},
  55 + configDirective = "tbFilterNodeGpsGeofencingConfig")
54 public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode<TbGpsGeofencingFilterNodeConfiguration> { 56 public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode<TbGpsGeofencingFilterNodeConfiguration> {
55 57
56 @Override 58 @Override
@@ -32,7 +32,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration @@ -32,7 +32,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration
32 32
33 private String latitudeKeyName; 33 private String latitudeKeyName;
34 private String longitudeKeyName; 34 private String longitudeKeyName;
35 - private boolean fetchPerimeterInfoFromMessage; 35 + private boolean fetchPerimeterInfoFromMessageMetadata;
36 36
37 private PerimeterType perimeterType; 37 private PerimeterType perimeterType;
38 38
@@ -50,7 +50,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration @@ -50,7 +50,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration
50 TbGpsGeofencingFilterNodeConfiguration configuration = new TbGpsGeofencingFilterNodeConfiguration(); 50 TbGpsGeofencingFilterNodeConfiguration configuration = new TbGpsGeofencingFilterNodeConfiguration();
51 configuration.setLatitudeKeyName("latitude"); 51 configuration.setLatitudeKeyName("latitude");
52 configuration.setLongitudeKeyName("longitude"); 52 configuration.setLongitudeKeyName("longitude");
53 - configuration.setFetchPerimeterInfoFromMessage(true); 53 + configuration.setFetchPerimeterInfoFromMessageMetadata(true);
54 return configuration; 54 return configuration;
55 } 55 }
56 } 56 }