Skip to content

Commit 6727324

Browse files
author
Vasile Baluta
committed
clean up
1 parent fe99743 commit 6727324

File tree

4 files changed

+212
-70
lines changed

4 files changed

+212
-70
lines changed

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

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,16 @@
1414

1515
package com.ericsson.ei.handlers;
1616

17-
import org.json.JSONArray;
18-
import org.json.JSONException;
19-
import org.json.JSONObject;
20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
22-
import org.springframework.beans.factory.annotation.Autowired;
23-
2417
import com.ericsson.ei.jmespath.JmesPathInterface;
2518
import com.ericsson.ei.jsonmerge.MergeHandler;
2619
import com.ericsson.ei.jsonmerge.MergePrepare;
2720
import com.ericsson.ei.rules.RulesObject;
2821
import com.fasterxml.jackson.databind.JsonNode;
29-
import com.fasterxml.jackson.databind.ObjectMapper;
30-
import com.fasterxml.jackson.databind.node.ArrayNode;
31-
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
32-
import com.fasterxml.jackson.databind.node.ObjectNode;
3322
import com.github.wnameless.json.flattener.JsonFlattener;
3423

24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
import org.springframework.beans.factory.annotation.Autowired;
3527
import org.springframework.stereotype.Component;
3628

3729
// TODO: Auto-generated Javadoc
@@ -76,16 +68,12 @@ public String runHistoryExtraction(String aggregatedObjectId, RulesObject rules,
7668
// if we need to add append to an array then array_path will not be
7769
// empty so we use it instead of passed pathInAggregatedObject
7870
String aggregatedObject = mergeHandler.getAggregatedObject(aggregatedObjectId, false);
79-
String longRuleString = createLongMergeRule(pathInAggregatedObject, ruleJson);
8071
String objAtPathStr = "";
8172
String pathTrimmed = mergePrepare.trimLastInPath(pathInAggregatedObject, ".");
8273
try {
83-
// if (!pathInAggregatedObject.isEmpty()) {
84-
8574
pathTrimmed = mergePrepare.makeJmespathArrayIndexes(pathTrimmed);
8675
JsonNode objAtPath = jmesPathInterface.runRuleOnEvent(pathTrimmed, aggregatedObject);
8776
objAtPathStr = objAtPath.toString();
88-
// }
8977
} catch (Exception e) {
9078
log.error(e.getMessage(), e);
9179
}
@@ -113,28 +101,6 @@ public String runHistoryExtraction(String aggregatedObjectId, RulesObject rules,
113101
return pathInAggregatedObject;
114102
}
115103

116-
private String createLongMergeRule(String longPath, JsonNode ruleJson) {
117-
// longPath = mergePrepare.trimLastInPath(longPath, ".");
118-
String pathNoIndexes = mergePrepare.removeArrayIndexes(longPath);
119-
String[] pathSubstrings = pathNoIndexes.split("\\.");
120-
JsonNode mergeObject = ruleJson;
121-
122-
try {
123-
String pathString = "";
124-
for (int i = 1; i < pathSubstrings.length; i++) {
125-
int mergePathIndex = pathSubstrings.length - (1 + i);
126-
String pathElement = pathSubstrings[mergePathIndex];
127-
ObjectNode newObject = JsonNodeFactory.instance.objectNode();
128-
newObject.put(pathElement, mergeObject);
129-
mergeObject = newObject;
130-
}
131-
} catch (Exception e) {
132-
log.info(e.getMessage(), e);
133-
}
134-
135-
return mergeObject.toString();
136-
}
137-
138104
/**
139105
* Get the rule path as dot notation
140106
*

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ public List<String> findObjectsByCondition(String condition) {
139139
public String findObjectById(String id) {
140140
String condition = "{\"_id\" : \"" + id + "\"}";
141141
String document = findObjectsByCondition(condition).get(0);
142-
// JsonNode result = getAggregatedObject(document);
143-
// if (result != null)
144-
// return result.asText();
145142
return document;
146143
}
147144

@@ -165,7 +162,7 @@ public JsonNode prepareDocumentForInsertion(String id, String object) {
165162

166163
return jsonNode;
167164
} catch (Exception e) {
168-
log.info(e.getMessage(), e);
165+
log.error(e.getMessage(), e);
169166
}
170167
return null;
171168
}
@@ -177,7 +174,7 @@ public JsonNode getAggregatedObject(String dbDocument) {
177174
JsonNode objectDoc = documentJson.get("aggregatedObject");
178175
return objectDoc;
179176
} catch (Exception e) {
180-
log.info(e.getMessage(), e);
177+
log.error(e.getMessage(), e);
181178
}
182179
return null;
183180
}
@@ -209,14 +206,14 @@ public String lockDocument(String id) {
209206
Document result = mongoDbHandler.findAndModify(databaseName, collectionName, queryCondition.toString(),
210207
documentJson.toString());
211208
if (result != null) {
212-
log.info("DB locked by " + Thread.currentThread().getId() + " thread");
209+
log.debug("DB locked by " + Thread.currentThread().getId() + " thread");
213210
documentLocked = false;
214211
return JSON.serialize(result);
215212
}
216213
// To Remove
217-
log.info("Waiting by " + Thread.currentThread().getId() + " thread");
214+
log.debug("Waiting by " + Thread.currentThread().getId() + " thread");
218215
} catch (Exception e) {
219-
log.info(e.getMessage(), e);
216+
log.error(e.getMessage(), e);
220217
}
221218
}
222219
return null;

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,6 @@ public static String longestCommonSubstring(String s1, String s2) {
122122
return s1.substring(start, (start + max));
123123
}
124124

125-
public static String longestCommonSubstring1(String s1, String s2) {
126-
String[] s1Substrings = s1.split("\\.");
127-
String[] s2Substrings = s2.split("\\.");
128-
129-
ArrayList<String> set1 = new ArrayList(Arrays.asList(s1Substrings));
130-
ArrayList<String> set2 = new ArrayList(Arrays.asList(s2Substrings));
131-
set1.retainAll(set2);
132-
String[] commonSubstrings = new String[set1.size()];
133-
commonSubstrings = (String[]) set1.toArray(commonSubstrings);
134-
String commonPath = StringUtils.join(commonSubstrings, ".");
135-
return commonPath;
136-
}
137-
138125
// TODO fix so that we do not need to pass both originObject and
139126
// stringObject which are
140127
// different representations of the same object.
@@ -173,7 +160,7 @@ public String getMergePathFromArrayMergeRules(String originObject, String mergeR
173160
return finalPath;
174161
}
175162
} catch (Exception ne) {
176-
log.info(ne.getMessage(), ne);
163+
log.error(ne.getMessage(), ne);
177164
}
178165
return "";
179166
}
@@ -228,7 +215,7 @@ public String getMergePath(String originObject, String mergeRule) {
228215
} catch (JSONException e) {
229216
return getMergePathFromArrayMergeRules(originObject, mergeRule, stringObject);
230217
} catch (Exception e) {
231-
log.info(e.getMessage(), e);
218+
log.error(e.getMessage(), e);
232219
}
233220
Map<String, Object> flattenJson = JsonFlattener.flattenAsMap(stringObject);
234221
String flattenRule = JsonFlattener.flatten(stringRule);
@@ -293,11 +280,9 @@ public String getMergePath(String originObject, String mergeRule) {
293280
if (index == 0) {
294281
String s1 = pathsContainingRule.get(index);
295282
String s2 = pathsContainingRule.get(index + 1);
296-
String temp = longestCommonSubstring1(s1, s2);
297283
longestCommonString = longestCommonSubstring(s1, s2);
298284
} else {
299285
String s1 = pathsContainingRule.get(index + 1);
300-
String temp = longestCommonSubstring1(s1, longestCommonString);
301286
longestCommonString = longestCommonSubstring(s1, longestCommonString);
302287
}
303288
}
@@ -307,11 +292,6 @@ public String getMergePath(String originObject, String mergeRule) {
307292
// remove index at the end
308293
String pattern = "\\.\\d*$";
309294
longestCommonString = longestCommonString.replaceAll(pattern, "");
310-
// if (longestCommonString.matches(".*\\.0")) {
311-
// longestCommonString = longestCommonString.substring(0,
312-
// longestCommonString.length() - 2);
313-
// int breakHere = 0;
314-
// }
315295
if (longestCommonString.startsWith(".")) {
316296
longestCommonString = "";
317297
}
@@ -438,7 +418,7 @@ public String addMissingLevels(String originObject, String objectToMerge, String
438418
}
439419
}
440420
} catch (Exception e) {
441-
log.info(e.getMessage(), e);
421+
log.error(e.getMessage(), e);
442422
}
443423
return newObject.toString();
444424
}
@@ -473,7 +453,7 @@ private int getOriginObjectArraySize(String originObject, JSONArray mergePathArr
473453
return size;
474454
}
475455
} catch (JSONException e) {
476-
log.info(e.getMessage(), e);
456+
log.error(e.getMessage(), e);
477457
}
478458

479459
return size;

0 commit comments

Comments
 (0)