Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 20, 2023
1 parent 3876910 commit 8bfebef
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,14 +153,49 @@ static public List<ValidationError> isTemplateTopicUnique(List<Mapping> mappings
static public List<ValidationError> isMappingValid(List<Mapping> mappings, Mapping mapping) {
ArrayList<ValidationError> result = new ArrayList<ValidationError>();
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<? extends ValidationError> isPublishTopicTemplateAndTopicSampleValid(
@NotNull String publishTopic, @NotNull String templateTopicSample) {
ArrayList<ValidationError> result = new ArrayList<ValidationError>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions mqtt-mapping-ui/mqtt-mapping/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mqtt-mapping-ui/mqtt-mapping/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"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",
"url": "[email protected]:SoftwareAG/cumulocity-dynamic-mqtt-mapper.git"
},
"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"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>3.3.5-SNAPSHOT</revision>
<revision>3.3.6-SNAPSHOT</revision>
<c8y.version>1016.0.214</c8y.version>
<lombok.version>1.18.24</lombok.version>
<maven.compiler.source>11</maven.compiler.source>
Expand Down

0 comments on commit 8bfebef

Please sign in to comment.