From f10fb6fb8cd1ced11d503aabac5d7d4a766b3057 Mon Sep 17 00:00:00 2001 From: sudharshan Date: Wed, 28 Apr 2021 17:24:03 +0530 Subject: [PATCH 1/2] Implemented code changes to add the default domainId value, if its not provided by user --- CHANGELOG.md | 3 ++ pom.xml | 2 +- .../remrem/semantics/SemanticsService.java | 22 +++++++++ .../eiffel/remrem/semantics/ServiceTest.java | 15 ++++++ .../ActivityStartedEventWithoutDomainID.json | 46 +++++++++++++++++++ wiki/usage.md | 7 ++- 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/input/ActivityStartedEventWithoutDomainID.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 593a9d0..4e0c68f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.2 +- Implemented code changes to add the default domainId value, if its not provided by user. + ## 2.1.1 - Uplifted eiffel-remrem-parent version from 2.0.4 to 2.0.5. - Uplifted eiffel-remrem-protocol-interface version from 2.1.0 to 2.1.1. diff --git a/pom.xml b/pom.xml index deb3250..ac97c76 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 2.0.5 eiffel-remrem-semantics - 2.1.1 + 2.1.2 jar 5.0.1.201806211838-r diff --git a/src/main/java/com/ericsson/eiffel/remrem/semantics/SemanticsService.java b/src/main/java/com/ericsson/eiffel/remrem/semantics/SemanticsService.java index 1092d60..c6e494e 100644 --- a/src/main/java/com/ericsson/eiffel/remrem/semantics/SemanticsService.java +++ b/src/main/java/com/ericsson/eiffel/remrem/semantics/SemanticsService.java @@ -127,6 +127,7 @@ public class SemanticsService implements MsgService { private static final String DOMAIN_ID = "domainId"; private static final String PROTOCOL = "eiffel"; private static final String DOT = "."; + private static final String DEFAULT_DOMAIN_ID = "domainID"; private final ArrayList supportedEventTypes = new ArrayList(); public static final Logger log = LoggerFactory.getLogger(SemanticsService.class); private Event event = new Event(); @@ -218,6 +219,8 @@ public String generateMsg(String msgType, JsonObject bodyJson, Boolean lenientVa log.error(Message + "\nCause: " + Cause); return createErrorResponse(Message, Cause); } + //set the default domainID if its empty + msgNodes = setDomainId(msgNodes); // Compare the input JSON EventType with query parameter(-t) and // also @@ -460,4 +463,23 @@ public static Source setSerializerGav(Source source) { source.setSerializer(serializer); return source; } + + /** + * This method returns the default Default domainId, if its empty + * + * @param msgNodes contains msgParams of eiffel message in json form + * @return msgNodes returns default domainId, if domainId value is empty. + */ + private JsonObject setDomainId(JsonObject msgNodes) { + if (msgNodes.isJsonObject() && msgNodes.getAsJsonObject().has(META) + && msgNodes.getAsJsonObject().getAsJsonObject(META).has(SOURCE) + && msgNodes.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).has(DOMAIN_ID)) { + String domainId = msgNodes.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).get(DOMAIN_ID) + .getAsString(); + if(domainId.isEmpty()) { + msgNodes.getAsJsonObject().getAsJsonObject(META).getAsJsonObject(SOURCE).addProperty(DOMAIN_ID, DEFAULT_DOMAIN_ID); + } + } + return msgNodes; + } } diff --git a/src/test/java/com/ericsson/eiffel/remrem/semantics/ServiceTest.java b/src/test/java/com/ericsson/eiffel/remrem/semantics/ServiceTest.java index 1811494..9455656 100644 --- a/src/test/java/com/ericsson/eiffel/remrem/semantics/ServiceTest.java +++ b/src/test/java/com/ericsson/eiffel/remrem/semantics/ServiceTest.java @@ -273,4 +273,19 @@ public void testInvalid_lv_Message_fail() throws JsonIOException, JsonSyntaxExce Assert.assertTrue(msg.contains("cause")); Assert.assertTrue(msg.contains("ECMA 262 regex")); } + + @Test + public void testActivityStartedEventWithOutDomainId() + throws FileNotFoundException, UnsupportedEncodingException { + URL url = getClass().getClassLoader() + .getResource("input/ActivityStartedEventWithoutDomainID.json"); + String path = URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8.name()); + File file = new File(path); + JsonObject input = parser.parse(new FileReader(file)).getAsJsonObject(); + String msg = service.generateMsg("EiffelActivityStartedEvent", input); + Assert.assertTrue(msg.contains("data")); + Assert.assertTrue(msg.contains("meta")); + Assert.assertTrue(msg.contains("links")); + Assert.assertTrue(msg.contains("domainID")); + } } diff --git a/src/test/resources/input/ActivityStartedEventWithoutDomainID.json b/src/test/resources/input/ActivityStartedEventWithoutDomainID.json new file mode 100644 index 0000000..2a9a895 --- /dev/null +++ b/src/test/resources/input/ActivityStartedEventWithoutDomainID.json @@ -0,0 +1,46 @@ +{ + "msgParams": { + "meta": { + "type": "EiffelActivityStartedEvent", + "version": "4.0.0", + "tags": ["product_development","product_feature1"], + "source": { + "domainId": "", + "host": "localhost", + "name": "LOCALHOST", + "uri": "https://localhost:8080/jenkins/job", + "serializer":"pkg:maven/com.github.eiffel-community/eiffel-remrem-semantics@2.0.2" + }, + "security": { + "authorIdentity": "abc" + } + } + }, + "eventParams": { + "data": { + "executionUri": "http://localhost:8080/job/dsd", + "liveLogs": [{ + "name": "console", + "uri": "http://localhost:8085/job/dsd/9/console" + } + ], + "customData": [{ + "key": "EIFFELVERSION", + "value": "eiffel2.0" + }, + { + "key": "FLOWCONTEXT", + "value": "master" + } + ] + }, + "links": [{ + "type": "ACTIVITY_EXECUTION", + "target": "e269b37d-17a1-4a10-aafb-c108735ee51f" + }, + { + "type": "PREVIOUS_ACTIVITY_EXECUTION", + "target": "e269b37d-17a1-4a10-aafb-c108735ee51c" + }] + } +} \ No newline at end of file diff --git a/wiki/usage.md b/wiki/usage.md index cec5540..0f29d0a 100644 --- a/wiki/usage.md +++ b/wiki/usage.md @@ -5,6 +5,9 @@ [Routing and Binding Key concepts](routingAndBindingKeyConcepts.md) Please refer to [Eiffel Syntax](https://github.com/eiffel-community/eiffel/tree/master/eiffel-syntax-and-usage) and [Eiffel Vocabulary](https://github.com/eiffel-community/eiffel/tree/master/eiffel-vocabulary) for usage. -Please note that **meta.id**, **meta.time**, **meta.version** are generated by Eiffel REMReM Generate. -Eiffel REMReM Semantics maintained by [EiffelCommunity](https://github.com/eiffel-community) +**Note:** +* **meta.id**, **meta.time**, **meta.version** are generated by Eiffel REMReM Generate. +* **meta.source.domainId** value is not provided then default value that is **domainID** will be added. + +Eiffel REMReM Semantic.s maintained by [EiffelCommunity](https://github.com/eiffel-community) From 7082e25f826ad5ba96b24724bbba44784673902d Mon Sep 17 00:00:00 2001 From: sudharshan Date: Wed, 28 Apr 2021 17:54:15 +0530 Subject: [PATCH 2/2] Updated the semantic version --- CHANGELOG.md | 4 +--- pom.xml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0c68f..0e1aa9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,5 @@ -## 2.1.2 -- Implemented code changes to add the default domainId value, if its not provided by user. - ## 2.1.1 +- Implemented code changes to add the default domainId value, if its not provided by user. - Uplifted eiffel-remrem-parent version from 2.0.4 to 2.0.5. - Uplifted eiffel-remrem-protocol-interface version from 2.1.0 to 2.1.1. diff --git a/pom.xml b/pom.xml index ac97c76..deb3250 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 2.0.5 eiffel-remrem-semantics - 2.1.2 + 2.1.1 jar 5.0.1.201806211838-r