Skip to content

Commit 79dacae

Browse files
author
Vasile Baluta
committed
fix handling of ER upstream response
1 parent 9dea488 commit 79dacae

File tree

6 files changed

+32
-48
lines changed

6 files changed

+32
-48
lines changed

pom.xml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -245,31 +245,7 @@
245245

246246
</dependencies>
247247
<build>
248-
<plugins>
249-
250-
<plugin>
251-
<groupId>org.eluder.coveralls</groupId>
252-
<artifactId>coveralls-maven-plugin</artifactId>
253-
<version>4.3.0</version>
254-
<configuration>
255-
<repoToken>yourcoverallsprojectrepositorytoken</repoToken>
256-
</configuration>
257-
</plugin>
258-
259-
<plugin>
260-
<groupId>org.jacoco</groupId>
261-
<artifactId>jacoco-maven-plugin</artifactId>
262-
<version>0.7.6.201602180812</version>
263-
<executions>
264-
<execution>
265-
<id>prepare-agent</id>
266-
<goals>
267-
<goal>prepare-agent</goal>
268-
</goals>
269-
</execution>
270-
</executions>
271-
</plugin>
272-
248+
<plugins>
273249
<plugin>
274250
<groupId>org.springframework.boot</groupId>
275251
<artifactId>spring-boot-maven-plugin</artifactId>

src/main/java/com/ericsson/ei/handlers/UpStreamEventsHandler.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.ericsson.ei.rules.RulesHandler;
2020
import com.ericsson.ei.rules.RulesObject;
2121
import com.fasterxml.jackson.databind.JsonNode;
22+
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425
import org.springframework.beans.factory.annotation.Autowired;
@@ -107,15 +108,21 @@ private void traverseTree(final JsonNode jsonArray, final String aggregatedObjec
107108
final String pathInAggregatedObject) {
108109

109110
final JsonNode parent = jsonArray.get(0);
110-
RulesObject rules = rulesHandler.getRulesForEvent(parent.toString());
111-
112-
String np = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, parent.toString(),
113-
pathInAggregatedObject);
111+
JsonNode parentId = parent.at("/meta/id");
112+
String np = pathInAggregatedObject;
113+
if (!aggregatedObjectId.equals(parentId.textValue())) {
114+
// parent event is not the same as the starting event so we can
115+
// start collecting history
116+
RulesObject rules = rulesHandler.getRulesForEvent(parent.toString());
117+
118+
np = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, parent.toString(),
119+
pathInAggregatedObject);
120+
}
114121
String prevNp = null;
115122
for (int i = 1; i < jsonArray.size(); i++) {
116123
if (jsonArray.get(i).isObject()) {
117124
String event = jsonArray.get(i).toString();
118-
rules = rulesHandler.getRulesForEvent(event);
125+
RulesObject rules = rulesHandler.getRulesForEvent(event);
119126
prevNp = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, event,
120127
pathInAggregatedObject);
121128
} else {

src/main/java/com/ericsson/ei/jmespath/JmesPathInterface.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
package com.ericsson.ei.jmespath;
1818

19+
import com.fasterxml.jackson.databind.JsonNode;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
1922
import org.slf4j.Logger;
2023
import org.slf4j.LoggerFactory;
2124
import org.springframework.stereotype.Component;
2225

23-
import com.fasterxml.jackson.databind.JsonNode;
24-
import com.fasterxml.jackson.databind.ObjectMapper;
25-
2626
import io.burt.jmespath.Expression;
2727
import io.burt.jmespath.JmesPath;
2828
import io.burt.jmespath.function.FunctionRegistry;
@@ -50,14 +50,16 @@ public JsonNode runRuleOnEvent(String rule, String input) {
5050
if (input == null) {
5151
input = "";
5252
}
53-
Expression<JsonNode> expression = jmespath.compile(rule);
53+
54+
JsonNode result = null;
5455
ObjectMapper objectMapper = new ObjectMapper();
5556
try {
57+
Expression<JsonNode> expression = jmespath.compile(rule);
5658
event = objectMapper.readValue(input, JsonNode.class);
59+
result = expression.search(event);
5760
} catch (Exception e) {
5861
log.info(e.getMessage(), e);
5962
}
60-
JsonNode result = expression.search(event);
6163

6264
return result;
6365
}

src/main/java/com/ericsson/ei/jsonmerge/MergePrepare.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ public String getMergePath(String originObject, String mergeRule, boolean skipPa
209209
String stringObject = "";
210210
String stringRule = "";
211211
JSONObject objectJSONObject = null;
212-
JsonNode objectJsonNode = null;
213212
try {
214-
ObjectMapper objectmapper = new ObjectMapper();
215-
objectJsonNode = objectmapper.readTree(originObject);
216213
objectJSONObject = new JSONObject(originObject);
217214
stringObject = objectJSONObject.toString();
218215
Object ruleJSONObject = new JSONObject(mergeRule);
@@ -249,10 +246,6 @@ public String getMergePath(String originObject, String mergeRule, boolean skipPa
249246
if (pos > 0)
250247
ruleKey = ruleKey.substring(0, pos);
251248
try {
252-
// Object object = objectJSONObject.get(ruleKey);
253-
// Object object = objectJsonNode.get(ruleKey);
254-
// Object object1 = objectJsonNode.path(ruleKey);
255-
// Object object2 = objectJsonNode.at(ruleKey);
256249
JsonNode jsonResult = jmesPathInterface.runRuleOnEvent(ruleKey, originObject);
257250
if (!(jsonResult instanceof NullNode))
258251
mergePath = ruleKey;

src/main/java/com/ericsson/ei/rules/RulesObject.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public String getDownstreamMergeRules() {
7171
}
7272

7373
public String getHistoryExtractionRules() {
74-
return rulesObject.get("HistoryExtractionRules").textValue();
74+
return getTextValue("HistoryExtractionRules");
7575
}
7676

7777
public String getHistoryPathRules() {
@@ -83,18 +83,18 @@ public String fetchProcessRules() {
8383
}
8484

8585
public String getTextValue(String fieldName) {
86-
JsonNode jsonNode = rulesObject.get(fieldName);
87-
if (jsonNode != null)
88-
return jsonNode.textValue();
89-
return null;
86+
JsonNode jsonNode = rulesObject.get(fieldName);
87+
if (jsonNode != null)
88+
return jsonNode.textValue();
89+
return null;
9090
}
9191

9292
public String getString(String fieldName) {
9393
JsonNode jsonNode = rulesObject.get(fieldName);
9494
if (jsonNode != null)
9595
return jsonNode.toString();
9696
return "";
97-
}
97+
}
9898

9999
public boolean equals(Object other) {
100100
if (other instanceof RulesObject) {

src/test/resources/arrayAggregationUpstreamResult.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[{
2+
"data":{"customData":[{"key":"Type","value":"Source"}],"name":"TestCompositionName","version":"TestCompositionVersion"},
3+
"links":[{"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2","type":"ELEMENT"}, {"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf","type":"ELEMENT"}],
4+
"meta":{"id":"175f08ff-1e4b-4265-a0d4-36e744297dc3","time":1529405139338,"type":"EiffelCompositionDefinedEvent","version":"1.1.0"}
5+
},
16
[
27
{
38
"data":{"customData":[],"gav":{"artifactId":"artifact id","groupId":"group id","version":"0.0.0a"}},
@@ -9,4 +14,5 @@
914
"links":[],
1015
"meta":{"id":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf","time":1529405139319,"type":"EiffelArtifactCreatedEvent","version":"1.1.0"}
1116
}
17+
]
1218
]

0 commit comments

Comments
 (0)