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 {
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();

View File

@ -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<TbGpsGeofencingActionNodeConfiguration> {
private final Map<EntityId, EntityGeofencingState> entityStates = new HashMap<>();
@ -81,7 +83,8 @@ public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofe
ctx.tellNext(msg, matches ? "Entered" : "Left");
} else if (!entityState.isStayed()) {
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);
ctx.tellNext(msg, entityState.isInside() ? "Inside" : "Outside");
}

View File

@ -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;
}
}

View File

@ -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<TbGpsGeofencingFilterNodeConfiguration> {
@Override

View File

@ -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;
}
}