This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch fork/dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 246b73e1315792220c41afbe0215c7de21555717
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Mon Jan 29 10:56:02 2024 +0100
fix(#2144): Set default static property values for adapter instance
---
.../opcua/migration/OpcUaAdapterMigrationV2.java | 20 ++++++++++++++++----
.../org/apache/streampipes/sdk/StaticProperties.java | 7 +++++++
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/migration/OpcUaAdapterMigrationV2.java b/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/migration/OpcUaAdapterMigrationV2.java
index 6296062871..4336287aab 100644
--- a/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/migration/OpcUaAdapterMigrationV2.java
+++ b/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/migration/OpcUaAdapterMigrationV2.java
@@ -20,6 +20,9 @@ package org.apache.streampipes.extensions.connectors.opcua.migration;
import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
import org.apache.streampipes.extensions.api.migration.IAdapterMigrator;
+import org.apache.streampipes.extensions.connectors.opcua.config.OpcUaConfig;
+import org.apache.streampipes.extensions.connectors.opcua.config.SpOpcUaConfigExtractor;
+import org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaUtil;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;
import org.apache.streampipes.model.migration.MigrationResult;
@@ -67,20 +70,29 @@ public class OpcUaAdapterMigrationV2 implements IAdapterMigrator {
return MigrationResult.success(element);
}
- private StaticProperty modifiedAlternatives() {
+ private StaticProperty modifiedAlternatives(IStaticPropertyExtractor extractor) {
+
+ var serverAddressValue =
+ extractor.singleValueParameter(OPC_SERVER_URL.name(), String.class);
+ var hostValue = OpcUaUtil.formatServerAddress(
+ extractor.singleValueParameter(OPC_SERVER_HOST.name(), String.class)
+ );
+ var portValue = extractor.singleValueParameter(OPC_SERVER_PORT.name(), int.class);
+
return StaticProperties.alternatives(Labels.withId(OPC_HOST_OR_URL),
Alternatives.from(
Labels.withId(OPC_URL),
StaticProperties.stringFreeTextProperty(
- Labels.withId(OPC_SERVER_URL), "opc.tcp://localhost:4840"))
+ Labels.withId(OPC_SERVER_URL),
+ serverAddressValue))
,
Alternatives.from(Labels.withId(OPC_HOST),
StaticProperties.group(
Labels.withId(HOST_PORT),
StaticProperties.stringFreeTextProperty(
- Labels.withId(OPC_SERVER_HOST)),
+ Labels.withId(OPC_SERVER_HOST), hostValue),
StaticProperties.integerFreeTextProperty(
- Labels.withId(OPC_SERVER_PORT))
+ Labels.withId(OPC_SERVER_PORT), portValue)
)));
}
diff --git a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/StaticProperties.java b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/StaticProperties.java
index a2d6092e21..ce8defc273 100644
--- a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/StaticProperties.java
+++ b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/StaticProperties.java
@@ -114,6 +114,13 @@ public class StaticProperties {
return freeTextProperty(label, Datatypes.Integer);
}
+ public static FreeTextStaticProperty integerFreeTextProperty(Label label, int defaultValue) {
+ var property = freeTextProperty(label, Datatypes.Integer);
+ property.setValue(String.valueOf(defaultValue));
+ return property;
+ }
+
+
public static FreeTextStaticProperty doubleFreeTextProperty(Label label) {
return freeTextProperty(label, Datatypes.Double);
}