Skip to content

armgit / core

Public Imported from GitHub
0

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

Fixed problem with lat long in Asset. Fixed Console groovy files

Michael Rademaker0f592d0c638a
diff --git a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
index 9c8ce07e2..84b15e0e0 100644
--- a/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
+++ b/console/iOS/ORLib/ORLib.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 4C31CE9F20AD80860073FA97 /* GeofenceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */; };
4C4C2FB81FD8044A0071CBDA /* ORNotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */; };
4C82D73F1FC58ED2009DE853 /* ORLib.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C82D73D1FC58ED2009DE853 /* ORLib.h */; settings = {ATTRIBUTES = (Public, ); }; };
4C82D74A1FC58F4E009DE853 /* ORViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C82D7451FC58F4E009DE853 /* ORViewController.swift */; };
@@ -21,6 +22,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeofenceProvider.swift; sourceTree = "<group>"; };
4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ORNotificationService.swift; sourceTree = "<group>"; };
4C82D73A1FC58ED2009DE853 /* ORLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ORLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C82D73D1FC58ED2009DE853 /* ORLib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ORLib.h; sourceTree = "<group>"; };
@@ -82,6 +84,7 @@
4C82D73D1FC58ED2009DE853 /* ORLib.h */,
4C82D73E1FC58ED2009DE853 /* Info.plist */,
4C4C2FB71FD8044A0071CBDA /* ORNotificationService.swift */,
+ 4C31CE9E20AD80860073FA97 /* GeofenceProvider.swift */,
);
path = ORLib;
sourceTree = "<group>";
@@ -221,6 +224,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4C31CE9F20AD80860073FA97 /* GeofenceProvider.swift in Sources */,
4C4C2FB81FD8044A0071CBDA /* ORNotificationService.swift in Sources */,
4C82D7581FC590FB009DE853 /* ErrorManager.swift in Sources */,
4C82D74E1FC58F4E009DE853 /* ORLoginViewController.swift in Sources */,
diff --git a/console/iOS/ORLib/ORLib.xcodeproj/project.xcworkspace/xcuserdata/michael.xcuserdatad/UserInterfaceState.xcuserstate b/console/iOS/ORLib/ORLib.xcodeproj/project.xcworkspace/xcuserdata/michael.xcuserdatad/UserInterfaceState.xcuserstate
index 5629158f3..c96bbd4d1 100644
Binary files a/console/iOS/ORLib/ORLib.xcodeproj/project.xcworkspace/xcuserdata/michael.xcuserdatad/UserInterfaceState.xcuserstate and b/console/iOS/ORLib/ORLib.xcodeproj/project.xcworkspace/xcuserdata/michael.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/console/iOS/ORLib/ORLib/GeofenceProvider.swift b/console/iOS/ORLib/ORLib/GeofenceProvider.swift
new file mode 100644
index 000000000..bec75d573
--- /dev/null
+++ b/console/iOS/ORLib/ORLib/GeofenceProvider.swift
@@ -0,0 +1,99 @@
+//
+// GeofenceProvider.swift
+// ORLib
+//
+// Created by Michael Rademaker on 17/05/2018.
+// Copyright © 2018 Open Remote Inc. All rights reserved.
+//
+
+import UIKit
+import CoreLocation
+
+class GeofenceProvider: NSObject {
+
+ let providerKey = "geofence"
+ let locationManager = CLLocationManager()
+
+ public var consoleId: String
+
+ public func checkPermission() -> Bool {
+ if CLLocationManager.locationServicesEnabled() {
+ if CLLocationManager.authorizationStatus() == .authorizedAlways{
+ return true
+ }
+ }
+ return false
+ }
+
+ public func clearAllRegions() {
+ for region in locationManager.monitoredRegions {
+ locationManager.stopMonitoring(for: region)
+ }
+ }
+
+ public func registerPermissions() {
+ locationManager.requestAlwaysAuthorization()
+ }
+
+ public func addGeofence(geofence: GeofenceDefinition) {
+ locationManager.startMonitoring(for: geofence)
+ }
+
+ public func removeGeofence(id: String) {
+ for region in locationManager.monitoredRegions {
+ guard let circularRegion = region as? GeofenceDefinition, circularRegion.identifier == id else {continue}
+ locationManager.stopMonitoring(for: circularRegion)
+ break
+ }
+ }
+
+ public func enable(callback: @escaping (AccesTokenResult<String>) -> ()) {
+ guard let tkurlRequest = URL(string: String(format:"\(ORServer.scheme)://%@/auth/realms/%@/protocol/openid-connect/token", ORServer.hostURL, ORServer.realm)) else { return }
+ let tkRequest = NSMutableURLRequest(url: tkurlRequest)
+ tkRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField:"Content-Type");
+ tkRequest.httpMethod = "POST"
+
+ let postData = [
+ "action":"PROVIDER_ENABLE",
+ "provider": providerKey,
+ "data": [
+ "baseUrl":String(format:"\(ORServer.scheme)://%@/", ORServer.hostURL),
+ "consoleId": consoleId
+ ]
+ ]
+
+ tkRequest.httpBody = JSONSerialization.data(withJSONObject: postData, options: [])
+ let sessionConfiguration = URLSessionConfiguration.default
+ let session = URLSession(configuration: sessionConfiguration, delegate: self, delegateQueue: nil)
+ let req = session.dataTask(with: tkRequest as URLRequest, completionHandler: { (data, response, error) in
+ if (data != nil){
+
+ } else {
+ NSLog("error %@", (error! as NSError).localizedDescription)
+ let error = NSError(domain: "", code: 0, userInfo: [
+ NSLocalizedDescriptionKey : NSLocalizedString("NoDataReceived", value: "Did not receive any data", comment: "")
+ ])
+ callback(AccesTokenResult.Failure(error))
+ }
+ })
+ req.resume()
+ }
+
+ class GeofenceDefinition: CLCircularRegion {
+ public let id: String
+ public let lat: double
+ public let lng: double
+ public let radius: int
+ public let postUrl: String
+ }
+}
+
+extension GeofenceProvider: CLLocationManagerDelegate {
+ func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
+ guard let geoDefinition = region as? GeofenceDefinition else {
+ return
+ }
+
+
+ }
+}
diff --git a/manager/src/main/resources/demo/rules/ConsoleLocationPredicate.groovy b/manager/src/main/resources/demo/rules/ConsoleLocationPredicate.groovy
index c9998d61e..cdd41093d 100644
--- a/manager/src/main/resources/demo/rules/ConsoleLocationPredicate.groovy
+++ b/manager/src/main/resources/demo/rules/ConsoleLocationPredicate.groovy
@@ -1,116 +1,19 @@
-package org.openremote.test.rules
+package demo.rules
import org.openremote.manager.rules.RulesBuilder
import org.openremote.model.asset.AssetQuery
-import org.openremote.model.asset.AssetType
import org.openremote.model.asset.BaseAssetQuery
-import org.openremote.model.notification.AlertNotification
RulesBuilder rules = binding.rules
rules.add()
- .name("Geofence - Airport Schiphol")
+ .name("Radial location predicate")
.when(
{ facts ->
- def consoles = facts.matchAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(new BaseAssetQuery.RadialLocationPredicate(4000, 4.761891d, 52.309197d)))
- .collect()
-
- consoles.size() > 0
- })
- .then(
- { facts ->
-
- AlertNotification alert = new AlertNotification(
- title: "Welcome in The Netherlands",
- message: "Have a look at the UNaLab program"
- )
- alert.addLinkAction("Yes Please", "https://www.eindhoven.nl/en/unalab-program")
- alert.addLinkAction("Not now", "#")
-
- })
-
-rules.add()
- .name("Geofence - Eindhoven Airport")
- .when(
- { facts ->
- def consoles = facts.matchFirstAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(new BaseAssetQuery.RadialLocationPredicate(1000, 5.391885d, 51.458181d)))
- .collect()
-
- consoles.size() > 0
- })
- .then(
- { facts ->
- AlertNotification alert = new AlertNotification(
- title: "Welcome in Eindhoven",
- message: "Have a look at the UNaLab program"
- )
- alert.addLinkAction("Yes Please", "https://www.eindhoven.nl/en/unalab-program")
- alert.addLinkAction("Not now", "#")
- })
-
-rules.add()
- .name("Geofence - van Abbe Museum")
- .when(
- { facts ->
- def consoles = facts.matchFirstAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(new BaseAssetQuery.RadialLocationPredicate(75, 5.481743d, 51.434402d)))
- .collect()
-
- consoles.size() > 0
- })
- .then(
- { facts ->
- AlertNotification alert = new AlertNotification(
- title: "Welcome in UNaLab consortium meeting",
- message: "Have a look at the program for our meeting in Eindhoven"
- )
- alert.addLinkAction("Yes Please", "https://www.eindhoven.nl/en/unalab-program")
- alert.addLinkAction("Not now", "#")
- })
-
-rules.add()
- .name("Geofence - Keizersgracht")
- .when(
- { facts ->
- def consoles = facts.matchFirstAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(new BaseAssetQuery.RadialLocationPredicate(100, 5.475926d, 51.437987d)))
- .collect()
-
- consoles.size() > 0
- })
- .then(
- { facts ->
- AlertNotification alert = new AlertNotification(
- title: "Hello, you are now at Keizersgracht",
- message: "How do you like this tour so far?"
- )
- alert.addLinkAction("Rate it", "https://www.eindhoven.nl/en/unalab-survey-2")
- alert.addLinkAction("Not now", "#")
- })
-
-rules.add()
- .name("Geofence - Cafe Centraal")
- .when(
- { facts ->
- def consoles = facts.matchFirstAssetState(new AssetQuery()
- .type(AssetType.CONSOLE)
- .location(new BaseAssetQuery.RadialLocationPredicate(100, 5.478801d, 51.439351d)))
- .collect()
-
- consoles.size() > 0
+ facts.matchFirstAssetState(new AssetQuery().location(new BaseAssetQuery.RadialLocationPredicate(100, 50, 100))).isPresent() &&
+ !facts.matchFirst("Location").isPresent()
})
.then(
{ facts ->
- AlertNotification alert = new AlertNotification(
- title: "Welcome at Cafe Centraal",
- message: "Now you have visited the NBS sites in Eindhoven, let us know your favorite project."
- )
- alert.addLinkAction("Fill in the survey", "https://www.eindhoven.nl/en/unalab-program#survey")
- alert.addLinkAction("Not now", "#")
+ facts.put("RadialLocation", "fired")
})
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.java
index efa8ff3c2..ec9d2c52e 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -646,7 +646,7 @@ public class Asset implements IdentifiableEntity {
Optional<Double> lat = obj.getNumber("latitude");
Optional<Double> lng = obj.getNumber("longitude");
if (lat.isPresent() && lng.isPresent()) {
- return new double[]{lat.get(), lng.get()};
+ return new double[]{lng.get(), lat.get()};
}
return null;