Skip to content

Commit 4863db4

Browse files
authored
subscription handling updated & activated, clean up & bugfixes (#24)
* subscription handling updated & activated, clean up & bugfixes * Removed subscriptionDataBaseName & subscriptionCollectionName * TemplateName injected in aggregated object, subsription type removed, aggregationtype injected
1 parent d865fda commit 4863db4

File tree

21 files changed

+237
-69
lines changed

21 files changed

+237
-69
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<parent>
99
<groupId>org.springframework.boot</groupId>
1010
<artifactId>spring-boot-starter-parent</artifactId>
11-
<version>1.5.2.RELEASE</version>
11+
<version>1.5.4.RELEASE</version>
12+
<relativePath/> <!-- .. lookup parent from repository -->
1213
</parent>
1314

1415
<properties>

src/main/java/com/ericsson/ei/controller/model/Requirement.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
@JsonInclude(JsonInclude.Include.NON_NULL)
1919
@JsonPropertyOrder({
20-
"conditions",
21-
"type"
20+
"conditions"
2221
})
2322
public class Requirement {
2423

2524
@JsonProperty("conditions")
2625
private List<Condition> conditions = new ArrayList<Condition>();
27-
@JsonProperty("type")
28-
private String type;
2926
@JsonIgnore
3027
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
3128

@@ -49,26 +46,6 @@ public void setConditions(List<Condition> conditions) {
4946
this.conditions = conditions;
5047
}
5148

52-
/**
53-
*
54-
* @return
55-
* The type
56-
*/
57-
@JsonProperty("type")
58-
public String getType() {
59-
return type;
60-
}
61-
62-
/**
63-
*
64-
* @param type
65-
* The type
66-
*/
67-
@JsonProperty("type")
68-
public void setType(String type) {
69-
this.type = type;
70-
}
71-
7249
@Override
7350
public String toString() {
7451
return ToStringBuilder.reflectionToString(this);
@@ -86,7 +63,7 @@ public void setAdditionalProperty(String name, Object value) {
8663

8764
@Override
8865
public int hashCode() {
89-
return new HashCodeBuilder().append(conditions).append(type).append(additionalProperties).toHashCode();
66+
return new HashCodeBuilder().append(conditions).append(additionalProperties).toHashCode();
9067
}
9168

9269
@Override
@@ -98,7 +75,7 @@ public boolean equals(Object other) {
9875
return false;
9976
}
10077
Requirement rhs = ((Requirement) other);
101-
return new EqualsBuilder().append(conditions, rhs.conditions).append(type, rhs.type).append(additionalProperties, rhs.additionalProperties).isEquals();
78+
return new EqualsBuilder().append(conditions, rhs.conditions).append(additionalProperties, rhs.additionalProperties).isEquals();
10279
}
10380

10481
}

src/main/java/com/ericsson/ei/controller/model/Subscription.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
@JsonInclude(JsonInclude.Include.NON_NULL)
1919
@JsonPropertyOrder({
20+
"aggregationtype",
2021
"created",
2122
"notificationMessage",
2223
"notificationMeta",
@@ -27,6 +28,8 @@
2728
})
2829
public class Subscription {
2930

31+
@JsonProperty("aggregationtype")
32+
private String aggregationtype;
3033
@JsonProperty("created")
3134
private String created;
3235
@JsonProperty("notificationMessage")
@@ -44,6 +47,26 @@ public class Subscription {
4447
@JsonIgnore
4548
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
4649

50+
/**
51+
*
52+
* @return
53+
* The aggregationtype
54+
*/
55+
@JsonProperty("aggregationtype")
56+
public String getAggregationtype() {
57+
return aggregationtype;
58+
}
59+
60+
/**
61+
*
62+
* @param aggregationtype
63+
* The aggregationtype
64+
*/
65+
@JsonProperty("aggregationtype")
66+
public void setAggregationtype(String aggregationtype) {
67+
this.aggregationtype = aggregationtype;
68+
}
69+
4770
/**
4871
*
4972
* @return
@@ -201,7 +224,7 @@ public void setAdditionalProperty(String name, Object value) {
201224

202225
@Override
203226
public int hashCode() {
204-
return new HashCodeBuilder().append(created).append(notificationMessage).append(notificationMeta).append(notificationType).append(repeat).append(requirements).append(subscriptionName).append(additionalProperties).toHashCode();
227+
return new HashCodeBuilder().append(aggregationtype).append(created).append(notificationMessage).append(notificationMeta).append(notificationType).append(repeat).append(requirements).append(subscriptionName).append(additionalProperties).toHashCode();
205228
}
206229

207230
@Override
@@ -213,7 +236,7 @@ public boolean equals(Object other) {
213236
return false;
214237
}
215238
Subscription rhs = ((Subscription) other);
216-
return new EqualsBuilder().append(created, rhs.created).append(notificationMessage, rhs.notificationMessage).append(notificationMeta, rhs.notificationMeta).append(notificationType, rhs.notificationType).append(repeat, rhs.repeat).append(requirements, rhs.requirements).append(subscriptionName, rhs.subscriptionName).append(additionalProperties, rhs.additionalProperties).isEquals();
239+
return new EqualsBuilder().append(aggregationtype, rhs.aggregationtype).append(created, rhs.created).append(notificationMessage, rhs.notificationMessage).append(notificationMeta, rhs.notificationMeta).append(notificationType, rhs.notificationType).append(repeat, rhs.repeat).append(requirements, rhs.requirements).append(subscriptionName, rhs.subscriptionName).append(additionalProperties, rhs.additionalProperties).isEquals();
217240
}
218241

219242
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44

5+
import com.fasterxml.jackson.databind.node.ObjectNode;
56
import org.json.JSONException;
67
import org.json.JSONObject;
78
import org.slf4j.Logger;
@@ -68,6 +69,8 @@ public void runExtraction(RulesObject rulesObject, String id, String event, Json
6869
mergedContent = processRulesHandler.runProcessRules(event, rulesObject, mergedContent, objectId);
6970
//historyIdRulesHandler.runHistoryIdRules(aggregationObject, rulesObject, event);
7071
} else {
72+
ObjectNode objectNode = (ObjectNode) extractedContent;
73+
objectNode.put("TemplateName", rulesObject.getTemplateName());
7174
mergeHandler.addNewObject(event, extractedContent, rulesObject);
7275
}
7376
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44

5+
import com.ericsson.ei.subscriptionhandler.SubscriptionHandler;
56
import com.mongodb.DBObject;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
@@ -49,10 +50,19 @@ public void setJmespathInterface(JmesPathInterface jmespathInterface) {
4950
@Autowired
5051
private EventToObjectMapHandler eventToObjectMap;
5152

53+
5254
public void setEventToObjectMap(EventToObjectMapHandler eventToObjectMap) {
5355
this.eventToObjectMap = eventToObjectMap;
5456
}
5557

58+
@Autowired
59+
private SubscriptionHandler subscriptionHandler;
60+
61+
public void setSubscriptionHandler(SubscriptionHandler subscriptionHandler) {
62+
this.subscriptionHandler = subscriptionHandler;
63+
}
64+
65+
5666
public boolean insertObject(String aggregatedObject, RulesObject rulesObject, String event, String id) {
5767
if (id == null) {
5868
String idRules = rulesObject.getIdRule();
@@ -64,6 +74,7 @@ public boolean insertObject(String aggregatedObject, RulesObject rulesObject, St
6474
boolean result = mongoDbHandler.insertDocument(databaseName, collectionName, documentStr);
6575
if (result)
6676
eventToObjectMap.updateEventToObjectMapInMemoryDB(rulesObject, event, id);
77+
subscriptionHandler.checkSubscriptionForObject(aggregatedObject);
6778
return result;
6879
}
6980

@@ -92,6 +103,7 @@ public boolean updateObject(String aggregatedObject, RulesObject rulesObject, St
92103
boolean result = mongoDbHandler.updateDocument(databaseName, collectionName, condition, documentStr);
93104
if (result)
94105
eventToObjectMap.updateEventToObjectMapInMemoryDB(rulesObject, event, id);
106+
subscriptionHandler.checkSubscriptionForObject(aggregatedObject);
95107
return result;
96108
}
97109

src/main/java/com/ericsson/ei/rules/RulesObject.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public JsonNode getJsonRulesObject() {
1414
return rulesObject;
1515
}
1616

17+
public String getTemplateName() {
18+
JsonNode jsonNode = rulesObject.get("TemplateName");
19+
if (jsonNode != null)
20+
return jsonNode.textValue();
21+
return "";
22+
}
23+
1724
public String getMatchIdRules() {
1825
JsonNode jsonNode = rulesObject.get("MatchIdRules");
1926
if (jsonNode != null)

src/main/java/com/ericsson/ei/services/SubscriptionService.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66

7+
import com.fasterxml.jackson.databind.node.ObjectNode;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
910
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,10 +15,13 @@
1415
import com.ericsson.ei.repository.ISubscriptionRepository;
1516
import com.fasterxml.jackson.core.JsonProcessingException;
1617
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import org.springframework.beans.factory.annotation.Value;
1719

1820
@Component
1921
public class SubscriptionService implements ISubscriptionService {
20-
22+
23+
@Value("${spring.application.name}") private String SpringApplicationName;
24+
2125
private static final String SUBSCRIPTION_NAME = "{'subscriptionName':'%s'}";
2226
@Autowired
2327
ISubscriptionRepository subscriptionRepository;
@@ -46,8 +50,16 @@ public Subscription getSubscription(String name) throws SubscriptionNotFoundExce
4650
throw new SubscriptionNotFoundException("No record found for the Subscription Name:" + name);
4751
}
4852
for (String input : list) {
53+
Subscription subscription;
4954
try {
50-
return mapper.readValue(input, Subscription.class);
55+
56+
subscription = mapper.readValue(input, Subscription.class);
57+
// Inject aggregationtype
58+
subscription.setAggregationtype(SpringApplicationName);
59+
return subscription;
60+
//return mapper.readValue(input, Subscription.class);
61+
62+
5163
} catch (IOException e) {
5264
LOG.error("malformed json string");
5365
}
@@ -95,7 +107,11 @@ public List<Subscription> getSubscription() throws SubscriptionNotFoundException
95107
for (String input : list) {
96108
Subscription subscription;
97109
try {
110+
98111
subscription = mapper.readValue(input, Subscription.class);
112+
// Inject aggregationtype
113+
subscription.setAggregationtype(SpringApplicationName);
114+
99115
subscriptions.add(subscription);
100116
} catch (IOException e) {
101117
LOG.error("malformed json string");

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ public boolean runSubscriptionOnObject(String aggregatedObject, ArrayNode fulfil
8282

8383
/**
8484
* This method check if the subscription requirement type and the
85-
* aggregatedObject type are same.
85+
* aggregatedObject TemplateName are same.
8686
*
8787
* @param requirementIterator
8888
* @param aggregatedObject
8989
* @return JsonNode
9090
*/
91+
9192
public ArrayNode checkRequirementType(Iterator<JsonNode> requirementIterator, String aggregatedObject) {
9293
ArrayNode fulfilledRequirements = new ObjectMapper().createArrayNode();
9394
;
@@ -100,25 +101,19 @@ public ArrayNode checkRequirementType(Iterator<JsonNode> requirementIterator, St
100101
} catch (Exception e) {
101102
log.error(e.getMessage(), e);
102103
}
103-
String aggregatedType = aggregatedJson.get("type").toString();
104-
log.info("AggregatedType : " + aggregatedType.toString());
104+
105+
106+
105107
while (requirementIterator.hasNext()) {
106108
requirement = requirementIterator.next();
107109
log.info("Requirements : " + requirement.toString());
108-
String requirementType = requirement.get("type").toString();
109-
log.info("Type of Subscription : " + requirementType);
110-
if (aggregatedType.equals(requirementType)) {
111-
log.info("Both the requirement types are equal");
112-
condition = true;
113-
log.info("The fulfilled requirement is : " + requirement.toString());
114-
fulfilledRequirements.add(requirement);
115-
} else
116-
log.info("Both requirement types are not equal");
110+
fulfilledRequirements.add(requirement);
117111
}
118-
if (condition == true)
119-
return fulfilledRequirements;
120-
else
121-
return null;
112+
113+
return fulfilledRequirements;
114+
115+
116+
122117
}
123118

124119
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
@Component
4141
public class SubscriptionHandler {
4242

43-
@Value("${subscriptionCollectionName}")
43+
@Value("${subscription.collection.name}")
4444
private String subscriptionCollectionName;
45-
@Value("${subscriptionDataBaseName}")
45+
@Value("${database.name}")
4646
private String subscriptionDataBaseName;
4747

4848
@Autowired
@@ -103,6 +103,11 @@ public void extractConditions(String aggregatedObject, String subscriptionData)
103103
} catch (Exception e) {
104104
log.error(e.getMessage(), e);
105105
}
106+
107+
108+
109+
110+
106111
ArrayNode requirementNode = (ArrayNode) subscriptionJson.get("requirements");
107112
log.info("RequirementNode : " + requirementNode.toString());
108113
Iterator<JsonNode> requirementIterator = requirementNode.elements();
@@ -115,6 +120,7 @@ public void extractConditions(String aggregatedObject, String subscriptionData)
115120
}
116121
} else
117122
log.info("The subscription conditions did not match for the aggregatedObject");
123+
118124
}
119125

120126
/**

src/main/resources/application.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
spring.application.name=eiffel-intelligence
2+
#${project.artifactId}
3+
4+
server.port: 8090
5+
16
rules.path: /ArtifactRules_new.json
27

38
logging.level.root: INFO
@@ -28,21 +33,16 @@ waitlist.collection.name: wait_list
2833
waitlist.collection.ttlValue: 600
2934
waitlist.initialDelayResend: 2000
3035
waitlist.fixedRateResend: 15000
31-
database.name: eiffel_intelligence_eiffelxxx
36+
database.name: eiffel_intelligence
3237
subscription.collection.name: subscription
3338

34-
server.port: 8090
35-
3639
threads.corePoolSize: 100
3740
threads.queueCapacity: 5000
3841
threads.maxPoolSize: 150
3942

4043
missedNotificationCollectionName: Notification
4144
missedNotificationDataBaseName: MissedNotification
4245

43-
subscriptionCollectionName: subscription
44-
subscriptionDataBaseName: subscription
45-
4646
email.sender: noreply@ericsson.com
4747
email.subject: Email Subscription Notification
4848
notification.failAttempt: 3

0 commit comments

Comments
 (0)