-
Notifications
You must be signed in to change notification settings - Fork 73
Fix for MongoDBHandling on ObjectToEvent map handling #472
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
Changes from all commits
bb9edc0
f520587
9f7a0df
74d6c4b
ab8d08f
84cea22
6a6894e
8fd5639
2b47e2c
a0b4b42
3a1753b
ec68d4b
319971a
f462b80
1199734
e7e2318
93f4395
1acd190
81da686
863659b
dbec64e
dba08e6
3728090
1248e62
abe9240
55f5eab
f0f3f85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,30 +81,36 @@ public ArrayList<String> getObjectsForEventId(String eventId) { | |
| return getEventToObjectList(eventId); | ||
| } | ||
|
|
||
| /** | ||
| * To check and save the eventIds to the objectId in the mapped database. | ||
| * @param rulesObject | ||
| * @param event | ||
| * @param objectId aggregated event object Id | ||
| */ | ||
| public void updateEventToObjectMapInMemoryDB(RulesObject rulesObject, String event, String objectId) { | ||
| String eventId = getEventId(rulesObject, event); | ||
| String condition = "{\"_id\" : \"" + eventId + "\"}"; | ||
| ArrayList<String> list = getEventToObjectList(eventId); | ||
| boolean firstTime = list.isEmpty(); | ||
| list = updateList(list, eventId, objectId); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| JsonNode entry = null; | ||
|
|
||
| String condition = "{\"_id\" : \"" + objectId + "\"}"; | ||
e-pettersson-ericsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOGGER.debug("Checking document exists in the collection with condition : {}\n EventId : {}", condition, eventId); | ||
| boolean docExists = mongodbhandler.checkDocumentExists(databaseName, collectionName, condition); | ||
| try { | ||
| entry = new ObjectMapper().readValue(condition, JsonNode.class); | ||
| ArrayNode jsonNode = mapper.convertValue(list, ArrayNode.class); | ||
| ((ObjectNode) entry).set(listPropertyName, mapper.readTree(jsonNode.toString())); | ||
| String mapStr = entry.toString(); | ||
| LOGGER.debug("MongoDbHandler Insert/Update Event: {}\nto database: {} and to Collection: {}", mapStr, databaseName, collectionName); | ||
| if (firstTime) { | ||
| mongodbhandler.insertDocument(databaseName, collectionName, mapStr); | ||
| if (!docExists) { | ||
| ArrayList<String> list = new ArrayList<String>(); | ||
| list.add(eventId); | ||
| final ObjectMapper mapper = new ObjectMapper(); | ||
| JsonNode entry = new ObjectMapper().readValue(condition, JsonNode.class); | ||
| ArrayNode jsonNode = mapper.convertValue(list, ArrayNode.class); | ||
| ((ObjectNode) entry).set(listPropertyName, mapper.readTree(jsonNode.toString())); | ||
| final String mapStr = entry.toString(); | ||
| LOGGER.debug("MongoDbHandler Insert/Update Event: {}\nto database: {} and to Collection: {}", mapStr, databaseName, collectionName); | ||
e-pettersson-ericsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mongodbhandler.insertDocument(databaseName, collectionName, mapStr ); | ||
| } else { | ||
| mongodbhandler.updateDocument(databaseName, collectionName, condition, mapStr); | ||
| mongodbhandler.updateDocumentAddToSet(databaseName, collectionName, condition, eventId); | ||
| } | ||
| } catch (Exception e) { | ||
| LOGGER.info("Failed to update event object list.", e); | ||
| LOGGER.error("Failed to update event object list.", e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| public String getEventId(RulesObject rulesObject, String event) { | ||
| String idRule = rulesObject.getIdRule(); | ||
|
|
@@ -148,7 +154,7 @@ public boolean deleteEventObjectMap(String templateName) { | |
| } | ||
|
|
||
| public boolean isEventInEventObjectMap(String eventId) { | ||
| String condition = "{\"_id\" : \"" + eventId + "\"}"; | ||
| String condition = "{\"objects\": { \"$in\" : [\"" + eventId + "\"]} }"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the top of this class a variable is defined for this key called 'listPropertyName' - use it here also. However, given that you've changed the structure of this document to look like: the key of the list should perhaps be called "events" instead of "objects"? It would look somehting like this instead:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
changed "events" instead of "objects"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "events" instead of "objects" changes will come in future, this changes will be release ASAP, could you please review the current changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see another PR open, which duplicates this one. Please update the changes in this PR and close the other one (then we keep the review history also) It's possible for @SantoshNC68 to allow @durga-vasaadi as collaborator on your fork, and this way you can both push to this one PR.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I have done that and we have worked together, but because of the issues on the travis we have another PR. We will close that.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we will not make changes for events in this PR but will do it another PR as we need to see the impact of that. |
||
| List<String> documents = mongodbhandler.find(databaseName, collectionName, condition); | ||
| return !documents.isEmpty(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,13 +67,15 @@ public String mergeObject(String id, String mergeId, RulesObject rules, String e | |
| try { | ||
| // lock and get the AggregatedObject | ||
| String aggregatedObject = getAggregatedObject(id, true); | ||
| LOGGER.debug("AGGREGATED OBJECT : " + aggregatedObject); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really want to log the entire aggregation twice? They can be very big, so it might clutter the log.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed logger |
||
| String mergeRule = getMergeRules(rules); | ||
| if (mergeRule != null && !mergeRule.isEmpty()) { | ||
| String updatedRule = replaceIdMarkerInRules(mergeRule, mergeId); | ||
| String ruleForMerge = jmesPathInterface.runRuleOnEvent(updatedRule, event).toString(); | ||
| String mergePath = prepareMergePrepareObject.getMergePath(aggregatedObject, ruleForMerge, false); | ||
| preparedToMergeObject = prepareMergePrepareObject.addMissingLevels(aggregatedObject, | ||
| objectToMerge.toString(), ruleForMerge, mergePath); | ||
| LOGGER.debug("PREPARE TO MERGE OBJECT : " + preparedToMergeObject); | ||
| } else { | ||
| preparedToMergeObject = objectToMerge.toString(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.