Skip to content

Commit 5869f81

Browse files
Ttl update for aggregation (#103)
* JMESPath REST API * JMESPath API with fixed reviews * partial work jmespath rest * JMESPath API with RAML 0.8 specification * remove componet comment * replace tab with spaces * fix usage examples * prepare for new asserts in flow test * fix unit tests * Subscription for individual events * pom file * subscription individual objects * pom * error removal * Subscription Individual Object * deleting unused import * jmespath comment correction * space removal and new clean build * review changes * review change file deleted * review change * review changes * log.info to log.error * required changes * raml * raml files * resolving conflict * self generated code raml * controllers auto generated * auto generated * removing ttl * adding ttl * copied pom * changes in app.properties * resolving conflict with upstream * adding more files * added time lapse variable * rebased... * new clone and update * reviewed changes * review changes-evasiba * review changes 2:evasiba * handling of authorization by Subscription REST API: 9584 * changing property name * pom updated * method change * reviewed changes-1 * some review changes regarding comments * some changes ´to get pass throguh tests * review changes * Update application.properties * Fix test * Update to check ttl value * updating ttl values * removed a comment * handling empty ttl * added try/catch block to ttl * reviewed change in properties file
1 parent ebd10ea commit 5869f81

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@
338338

339339
</plugins>
340340
</build>
341-
</project>
341+
</project>

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

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

51-
@Getter @Setter
51+
@Getter
52+
@Setter
5253
@Value("${spring.data.mongodb.database}")
5354
private String databaseName;
5455

@@ -70,7 +71,7 @@ public class ObjectHandler {
7071

7172
@Getter
7273
@Value("${aggregated.collection.ttlValue}")
73-
private int ttlValue;
74+
private String ttlValue;
7475

7576
public boolean insertObject(String aggregatedObject, RulesObject rulesObject, String event, String id) {
7677
if (id == null) {
@@ -81,7 +82,9 @@ public boolean insertObject(String aggregatedObject, RulesObject rulesObject, St
8182
JsonNode document = prepareDocumentForInsertion(id, aggregatedObject);
8283
log.debug("ObjectHandler: Aggregated Object document to be inserted: " + document.toString());
8384

84-
mongoDbHandler.createTTLIndex(databaseName, collectionName, "Time", ttlValue);
85+
if (getTtl() > 0) {
86+
mongoDbHandler.createTTLIndex(databaseName, collectionName, "Time", getTtl());
87+
}
8588

8689
boolean result = mongoDbHandler.insertDocument(databaseName, collectionName, document.toString());
8790
if (result)
@@ -96,9 +99,9 @@ public boolean insertObject(JsonNode aggregatedObject, RulesObject rulesObject,
9699
}
97100

98101
/**
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
102105
*
103106
* @param aggregatedObject
104107
* String to insert in database
@@ -185,8 +188,7 @@ public String extractObjectId(JsonNode aggregatedDbObject) {
185188

186189
/**
187190
* 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.
190192
*
191193
* @param id
192194
* String to search
@@ -218,4 +220,16 @@ public String lockDocument(String id) {
218220
}
219221
return null;
220222
}
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+
}
221235
}

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spring.data.mongodb.database: eiffel_intelligence
3939
server.session-timeout: 1200
4040

4141
aggregated.collection.name: aggregated_objects
42-
aggregated.collection.ttlValue: 600
42+
aggregated.collection.ttlValue:
4343
event_object_map.collection.name: event_object_map
4444
waitlist.collection.name: wait_list
4545
waitlist.collection.ttlValue: 600

0 commit comments

Comments
 (0)