From 8bfebeff95d27dfdabbcc8b7f88b42e3c3bf0f47 Mon Sep 17 00:00:00 2001 From: sagIoTPower Date: Wed, 20 Dec 2023 13:31:32 +0100 Subject: [PATCH] fixing bugs --- .../mapping/model/MappingRepresentation.java | 41 ++++++++++++++++++- .../mqtt/mapping/model/ValidationError.java | 3 ++ .../mqtt-mapping/package-lock.json | 4 +- mqtt-mapping-ui/mqtt-mapping/package.json | 4 +- pom.xml | 2 +- 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/mqtt-mapping-service/src/main/java/mqtt/mapping/model/MappingRepresentation.java b/mqtt-mapping-service/src/main/java/mqtt/mapping/model/MappingRepresentation.java index 32d39942..f9850b0f 100644 --- a/mqtt-mapping-service/src/main/java/mqtt/mapping/model/MappingRepresentation.java +++ b/mqtt-mapping-service/src/main/java/mqtt/mapping/model/MappingRepresentation.java @@ -29,6 +29,8 @@ import java.util.function.BiFunction; import java.util.regex.Pattern; +import javax.validation.constraints.NotNull; + import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; @@ -151,14 +153,49 @@ static public List isTemplateTopicUnique(List mappings static public List isMappingValid(List mappings, Mapping mapping) { ArrayList result = new ArrayList(); result.addAll(isSubstituionValid(mapping)); - result.addAll(isSubscriptionTopicValid(mapping.subscriptionTopic)); result.addAll(isTemplateTopicValid(mapping.templateTopic)); - result.addAll(isTemplateTopicTemplateAndTopicSampleValid(mapping.templateTopic, mapping.templateTopicSample)); + if (mapping.direction.equals(Direction.INBOUND)) { + result.addAll(isSubscriptionTopicValid(mapping.subscriptionTopic)); + result.addAll(isTemplateTopicTemplateAndTopicSampleValid(mapping.templateTopic, mapping.templateTopicSample)); + } else { + // test if we can attach multiple outbound mappings to the same filterOutbound + // result.addAll(isFilterOutboundUnique(mappings,mapping)); + result.addAll(isPublishTopicTemplateAndTopicSampleValid(mapping.publishTopic, mapping.templateTopicSample)); + } + result.addAll(areJSONTemplatesValid(mapping)); // result.addAll(isTemplateTopicUnique(mappings, mapping)); return result; } + private static Collection isPublishTopicTemplateAndTopicSampleValid( + @NotNull String publishTopic, @NotNull String templateTopicSample) { + ArrayList result = new ArrayList(); + String[] splitPT = Mapping.splitTopicIncludingSeparatorAsArray(publishTopic); + String[] splitTTS = Mapping.splitTopicIncludingSeparatorAsArray(templateTopicSample); + if (splitPT.length != splitTTS.length) { + result.add(ValidationError.PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Number_Of_Levels_In_Topic_Name); + } else { + for (int i = 0; i < splitPT.length; i++) { + if (("/").equals(splitPT[i]) && !("/").equals(splitTTS[i])) { + result.add(ValidationError.PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Structure_In_Topic_Name); + break; + } + if (("/").equals(splitTTS[i]) && !("/").equals(splitPT[i])) { + result.add(ValidationError.PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Structure_In_Topic_Name); + break; + } + if (!("/").equals(splitPT[i]) && !("+").equals(splitPT[i]) && !("#").equals(splitPT[i])) { + if (!splitPT[i].equals(splitTTS[i])) { + result.add(ValidationError.PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Structure_In_Topic_Name); + break; + } + } + } + } + return result; + } + /* * test if mapping.templateTopic and mapping.templateTopicSample have the same * structure and same number of levels diff --git a/mqtt-mapping-service/src/main/java/mqtt/mapping/model/ValidationError.java b/mqtt-mapping-service/src/main/java/mqtt/mapping/model/ValidationError.java index 66c4ba13..658327be 100644 --- a/mqtt-mapping-service/src/main/java/mqtt/mapping/model/ValidationError.java +++ b/mqtt-mapping-service/src/main/java/mqtt/mapping/model/ValidationError.java @@ -36,4 +36,7 @@ public enum ValidationError { Device_Identifier_Must_Be_Selected, TemplateTopic_And_TemplateTopicSample_Do_Not_Have_Same_Number_Of_Levels_In_Topic_Name, TemplateTopic_And_TemplateTopicSample_Do_Not_Have_Same_Structure_In_Topic_Name, + PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Number_Of_Levels_In_Topic_Name, + PublishTopic_And_TemplateTopicSample_Do_Not_Have_Same_Structure_In_Topic_Name, + FilterOutbound_Must_Be_Unique } diff --git a/mqtt-mapping-ui/mqtt-mapping/package-lock.json b/mqtt-mapping-ui/mqtt-mapping/package-lock.json index 4a29a398..cf577c4c 100644 --- a/mqtt-mapping-ui/mqtt-mapping/package-lock.json +++ b/mqtt-mapping-ui/mqtt-mapping/package-lock.json @@ -1,12 +1,12 @@ { "name": "mqtt-mapping", - "version": "3.3.5", + "version": "3.3.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mqtt-mapping", - "version": "3.3.5", + "version": "3.3.6", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/mqtt-mapping-ui/mqtt-mapping/package.json b/mqtt-mapping-ui/mqtt-mapping/package.json index 9f021e96..b6febc4b 100644 --- a/mqtt-mapping-ui/mqtt-mapping/package.json +++ b/mqtt-mapping-ui/mqtt-mapping/package.json @@ -1,6 +1,6 @@ { "name": "mqtt-mapping", - "version": "3.3.5", + "version": "3.3.6", "description": "Cumulocity plugin to map custom JSON payloads to C8Y payloads.The lugin support both directions: inbound/outbound.", "repository": { "type": "git", @@ -8,7 +8,7 @@ }, "scripts": { "start": "c8ycli server", - "start:admin": "npm start -- --shell administration", + "start:admin": "npm start -- --shell administration -u https://ck2.eu-latest.cumulocity.com", "build": "c8ycli build", "deploy": "c8ycli deploy", "postinstall": "ngcc" diff --git a/pom.xml b/pom.xml index 11a3ede2..eab5aad4 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ UTF-8 - 3.3.5-SNAPSHOT + 3.3.6-SNAPSHOT 1016.0.214 1.18.24 11