|
|
|
@ -15,6 +15,7 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.script.api.tbel; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.google.common.primitives.Bytes; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.ArrayUtils; |
|
|
|
@ -23,6 +24,10 @@ import org.mvel2.ParserConfiguration; |
|
|
|
import org.mvel2.execution.ExecutionArrayList; |
|
|
|
import org.mvel2.execution.ExecutionHashMap; |
|
|
|
import org.mvel2.util.MethodStub; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.rule.engine.geo.Coordinates; |
|
|
|
import org.thingsboard.rule.engine.geo.GeoUtil; |
|
|
|
import org.thingsboard.rule.engine.geo.RangeUnit; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
@ -371,6 +376,10 @@ public class TbUtils { |
|
|
|
byte[].class, int.class))); |
|
|
|
parserConfig.addImport("parseBinaryArrayToInt", new MethodStub(TbUtils.class.getMethod("parseBinaryArrayToInt", |
|
|
|
byte[].class, int.class, int.class))); |
|
|
|
parserConfig.addImport("isInsidePolygon", new MethodStub(TbUtils.class.getMethod("isInsidePolygon", |
|
|
|
double.class, double.class, String.class))); |
|
|
|
parserConfig.addImport("isInsideCircle", new MethodStub(TbUtils.class.getMethod("isInsideCircle", |
|
|
|
double.class, double.class, String.class))); |
|
|
|
} |
|
|
|
|
|
|
|
public static String btoa(String input) { |
|
|
|
@ -1437,6 +1446,22 @@ public class TbUtils { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static boolean isInsidePolygon(double latitude, double longitude, String perimeter) { |
|
|
|
return GeoUtil.contains(perimeter, new Coordinates(latitude, longitude)); |
|
|
|
} |
|
|
|
|
|
|
|
public static boolean isInsideCircle(double latitude, double longitude, String perimeter) { |
|
|
|
JsonNode perimeterJson = JacksonUtil.toJsonNode(perimeter); |
|
|
|
double centerLatitude = Double.parseDouble(perimeterJson.get("latitude").asText()); |
|
|
|
double centerLongitude = Double.parseDouble(perimeterJson.get("longitude").asText()); |
|
|
|
double range = Double.parseDouble(perimeterJson.get("radius").asText()); |
|
|
|
RangeUnit rangeUnit = perimeterJson.has("radiusUnit") ? RangeUnit.valueOf(perimeterJson.get("radiusUnit").asText()) : RangeUnit.METER; |
|
|
|
|
|
|
|
Coordinates entityCoordinates = new Coordinates(latitude, longitude); |
|
|
|
Coordinates perimeterCoordinates = new Coordinates(centerLatitude, centerLongitude); |
|
|
|
return range > GeoUtil.distance(entityCoordinates, perimeterCoordinates, rangeUnit); |
|
|
|
} |
|
|
|
|
|
|
|
private static byte isValidIntegerToByte(Integer val) { |
|
|
|
if (val > 255 || val < -128) { |
|
|
|
throw new NumberFormatException("The value '" + val + "' could not be correctly converted to a byte. " + |
|
|
|
|