From fca8e848caf12d5db4a1858ae198b3a98f3b2da5 Mon Sep 17 00:00:00 2001 From: pankalog Date: Tue, 30 Jan 2024 13:33:47 +0100 Subject: [PATCH 1/2] Telematics Device Processor Interface - Organize Packages --- .../custom/telematics/TelematicsDeviceProcessor.java | 9 +++++++++ .../processors}/teltonika/TeltonikaMQTTHandler.java | 5 ++--- .../helpers/TeltonikaAttributeProcessingHelper.java | 2 +- .../services/org.openremote.manager.mqtt.MQTTHandler | 2 +- .../test/custom/TeltonikaMQTTProtocolTest.groovy | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 manager/src/main/java/org/openremote/manager/custom/telematics/TelematicsDeviceProcessor.java rename manager/src/main/java/org/openremote/manager/custom/{ => telematics/processors}/teltonika/TeltonikaMQTTHandler.java (99%) rename manager/src/main/java/org/openremote/manager/custom/{ => telematics/processors}/teltonika/helpers/TeltonikaAttributeProcessingHelper.java (99%) diff --git a/manager/src/main/java/org/openremote/manager/custom/telematics/TelematicsDeviceProcessor.java b/manager/src/main/java/org/openremote/manager/custom/telematics/TelematicsDeviceProcessor.java new file mode 100644 index 0000000..692689c --- /dev/null +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/TelematicsDeviceProcessor.java @@ -0,0 +1,9 @@ +package org.openremote.manager.custom.telematics; + +/* +* Interface to be implemented by all handlers for device-specific payload parsing of Telematics equipment. +* +* +* */ +public interface TelematicsDeviceProcessor { +} diff --git a/manager/src/main/java/org/openremote/manager/custom/teltonika/TeltonikaMQTTHandler.java b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java similarity index 99% rename from manager/src/main/java/org/openremote/manager/custom/teltonika/TeltonikaMQTTHandler.java rename to manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java index 74e9d1a..e553825 100644 --- a/manager/src/main/java/org/openremote/manager/custom/teltonika/TeltonikaMQTTHandler.java +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java @@ -1,4 +1,4 @@ -package org.openremote.manager.custom.teltonika; +package org.openremote.manager.custom.telematics.processors.teltonika; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -10,7 +10,7 @@ import org.openremote.container.util.UniqueIdentifierGenerator; import org.openremote.manager.asset.AssetProcessingService; import org.openremote.manager.asset.AssetStorageService; -import org.openremote.manager.custom.teltonika.helpers.TeltonikaAttributeProcessingHelper; +import org.openremote.manager.custom.telematics.processors.teltonika.helpers.TeltonikaAttributeProcessingHelper; import org.openremote.manager.datapoint.AssetDatapointService; import org.openremote.manager.mqtt.MQTTHandler; import org.openremote.manager.mqtt.Topic; @@ -35,7 +35,6 @@ import java.nio.file.Paths; import java.sql.Timestamp; import java.text.MessageFormat; -import java.time.Instant; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; diff --git a/manager/src/main/java/org/openremote/manager/custom/teltonika/helpers/TeltonikaAttributeProcessingHelper.java b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java similarity index 99% rename from manager/src/main/java/org/openremote/manager/custom/teltonika/helpers/TeltonikaAttributeProcessingHelper.java rename to manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java index c97b970..54a77b6 100644 --- a/manager/src/main/java/org/openremote/manager/custom/teltonika/helpers/TeltonikaAttributeProcessingHelper.java +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java @@ -1,4 +1,4 @@ -package org.openremote.manager.custom.teltonika.helpers; +package org.openremote.manager.custom.telematics.processors.teltonika.helpers; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/manager/src/main/resources/META-INF/services/org.openremote.manager.mqtt.MQTTHandler b/manager/src/main/resources/META-INF/services/org.openremote.manager.mqtt.MQTTHandler index efbe5c1..c24ebbf 100644 --- a/manager/src/main/resources/META-INF/services/org.openremote.manager.mqtt.MQTTHandler +++ b/manager/src/main/resources/META-INF/services/org.openremote.manager.mqtt.MQTTHandler @@ -1 +1 @@ -org.openremote.manager.custom.teltonika.TeltonikaMQTTHandler +org.openremote.manager.custom.telematics.processors.teltonika.TeltonikaMQTTHandler diff --git a/test/src/test/groovy/org/openremote/test/custom/TeltonikaMQTTProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/custom/TeltonikaMQTTProtocolTest.groovy index 59b1d0d..71b0458 100644 --- a/test/src/test/groovy/org/openremote/test/custom/TeltonikaMQTTProtocolTest.groovy +++ b/test/src/test/groovy/org/openremote/test/custom/TeltonikaMQTTProtocolTest.groovy @@ -10,7 +10,7 @@ import org.openremote.manager.asset.AssetProcessingService import org.openremote.manager.asset.AssetStorageService import org.openremote.manager.event.ClientEventService import org.openremote.manager.mqtt.MQTTBrokerService -import org.openremote.manager.custom.teltonika.TeltonikaMQTTHandler +import org.openremote.manager.custom.telematics.processors.teltonika.TeltonikaMQTTHandler import org.openremote.manager.setup.SetupService import org.openremote.manager.setup.custom.CustomKeycloakSetup import org.openremote.model.Constants From 9b5516240e25e724ee9cce20bf5447969a0e3e26 Mon Sep 17 00:00:00 2001 From: pankalog Date: Wed, 31 Jan 2024 16:06:36 +0100 Subject: [PATCH 2/2] First version of handler rewrite * Moved some methods to TeltonikaAttributeProcessingHelper * Added more comments to TeltonikaMQTTHandler * Removed some redundant try/catches for readability * Created TeltonikaParameterData for use as a type-safe data structure to store parameter data and their values instead of relying on Map> --- .../teltonika/TeltonikaMQTTHandler.java | 3 +-- .../TeltonikaAttributeProcessingHelper.java | 1 + .../helpers/TeltonikaParameterData.java | 23 +++++++++++++++++++ .../model/teltonika/TeltonikaParameter.java | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaParameterData.java diff --git a/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java index e553825..0667bf2 100644 --- a/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/TeltonikaMQTTHandler.java @@ -508,6 +508,7 @@ private void createNewAsset(String newDeviceId, String newDeviceImei, String rea TeltonikaConfiguration config = getConfig(); + // This is where you would specify the Asset type that is inherited from the CarAsset class. CarAsset testAsset = new CarAsset("Teltonika Asset "+newDeviceImei) .setRealm(realm) .setModelNumber(getConfig().getDefaultModelNumber()) @@ -536,8 +537,6 @@ private void createNewAsset(String newDeviceId, String newDeviceImei, String rea attributes.forEach(attribute -> attribute.setTimestamp(dateVal.getTime())); }); - - updateAsset(testAsset, attributes); } diff --git a/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java index 54a77b6..853cda0 100644 --- a/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaAttributeProcessingHelper.java @@ -172,6 +172,7 @@ public static AttributeMap getAttributes(Map(CarAsset.LAST_CONTACT, deviceTimestamp, deviceTimestamp.getTime())); //Update all affected attribute timestamps diff --git a/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaParameterData.java b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaParameterData.java new file mode 100644 index 0000000..88bdfd5 --- /dev/null +++ b/manager/src/main/java/org/openremote/manager/custom/telematics/processors/teltonika/helpers/TeltonikaParameterData.java @@ -0,0 +1,23 @@ +package org.openremote.manager.custom.telematics.processors.teltonika.helpers; + +import org.openremote.model.teltonika.TeltonikaParameter; + +import java.util.Map; + +public class TeltonikaParameterData { + String key; + TeltonikaParameter value; + + public TeltonikaParameterData(String key, TeltonikaParameter value) { + this.key = key; + this.value = value; + } + + public String getParameterId() { + return key; + } + + public TeltonikaParameter getParameter() { + return value; + } +} diff --git a/model/src/main/java/org/openremote/model/teltonika/TeltonikaParameter.java b/model/src/main/java/org/openremote/model/teltonika/TeltonikaParameter.java index 70d1a0d..0d60174 100644 --- a/model/src/main/java/org/openremote/model/teltonika/TeltonikaParameter.java +++ b/model/src/main/java/org/openremote/model/teltonika/TeltonikaParameter.java @@ -27,6 +27,7 @@ "hwSupport", "parameterGroup" }) +//TODO: Create interface for this class called TelematicsDeviceParameter public class TeltonikaParameter implements Serializable { @JsonProperty("propertyIdInAvlPacket")