Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Updated consoles to send null for Location attribute when leaving geofence

Michael Rademakerf01845d29669
diff --git a/console/android/src/main/AndroidManifest.xml b/console/android/src/main/AndroidManifest.xml
index f6c532323..45d4416ee 100644
--- a/console/android/src/main/AndroidManifest.xml
+++ b/console/android/src/main/AndroidManifest.xml
@@ -21,7 +21,7 @@
See README(https://goo.gl/l4GJaQ) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
- android:resource="@drawable/ic_launcher"/>
+ android:resource="@drawable/ic_notification"/>
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
diff --git a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
index 4845235bf..280cbbc20 100644
--- a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
+++ b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt
@@ -28,7 +28,7 @@ class GeofenceProvider(val activity: Activity) {
val baseUrlKey = "baseUrl"
val consoleIdKey = "consoleId"
val geoPostUrlsKey = "geoPostUrls"
- var geoPostUrls = hashMapOf<String, String>()
+ var geoPostUrls = hashMapOf<String, List<String>>()
var locationReponseCode = 101
}
@@ -40,7 +40,7 @@ class GeofenceProvider(val activity: Activity) {
lateinit var geofencingClient: GeofencingClient
private val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent("org.openremote.android.geofence.ACTION_RECEIVE")
- intent.putExtra(consoleIdKey, consoleId)
+ intent.putExtra(baseUrlKey, baseURL)
// We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
// addGeofences() and removeGeofences().
PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
@@ -57,7 +57,7 @@ class GeofenceProvider(val activity: Activity) {
try {
val file = File(activity.getDir("data", MODE_PRIVATE), geoPostUrlsKey)
inputStream = ObjectInputStream(FileInputStream(file))
- geoPostUrls = inputStream.readObject() as? HashMap<String, String> ?: hashMapOf()
+ geoPostUrls = inputStream.readObject() as? HashMap<String, List<String>> ?: hashMapOf()
} catch (e: Exception) {
geoPostUrls = hashMapOf()
} finally {
@@ -139,7 +139,7 @@ class GeofenceProvider(val activity: Activity) {
geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent).run {
addOnSuccessListener {
Log.i("GeofenceProvider", "Geofence added: lat${geofenceDefinition.lat}/lng${geofenceDefinition.lng}/rad${geofenceDefinition.radius}")
- geoPostUrls.put(geofenceDefinition.id, geofenceDefinition.postUrl)
+ geoPostUrls.put(geofenceDefinition.id, listOf(geofenceDefinition.httpMethod, geofenceDefinition.url))
}
addOnFailureListener { exception ->
@@ -157,13 +157,15 @@ class GeofenceProvider(val activity: Activity) {
}
fun clearAllRegions() {
- geofencingClient.removeGeofences(geoPostUrls.keys.toList()).run {
- addOnSuccessListener {
- Log.i("GeofenceProvider", "Geofences removed")
- }
+ if(geoPostUrls.keys.any()) {
+ geofencingClient.removeGeofences(geoPostUrls.keys.toList()).run {
+ addOnSuccessListener {
+ Log.i("GeofenceProvider", "Geofences removed")
+ }
- addOnFailureListener { exception ->
- Log.e("GeofenceProvider", exception.message, exception)
+ addOnFailureListener { exception ->
+ Log.e("GeofenceProvider", exception.message, exception)
+ }
}
}
geoPostUrls = hashMapOf()
@@ -182,7 +184,7 @@ class GeofenceProvider(val activity: Activity) {
Log.i("fetchGeofences", "${geofences.size} geofences")
geofences.forEach {
addGeofence(it)
- geoPostUrls[it.id] = it.postUrl
+ geoPostUrls[it.id] = listOf(it.httpMethod, it.url)
}
val file = File(activity.getDir("data", MODE_PRIVATE), geoPostUrlsKey)
val outputStream = ObjectOutputStream(FileOutputStream(file))
@@ -196,7 +198,8 @@ class GeofenceProvider(val activity: Activity) {
var lat: Double = 0.0
var lng: Double = 0.0
var radius: Float = 0.0F
- var postUrl: String = ""
+ var httpMethod: String = ""
+ var url: String = ""
}
class LocationService : Service() {
@@ -231,7 +234,7 @@ class GeofenceProvider(val activity: Activity) {
}
val notification = notificationBuilder.setOngoing(true)
- .setSmallIcon(R.drawable.ic_launcher)
+ .setSmallIcon(R.drawable.ic_notification)
.setCategory(Notification.CATEGORY_SERVICE)
.setContentTitle("Tracking location")
.build()
diff --git a/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt b/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt
index 616d72f7e..815ddafd3 100644
--- a/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt
+++ b/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt
@@ -7,10 +7,8 @@ import android.util.Log
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingEvent
-import org.openremote.android.R
-import retrofit2.Retrofit
-import retrofit2.converter.jackson.JacksonConverterFactory
-import retrofit2.converter.scalars.ScalarsConverterFactory
+import java.net.HttpURLConnection
+import java.net.URL
import java.util.logging.Logger
class GeofenceTransitionsIntentService : BroadcastReceiver() {
@@ -27,39 +25,48 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {
LOG.fine("Geofence '" + geofencingEvent.geofenceTransition + "' occurred")
- val consoleId = intent!!.getStringExtra(GeofenceProvider.consoleIdKey)
+ val baseUrl = intent!!.getStringExtra(GeofenceProvider.baseUrlKey)
val geofenceTransition = geofencingEvent.geofenceTransition
+ val geofence = geofencingEvent.triggeringGeofences.first()
+ GeofenceProvider.geoPostUrls[geofence.requestId]?.let { data ->
- val postJson = when (geofenceTransition) {
- Geofence.GEOFENCE_TRANSITION_ENTER -> {
- hashMapOf(
- "type" to "Point",
- "coordinates" to arrayOf(geofencingEvent.triggeringLocation.longitude, geofencingEvent.triggeringLocation.latitude)
- )
- }
- else -> {
- hashMapOf(
- "type" to "Point",
- "coordinates" to arrayOf(0, 0)
- )
+ val url = URL("$baseUrl${data[1]}")
+ val connection = url.openConnection() as HttpURLConnection
+ connection.setRequestProperty("Content-Type", "application/json")
+ connection.requestMethod = data[0]
+ connection.connectTimeout = 10000
+ connection.doInput = false
+
+ val postJson = when (geofenceTransition) {
+ Geofence.GEOFENCE_TRANSITION_ENTER -> {
+ hashMapOf(
+ "type" to "Point",
+ "coordinates" to arrayOf(geofencingEvent.triggeringLocation.longitude, geofencingEvent.triggeringLocation.latitude)
+ )
+ }
+ else -> {
+ null
+ }
}
- }
- Thread({
- try {
- val restApiResource = Retrofit.Builder()
- .baseUrl(context?.getString(R.string.OR_BASE_SERVER))
- .addConverterFactory(ScalarsConverterFactory.create())
- .addConverterFactory(JacksonConverterFactory.create())
- .build().create(RestApiResource::class.java);
+ Thread({
+ try {
+ connection.doOutput = true
+ connection.setChunkedStreamingMode(0)
+ connection.outputStream
+ ObjectMapper().writeValue(connection.outputStream, postJson)
- val response = restApiResource
- .updateAssetAction(context?.getString(R.string.OR_REALM), null, consoleId, "location", ObjectMapper().writeValueAsString(postJson))
- .execute()
- Log.i("Geofence", "Location posted to server: response=" + response.code());
- } catch (exception: Exception) {
- Log.e("Geofence", exception.message, exception)
- }
- }).start()
+ connection.outputStream.flush()
+ val responseCode = connection.responseCode
+ Log.i("Geofence", "Location posted to server: response=" + responseCode)
+
+ } catch (exception: Exception) {
+ Log.e("Geofence", exception.message, exception)
+ print(exception)
+ } finally {
+ connection.disconnect()
+ }
+ }).start()
+ }
}
}
\ No newline at end of file
diff --git a/console/android/src/main/res/drawable-hdpi/ic_launcher.png b/console/android/src/main/res/drawable-hdpi/ic_launcher.png
deleted file mode 100644
index 417e9cf46..000000000
Binary files a/console/android/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ
diff --git a/console/android/src/main/res/drawable-mdpi/ic_launcher.png b/console/android/src/main/res/drawable-mdpi/ic_launcher.png
deleted file mode 100644
index fd5a4282b..000000000
Binary files a/console/android/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ
diff --git a/console/android/src/main/res/drawable-xhdpi/ic_launcher.png b/console/android/src/main/res/drawable-xhdpi/ic_launcher.png
deleted file mode 100644
index 9a563a433..000000000
Binary files a/console/android/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/console/android/src/main/res/drawable-xxhdpi/ic_launcher.png b/console/android/src/main/res/drawable-xxhdpi/ic_launcher.png
deleted file mode 100644
index e9b08914a..000000000
Binary files a/console/android/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/console/android/src/main/res/drawable-xxxhdpi/ic_launcher.png b/console/android/src/main/res/drawable-xxxhdpi/ic_launcher.png
deleted file mode 100644
index e0107cd52..000000000
Binary files a/console/android/src/main/res/drawable-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/console/android/src/main/res/drawable/app_icon.xml b/console/android/src/main/res/drawable/app_icon.xml
index 244402910..37d07f447 100644
--- a/console/android/src/main/res/drawable/app_icon.xml
+++ b/console/android/src/main/res/drawable/app_icon.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/ic_launcher">
+ android:src="@drawable/ic_notification">
</bitmap>
\ No newline at end of file
diff --git a/console/android/src/main/res/drawable/notification_icon.xml b/console/android/src/main/res/drawable/notification_icon.xml
index 244402910..37d07f447 100644
--- a/console/android/src/main/res/drawable/notification_icon.xml
+++ b/console/android/src/main/res/drawable/notification_icon.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/ic_launcher">
+ android:src="@drawable/ic_notification">
</bitmap>
\ No newline at end of file
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
index 4d219da67..1b3e899e8 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -350,7 +350,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
AssetModel.getAttributeDescriptor(oldAttribute.name).ifPresent(wellKnownAttribute -> {
// Check if the value is valid
wellKnownAttribute.getValueType()
- .isValidValue(event.getValue().orElseThrow(() -> new AssetProcessingException(INVALID_VALUE_FOR_WELL_KNOWN_ATTRIBUTE)))
+ .isValidValue(event.getValue().orElse(null))
.ifPresent(validationFailure -> {
throw new AssetProcessingException(
INVALID_VALUE_FOR_WELL_KNOWN_ATTRIBUTE
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index a748caebf..8b732f50e 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -27,11 +27,12 @@ import org.openremote.model.Constants;
import org.openremote.model.asset.*;
import org.openremote.model.asset.BaseAssetQuery.Select;
import org.openremote.model.attribute.*;
-import org.openremote.model.geo.GeoJSONPoint;
import org.openremote.model.http.RequestParams;
import org.openremote.model.security.Tenant;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.value.*;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueException;
+import org.openremote.model.value.Values;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
@@ -371,7 +372,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
Map<String, Object> headers = new HashMap<>();
headers.put(AttributeEvent.HEADER_SOURCE, CLIENT);
//TODO needed for anonymous?
- if(isAuthenticated()) {
+ if (isAuthenticated()) {
headers.put(Constants.AUTH_CONTEXT, getAuthContext());
}
Object result = messageBrokerService.getProducerTemplate().requestBodyAndHeaders(
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
index 8b10e209e..82f3601c2 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
@@ -57,8 +57,8 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
private static final Logger LOG = Logger.getLogger(ORConsoleGeofenceAssetAdapter.class.getName());
public static final String NAME = "ORConsole";
- //TODO not needed anymore? We use writeAttributeValue now
- public static final String LOCATION_URL_FORMAT_TEMPLATE = "/asset/%1$s/location";
+ public static final String HTTP_METHOD = "PUT";
+ public static final String LOCATION_URL_FORMAT_TEMPLATE = "/asset/%1$s/attribute/location";
protected Map<String, RulesEngine.AssetStateLocationPredicates> assetLocationPredicatesMap = new HashMap<>();
protected NotificationService notificationService;
protected AssetStorageService assetStorageService;
@@ -188,13 +188,14 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
protected GeofenceDefinition locationPredicateToGeofenceDefinition(String assetId, BaseAssetQuery.LocationPredicate locationPredicate) {
BaseAssetQuery.RadialLocationPredicate radialLocationPredicate = (BaseAssetQuery.RadialLocationPredicate) locationPredicate;
String id = assetId + "_" + Integer.toString(radialLocationPredicate.hashCode());
- String postUrl = String.format(LOCATION_URL_FORMAT_TEMPLATE,
+ String url = String.format(LOCATION_URL_FORMAT_TEMPLATE,
assetId);
return new GeofenceDefinition(id,
radialLocationPredicate.getLat(),
radialLocationPredicate.getLng(),
radialLocationPredicate.getRadius(),
- postUrl);
+ HTTP_METHOD,
+ url);
}
protected void notifyAssetGeofencesChanged(String assetId) {
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
index 5778a7ae9..f232766f9 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -229,13 +229,7 @@ public enum AttributeValueType {
new MetaItem(FORMAT, Values.create("%0.1f deg"))
),
- GEO_JSON_POINT("map-marker", ValueType.OBJECT, value -> {
- if (value != null && !GeoJSONPoint.fromValue(value).isPresent()) {
- return Optional.of(new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID));
- }
-
- return Optional.empty();
- });
+ GEO_JSON_POINT("map-marker", ValueType.OBJECT, value -> Optional.empty());
public static final String DEFAULT_ICON = "circle-thin";
diff --git a/model/src/main/java/org/openremote/model/rules/geofence/GeofenceDefinition.java b/model/src/main/java/org/openremote/model/rules/geofence/GeofenceDefinition.java
index adbf4583b..01a2b4ec1 100644
--- a/model/src/main/java/org/openremote/model/rules/geofence/GeofenceDefinition.java
+++ b/model/src/main/java/org/openremote/model/rules/geofence/GeofenceDefinition.java
@@ -25,14 +25,16 @@ public class GeofenceDefinition {
protected double lat;
protected double lng;
protected int radius;
- protected String postUrl;
+ protected String httpMethod;
+ protected String url;
- public GeofenceDefinition(String id, double lat, double lng, int radius, String postUrl) {
+ public GeofenceDefinition(String id, double lat, double lng, int radius, String httpMethod, String url) {
this.id = id;
this.lat = lat;
this.lng = lng;
this.radius = radius;
- this.postUrl = postUrl;
+ this.httpMethod = httpMethod;
+ this.url = url;
}
public String getId() {
@@ -51,7 +53,11 @@ public class GeofenceDefinition {
return radius;
}
- public String getPostUrl() {
- return postUrl;
+ public String getHttpMethod() {
+ return httpMethod;
+ }
+
+ public String getUrl() {
+ return url;
}
}
diff --git a/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java b/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
index c731b07bc..473325be7 100644
--- a/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
+++ b/model/src/main/java/org/openremote/model/syslog/SyslogCategory.java
@@ -39,7 +39,8 @@ public enum SyslogCategory {
NOTIFICATION(
"Notification",
false,
- "NotificationService"
+ "NotificationService",
+ "FCMDeliveryService"
),
RULES(
"Rules",
diff --git a/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy
index d1448640f..bfdf6cdc6 100644
--- a/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/geofence/BasicGeofenceProcessingTest.groovy
@@ -71,7 +71,7 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
assert geofences[0].lat == 50
assert geofences[0].lng == 100
assert geofences[0].id == managerDemoSetup.consoleId + "_-174661203"
- assert geofences[0].postUrl == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"
+ assert geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"
}
when: "another console asset is added with its location attribute marked as RULE_STATE and it has a CONSOLE_PROVIDER_GEOFENCE attribute"
@@ -109,7 +109,7 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
assert geofences[0].lat == 50
assert geofences[0].lng == 100
assert geofences[0].id == console2Id + "_-174661203"
- assert geofences[0].postUrl == "/master/asset/public/${console2Id}/updateLocation"
+ assert geofences[0].url == "/master/asset/public/${console2Id}/updateLocation"
}
when: "a new ruleset is deployed with multiple location predicate rules (including a duplicate and a rectangular predicate) on the lobby asset"
@@ -143,14 +143,14 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
assert console1Geofences[0].lat == 50
assert console1Geofences[0].lng == 100
assert console1Geofences[0].id == managerDemoSetup.consoleId + "_-174661203"
- assert console1Geofences[0].postUrl == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"
+ assert console1Geofences[0].url == "/master/asset/public/${managerDemoSetup.consoleId}/updateLocation"
def console2Geofence1 = console2Geofences.find {
it.radius == 100 &&
it.lat == 50 &&
it.lng == 100 &&
it.id == console2Id + "_-174661203" &&
- it.postUrl == "/master/asset/public/${console2Id}/updateLocation"
+ it.url == "/master/asset/public/${console2Id}/updateLocation"
}
assert console2Geofence1 != null
@@ -159,7 +159,7 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
it.lat == 0 &&
it.lng == -60 &&
it.id == console2Id + "_-1397479941" &&
- it.postUrl == "/master/asset/public/${console2Id}/updateLocation"
+ it.url == "/master/asset/public/${console2Id}/updateLocation"
}
assert console2Geofence2 != null
}
@@ -179,7 +179,7 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
it.lat == 50 &&
it.lng == 100 &&
it.id == console2Id + "_-174661203" &&
- it.postUrl == "/master/asset/public/${console2Id}/updateLocation"
+ it.url == "/master/asset/public/${console2Id}/updateLocation"
}
assert console2Geofence1 != null
@@ -188,7 +188,7 @@ class BasicGeofenceProcessingTest extends Specification implements ManagerContai
it.lat == 0 &&
it.lng == -60 &&
it.id == console2Id + "_-1397479941" &&
- it.postUrl == "/master/asset/public/${console2Id}/updateLocation"
+ it.url == "/master/asset/public/${console2Id}/updateLocation"
}
assert console2Geofence2 != null
}