Skip to content

Commit fe99743

Browse files
Merge branch 'master' into master
2 parents ab7629e + 5868466 commit fe99743

File tree

11 files changed

+666
-32
lines changed

11 files changed

+666
-32
lines changed

pom.xml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,60 @@
201201
<plugin>
202202
<groupId>org.springframework.boot</groupId>
203203
<artifactId>spring-boot-maven-plugin</artifactId>
204-
</plugin>
204+
</plugin>
205+
206+
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
207+
from raml -->
208+
<plugin>
209+
<groupId>com.phoenixnap.oss</groupId>
210+
<artifactId>springmvc-raml-plugin</artifactId>
211+
<version>${plugin-version}</version>
212+
<configuration>
213+
<!-- path to raml file -->
214+
<ramlPath>${raml-path}</ramlPath>
215+
<!-- output of generated code -->
216+
<outputRelativePath>${output-relative-path}</outputRelativePath>
217+
<addTimestampFolder>false</addTimestampFolder>
218+
<!-- package for generated sources -->
219+
<basePackage>${base-package}</basePackage>
220+
<baseUri>/</baseUri>
221+
<seperateMethodsByContentType>false</seperateMethodsByContentType>
222+
<useJackson1xCompatibility>false</useJackson1xCompatibility>
223+
<rule>com.phoenixnap.oss.ramlapisync.generation.rules.Spring4ControllerInterfaceRule</rule>
224+
<generationConfig>
225+
<useCommonsLang3>true</useCommonsLang3>
226+
</generationConfig>
227+
</configuration>
228+
<executions>
229+
<execution>
230+
<id>generate-springmvc-controllers</id>
231+
<phase>generate-sources</phase>
232+
<goals>
233+
<goal>generate-springmvc-endpoints</goal>
234+
</goals>
235+
</execution>
236+
</executions>
237+
</plugin>
238+
239+
<!-- required for adding generated sources -->
240+
<plugin>
241+
<groupId>org.codehaus.mojo</groupId>
242+
<artifactId>build-helper-maven-plugin</artifactId>
243+
<executions>
244+
<execution>
245+
<phase>generate-sources</phase>
246+
<goals>
247+
<goal>add-source</goal>
248+
</goals>
249+
<configuration>
250+
<sources>
251+
<!-- where to find the generated sources -->
252+
<source>${output-relative-path}</source>
253+
</sources>
254+
</configuration>
255+
</execution>
256+
</executions>
257+
</plugin>
205258

206259
<plugin>
207260
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/ericsson/ei/mongodbhandler/MongoDBHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,11 @@ private MongoCollection<Document> getMongoCollection(String dataBaseName, String
290290
MongoCollection<Document> collection = db.getCollection(collectionName);
291291
return collection;
292292
}
293+
294+
public void dropCollection(String dataBaseName, String collectionName) {
295+
MongoDatabase db = mongoClient.getDatabase(dataBaseName);
296+
MongoCollection<Document> mongoCollection = db.getCollection(collectionName);
297+
mongoCollection.drop();
298+
}
293299

294300
}

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

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
*/
1717
package com.ericsson.ei.subscriptionhandler;
1818

19-
import com.ericsson.ei.jmespath.JmesPathInterface;
20-
import com.fasterxml.jackson.databind.JsonNode;
21-
import com.fasterxml.jackson.databind.node.ArrayNode;
19+
import java.util.HashMap;
20+
import java.util.Iterator;
21+
import java.util.concurrent.ConcurrentHashMap;
22+
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425
import org.springframework.beans.factory.annotation.Autowired;
2526
import org.springframework.stereotype.Component;
2627

27-
import java.util.Iterator;
28+
import com.ericsson.ei.jmespath.JmesPathInterface;
29+
import com.fasterxml.jackson.databind.JsonNode;
30+
import com.fasterxml.jackson.databind.ObjectMapper;
31+
import com.fasterxml.jackson.databind.node.ArrayNode;
2832

2933

3034
/**
@@ -42,8 +46,11 @@ public class RunSubscription {
4246

4347
@Autowired
4448
private JmesPathInterface jmespath;
45-
46-
/**
49+
50+
@Autowired
51+
private SubscriptionRepeatDbHandler subscriptionRepeatDbHandler;
52+
53+
/**
4754
* This method matches every condition specified in the subscription Object
4855
* and if all conditions are matched then only the aggregatedObject is
4956
* eligible for notification via e-mail or REST POST.
@@ -54,34 +61,75 @@ public class RunSubscription {
5461
* @param requirementIterator
5562
* @return boolean
5663
*/
57-
public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNode> requirementIterator) {
64+
public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNode> requirementIterator, JsonNode subscriptionJson) {
5865
boolean conditionFulfilled = false;
59-
int countConditionFulfillment;
60-
int countConditions;
66+
int count_condition_fulfillment = 0;
67+
int count_conditions = 0;
68+
69+
int requirementIndex = 0;
70+
6171
while (requirementIterator.hasNext()) {
72+
73+
JsonNode aggrObjJsonNode = null;
74+
ObjectMapper objectMapper = new ObjectMapper();
75+
try {
76+
aggrObjJsonNode = objectMapper.readValue(aggregatedObject, JsonNode.class);
77+
} catch (Exception e) {
78+
LOGGER.error(e.getMessage(), e);
79+
}
80+
81+
82+
String aggrObjId = aggrObjJsonNode.get("id").asText();
83+
String subscriptionName = subscriptionJson.get("subscriptionName").asText();
84+
String subscriptionRepeatFlag = subscriptionJson.get("repeat").asText();
85+
86+
if (subscriptionRepeatFlag == "false" && subscriptionRepeatDbHandler.checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(subscriptionName, requirementIndex, aggrObjId)){
87+
LOGGER.info("Subscription has already matched with AggregatedObject Id: " + aggrObjId +
88+
"\nSubscriptionName: " + subscriptionName +
89+
"\nand has Subsctrion Repeat flag set to: " + subscriptionRepeatFlag);
90+
break;
91+
}
92+
6293
JsonNode requirement = requirementIterator.next();
63-
LOGGER.debug("The fulfilled requirement which will condition checked is : " + requirement.toString());
94+
95+
LOGGER.info("The fulfilled requirement which will condition checked is : " + requirement.toString());
6496
ArrayNode conditions = (ArrayNode) requirement.get("conditions");
65-
countConditionFulfillment = 0;
66-
countConditions = conditions.size();
67-
LOGGER.debug("Conditions of the subscription : " + conditions.toString());
97+
98+
count_condition_fulfillment = 0;
99+
count_conditions = conditions.size();
100+
101+
LOGGER.info("Conditions of the subscription : " + conditions.toString());
68102
Iterator<JsonNode> conditionIterator = conditions.elements();
69103
while (conditionIterator.hasNext()) {
70104
String rule = conditionIterator.next().get("jmespath").toString().replaceAll("^\"|\"$", "");
71-
String newRule = rule.replace("'", "\"");
72-
LOGGER.debug("Rule : " + rule);
73-
LOGGER.debug("New Rule after replacing single quote : " + newRule);
105+
String new_Rule = rule.replace("'", "\"");
106+
LOGGER.info("Rule : " + rule);
107+
LOGGER.info("New Rule after replacing single quote : " + new_Rule);
74108
JsonNode result = jmespath.runRuleOnEvent(rule, aggregatedObject);
75-
LOGGER.debug("Result : " + result.toString());
76-
if (result.toString() != null && !result.toString().equals("false") && !result.toString().equals("[]")) {
77-
countConditionFulfillment++;
109+
LOGGER.info("Result : " + result.toString());
110+
if (result.toString() != null && result.toString() != "false" && !result.toString().equals("[]")){
111+
count_condition_fulfillment++;
78112
}
79113
}
80-
if (countConditions != 0 && countConditionFulfillment == countConditions) {
114+
115+
if(count_conditions != 0 && count_condition_fulfillment == count_conditions){
81116
conditionFulfilled = true;
117+
if (subscriptionJson.get("repeat").toString() == "false") {
118+
LOGGER.info("Adding matched AggrObj id to SubscriptionRepeatFlagHandlerDb.");
119+
try {
120+
subscriptionRepeatDbHandler.addMatchedAggrObjToSubscriptionId(subscriptionName, requirementIndex, aggrObjId);
121+
} catch (Exception e) {
122+
LOGGER.error(e.getMessage());
123+
e.printStackTrace();
124+
}
125+
}
82126
}
127+
128+
requirementIndex++;
83129
}
84-
LOGGER.debug("The final value of conditionFulfilled is : " + conditionFulfilled);
130+
131+
LOGGER.info("The final value of conditionFulfilled is : " + conditionFulfilled);
132+
85133
return conditionFulfilled;
86134
}
87135
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ private void extractConditions(String aggregatedObject, String subscriptionData)
102102
LOGGER.error(e.getMessage(), e);
103103
}
104104
ArrayNode requirementNode = (ArrayNode) subscriptionJson.get("requirements");
105-
LOGGER.debug("RequirementNode : " + requirementNode.toString());
105+
LOGGER.debug("Requirements : " + requirementNode.toString());
106106
Iterator<JsonNode> requirementIterator = requirementNode.elements();
107-
if (runSubscription.runSubscriptionOnObject(aggregatedObject, requirementIterator)) {
107+
if (runSubscription.runSubscriptionOnObject(aggregatedObject, requirementIterator, subscriptionJson)) {
108108
LOGGER.debug("The subscription conditions match for the aggregatedObject");
109109
informSubscription.informSubscriber(aggregatedObject, subscriptionJson);
110110
}

0 commit comments

Comments
 (0)