From b487424b8d13381688aa937f842b37a1b42192b4 Mon Sep 17 00:00:00 2001 From: ck-c8y Date: Wed, 25 Dec 2024 18:31:53 +0100 Subject: [PATCH] Use mqttTestClient with no authentication --- .../dynamic/mapping/ProtobufMqttClient.java | 30 ++++--- .../internal/InternalCustomAlarmOuter.java | 78 +++++++++---------- .../ProcessorExtensionSourceCustomAlarm.java | 2 +- .../inbound/BasePayloadProcessorInbound.java | 2 +- .../processor/model/ProcessingContext.java | 2 - .../dynamic/mapping/ProtobufMqttClient.java | 15 ++-- 6 files changed, 67 insertions(+), 62 deletions(-) diff --git a/dynamic-mapping-extension/src/test/java/dynamic/mapping/ProtobufMqttClient.java b/dynamic-mapping-extension/src/test/java/dynamic/mapping/ProtobufMqttClient.java index 9abc989df..f4b5a238d 100644 --- a/dynamic-mapping-extension/src/test/java/dynamic/mapping/ProtobufMqttClient.java +++ b/dynamic-mapping-extension/src/test/java/dynamic/mapping/ProtobufMqttClient.java @@ -47,16 +47,26 @@ public ProtobufMqttClient(Mqtt3BlockingClient sampleClient) { } public static void main(String[] args) { - - Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username) - .password(broker_password.getBytes()).build(); - Mqtt3BlockingClient sampleClient = Mqtt3Client.builder() - .serverHost(broker_host) - .serverPort(broker_port) - .identifier(client_id) - .simpleAuth(simpleAuth) - .sslWithDefaultConfig() - .buildBlocking(); + Mqtt3BlockingClient sampleClient; + if (broker_username == null || broker_username.isEmpty() || + broker_password == null || broker_password.isEmpty()) { + sampleClient = Mqtt3Client.builder() + .serverHost(broker_host) + .serverPort(broker_port) + .identifier(client_id) + .sslWithDefaultConfig() + .buildBlocking(); + } else { + Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username) + .password(broker_password.getBytes()).build(); + sampleClient = Mqtt3Client.builder() + .serverHost(broker_host) + .serverPort(broker_port) + .identifier(client_id) + .simpleAuth(simpleAuth) + .sslWithDefaultConfig() + .buildBlocking(); + } ProtobufMqttClient client = new ProtobufMqttClient(sampleClient); client.testSendEvent(); } diff --git a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/InternalCustomAlarmOuter.java b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/InternalCustomAlarmOuter.java index d5237b2b9..9d66f8482 100644 --- a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/InternalCustomAlarmOuter.java +++ b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/InternalCustomAlarmOuter.java @@ -121,12 +121,12 @@ public interface InternalCustomAlarmOrBuilder extends * Protobuf type {@code processor.protobuf.InternalCustomAlarm} */ public static final class InternalCustomAlarm extends - com.google.protobuf.GeneratedMessageV3 implements + com.google.protobuf.GeneratedMessage implements // @@protoc_insertion_point(message_implements:processor.protobuf.InternalCustomAlarm) InternalCustomAlarmOrBuilder { private static final long serialVersionUID = 0L; // Use InternalCustomAlarm.newBuilder() to construct. - private InternalCustomAlarm(com.google.protobuf.GeneratedMessageV3.Builder builder) { + private InternalCustomAlarm(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); } private InternalCustomAlarm() { @@ -156,7 +156,7 @@ protected java.lang.Object newInstance( } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return InternalCustomAlarmOuter.internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -419,23 +419,23 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (timestamp_ != 0L) { output.writeInt64(1, timestamp_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(txt_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, txt_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(txt_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 2, txt_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(unit_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, unit_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(unit_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 3, unit_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalIdType_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, externalIdType_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalIdType_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 4, externalIdType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalId_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, externalId_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalId_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 5, externalId_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alarmType_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, alarmType_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(alarmType_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 6, alarmType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(severity_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, severity_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(severity_)) { + com.google.protobuf.GeneratedMessage.writeString(output, 7, severity_); } getUnknownFields().writeTo(output); } @@ -450,23 +450,23 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeInt64Size(1, timestamp_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(txt_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, txt_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(txt_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(2, txt_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(unit_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, unit_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(unit_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(3, unit_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalIdType_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, externalIdType_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalIdType_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(4, externalIdType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalId_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, externalId_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalId_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(5, externalId_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alarmType_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, alarmType_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(alarmType_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(6, alarmType_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(severity_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, severity_); + if (!com.google.protobuf.GeneratedMessage.isStringEmpty(severity_)) { + size += com.google.protobuf.GeneratedMessage.computeStringSize(7, severity_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -562,39 +562,39 @@ public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom( } public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input); } public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input, extensionRegistry); } public static InternalCustomAlarmOuter.InternalCustomAlarm parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseDelimitedWithIOException(PARSER, input); } public static InternalCustomAlarmOuter.InternalCustomAlarm parseDelimitedFrom( java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseDelimitedWithIOException(PARSER, input, extensionRegistry); } public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom( com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input); } public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 + return com.google.protobuf.GeneratedMessage .parseWithIOException(PARSER, input, extensionRegistry); } @@ -614,7 +614,7 @@ public Builder toBuilder() { @java.lang.Override protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessage.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -622,7 +622,7 @@ protected Builder newBuilderForType( * Protobuf type {@code processor.protobuf.InternalCustomAlarm} */ public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements + com.google.protobuf.GeneratedMessage.Builder implements // @@protoc_insertion_point(builder_implements:processor.protobuf.InternalCustomAlarm) InternalCustomAlarmOuter.InternalCustomAlarmOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor @@ -631,7 +631,7 @@ public static final class Builder extends } @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { return InternalCustomAlarmOuter.internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable .ensureFieldAccessorsInitialized( @@ -644,7 +644,7 @@ private Builder() { } private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + com.google.protobuf.GeneratedMessage.BuilderParent parent) { super(parent); } @@ -1403,7 +1403,7 @@ public InternalCustomAlarmOuter.InternalCustomAlarm getDefaultInstanceForType() private static final com.google.protobuf.Descriptors.Descriptor internal_static_processor_protobuf_InternalCustomAlarm_descriptor; private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor @@ -1429,7 +1429,7 @@ public InternalCustomAlarmOuter.InternalCustomAlarm getDefaultInstanceForType() internal_static_processor_protobuf_InternalCustomAlarm_descriptor = getDescriptor().getMessageTypes().get(0); internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_processor_protobuf_InternalCustomAlarm_descriptor, new java.lang.String[] { "Timestamp", "Txt", "Unit", "ExternalIdType", "ExternalId", "AlarmType", "Severity", }); } diff --git a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/ProcessorExtensionSourceCustomAlarm.java b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/ProcessorExtensionSourceCustomAlarm.java index 402683b9b..44130396d 100644 --- a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/ProcessorExtensionSourceCustomAlarm.java +++ b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/extension/internal/ProcessorExtensionSourceCustomAlarm.java @@ -74,7 +74,7 @@ public void extractFromSource(ProcessingContext context) .getAlarmType(), MappingSubstitution.SubstituteValue.TYPE.TEXTUAL, RepairStrategy.DEFAULT)))); - postProcessingCache.put(context.getMapping().targetAPI.identifier, + postProcessingCache.put(context.getMapping().getGenericDeviceIdentifier(), new ArrayList(Arrays.asList( new MappingSubstitution.SubstituteValue( payloadProtobuf.getExternalId(), diff --git a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/inbound/BasePayloadProcessorInbound.java b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/inbound/BasePayloadProcessorInbound.java index 1a29420eb..d5c93b1f7 100644 --- a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/inbound/BasePayloadProcessorInbound.java +++ b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/inbound/BasePayloadProcessorInbound.java @@ -97,7 +97,7 @@ public void substituteInTargetAndSend(ProcessingContext context) { int countMaxEntries = postProcessingCache.get(entryWithMaxSubstitutes).size(); List pathsTargetForDeviceIdentifiers; - if (mapping.extension == null || MappingType.PROTOBUF_STATIC.equals(mapping.getMappingType())) { + if (mapping.extension != null || MappingType.PROTOBUF_STATIC.equals(mapping.getMappingType())) { pathsTargetForDeviceIdentifiers = new ArrayList<>(Arrays.asList(mapping.getGenericDeviceIdentifier())); } else { pathsTargetForDeviceIdentifiers = getPathTargetForDeviceIdentifiers(mapping); diff --git a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/model/ProcessingContext.java b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/model/ProcessingContext.java index 3d7c1da91..eaf4acf9a 100644 --- a/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/model/ProcessingContext.java +++ b/dynamic-mapping-service/src/main/java/dynamic/mapping/processor/model/ProcessingContext.java @@ -87,8 +87,6 @@ public class ProcessingContext { private String sourceId; - private String targetPathIdentifier; - public static final String SOURCE_ID = "source.id"; public boolean hasError() { diff --git a/dynamic-mapping-service/src/test/java/dynamic/mapping/ProtobufMqttClient.java b/dynamic-mapping-service/src/test/java/dynamic/mapping/ProtobufMqttClient.java index 80e9c2697..ce5637764 100644 --- a/dynamic-mapping-service/src/test/java/dynamic/mapping/ProtobufMqttClient.java +++ b/dynamic-mapping-service/src/test/java/dynamic/mapping/ProtobufMqttClient.java @@ -45,32 +45,29 @@ public ProtobufMqttClient(Mqtt3BlockingClient sampleClient) { } public static void main(String[] args) { - + Mqtt3BlockingClient sampleClient; if (broker_username == null || broker_username.isEmpty() || broker_password == null || broker_password.isEmpty()) { - Mqtt3BlockingClient sampleClient = Mqtt3Client.builder() + sampleClient = Mqtt3Client.builder() .serverHost(broker_host) .serverPort(broker_port) .identifier(client_id) .sslWithDefaultConfig() .buildBlocking(); - ProtobufMqttClient client = new ProtobufMqttClient(sampleClient); - client.testSendMeasurement(); - client.testSendAlarm(); } else { Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username) .password(broker_password.getBytes()).build(); - Mqtt3BlockingClient sampleClient = Mqtt3Client.builder() + sampleClient = Mqtt3Client.builder() .serverHost(broker_host) .serverPort(broker_port) .identifier(client_id) .simpleAuth(simpleAuth) .sslWithDefaultConfig() .buildBlocking(); - ProtobufMqttClient client = new ProtobufMqttClient(sampleClient); - client.testSendMeasurement(); - client.testSendAlarm(); } + ProtobufMqttClient client = new ProtobufMqttClient(sampleClient); + client.testSendMeasurement(); + client.testSendAlarm(); }