From b37c8a2e53a961164af3ccb23119c322e9f56f96 Mon Sep 17 00:00:00 2001 From: pyshankov Date: Mon, 19 Sep 2016 13:33:58 +0300 Subject: [PATCH] Configuration parameter for default notification TTL --- .../common/dao/service/NotificationServiceImpl.java | 12 +++++++----- .../dao/src/test/resources/dao_test.properties | 3 ++- server/node/src/main/resources/kaaNodeContext.xml | 5 ++++- .../node/src/test/resources/common-test-context.xml | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java index 3ee010a1f1..63bd5df575 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/NotificationServiceImpl.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.TimeZone; +import javax.annotation.Resource; import org.apache.avro.generic.GenericRecord; import org.apache.commons.lang.StringUtils; import org.kaaproject.kaa.common.avro.GenericAvroConverter; @@ -71,6 +72,10 @@ public class NotificationServiceImpl implements NotificationService { @Value("#{sql_dao[dao_max_wait_time]}") private int waitSeconds; + + @Autowired(required = false) + private int ttl = 7 * 24 * 3600; + @Autowired private TopicDao topicDao; @Autowired @@ -80,9 +85,6 @@ public class NotificationServiceImpl implements NotificationService { private NotificationDao notificationDao; private EndpointNotificationDao unicastNotificationDao; - @Value("#{properties[default_ttl]}") - private int TTL; - @Override public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchemaDto) { validateNotificationSchemaObject(notificationSchemaDto); @@ -141,7 +143,7 @@ public UpdateNotificationDto saveNotification(NotificationDto d long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis(); Date expiredAt = dto.getExpiredAt(); - dto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + TTL)); + dto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + ttl)); dto.setLastTimeModify(new Date(currentTime)); NotificationDto notificationDto = saveNotificationAndIncTopicSecNum(dto); if (notificationDto != null) { @@ -305,7 +307,7 @@ public UpdateNotificationDto saveUnicastNotification(En } long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis(); Date expiredAt = notificationDto.getExpiredAt(); - notificationDto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + TTL)); + notificationDto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + ttl)); notificationDto.setLastTimeModify(new Date(currentTime)); EndpointNotificationDto unicast = getDto(unicastNotificationDao.save(dto)); diff --git a/server/common/dao/src/test/resources/dao_test.properties b/server/common/dao/src/test/resources/dao_test.properties index a81844ff28..81b50b1dcc 100644 --- a/server/common/dao/src/test/resources/dao_test.properties +++ b/server/common/dao/src/test/resources/dao_test.properties @@ -34,4 +34,5 @@ jdbc_port=9092 # Path to logs root directory logs_root_dir=logs_root -jdbc_url_db_name=h2 \ No newline at end of file +jdbc_url_db_name=h2 + diff --git a/server/node/src/main/resources/kaaNodeContext.xml b/server/node/src/main/resources/kaaNodeContext.xml index e96fbb79c0..33e08aa26d 100644 --- a/server/node/src/main/resources/kaaNodeContext.xml +++ b/server/node/src/main/resources/kaaNodeContext.xml @@ -44,6 +44,10 @@ + + + + @@ -59,7 +63,6 @@ - diff --git a/server/node/src/test/resources/common-test-context.xml b/server/node/src/test/resources/common-test-context.xml index 0b30c7d110..c8d38fd9fc 100644 --- a/server/node/src/test/resources/common-test-context.xml +++ b/server/node/src/test/resources/common-test-context.xml @@ -41,6 +41,7 @@ +