Skip to content

Commit 0aaae1d

Browse files
Merge branch 'master' into master
2 parents b118073 + 7a529ac commit 0aaae1d

File tree

10 files changed

+143
-90
lines changed

10 files changed

+143
-90
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@
221221
<plugin>
222222
<groupId>org.springframework.boot</groupId>
223223
<artifactId>spring-boot-maven-plugin</artifactId>
224-
</plugin>
224+
</plugin>
225225

226-
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
226+
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
227227
from raml -->
228228
<plugin>
229229
<groupId>com.phoenixnap.oss</groupId>
@@ -274,8 +274,8 @@
274274
</configuration>
275275
</execution>
276276
</executions>
277-
</plugin>
278-
277+
</plugin>
278+
279279
<plugin>
280280
<groupId>org.apache.maven.plugins</groupId>
281281
<artifactId>maven-surefire-plugin</artifactId>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class ObjectHandler {
4848
@Value("${aggregated.collection.name}")
4949
private String collectionName;
5050

51-
5251
@Getter @Setter
5352
@Value("${spring.data.mongodb.database}")
5453
private String databaseName;
@@ -87,7 +86,8 @@ public boolean insertObject(String aggregatedObject, RulesObject rulesObject, St
8786
boolean result = mongoDbHandler.insertDocument(databaseName, collectionName, document.toString());
8887
if (result)
8988
eventToObjectMap.updateEventToObjectMapInMemoryDB(rulesObject, event, id);
90-
subscriptionHandler.checkSubscriptionForObject(aggregatedObject);
89+
90+
subscriptionHandler.checkSubscriptionForObject(aggregatedObject, id);
9191
return result;
9292
}
9393

@@ -123,7 +123,7 @@ public boolean updateObject(String aggregatedObject, RulesObject rulesObject, St
123123
boolean result = mongoDbHandler.updateDocument(databaseName, collectionName, condition, documentStr);
124124
if (result) {
125125
eventToObjectMap.updateEventToObjectMapInMemoryDB(rulesObject, event, id);
126-
subscriptionHandler.checkSubscriptionForObject(aggregatedObject);
126+
subscriptionHandler.checkSubscriptionForObject(aggregatedObject, id);
127127
}
128128
return result;
129129
}

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.fasterxml.jackson.databind.ObjectMapper;
3131
import com.fasterxml.jackson.databind.node.ArrayNode;
3232

33-
3433
/**
3534
* This class represents the mechanism to fetch the rule conditions from the
3635
* Subscription Object and match it with the aggregatedObject to check if it is
@@ -46,53 +45,58 @@ public class RunSubscription {
4645

4746
@Autowired
4847
private JmesPathInterface jmespath;
49-
48+
5049
@Autowired
51-
private SubscriptionRepeatDbHandler subscriptionRepeatDbHandler;
52-
53-
/**
50+
private SubscriptionRepeatDbHandler subscriptionRepeatDbHandler;
51+
52+
/**
5453
* This method matches every condition specified in the subscription Object
5554
* and if all conditions are matched then only the aggregatedObject is
5655
* eligible for notification via e-mail or REST POST.
5756
*
58-
* (AND between conditions in requirements, "OR" between requirements with conditions)
57+
* (AND between conditions in requirements, "OR" between requirements with
58+
* conditions)
5959
*
6060
* @param aggregatedObject
6161
* @param requirementIterator
6262
* @return boolean
6363
*/
64-
public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNode> requirementIterator, JsonNode subscriptionJson) {
64+
public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNode> requirementIterator,
65+
JsonNode subscriptionJson, String id) {
6566
boolean conditionFulfilled = false;
6667
int count_condition_fulfillment = 0;
6768
int count_conditions = 0;
6869

6970
int requirementIndex = 0;
7071

7172
while (requirementIterator.hasNext()) {
72-
73+
7374
JsonNode aggrObjJsonNode = null;
7475
ObjectMapper objectMapper = new ObjectMapper();
7576
try {
76-
aggrObjJsonNode = objectMapper.readValue(aggregatedObject, JsonNode.class);
77+
aggrObjJsonNode = objectMapper.readValue(aggregatedObject, JsonNode.class);
7778
} catch (Exception e) {
7879
LOGGER.error(e.getMessage(), e);
7980
}
80-
81-
82-
String aggrObjId = aggrObjJsonNode.get("id").asText();
81+
8382
String subscriptionName = subscriptionJson.get("subscriptionName").asText();
8483
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;
84+
85+
if (id == null) {
86+
LOGGER.error(
87+
"ID has not been passed for given aggregated object. The subscription will be triggered again.");
88+
}
89+
90+
if (subscriptionRepeatFlag == "false" && id != null && subscriptionRepeatDbHandler
91+
.checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(subscriptionName, requirementIndex, id)) {
92+
LOGGER.info("Subscription has already matched with AggregatedObject Id: " + id + "\nSubscriptionName: "
93+
+ subscriptionName + "\nand has Subscrption Repeat flag set to: " + subscriptionRepeatFlag);
94+
break;
9195
}
92-
96+
9397
JsonNode requirement = requirementIterator.next();
9498

95-
LOGGER.info("The fulfilled requirement which will condition checked is : " + requirement.toString());
99+
LOGGER.info("The fulfilled requirement which condition will check is : " + requirement.toString());
96100
ArrayNode conditions = (ArrayNode) requirement.get("conditions");
97101

98102
count_condition_fulfillment = 0;
@@ -107,24 +111,25 @@ public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNod
107111
LOGGER.info("New Rule after replacing single quote : " + new_Rule);
108112
JsonNode result = jmespath.runRuleOnEvent(rule, aggregatedObject);
109113
LOGGER.info("Result : " + result.toString());
110-
if (result.toString() != null && result.toString() != "false" && !result.toString().equals("[]")){
114+
if (result.toString() != null && result.toString() != "false" && !result.toString().equals("[]")) {
111115
count_condition_fulfillment++;
112116
}
113117
}
114118

115-
if(count_conditions != 0 && count_condition_fulfillment == count_conditions){
119+
if (count_conditions != 0 && count_condition_fulfillment == count_conditions) {
116120
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-
}
121+
if (subscriptionJson.get("repeat").toString() == "false" && id != null) {
122+
LOGGER.info("Adding matched AggrObj id to SubscriptionRepeatFlagHandlerDb.");
123+
try {
124+
subscriptionRepeatDbHandler.addMatchedAggrObjToSubscriptionId(subscriptionName,
125+
requirementIndex, id);
126+
} catch (Exception e) {
127+
LOGGER.error(e.getMessage());
128+
e.printStackTrace();
129+
}
125130
}
126131
}
127-
132+
128133
requirementIndex++;
129134
}
130135

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public class SubscriptionHandler {
7373
*
7474
* @param aggregatedObject
7575
*/
76-
public void checkSubscriptionForObject(final String aggregatedObject) {
76+
public void checkSubscriptionForObject(final String aggregatedObject, final String id) {
7777
Thread subscriptionThread = new Thread(() -> {
7878
List<String> subscriptions = mongoDBHandler.getAllDocuments(subscriptionDataBaseName,
7979
subscriptionCollectionName);
80-
subscriptions.forEach(subscription -> extractConditions(aggregatedObject, subscription));
80+
subscriptions.forEach(subscription -> extractConditions(aggregatedObject, subscription, id));
8181
});
8282
subscriptionThread.setName("SubscriptionHandler");
8383
subscriptionThread.start();
@@ -90,8 +90,9 @@ public void checkSubscriptionForObject(final String aggregatedObject) {
9090
*
9191
* @param aggregatedObject
9292
* @param subscriptionData
93+
* @param id
9394
*/
94-
private void extractConditions(String aggregatedObject, String subscriptionData) {
95+
private void extractConditions(String aggregatedObject, String subscriptionData, String id) {
9596
JsonNode subscriptionJson = null;
9697
try {
9798
subscriptionJson = new ObjectMapper().readTree(subscriptionData);
@@ -104,7 +105,7 @@ private void extractConditions(String aggregatedObject, String subscriptionData)
104105
ArrayNode requirementNode = (ArrayNode) subscriptionJson.get("requirements");
105106
LOGGER.debug("Requirements : " + requirementNode.toString());
106107
Iterator<JsonNode> requirementIterator = requirementNode.elements();
107-
if (runSubscription.runSubscriptionOnObject(aggregatedObject, requirementIterator, subscriptionJson)) {
108+
if (runSubscription.runSubscriptionOnObject(aggregatedObject, requirementIterator, subscriptionJson, id)) {
108109
LOGGER.debug("The subscription conditions match for the aggregatedObject");
109110
informSubscription.informSubscriber(aggregatedObject, subscriptionJson);
110111
}

src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ server.port: 8090
88
rules.path: /ArtifactRules_new.json
99

1010
logging.level.root: OFF
11-
1211
logging.level.org.springframework.web: ERROR
1312
logging.level.com.ericsson.ei: ERROR
1413

src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.mongodb.client.MongoDatabase;
2525
import com.rabbitmq.client.Channel;
2626

27-
2827
import java.io.File;
2928
import java.io.IOException;
3029
import java.util.HashMap;

src/test/java/com/ericsson/ei/flowtests/SingleEventAggregationTest.java

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.ericsson.ei.flowtests;
1818

1919
import org.apache.commons.io.FileUtils;
20+
import org.json.JSONArray;
2021
import org.junit.Before;
2122
import org.junit.runner.RunWith;
2223
import org.mockito.Mock;
@@ -29,10 +30,12 @@
2930
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3031
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
3132

33+
import com.ericsson.ei.controller.model.Subscription;
3234
import com.ericsson.ei.erqueryservice.ERQueryService;
3335
import com.ericsson.ei.erqueryservice.SearchOption;
3436
import com.ericsson.ei.handlers.ObjectHandler;
3537
import com.ericsson.ei.handlers.UpStreamEventsHandler;
38+
import com.ericsson.ei.services.ISubscriptionService;
3639
import com.fasterxml.jackson.databind.JsonNode;
3740
import com.fasterxml.jackson.databind.ObjectMapper;
3841
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -59,13 +62,17 @@ public class SingleEventAggregationTest extends FlowTestBase {
5962

6063
private static final String RULES_FILE_PATH = "src/test/resources/all_event_rules.json";
6164
private static final String EVENTS_FILE_PATH = "src/test/resources/test_All_Events.json";
65+
private static final String subscriptionJsonPath = "src/test/resources/subscription_CLME.json";
6266

6367
@Autowired
6468
private ObjectHandler objectHandler;
6569

6670
@Autowired
6771
private UpStreamEventsHandler upStreamEventsHandler;
6872

73+
@Autowired
74+
private ISubscriptionService subscriptionService;
75+
6976
@Mock
7077
private ERQueryService erQueryService;
7178

@@ -86,43 +93,54 @@ public void before() {
8693
when(erQueryService.getEventStreamDataById(anyString(), any(SearchOption.class), anyInt(), anyInt(),
8794
anyBoolean())).thenReturn(null);
8895
super.setFirstEventWaitTime(5000);
96+
97+
try {
98+
ObjectMapper mapper = new ObjectMapper();
99+
String readFileToString = FileUtils.readFileToString(new File(subscriptionJsonPath), "UTF-8");
100+
JSONArray jsonArray = new JSONArray(readFileToString);
101+
Subscription subscription = mapper.readValue(jsonArray.getJSONObject(0).toString(), Subscription.class);
102+
boolean addSubscription = subscriptionService.addSubscription(subscription);
103+
assertEquals(addSubscription, true);
104+
} catch (Exception e) {
105+
106+
}
89107
}
90108

91109
@Override
92110
List<String> getEventNamesToSend() {
93111
ArrayList<String> eventNames = new ArrayList<>();
94-
eventNames.add("EiffelActivityCanceledEvent");
95-
eventNames.add("EiffelActivityStartedEvent");
96-
eventNames.add("EiffelActivityFinishedEvent");
97-
eventNames.add("EiffelActivityTriggeredEvent");
98-
eventNames.add("EiffelAnnouncementPublishedEvent");
99-
eventNames.add("EiffelArtifactCreatedEvent");
100-
eventNames.add("EiffelArtifactPublishedEvent");
101-
eventNames.add("EiffelArtifactReusedEvent");
102-
eventNames.add("EiffelCompositionDefinedEvent");
112+
// eventNames.add("EiffelActivityCanceledEvent");
113+
// eventNames.add("EiffelActivityStartedEvent");
114+
// eventNames.add("EiffelActivityFinishedEvent");
115+
// eventNames.add("EiffelActivityTriggeredEvent");
116+
// eventNames.add("EiffelAnnouncementPublishedEvent");
117+
// eventNames.add("EiffelArtifactCreatedEvent");
118+
// eventNames.add("EiffelArtifactPublishedEvent");
119+
// eventNames.add("EiffelArtifactReusedEvent");
120+
// eventNames.add("EiffelCompositionDefinedEvent");
103121
eventNames.add("EiffelConfidenceLevelModifiedEvent");
104-
eventNames.add("EiffelEnvironmentDefinedEvent");
105-
eventNames.add("EiffelFlowContextDefinedEvent");
106-
eventNames.add("EiffelIssueVerifiedEvent");
107-
eventNames.add("EiffelSourceChangeCreatedEvent");
108-
eventNames.add("EiffelSourceChangeSubmittedEvent");
109-
eventNames.add("EiffelTestCaseCanceledEvent");
110-
eventNames.add("EiffelTestCaseFinishedEvent");
111-
eventNames.add("EiffelTestCaseStartedEvent");
112-
eventNames.add("EiffelTestCaseTriggeredEvent");
113-
eventNames.add("EiffelTestExecutionRecipeCollectionCreatedEvent");
114-
eventNames.add("EiffelTestSuiteFinishedEvent");
115-
eventNames.add("EiffelTestSuiteStartedEvent");
116-
eventNames.add("EiffelArtifactDeployedEvent");
117-
eventNames.add("EiffelServiceAllocatedEvent");
118-
eventNames.add("EiffelServiceDeployedEvent");
119-
eventNames.add("EiffelServiceDiscontinuedEvent");
120-
eventNames.add("EiffelServiceReturnedEvent");
121-
eventNames.add("EiffelServiceStartedEvent");
122-
eventNames.add("EiffelServiceStoppedEvent");
123-
eventNames.add("EiffelAlertAcknowledgedEvent");
124-
eventNames.add("EiffelAlertCeasedEvent");
125-
eventNames.add("EiffelAlertRaisedEvent");
122+
// eventNames.add("EiffelEnvironmentDefinedEvent");
123+
// eventNames.add("EiffelFlowContextDefinedEvent");
124+
// eventNames.add("EiffelIssueVerifiedEvent");
125+
// eventNames.add("EiffelSourceChangeCreatedEvent");
126+
// eventNames.add("EiffelSourceChangeSubmittedEvent");
127+
// eventNames.add("EiffelTestCaseCanceledEvent");
128+
// eventNames.add("EiffelTestCaseFinishedEvent");
129+
// eventNames.add("EiffelTestCaseStartedEvent");
130+
// eventNames.add("EiffelTestCaseTriggeredEvent");
131+
// eventNames.add("EiffelTestExecutionRecipeCollectionCreatedEvent");
132+
// eventNames.add("EiffelTestSuiteFinishedEvent");
133+
// eventNames.add("EiffelTestSuiteStartedEvent");
134+
// eventNames.add("EiffelArtifactDeployedEvent");
135+
// eventNames.add("EiffelServiceAllocatedEvent");
136+
// eventNames.add("EiffelServiceDeployedEvent");
137+
// eventNames.add("EiffelServiceDiscontinuedEvent");
138+
// eventNames.add("EiffelServiceReturnedEvent");
139+
// eventNames.add("EiffelServiceStartedEvent");
140+
// eventNames.add("EiffelServiceStoppedEvent");
141+
// eventNames.add("EiffelAlertAcknowledgedEvent");
142+
// eventNames.add("EiffelAlertCeasedEvent");
143+
// eventNames.add("EiffelAlertRaisedEvent");
126144

127145
return eventNames;
128146
}

src/test/java/com/ericsson/ei/subscription/SubscriptionServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class SubscriptionServiceTest {
7070

7171
private ObjectMapper mapper = new ObjectMapper();
7272

73-
private static final String subscriptionJsonPath = "src/test/resources/subscription_single.json";
73+
private static final String subscriptionJsonPath = "src/test/resources/subscription_CLME.json";
7474

7575
static JSONArray jsonArray = null;
7676
static MongoClient mongoClient = null;

0 commit comments

Comments
 (0)