add time-units to ActionNode and UI

This commit is contained in:
ShvaykaD 2019-04-01 13:22:33 +03:00 committed by Andrew Shvayka
parent 42d2f0be10
commit 0a668d0a6f
5 changed files with 21 additions and 11 deletions

View File

@ -78,7 +78,7 @@ public abstract class AbstractGeofencingNode<T extends TbGpsGeofencingFilterNode
} }
protected List<Perimeter> getPerimeters(TbMsg msg, JsonObject msgDataObj) throws TbNodeException { protected List<Perimeter> 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. //TODO: add fetching perimeters from the message itself, if configuration is empty.
if (!StringUtils.isEmpty(msg.getMetaData().getValue("perimeter"))) { if (!StringUtils.isEmpty(msg.getMetaData().getValue("perimeter"))) {
Perimeter perimeter = new Perimeter(); Perimeter perimeter = new Perimeter();

View File

@ -49,7 +49,9 @@ import java.util.concurrent.TimeoutException;
configClazz = TbGpsGeofencingActionNodeConfiguration.class, configClazz = TbGpsGeofencingActionNodeConfiguration.class,
relationTypes = {"Entered", "Left", "Inside", "Outside"}, relationTypes = {"Entered", "Left", "Inside", "Outside"},
nodeDescription = "Produces incoming messages using GPS based geofencing", 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<TbGpsGeofencingActionNodeConfiguration> { public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofencingActionNodeConfiguration> {
private final Map<EntityId, EntityGeofencingState> entityStates = new HashMap<>(); private final Map<EntityId, EntityGeofencingState> entityStates = new HashMap<>();
@ -81,7 +83,8 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe
ctx.tellNext(msg, matches ? "Entered" : "Left"); ctx.tellNext(msg, matches ? "Entered" : "Left");
} else if (!entityState.isStayed()) { } else if (!entityState.isStayed()) {
long stayTime = ts - entityState.getStateSwitchTime(); long stayTime = ts - entityState.getStateSwitchTime();
if (stayTime > (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); setStaid(ctx, msg.getOriginator(), entityState);
ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside"); ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside");
} }

View File

@ -28,17 +28,22 @@ import java.util.concurrent.TimeUnit;
@Data @Data
public class TbGpsGeofencingActionNodeConfiguration extends TbGpsGeofencingFilterNodeConfiguration { public class TbGpsGeofencingActionNodeConfiguration extends TbGpsGeofencingFilterNodeConfiguration {
private double minInsideDuration; private int minInsideDuration;
private double minOutsideDuration; private int minOutsideDuration;
private String minInsideDurationTimeUnit;
private String minOutsideDurationTimeUnit;
@Override @Override
public TbGpsGeofencingActionNodeConfiguration defaultConfiguration() { public TbGpsGeofencingActionNodeConfiguration defaultConfiguration() {
TbGpsGeofencingActionNodeConfiguration configuration = new TbGpsGeofencingActionNodeConfiguration(); TbGpsGeofencingActionNodeConfiguration configuration = new TbGpsGeofencingActionNodeConfiguration();
configuration.setLatitudeKeyName("latitude"); configuration.setLatitudeKeyName("latitude");
configuration.setLongitudeKeyName("longitude"); configuration.setLongitudeKeyName("longitude");
configuration.setFetchPerimeterInfoFromMessage(true); configuration.setFetchPerimeterInfoFromMessageMetadata(true);
configuration.setMinInsideDuration(TimeUnit.MINUTES.toMillis(1)); configuration.setMinInsideDurationTimeUnit(TimeUnit.MINUTES.name());
configuration.setMinOutsideDuration(TimeUnit.MINUTES.toMillis(1)); configuration.setMinOutsideDurationTimeUnit(TimeUnit.MINUTES.name());
configuration.setMinInsideDuration(1);
configuration.setMinOutsideDuration(1);
return configuration; return configuration;
} }
} }

View File

@ -50,7 +50,9 @@ import java.util.List;
configClazz = TbGpsGeofencingFilterNodeConfiguration.class, configClazz = TbGpsGeofencingFilterNodeConfiguration.class,
relationTypes = {"True", "False"}, relationTypes = {"True", "False"},
nodeDescription = "Filter incoming messages by GPS based geofencing", 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<TbGpsGeofencingFilterNodeConfiguration> { public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode<TbGpsGeofencingFilterNodeConfiguration> {
@Override @Override

View File

@ -32,7 +32,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration
private String latitudeKeyName; private String latitudeKeyName;
private String longitudeKeyName; private String longitudeKeyName;
private boolean fetchPerimeterInfoFromMessage; private boolean fetchPerimeterInfoFromMessageMetadata;
private PerimeterType perimeterType; private PerimeterType perimeterType;
@ -50,7 +50,7 @@ public class TbGpsGeofencingFilterNodeConfiguration implements NodeConfiguration
TbGpsGeofencingFilterNodeConfiguration configuration = new TbGpsGeofencingFilterNodeConfiguration(); TbGpsGeofencingFilterNodeConfiguration configuration = new TbGpsGeofencingFilterNodeConfiguration();
configuration.setLatitudeKeyName("latitude"); configuration.setLatitudeKeyName("latitude");
configuration.setLongitudeKeyName("longitude"); configuration.setLongitudeKeyName("longitude");
configuration.setFetchPerimeterInfoFromMessage(true); configuration.setFetchPerimeterInfoFromMessageMetadata(true);
return configuration; return configuration;
} }
} }