Skip to content

Commit 4966438

Browse files
tobiasakevasile-baluta
authored andcommitted
Fixed some of RepeatDBHandling of matched Aggregated Objects ids issues. (#251)
* Fix clean RepeateHandler AggregatedobjectIds log message. * Fixed RepeatDBHandles storing matched Aggregated Objects ids issues.
1 parent fe0e699 commit 4966438

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

src/functionaltests/java/com/ericsson/ei/subscriptions/repeatHandler/SubscriptionRepeatHandlerSteps.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void in_MongoDb_RepeatFlagHandler_collection_the_subscription_has_matched
144144
processSubscription(subscriptionStrWithTwoMatch, subscriptionWithTwoMatch);
145145
List<String> resultRepeatFlagHandler = mongoDBHandler.find(dataBaseName, repeatFlagHandlerCollection,
146146
subscriptionIdMatchedAggrIdObjQuery);
147-
assertEquals(2, resultRepeatFlagHandler.size());
147+
assertEquals(1, resultRepeatFlagHandler.size());
148148
assertEquals("\"" + AGGREGATED_OBJECT_ID + "\"", getAggregatedObjectId(resultRepeatFlagHandler, 0));
149149
assertEquals("\"" + AGGREGATED_OBJECT_ID + "\"", getAggregatedObjectId(resultRepeatFlagHandler, 1));
150150
}
@@ -165,7 +165,7 @@ public List<String> getEventNamesToSend() {
165165
*/
166166
private String getAggregatedObjectId(List<String> resultRepeatFlagHandler, int index) {
167167
JsonParser parser = new JsonParser();
168-
JsonObject jsonObject = parser.parse(resultRepeatFlagHandler.get(index)).getAsJsonObject();
168+
JsonObject jsonObject = parser.parse(resultRepeatFlagHandler.get(0)).getAsJsonObject();
169169
JsonObject requirements = jsonObject.get("requirements").getAsJsonObject();
170170
return requirements.get(String.valueOf(index)).getAsJsonArray().get(0).toString();
171171
}

src/main/java/com/ericsson/ei/subscriptionhandler/RunSubscription.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.ericsson.ei.jmespath.JmesPathInterface;
2020
import com.fasterxml.jackson.databind.JsonNode;
21-
import com.fasterxml.jackson.databind.ObjectMapper;
2221
import com.fasterxml.jackson.databind.node.ArrayNode;
2322

2423
import java.util.Iterator;
@@ -64,19 +63,10 @@ public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNod
6463
boolean conditionFulfilled = false;
6564
int count_condition_fulfillment = 0;
6665
int count_conditions = 0;
67-
6866
int requirementIndex = 0;
6967

7068
while (requirementIterator.hasNext()) {
7169

72-
JsonNode aggrObjJsonNode = null;
73-
ObjectMapper objectMapper = new ObjectMapper();
74-
try {
75-
aggrObjJsonNode = objectMapper.readValue(aggregatedObject, JsonNode.class);
76-
} catch (Exception e) {
77-
LOGGER.error(e.getMessage(), e);
78-
}
79-
8070
String subscriptionName = subscriptionJson.get("subscriptionName").asText();
8171
String subscriptionRepeatFlag = subscriptionJson.get("repeat").asText();
8272

@@ -91,7 +81,7 @@ public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNod
9181
+ subscriptionName + "\nand has Subscrption Repeat flag set to: " + subscriptionRepeatFlag);
9282
break;
9383
}
94-
84+
9585
JsonNode requirement = requirementIterator.next();
9686

9787
LOGGER.info("The fulfilled requirement which condition will check is : " + requirement.toString());

src/main/java/com/ericsson/ei/subscriptionhandler/SubscriptionRepeatDbHandler.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.List;
2828

29+
import org.bson.Document;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132
import org.springframework.beans.factory.annotation.Autowired;
@@ -95,7 +96,6 @@ public void addMatchedAggrObjToSubscriptionId(String subscriptionId, int require
9596

9697
if (!updateExistingMatchedSubscriptionWithAggrObjId(subscriptionId, requirementId, aggrObjId)) {
9798
LOGGER.error("Couldn't update SubscriptionMathced id.");
98-
} else {
9999
LOGGER.debug(
100100
"New Subscription AggrId has not matched, inserting new SubscriptionId and AggrObjId to matched list.");
101101
BasicDBObject document = new BasicDBObject();
@@ -120,25 +120,33 @@ public void addMatchedAggrObjToSubscriptionId(String subscriptionId, int require
120120
private boolean updateExistingMatchedSubscriptionWithAggrObjId(String subscriptionId, int requirementId,
121121
String aggrObjId) throws Exception {
122122
String subscriptionQuery = "{\"subscriptionId\" : \"" + subscriptionId + "\"}";
123-
124123
JsonNode updateDocJsonNode = mapper.readValue(
125124
"{\"$push\" : { \"requirements." + requirementId + "\" : \"" + aggrObjId + "\"}}", JsonNode.class);
126-
127-
LOGGER.debug("SubscriptionId \"", subscriptionId,
125+
LOGGER.debug("SubscriptionId \"", subscriptionId +
128126
"\" document will be updated with following requirement update object: "
129127
+ updateDocJsonNode.toString());
130128

131129
JsonNode queryJsonNode = mapper.readValue(subscriptionQuery, JsonNode.class);
130+
131+
Document document = null;
132132
try {
133-
mongoDbHandler.findAndModify(dataBaseName, collectionName, queryJsonNode.toString(),
133+
document = mongoDbHandler.findAndModify(dataBaseName, collectionName, queryJsonNode.toString(),
134134
updateDocJsonNode.toString());
135135
} catch (Exception e) {
136136
LOGGER.debug("Failed to update existing matched SubscriptionId with new AggrId." + "SubscriptionId: "
137137
+ subscriptionId + "New matched AggrObjId: " + aggrObjId + "RequirementId that have matched: "
138138
+ requirementId);
139139
return false;
140140
}
141-
return true;
141+
if (document != null && !document.isEmpty()) {
142+
LOGGER.debug("Successfully updated Matched Subscription Aggregated Object list:" +
143+
"\nfor subsruptionId: " + subscriptionId +
144+
"\nwith Aggregated Object Id: " + aggrObjId +
145+
"\nwith matched Requirement Id: " + requirementId);
146+
147+
return true;
148+
}
149+
return false;
142150
}
143151

144152
public boolean checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(String subscriptionId, int requirementId,
@@ -153,18 +161,18 @@ public boolean checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(String subs
153161
try {
154162
JsonNode jNode = mapper.readTree(objArray.get(0));
155163
if (jNode.get("subscriptionId").asText().trim().equals(subscriptionId)) {
156-
LOGGER.debug("SubscriptionId \"", subscriptionId,
164+
LOGGER.debug("SubscriptionId \"" + subscriptionId +
157165
"\" , exist in document. Checking if AggrObjId has matched earlier.");
158166

159167
LOGGER.debug("Subscription requirementId: " + requirementId + " and Requirements content:\n"
160168
+ jNode.get("requirements").get(new Integer(requirementId).toString()));
161169

162170
boolean triggered = checkRequirementIdTriggered(jNode, requirementId, aggrObjId);
163171

164-
if (!triggered)
172+
if (!triggered) {
165173
LOGGER.debug("RequirementId: " + requirementId + " and SubscriptionId: " + subscriptionId
166174
+ "\nhas not matched any AggregatedObject.");
167-
175+
}
168176
return triggered;
169177
}
170178
} catch (Exception e) {
@@ -189,8 +197,7 @@ private boolean checkRequirementIdTriggered(JsonNode jNode, int requirementId, S
189197
return false;
190198
}
191199

192-
String idStr = listAggrObjIds.get(requirementId);
193-
if (idStr.equals(aggrObjId)) {
200+
if (listAggrObjIds.contains(aggrObjId)) {
194201
LOGGER.debug("Subscription has matched aggrObjId already: " + aggrObjId);
195202
return true;
196203
}

0 commit comments

Comments
 (0)