@@ -48,7 +48,8 @@ public class ObjectHandler {
48
48
@ Value ("${aggregated.collection.name}" )
49
49
private String collectionName ;
50
50
51
- @ Getter @ Setter
51
+ @ Getter
52
+ @ Setter
52
53
@ Value ("${spring.data.mongodb.database}" )
53
54
private String databaseName ;
54
55
@@ -70,7 +71,7 @@ public class ObjectHandler {
70
71
71
72
@ Getter
72
73
@ Value ("${aggregated.collection.ttlValue}" )
73
- private int ttlValue ;
74
+ private String ttlValue ;
74
75
75
76
public boolean insertObject (String aggregatedObject , RulesObject rulesObject , String event , String id ) {
76
77
if (id == null ) {
@@ -81,7 +82,9 @@ public boolean insertObject(String aggregatedObject, RulesObject rulesObject, St
81
82
JsonNode document = prepareDocumentForInsertion (id , aggregatedObject );
82
83
log .debug ("ObjectHandler: Aggregated Object document to be inserted: " + document .toString ());
83
84
84
- mongoDbHandler .createTTLIndex (databaseName , collectionName , "Time" , ttlValue );
85
+ if (getTtl () > 0 ) {
86
+ mongoDbHandler .createTTLIndex (databaseName , collectionName , "Time" , getTtl ());
87
+ }
85
88
86
89
boolean result = mongoDbHandler .insertDocument (databaseName , collectionName , document .toString ());
87
90
if (result )
@@ -96,9 +99,9 @@ public boolean insertObject(JsonNode aggregatedObject, RulesObject rulesObject,
96
99
}
97
100
98
101
/**
99
- * This method uses previously locked in database aggregatedObject (lock was
100
- * set in lockDocument method) and modifies this document with the new
101
- * values and removes the lock in one query
102
+ * This method uses previously locked in database aggregatedObject (lock was set
103
+ * in lockDocument method) and modifies this document with the new values and
104
+ * removes the lock in one query
102
105
*
103
106
* @param aggregatedObject
104
107
* String to insert in database
@@ -185,8 +188,7 @@ public String extractObjectId(JsonNode aggregatedDbObject) {
185
188
186
189
/**
187
190
* Locks the document in database to achieve pessimistic locking. Method
188
- * findAndModify is used to optimize the quantity of requests towards
189
- * database.
191
+ * findAndModify is used to optimize the quantity of requests towards database.
190
192
*
191
193
* @param id
192
194
* String to search
@@ -218,4 +220,16 @@ public String lockDocument(String id) {
218
220
}
219
221
return null ;
220
222
}
223
+
224
+ public int getTtl () {
225
+ int ttl = 0 ;
226
+ if (ttlValue != null && !ttlValue .isEmpty ()) {
227
+ try {
228
+ ttl = Integer .parseInt (ttlValue );
229
+ } catch (NumberFormatException e ) {
230
+ log .error (e .getMessage (), e );
231
+ }
232
+ }
233
+ return ttl ;
234
+ }
221
235
}
0 commit comments