Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented code changes to add the default domainId value, #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>2.0.5</version>
</parent>
<artifactId>eiffel-remrem-semantics</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<properties>
<eclipse.jgit.version>5.0.1.201806211838-r</eclipse.jgit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> supportedEventTypes = new ArrayList<String>();
public static final Logger log = LoggerFactory.getLogger(SemanticsService.class);
private Event event = new Event();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
46 changes: 46 additions & 0 deletions src/test/resources/input/ActivityStartedEventWithoutDomainID.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"msgParams": {
"meta": {
"type": "EiffelActivityStartedEvent",
"version": "4.0.0",
"tags": ["product_development","product_feature1"],
"source": {
"domainId": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event has an empty domain id yet the filename suggests that the domain id is missing. The way I read setDomainId() it won't touch the domain id if the key is missing altogether, it'll only set it if the string is empty. Is that really what's intended?

"host": "localhost",
"name": "LOCALHOST",
"uri": "https://localhost:8080/jenkins/job",
"serializer":"pkg:maven/com.github.eiffel-community/[email protected]"
},
"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"
}]
}
}
7 changes: 5 additions & 2 deletions wiki/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)