You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by mi...@apache.org on 2020/05/16 16:27:48 UTC
[incubator-streampipes-extensions] 03/03: adding range check for
user input lat lng values
This is an automated email from the ASF dual-hosted git repository.
micklich pushed a commit to branch feature/geodesicCalc
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
commit 4a5f08797cb0f65d62b620105fba0e7d54ea5434
Author: micklich <fl...@disy.net>
AuthorDate: Sat May 16 18:27:24 2020 +0200
adding range check for user input lat lng values
---
.../StaticDistanceCalculator.java | 29 +++++++++++++++++-----
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
index 0b5eca8..d0e95a4 100644
--- a/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
+++ b/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/processor/staticdistancecalculator/StaticDistanceCalculator.java
@@ -17,14 +17,19 @@
package org.apache.streampipes.processors.geo.jvm.processor.staticdistancecalculator;
import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.logging.api.Logger;
import org.apache.streampipes.model.runtime.Event;
import org.apache.streampipes.processors.geo.jvm.processor.util.SpLengthCalculator;
import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
import org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;
+import org.apache.streampipes.processors.geo.jvm.jts.helper.SpGeometryBuilder;
+
public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCalculatorParameters> {
+ private static Logger LOG;
+
private String latitudeFieldName;
private String longitudeFieldName;
@@ -37,6 +42,8 @@ public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCa
@Override
public void onInvocation(StaticDistanceCalculatorParameters parameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
+ LOG = parameters.getGraph().getLogger(StaticDistanceCalculatorParameters.class);
+
this.latitudeFieldName = parameters.getLatitudeFieldName();
this.longitudeFieldName = parameters.getLongitudeFieldName();
@@ -53,16 +60,26 @@ public class StaticDistanceCalculator implements EventProcessor<StaticDistanceCa
Double latitude = event.getFieldBySelector(latitudeFieldName).getAsPrimitive().getAsDouble();
Double longitude = event.getFieldBySelector(longitudeFieldName).getAsPrimitive().getAsDouble();
- staticLength.calcGeodesicDistance(latitude, longitude, selectedLocationLatitude, selectedLocationLongitude);
+ if ((SpGeometryBuilder.isInWGSCoordinateRange(latitude, -90, 90))
+ && (SpGeometryBuilder.isInWGSCoordinateRange(longitude, -180, 180))) {
+
+ staticLength.calcGeodesicDistance(latitude, longitude, selectedLocationLatitude, selectedLocationLongitude);
+
+ if (unit != 1) {
+ staticLength.convertUnit(unit);
+ }
+
+ event.addField(StaticDistanceCalculatorController.LENGTH_RUNTIME, staticLength.getLengthValueRoundet());
+ event.addField(StaticDistanceCalculatorController.UNIT_RUNTIME, staticLength.getLengthUnit());
- if (unit != 1) {
- staticLength.convertUnit(unit);
+ collector.collect(event);
+ } else {
+ //todo how to handle error visible to the user
+ LOG.error("User Longitude and Latitude value are out of Range. "
+ + latitude + ": allowed -90 and 90)" + longitude + ": allowed -180 and 180)" );
}
- event.addField(StaticDistanceCalculatorController.LENGTH_RUNTIME, staticLength.getLengthValueRoundet());
- event.addField(StaticDistanceCalculatorController.UNIT_RUNTIME, staticLength.getLengthUnit());
- collector.collect(event);
}
@Override