From 9f9208cebcbbc87e9d9014d5f747489f7cb2eee9 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Wed, 7 Jun 2017 09:25:16 +0530 Subject: [PATCH] adding default values for timestamp --- .../impl/ActivityProviderServiceImpl.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 6ef0a8664d..d06b8a8180 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -83,6 +83,10 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService long timestamp = 0; boolean isIfModifiedSinceSet = false; boolean isSinceSet = false; + if (log.isDebugEnabled()) { + log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," + + "ifModifiedSince: " + ifModifiedSince); + } RequestValidationUtil.validatePaginationParameters(offset, limit); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { Date ifSinceDate; @@ -112,14 +116,32 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService timestamp = sinceTimestamp / 1000; } + if (timestamp == 0) { + //If timestamp is not sent by the user, a default value is set, that is equal to current time-12 hours. + long time = System.currentTimeMillis() / 1000; + timestamp = time - 42300; + } + if (log.isDebugEnabled()) { + log.debug("getActivities final timestamp " + timestamp); + } + List activities; ActivityList activityList = new ActivityList(); DeviceManagementProviderService dmService; try { + if (log.isDebugEnabled()) { + log.debug("Calling database to get activities."); + } dmService = DeviceMgtAPIUtils.getDeviceManagementService(); activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset); activityList.setList(activities); + if (log.isDebugEnabled()) { + log.debug("Calling database to get activity count."); + } int count = dmService.getActivityCountUpdatedAfter(timestamp); + if (log.isDebugEnabled()) { + log.debug("Activity count: " + count); + } activityList.setCount(count); if (activities == null || activities.size() == 0) { if (isIfModifiedSinceSet) {