Skip to content

Commit c7cf382

Browse files
Fix use of mergeidmarker property in MatchIdRulesHandler (#391)
* Rename property mergeidmarker to rules.replacement.marker * Update documentation for configuration and rules.replacement.marker * Update application.properties with comments * Update all rules with new placeholder key * Move rules classes into rules package
1 parent e1d4d66 commit c7cf382

39 files changed

+510
-425
lines changed

src/main/java/com/ericsson/ei/config/ConfigurationLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private void logConfiguration() {
3838
+ "rabbitmq.queue.durable: " + environment.getProperty("rabbitmq.queue.durable") + "\n"
3939
+ "rabbitmq.binding.key: " + environment.getProperty("rabbitmq.binding.key") + "\n"
4040
+ "rabbitmq.waitlist.queue.suffix: " + environment.getProperty("rabbitmq.waitlist.queue.suffix") + "\n"
41-
+ "mergeidmarker: " + environment.getProperty("mergeidmarker") + "\n"
41+
+ "rules.replacement.marker: " + environment.getProperty("rules.replacement.marker") + "\n"
4242
+ "spring.data.mongodb.host: " + environment.getProperty("spring.data.mongodb.host") + "\n"
4343
+ "spring.data.mongodb.port: " + environment.getProperty("spring.data.mongodb.port") + "\n"
4444
+ "spring.data.mongodb.username: " + environment.getProperty("spring.data.mongodb.username") + "\n"

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

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

1919
import java.util.List;
2020

21+
import com.ericsson.ei.rules.MatchIdRulesHandler;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324
import org.springframework.beans.factory.annotation.Autowired;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package com.ericsson.ei.handlers;
1818

19+
import com.ericsson.ei.rules.IdRulesHandler;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122
import org.springframework.amqp.core.Message;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package com.ericsson.ei.handlers;
1818

19+
import com.ericsson.ei.rules.ProcessRulesHandler;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122
import org.springframework.beans.factory.annotation.Autowired;

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class MergeHandler {
3737

3838
private static final Logger LOGGER = LoggerFactory.getLogger(MergeHandler.class);
3939

40-
@Value("${mergeidmarker}")
41-
private String mergeIdMarker;
40+
@Value("${rules.replacement.marker}")
41+
private String replacementMarker;
4242

4343
@Autowired
4444
private JmesPathInterface jmesPathInterface;
@@ -57,8 +57,8 @@ public void setPrepareMergePrepareObject(MergePrepare prepareMergePrepareObject)
5757
this.prepareMergePrepareObject = prepareMergePrepareObject;
5858
}
5959

60-
public void setMergeIdMarker(String marker) {
61-
mergeIdMarker = marker;
60+
public void setReplacementMarker(String marker) {
61+
replacementMarker = marker;
6262
}
6363

6464
/**
@@ -102,7 +102,7 @@ public String mergeObject(String id, String mergeId, RulesObject rules, String e
102102
}
103103

104104
/**
105-
*
105+
*
106106
* @param id the id of the aggregated object
107107
* @param mergeId the id of the link used to identify this aggregated
108108
* object
@@ -143,18 +143,19 @@ protected String getMergeRules(RulesObject rules) {
143143
}
144144

145145
/**
146-
* The merge rule can contain a placeholder for the ids from IdentifyRules. This
147-
* placeholder need to be replaced with an id from the ones extracted with
148-
* IdentifyRules before we use it in JMESPath.
149-
*
146+
* The merge rule can contain a placeholder for the ids extracted from IdentifyRules.
147+
* This placeholder need to be replaced with an id from the ones extracted with
148+
* IdentifyRules before we use it in JMESPath. The placeholder is defined in
149+
* application.properties as 'rules.replacement.marker'.
150+
*
150151
* @param rule string
151152
* @param id that the mergeIdMarker will be replaced with
152153
* @return JSON object ready to be used in JMESPath
153154
*/
154155
public String replaceIdMarkerInRules(String rule, String id) {
155156

156-
if (rule.contains(mergeIdMarker)) {
157-
String updatedRule = rule.replaceAll(mergeIdMarker, "\"" + id + "\"");
157+
if (rule.contains(replacementMarker)) {
158+
String updatedRule = rule.replaceAll(replacementMarker, "\"" + id + "\"");
158159
updatedRule = "`" + updatedRule + "`";
159160
return updatedRule;
160161
}
@@ -175,7 +176,7 @@ public String mergeContentToObject(String aggregatedObject, String preparedObjec
175176

176177
/**
177178
* Append preparedJsonObject to the given aggregatedJsonObject
178-
*
179+
*
179180
* @param aggregatedJsonObject JSON object
180181
* @param preparedJsonObject JSON object
181182
*/
@@ -217,7 +218,7 @@ private void updateJsonObject(JSONObject aggregatedJsonObject, JSONObject prepar
217218
/**
218219
* Append JSON elements from preparedJsonObject element-wise into
219220
* aggregatedJsonObject JSON array
220-
*
221+
*
221222
* @param aggregatedJsonObject JSON array
222223
* @param preparedJsonObject JSON array
223224
*/

src/main/java/com/ericsson/ei/notifications/UrlParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class UrlParser {
4949
* the url containing the new parameters.
5050
*
5151
* @param url
52+
* @param aggregatedObject
5253
*
5354
* @return String
5455
*/
@@ -87,7 +88,6 @@ public String runJmesPathOnParameters(String url, String aggregatedObject) {
8788
* @param url A String containing a URL
8889
* @return The base url, which excludes context path and parameters.
8990
* @throws MalformedURLException
90-
* @throws URISyntaxException
9191
*/
9292
public String extractBaseUrl(String url) throws MalformedURLException {
9393
URL absoluteUrl = new URL(url);
@@ -117,8 +117,7 @@ private String extractContextPath(String url) throws MalformedURLException {
117117
* @return
118118
* @throws MalformedURLException
119119
*/
120-
private List<NameValuePair> extractUrlParameters(String url)
121-
throws MalformedURLException {
120+
private List<NameValuePair> extractUrlParameters(String url) throws MalformedURLException {
122121
URL absoluteUrl = new URL(url);
123122
String query = absoluteUrl.getQuery();
124123
List<NameValuePair> params = splitQuery(query);

src/main/java/com/ericsson/ei/handlers/IdRulesHandler.java renamed to src/main/java/com/ericsson/ei/rules/IdRulesHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
17-
package com.ericsson.ei.handlers;
17+
package com.ericsson.ei.rules;
1818

19+
import com.ericsson.ei.handlers.ExtractionHandler;
1920
import com.ericsson.ei.jmespath.JmesPathInterface;
20-
import com.ericsson.ei.rules.RulesObject;
2121
import com.ericsson.ei.waitlist.WaitListStorageHandler;
2222
import com.fasterxml.jackson.databind.JsonNode;
2323
import org.slf4j.Logger;

src/main/java/com/ericsson/ei/handlers/MatchIdRulesHandler.java renamed to src/main/java/com/ericsson/ei/rules/MatchIdRulesHandler.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
17-
package com.ericsson.ei.handlers;
17+
package com.ericsson.ei.rules;
1818

1919
import java.util.List;
2020

21+
import com.ericsson.ei.handlers.ObjectHandler;
2122
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.beans.factory.annotation.Value;
2224
import org.springframework.stereotype.Component;
2325

2426
import com.ericsson.ei.mongo.MongoQuery;
@@ -28,9 +30,16 @@
2830
@Component
2931
public class MatchIdRulesHandler {
3032

33+
@Value("${rules.replacement.marker:%IdentifyRulesEventId%}")
34+
private String replacementMarker;
35+
3136
@Autowired
3237
private ObjectHandler objHandler;
3338

39+
/**
40+
* This method searches the database for any aggregated objects matching the search condition
41+
* written in the rules MatchIdRules.
42+
* */
3443
public List<String> fetchObjectsById(RulesObject ruleObject, String id) {
3544
String matchIdString = ruleObject.getMatchIdRules();
3645
String fetchQueryString = replaceIdInRules(matchIdString, id);
@@ -39,11 +48,24 @@ public List<String> fetchObjectsById(RulesObject ruleObject, String id) {
3948
return objects;
4049
}
4150

42-
public static String replaceIdInRules(String matchIdString, String id) {
43-
if (matchIdString.contains("%IdentifyRules%")) {
44-
return matchIdString.replace("%IdentifyRules%", id);
45-
} else if (matchIdString.contains("%IdentifyRules_objid%")) {
46-
return matchIdString.replace("%IdentifyRules_objid%", id);
51+
/**
52+
* This method replaces the 'replacementMarker' placeholder in MatchIdRules with a given Eiffel
53+
* event id. The 'replacementMarker' property is defined in application.properties.
54+
*
55+
* <p>
56+
* If 'replacementMarker' is defined as:'%myPlaceHolderId%', <br />
57+
* and this method is called with the matchIdString: {"_id": "%myPlaceHolderId%"} <br />
58+
* and the id: aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee0 <br />
59+
* the updated string will look like: {"_id":"aaaaaaaa-bbbb-5ccc-8ddd-eeeeeeeeeee0"}
60+
* </p>
61+
*
62+
* @param matchIdString the string containing a placeholder key to be replaced
63+
* @param id the Eiffel event id to replace placeholder with
64+
* @return an updated matchIdString
65+
*/
66+
public String replaceIdInRules(String matchIdString, String id) {
67+
if (matchIdString.contains(replacementMarker)) {
68+
return matchIdString.replace(replacementMarker, id);
4769
} else {
4870
return null;
4971
}

src/main/java/com/ericsson/ei/handlers/ProcessRulesHandler.java renamed to src/main/java/com/ericsson/ei/rules/ProcessRulesHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
17-
package com.ericsson.ei.handlers;
17+
package com.ericsson.ei.rules;
1818

19-
import com.ericsson.ei.rules.RulesHandler;
2019
import org.slf4j.Logger;
2120
import org.slf4j.LoggerFactory;
2221
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.beans.factory.annotation.Value;
2323
import org.springframework.stereotype.Component;
2424

2525
import com.ericsson.ei.jmespath.JmesPathInterface;
2626
import com.ericsson.ei.jsonmerge.MergeHandler;
27-
import com.ericsson.ei.rules.RulesObject;
2827
import com.fasterxml.jackson.databind.JsonNode;
2928

3029
@Component
3130
public class ProcessRulesHandler {
3231

3332
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessRulesHandler.class);
3433

34+
@Value("${rules.replacement.marker:%IdentifyRulesEventId%}")
35+
private String replacementMarker;
36+
3537
@Autowired
3638
private JmesPathInterface jmespath;
3739

@@ -55,8 +57,8 @@ public String runProcessRules(String event, RulesObject rulesObject, String aggr
5557
String identifyRule = rulesHandler.getRulesForEvent(event).getIdentifyRules();
5658
String id = jmespath.runRuleOnEvent(identifyRule, event).get(0).textValue();
5759

58-
if(processRules.contains("%IdentifyRules%")) {
59-
processRules = processRules.replace("%IdentifyRules%", id);
60+
if(processRules.contains(replacementMarker)) {
61+
processRules = processRules.replace(replacementMarker, id);
6062
}
6163

6264
LOGGER.info("processRules: {}\n aggregationObject: {}\n event: {}", processRules, aggregationObject, event);

src/main/java/com/ericsson/ei/waitlist/WaitListWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.stereotype.Component;
2929

3030
import com.ericsson.ei.handlers.EventToObjectMapHandler;
31-
import com.ericsson.ei.handlers.MatchIdRulesHandler;
31+
import com.ericsson.ei.rules.MatchIdRulesHandler;
3232
import com.ericsson.ei.handlers.RMQHandler;
3333
import com.ericsson.ei.jmespath.JmesPathInterface;
3434
import com.ericsson.ei.rules.RulesHandler;

0 commit comments

Comments
 (0)