Skip to content

Commit 9dea488

Browse files
author
Vasile Baluta
committed
second version of aggregation proposal
1 parent 8610503 commit 9dea488

File tree

5 files changed

+224
-40
lines changed

5 files changed

+224
-40
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.databind.JsonNode;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.fasterxml.jackson.databind.node.ArrayNode;
23+
import com.fasterxml.jackson.databind.node.NullNode;
2324
import com.github.wnameless.json.flattener.JsonFlattener;
2425

2526
import java.util.ArrayList;
@@ -208,7 +209,10 @@ public String getMergePath(String originObject, String mergeRule, boolean skipPa
208209
String stringObject = "";
209210
String stringRule = "";
210211
JSONObject objectJSONObject = null;
212+
JsonNode objectJsonNode = null;
211213
try {
214+
ObjectMapper objectmapper = new ObjectMapper();
215+
objectJsonNode = objectmapper.readTree(originObject);
212216
objectJSONObject = new JSONObject(originObject);
213217
stringObject = objectJSONObject.toString();
214218
Object ruleJSONObject = new JSONObject(mergeRule);
@@ -245,10 +249,14 @@ public String getMergePath(String originObject, String mergeRule, boolean skipPa
245249
if (pos > 0)
246250
ruleKey = ruleKey.substring(0, pos);
247251
try {
248-
Object object = objectJSONObject.get(ruleKey);
249-
if (object != null)
252+
// Object object = objectJSONObject.get(ruleKey);
253+
// Object object = objectJsonNode.get(ruleKey);
254+
// Object object1 = objectJsonNode.path(ruleKey);
255+
// Object object2 = objectJsonNode.at(ruleKey);
256+
JsonNode jsonResult = jmesPathInterface.runRuleOnEvent(ruleKey, originObject);
257+
if (!(jsonResult instanceof NullNode))
250258
mergePath = ruleKey;
251-
} catch (JSONException e) {
259+
} catch (Exception e) {
252260
log.error(e.getMessage(), e);
253261
}
254262
} else {

src/test/java/com/ericsson/ei/flowtests/ArrayAggregationTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,20 @@ String getEventsFilePath() {
7575
return EVENTS_FILE_PATH;
7676
}
7777

78+
@Override
79+
protected int extraEventsCount() {
80+
// extra events from ER upstream
81+
return 2;
82+
}
83+
7884
@Override
7985
List<String> getEventNamesToSend() {
8086
List<String> eventNames = new ArrayList<>();
81-
// eventNames.add("EiffelArtifactPublishedEvent_1");
82-
// eventNames.add("EiffelArtifactPublishedEvent_2");
87+
eventNames.add("EiffelArtifactPublishedEvent_1");
88+
eventNames.add("EiffelArtifactPublishedEvent_2");
8389
eventNames.add("EiffelCompositionDefinedEvent");
84-
// eventNames.add("EiffelArtifactPublishedEvent_3");
85-
// eventNames.add("EiffelArtifactPublishedEvent_4");
90+
eventNames.add("EiffelArtifactPublishedEvent_3");
91+
eventNames.add("EiffelArtifactPublishedEvent_4");
8692
return eventNames;
8793
}
8894

src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void setFirstEventWaitTime(int value) {
121121

122122
/**
123123
* Override this if you have more events that will be registered to event to
124-
* object map but it is not visible in the test. For example form upstream
124+
* object map but it is not visible in the test. For example from upstream
125125
* or downstream from event repository
126126
*
127127
* @return
Lines changed: 197 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,199 @@
11
{
2-
"events": [
3-
{
4-
"data":{"customData":[],"gav":{"artifactId":"artifact id","groupId":"group id","version":"0.0.0a"}},
5-
"links":[],
6-
"meta":{"id":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2","time":1529405139319,"type":"EiffelArtifactCreatedEvent","version":"1.1.0"}
7-
},
8-
{
9-
"data":{"customData":[],"gav":{"artifactId":"artifact id","groupId":"group id","version":"0.0.0a"}},
10-
"links":[],
11-
"meta":{"id":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf","time":1529405139319,"type":"EiffelArtifactCreatedEvent","version":"1.1.0"}
12-
},
13-
{
14-
"data":{"customData":[],"locations":[{"type":"PLAIN","uri":"https://external.example.com/84e9dfe1-09f7-4002-83b9-1aff4b7844a2"}]},
15-
"links":[{"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2","type":"ARTIFACT"}],
16-
"meta":{"id":"cc78087b-dc58-4da6-a009-51cea15bfa46","time":1529405139327,"type":"EiffelArtifactPublishedEvent","version":"1.1.0"}
17-
},
18-
{
19-
"data":{"customData":[],"locations":[{"type":"PLAIN","uri":"https://external.example.com/cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"}]},
20-
"links":[{"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf","type":"ARTIFACT"}],
21-
"meta":{"id":"d7cf357d-9c05-4b51-84e7-af36b73d42df","time":1529405139330,"type":"EiffelArtifactPublishedEvent","version":"1.1.0"}
22-
},
23-
{
24-
"data":{"customData":[{"key":"Type","value":"Source"}],"name":"TestCompositionName","version":"TestCompositionVersion"},
25-
"links":[{"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2","type":"ELEMENT"}, {"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf","type":"ELEMENT"}],
26-
"meta":{"id":"175f08ff-1e4b-4265-a0d4-36e744297dc3","time":1529405139338,"type":"EiffelCompositionDefinedEvent","version":"1.1.0"}
27-
}
28-
]
2+
"_id":"175f08ff-1e4b-4265-a0d4-36e744297dc3",
3+
"aggregatedObject":{
4+
"eventId":"175f08ff-1e4b-4265-a0d4-36e744297dc3",
5+
"actualevent":{
6+
"data":{
7+
"name":"TestCompositionName",
8+
"customData":[
9+
{
10+
"value":"Source",
11+
"key":"Type"
12+
}
13+
],
14+
"version":"TestCompositionVersion"
15+
},
16+
"meta":{
17+
"id":"175f08ff-1e4b-4265-a0d4-36e744297dc3",
18+
"time":1529405139338,
19+
"type":"EiffelCompositionDefinedEvent",
20+
"version":"1.1.0"
21+
},
22+
"links":[
23+
{
24+
"type":"ELEMENT",
25+
"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2"
26+
},
27+
{
28+
"type":"ELEMENT",
29+
"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"
30+
}
31+
]
32+
},
33+
"internalComposition":{
34+
"artifacts":[
35+
{
36+
"actualevent":{
37+
"data":{
38+
"customData":[
39+
40+
],
41+
"gav":{
42+
"groupId":"group id",
43+
"artifactId":"artifact id",
44+
"version":"0.0.0a"
45+
}
46+
},
47+
"meta":{
48+
"id":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2",
49+
"time":1529405139319,
50+
"type":"EiffelArtifactCreatedEvent",
51+
"version":"1.1.0"
52+
},
53+
"links":[
54+
55+
]
56+
}
57+
},
58+
{
59+
"actualevent":{
60+
"data":{
61+
"customData":[
62+
63+
],
64+
"gav":{
65+
"groupId":"group id",
66+
"artifactId":"artifact id",
67+
"version":"0.0.0a"
68+
}
69+
},
70+
"meta":{
71+
"id":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf",
72+
"time":1529405139319,
73+
"type":"EiffelArtifactCreatedEvent",
74+
"version":"1.1.0"
75+
},
76+
"links":[
77+
78+
]
79+
}
80+
}
81+
]
82+
},
83+
"TemplateName":"ARRAY_AGGREGATION_1",
84+
"publications":[
85+
{
86+
"eventId":"cc78087b-dc58-4da6-a009-51cea15bfa46",
87+
"actualevent":{
88+
"data":{
89+
"customData":[
90+
91+
],
92+
"locations":[
93+
{
94+
"type":"PLAIN",
95+
"uri":"https://external.example.com/84e9dfe1-09f7-4002-83b9-1aff4b7844a2"
96+
}
97+
]
98+
},
99+
"meta":{
100+
"id":"cc78087b-dc58-4da6-a009-51cea15bfa46",
101+
"time":1529405139327,
102+
"type":"EiffelArtifactPublishedEvent",
103+
"version":"1.1.0"
104+
},
105+
"links":[
106+
{
107+
"type":"ARTIFACT",
108+
"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2"
109+
}
110+
]
111+
}
112+
},
113+
{
114+
"eventId":"908ff42d-786c-4a45-bf94-b43883d29784",
115+
"actualevent":{
116+
"data":{
117+
"customData":[
118+
119+
],
120+
"locations":[
121+
{
122+
"type":"PLAIN",
123+
"uri":"https://subdomain.example.com/84e9dfe1-09f7-4002-83b9-1aff4b7844a2"
124+
}
125+
]
126+
},
127+
"meta":{
128+
"id":"908ff42d-786c-4a45-bf94-b43883d29784",
129+
"time":1529405139639,
130+
"type":"EiffelArtifactPublishedEvent",
131+
"version":"1.1.0"
132+
},
133+
"links":[
134+
{
135+
"type":"ARTIFACT",
136+
"target":"84e9dfe1-09f7-4002-83b9-1aff4b7844a2"
137+
}
138+
]
139+
}
140+
},
141+
{
142+
"eventId":"d7cf357d-9c05-4b51-84e7-af36b73d42df",
143+
"actualevent":{
144+
"data":{
145+
"customData":[
146+
147+
],
148+
"locations":[
149+
{
150+
"type":"PLAIN",
151+
"uri":"https://external.example.com/cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"
152+
}
153+
]
154+
},
155+
"meta":{
156+
"id":"d7cf357d-9c05-4b51-84e7-af36b73d42df",
157+
"time":1529405139330,
158+
"type":"EiffelArtifactPublishedEvent",
159+
"version":"1.1.0"
160+
},
161+
"links":[
162+
{
163+
"type":"ARTIFACT",
164+
"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"
165+
}
166+
]
167+
}
168+
},
169+
{
170+
"eventId":"908ff42d-786c-4a45-bf94-b43883d49784",
171+
"actualevent":{
172+
"data":{
173+
"customData":[
174+
175+
],
176+
"locations":[
177+
{
178+
"type":"PLAIN",
179+
"uri":"https://subdomain.example.com/cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"
180+
}
181+
]
182+
},
183+
"meta":{
184+
"id":"908ff42d-786c-4a45-bf94-b43883d49784",
185+
"time":1529405139701,
186+
"type":"EiffelArtifactPublishedEvent",
187+
"version":"1.1.0"
188+
},
189+
"links":[
190+
{
191+
"type":"ARTIFACT",
192+
"target":"cdffc8e9-5ee5-45c5-9f0e-0e89cea51dcf"
193+
}
194+
]
195+
}
196+
}
197+
]
198+
}
29199
}

src/test/resources/arrayAggregationRules.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"StartEvent": "YES",
88
"IdentifyRules" : "[meta.id]",
99
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
10-
"ExtractionRules" : "{events:[@]}"
10+
"ExtractionRules" : "{eventId: meta.id, actualevent:@}"
1111
},
1212
{
1313
"TemplateName":"ARRAY_AGGREGATION_1",
@@ -17,8 +17,8 @@
1717
"StartEvent": "NO",
1818
"IdentifyRules" : "links | [?type=='ARTIFACT'].target",
1919
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
20-
"ExtractionRules" : "@",
21-
"MergeResolverRules": "[ {NONEPATH:NONE}, {events: []} ]"
20+
"ExtractionRules" : "{actualevent:@}",
21+
"MergeResolverRules": "[ {NONEPATH:NONE}, {publications: [{ eventId: meta.id }]} ]"
2222
},
2323
{
2424
"TemplateName":"ARRAY_AGGREGATION_1",
@@ -29,7 +29,7 @@
2929
"IdentifyRules" : "",
3030
"MatchIdRules": {},
3131
"ExtractionRules" : "",
32-
"HistoryExtractionRules":"@",
33-
"HistoryPathRules": "{events: []}"
32+
"HistoryExtractionRules":"{actualevent:@}",
33+
"HistoryPathRules": "{internalComposition:{artifacts: [{eventId: meta.id}]}}"
3434
}
3535
]

0 commit comments

Comments
 (0)