|
21 | 21 |
|
22 | 22 | import javax.annotation.PostConstruct; |
23 | 23 |
|
| 24 | +import org.apache.commons.lang3.StringUtils; |
24 | 25 | import org.bson.Document; |
25 | 26 | import org.slf4j.Logger; |
26 | 27 | import org.slf4j.LoggerFactory; |
|
35 | 36 | import com.ericsson.ei.mongo.MongoDBHandler; |
36 | 37 | import com.ericsson.ei.mongo.MongoStringQuery; |
37 | 38 | import com.ericsson.ei.rules.RulesObject; |
| 39 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
38 | 40 | import com.fasterxml.jackson.core.type.TypeReference; |
39 | 41 | import com.fasterxml.jackson.databind.JsonNode; |
40 | 42 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -65,14 +67,14 @@ public class EventToObjectMapHandler { |
65 | 67 | @Autowired |
66 | 68 | JmesPathInterface jmesPathInterface; |
67 | 69 |
|
68 | | - @Value("${aggregations.collection.ttl:0}") |
| 70 | + @Value("${aggregations.collection.ttl}") |
69 | 71 | private String eventToObjectTtl; |
70 | 72 |
|
71 | 73 | @PostConstruct |
72 | 74 | public void init() throws AbortExecutionException { |
73 | 75 | try { |
74 | | - if (Integer.parseInt(eventToObjectTtl) > 0) { |
75 | | - mongodbhandler.createTTLIndex(databaseName, collectionName, MongoConstants.TIME, Integer.parseInt(eventToObjectTtl)); |
| 76 | + if (getTtl() > 0) { |
| 77 | + mongodbhandler.createTTLIndex(databaseName, collectionName, MongoConstants.TIME, getTtl()); |
76 | 78 | } |
77 | 79 | } catch (Exception e) { |
78 | 80 | LOGGER.error("Failed to create an index for {} due to: {}", collectionName, e); |
@@ -135,7 +137,7 @@ public void updateEventToObjectMapInMemoryDB(RulesObject rulesObject, String eve |
135 | 137 | mapStr, databaseName, collectionName); |
136 | 138 | Document document = Document.parse(mapStr); |
137 | 139 | document.append("Time", DateUtils.getDate()); |
138 | | - mongodbhandler.insertDocumentObject(databaseName, collectionName, document); |
| 140 | + mongodbhandler.insertDocumentObject(databaseName, collectionName, document, condition, eventId); |
139 | 141 | } else { |
140 | 142 | mongodbhandler.updateDocumentAddToSet(databaseName, collectionName, condition, |
141 | 143 | eventId); |
@@ -194,5 +196,24 @@ public boolean isEventInEventObjectMap(String eventId) { |
194 | 196 | List<String> documents = mongodbhandler.find(databaseName, collectionName, query); |
195 | 197 | return !documents.isEmpty(); |
196 | 198 | } |
197 | | - |
| 199 | + |
| 200 | + /** |
| 201 | + * This method gives the TTL (time to live) value for documents stored in the database. This |
| 202 | + * value is set in application.properties when starting Eiffel Intelligence. |
| 203 | + * |
| 204 | + * @return ttl Integer value representing time to live for documents |
| 205 | + */ |
| 206 | + @JsonIgnore |
| 207 | + public int getTtl() { |
| 208 | + int ttl = 0; |
| 209 | + if (StringUtils.isNotEmpty(eventToObjectTtl)) { |
| 210 | + try { |
| 211 | + ttl = Integer.parseInt(eventToObjectTtl); |
| 212 | + } catch (NumberFormatException e) { |
| 213 | + LOGGER.error("Failed to parse TTL value.", e); |
| 214 | + } |
| 215 | + } |
| 216 | + return ttl; |
| 217 | + } |
| 218 | + |
198 | 219 | } |
0 commit comments