From 852fa3ad393db2ae76a789ccd878fa6a01688cde Mon Sep 17 00:00:00 2001 From: inoshperera Date: Mon, 22 Nov 2021 12:28:39 +0530 Subject: [PATCH 1/8] Remove duplicate app subscriptions When there are multiple groups on the list, there is a possibility to create multiple subscriptions. The fix is to address this problem. Fixes https://gitlab.com/entgra/product-iots/-/issues/1189 (cherry picked from commit b6c41eabb914b20312a02fa4b2427a1906ba8fe9) --- .../mgt/core/impl/SubscriptionManagerImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 2de1094c1f..7ddd76c6cd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -97,9 +97,11 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -434,7 +436,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); - List devices = new ArrayList<>(); + Set devices = new HashSet<>(); List subscribers = new ArrayList<>(); List errorDeviceIdentifiers = new ArrayList<>(); String deviceTypeName = null; @@ -511,8 +513,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager { devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType())); } + List deviceList = new ArrayList<>(); + deviceList.addAll(devices); ApplicationSubscriptionInfo applicationSubscriptionInfo = new ApplicationSubscriptionInfo(); - applicationSubscriptionInfo.setDevices(devices); + applicationSubscriptionInfo.setDevices(deviceList); applicationSubscriptionInfo.setSubscribers(subscribers); applicationSubscriptionInfo.setErrorDeviceIdentifiers(errorDeviceIdentifiers); applicationSubscriptionInfo.setAppSupportingDeviceTypeName(deviceTypeName); From 86495d9ba550dacd4783a2483d9e542fae3ef4f0 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Tue, 30 Nov 2021 22:28:03 +0530 Subject: [PATCH 2/8] Add missing ios scopes into mdm-ui-config.xml --- .../src/main/resources/conf/mdm-ui-config.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index aa3f169a33..33b5c94b07 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -183,6 +183,19 @@ perm:metadata:update perm:android:google-account perm:android:update-default-sim + perm:ios:lock + perm:ios:location + perm:ios:ring + perm:ios:clear-passcode + perm:ios:enterprise-wipe + perm:ios:notification + perm:ios:wipe-data + perm:ios:boolean-setting + perm:ios:wallpaper + perm:ios:app-attributes + perm:ios:app-configurations + perm:mac-os:shut-down + perm:mac-os:restart device-mgt From 007b309c7174106e808626b8221544e8c12cf4cf Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 1 Dec 2021 11:53:37 +0530 Subject: [PATCH 3/8] Add time duration filtering to activities EP --- .../api/ActivityInfoProviderService.java | 12 +++++++- .../impl/ActivityProviderServiceImpl.java | 17 +++++++++-- .../impl/util/RequestValidationUtil.java | 8 ++++++ .../mgt/common/ActivityPaginationRequest.java | 17 +++++++++++ .../mgt/dao/impl/GenericOperationDAOImpl.java | 28 +++++++++++++++++-- 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 18241eab75..75af90eed6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -477,6 +477,16 @@ public interface ActivityInfoProviderService { "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z\n." + "Example: Mon, 05 Jan 2014 15:10:00 +0200" ) - @HeaderParam("If-Modified-Since") String ifModifiedSince); + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "startTimestamp", + value = "Starting unix timestamp value for filtering activities" + ) + @QueryParam("startTimestamp") long startTimestamp, + @ApiParam( + name = "endTimestamp", + value = "Ending unix timestamp value for filtering activities" + ) + @QueryParam("endTimestamp") long endTimestamp); } 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 29f1476138..8b74afc8c4 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 @@ -228,11 +228,14 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService @QueryParam("deviceId") String deviceId, @QueryParam("type") String type, @QueryParam("status") String status, - @HeaderParam("If-Modified-Since") String ifModifiedSince) { + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @QueryParam("startTimestamp") long startTimestamp, + @QueryParam("endTimestamp") long endTimestamp) { long ifModifiedSinceTimestamp; long sinceTimestamp; long timestamp = 0; + boolean isTimeDurationProvided = false; if (log.isDebugEnabled()) { log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," + "ifModifiedSince: " + ifModifiedSince); @@ -262,9 +265,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService } sinceTimestamp = sinceDate.getTime(); timestamp = sinceTimestamp / 1000; + } else if (startTimestamp > 0 && endTimestamp > 0) { + RequestValidationUtil.validateTimeDuration(startTimestamp, endTimestamp); + isTimeDurationProvided = true; } - if (timestamp == 0) { + if (timestamp == 0 && !isTimeDurationProvided) { //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; @@ -300,7 +306,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService if (status != null && !status.isEmpty()) { activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); } - activityPaginationRequest.setSince(timestamp); + if (timestamp > 0) { + activityPaginationRequest.setSince(timestamp); + } else { + activityPaginationRequest.setStartTimestamp(startTimestamp); + activityPaginationRequest.setEndTimestamp(endTimestamp); + } if (log.isDebugEnabled()) { log.debug("Activity request: " + new Gson().toJson(activityPaginationRequest)); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index 8846944110..4d16878f73 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -769,4 +769,12 @@ public class RequestValidationUtil { } } } + + public static void validateTimeDuration(long startTimestamp, long endTimestamp) { + if (startTimestamp > endTimestamp) { + throw new InputValidationException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter startTimestamp" + + " should not be higher values than endTimestamp").build()); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/ActivityPaginationRequest.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/ActivityPaginationRequest.java index bf4fe3e113..08cc89093a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/ActivityPaginationRequest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/ActivityPaginationRequest.java @@ -34,6 +34,8 @@ public class ActivityPaginationRequest { private long since; private Operation.Type type; private Operation.Status status; + private long startTimestamp; + private long endTimestamp; public ActivityPaginationRequest(int offset, int limit) { this.offset = offset; @@ -113,4 +115,19 @@ public class ActivityPaginationRequest { this.status = status; } + public long getStartTimestamp() { + return startTimestamp; + } + + public void setStartTimestamp(long startTimestamp) { + this.startTimestamp = startTimestamp; + } + + public long getEndTimestamp() { + return endTimestamp; + } + + public void setEndTimestamp(long endTimestamp) { + this.endTimestamp = endTimestamp; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index b4229f1357..1c48fa63bf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -1726,6 +1726,7 @@ public class GenericOperationDAOImpl implements OperationDAO { public List getActivities(ActivityPaginationRequest activityPaginationRequest) throws OperationManagementDAOException { try { + boolean isTimeDurationFilteringProvided = false; Connection conn = OperationManagementDAOFactory.getConnection(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String sql = "SELECT " + @@ -1766,6 +1767,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getSince() != 0) { sql += "AND UPDATED_TIMESTAMP > ? "; } + if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { + isTimeDurationFilteringProvided = true; + sql += "AND UPDATED_TIMESTAMP BETWEEN ? AND ? "; + } if (activityPaginationRequest.getType() != null) { sql += "AND TYPE = ? "; } @@ -1791,6 +1796,9 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getSince() != 0) { sql += "AND eom.UPDATED_TIMESTAMP > ? "; } + if (isTimeDurationFilteringProvided) { + sql += "AND eom.UPDATED_TIMESTAMP BETWEEN ? AND ? "; + } if (activityPaginationRequest.getType() != null) { sql += "AND eom.TYPE = ? "; } @@ -1818,6 +1826,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getSince() != 0) { stmt.setLong(index++, activityPaginationRequest.getSince()); } + if (isTimeDurationFilteringProvided) { + stmt.setLong(index++, activityPaginationRequest.getStartTimestamp()); + stmt.setLong(index++, activityPaginationRequest.getEndTimestamp()); + } if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } @@ -1844,6 +1856,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getSince() != 0) { stmt.setLong(index++, activityPaginationRequest.getSince()); } + if (isTimeDurationFilteringProvided) { + stmt.setLong(index++, activityPaginationRequest.getStartTimestamp()); + stmt.setLong(index++, activityPaginationRequest.getEndTimestamp()); + } if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } @@ -1872,6 +1888,7 @@ public class GenericOperationDAOImpl implements OperationDAO { public int getActivitiesCount(ActivityPaginationRequest activityPaginationRequest) throws OperationManagementDAOException { try { + boolean isTimeDurationFilteringProvided = false; Connection conn = OperationManagementDAOFactory.getConnection(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String sql = "SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT FROM DM_ENROLMENT_OP_MAPPING " + @@ -1898,7 +1915,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getStatus() != null) { sql += "AND STATUS = ? "; } - + if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { + isTimeDurationFilteringProvided = true; + sql += "AND UPDATED_TIMESTAMP BETWEEN ? AND ? "; + } int index = 1; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(index++, tenantId); @@ -1921,7 +1941,11 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setString(index++, activityPaginationRequest.getType().name()); } if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index, activityPaginationRequest.getStatus().name()); + stmt.setString(index++, activityPaginationRequest.getStatus().name()); + } + if (isTimeDurationFilteringProvided) { + stmt.setLong(index++, activityPaginationRequest.getStartTimestamp()); + stmt.setLong(index, activityPaginationRequest.getEndTimestamp()); } try (ResultSet rs = stmt.executeQuery()) { From cf4f45c89da605411730a93d3e10f161ceabf9cb Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 1 Dec 2021 17:10:45 +0530 Subject: [PATCH 4/8] Change time filtering DB column --- .../mgt/jaxrs/service/impl/util/RequestValidationUtil.java | 5 +++-- .../operation/mgt/dao/impl/GenericOperationDAOImpl.java | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index 4d16878f73..116c715eb2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -773,8 +773,9 @@ public class RequestValidationUtil { public static void validateTimeDuration(long startTimestamp, long endTimestamp) { if (startTimestamp > endTimestamp) { throw new InputValidationException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter startTimestamp" + - " should not be higher values than endTimestamp").build()); + new ErrorResponse.ErrorResponseBuilder().setCode(400l) + .setMessage("Request parameter startTimestamp should not be " + + "a higher value than endTimestamp").build()); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 1c48fa63bf..de92618c46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -1769,7 +1769,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { isTimeDurationFilteringProvided = true; - sql += "AND UPDATED_TIMESTAMP BETWEEN ? AND ? "; + sql += "AND CREATED_TIMESTAMP BETWEEN ? AND ? "; } if (activityPaginationRequest.getType() != null) { sql += "AND TYPE = ? "; @@ -1797,7 +1797,7 @@ public class GenericOperationDAOImpl implements OperationDAO { sql += "AND eom.UPDATED_TIMESTAMP > ? "; } if (isTimeDurationFilteringProvided) { - sql += "AND eom.UPDATED_TIMESTAMP BETWEEN ? AND ? "; + sql += "AND eom.CREATED_TIMESTAMP BETWEEN ? AND ? "; } if (activityPaginationRequest.getType() != null) { sql += "AND eom.TYPE = ? "; @@ -1917,8 +1917,9 @@ public class GenericOperationDAOImpl implements OperationDAO { } if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { isTimeDurationFilteringProvided = true; - sql += "AND UPDATED_TIMESTAMP BETWEEN ? AND ? "; + sql += "AND CREATED_TIMESTAMP BETWEEN ? AND ? "; } + int index = 1; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(index++, tenantId); From 4691b1d7bdb1dff5f37880b653cc21cc74d059fd Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 10 Nov 2021 10:41:48 +0530 Subject: [PATCH 5/8] Add timestamp issue fixes --- .../GenericLifecycleStateDAOImpl.java | 9 +- .../dao/impl/review/GenericReviewDAOImpl.java | 15 +- .../mgt/core/impl/ReviewManagerImpl.java | 1 + .../core/impl/SubscriptionManagerImpl.java | 2 +- .../application/mgt/core/util/DAOUtil.java | 12 +- .../dao/util/DeviceManagementDAOUtil.java | 19 +- .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 8 +- .../mgt/dao/impl/CommandOperationDAOImpl.java | 9 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 7 +- .../mgt/dao/impl/GenericOperationDAOImpl.java | 187 +++++++++--------- .../mgt/dao/impl/PolicyOperationDAOImpl.java | 7 +- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 9 +- .../dbscripts/cdm/application-mgt/mysql.sql | 6 +- .../main/resources/dbscripts/cdm/mysql.sql | 4 +- 14 files changed, 156 insertions(+), 139 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index ee90772205..2a68f4d7a6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -161,14 +161,13 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif + "VALUES (?, ?, ?, ?, ?, ?, ?)"; try { Connection conn = this.getDBConnection(); - Calendar calendar = Calendar.getInstance(); - Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + long timestamp = DAOUtil.getCurrentUTCTime(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, state.getCurrentState().toUpperCase()); stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setTimestamp(5, timestamp); + stmt.setLong(5, timestamp); stmt.setString(6, state.getReasonForChange()); stmt.setInt(7, appReleaseId); stmt.executeUpdate(); @@ -254,7 +253,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); + lifecycleState.setUpdatedAt(new Timestamp(rs.getLong("UPDATED_AT"))); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); } } catch (SQLException e) { @@ -280,7 +279,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); + lifecycleState.setUpdatedAt(new Timestamp(rs.getLong("UPDATED_AT") * 1000L)); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java index 24052730b3..413d627b54 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java @@ -68,8 +68,7 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )"; try { int reviewId = -1; - Calendar calendar = Calendar.getInstance(); - Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + long timestamp = DAOUtil.getCurrentUTCTime(); Connection conn = this.getDBConnection(); try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) { statement.setInt(1, tenantId); @@ -78,8 +77,8 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { statement.setInt(4, reviewDTO.getImmediateParentId()); statement.setInt(5, reviewDTO.getRating()); statement.setString(6, reviewDTO.getUsername()); - statement.setTimestamp(7, timestamp); - statement.setTimestamp(8, timestamp); + statement.setLong(7, timestamp); + statement.setLong(8, timestamp); statement.setInt(9, appReleaseId); statement.executeUpdate(); try (ResultSet rs = statement.getGeneratedKeys()) { @@ -158,19 +157,17 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { + "ACTIVE_REVIEW = ? " + "WHERE ID = ? AND TENANT_ID = ?"; try { - Calendar calendar = Calendar.getInstance(); - Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); - + long timestamp = DAOUtil.getCurrentUTCTime(); Connection connection = this.getDBConnection(); try (PreparedStatement statement = connection.prepareStatement(sql)){ statement.setString(1, reviewDTO.getContent()); statement.setInt(2, reviewDTO.getRating()); - statement.setTimestamp(3, timestamp); + statement.setLong(3, timestamp); statement.setBoolean(4, isActiveReview); statement.setInt(5, reviewId); statement.setInt(6, tenantId); if (statement.executeUpdate() == 1) { - reviewDTO.setModifiedAt(timestamp); + reviewDTO.setModifiedAt(new Timestamp(timestamp * 1000)); return reviewDTO; } return null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index 92e281fd6b..2db6925dd8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -46,6 +46,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAO import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index cdd18c5678..b7d134a8c7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -431,7 +431,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * * @param applicationDTO Application DTO * @param params list of subscribers. This list can be of either - * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal + * {@link DeviceIdentifier} if {@param subType} is equal * to DEVICE or * {@link String} if {@param subType} is USER, ROLE or GROUP * @param subType subscription type. E.g. DEVICE, USER, ROLE, GROUP {@see { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java index 4950fe3c6e..def4c74d96 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java @@ -36,7 +36,11 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -226,8 +230,8 @@ public class DAOUtil { ReviewDTO reviewDTO = new ReviewDTO(); reviewDTO.setId(rs.getInt("ID")); reviewDTO.setContent(rs.getString("COMMENT")); - reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); - reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); + reviewDTO.setCreatedAt(new Timestamp(rs.getLong("CREATED_AT") * 1000L)); + reviewDTO.setModifiedAt(new Timestamp(rs.getLong("MODIFIED_AT") * 1000L)); reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); reviewDTO.setUsername(rs.getString("USERNAME")); @@ -304,4 +308,8 @@ public class DAOUtil { } } } + + public static long getCurrentUTCTime() { + return new Date().getTime() / 1000; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 68e1b1dd1f..0c5f43668a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -17,6 +17,9 @@ */ package org.wso2.carbon.device.mgt.core.dao.util; +import java.sql.*; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,10 +39,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.naming.InitialContext; import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -262,7 +261,7 @@ public final class DeviceManagementDAOUtil { deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); + deviceInfo.setUpdatedTime(new Date(rs.getLong("UPDATE_TIMESTAMP"))); return deviceInfo; } @@ -285,4 +284,14 @@ public final class DeviceManagementDAOUtil { return deviceLocationHistory; } + public static long getCurrentUTCTime() { + return new Date().getTime() / 1000; + } + + public static long convertLocalTimeIntoUTC(Date localDate) { + LocalDateTime l = localDate.toInstant() + .atZone(ZoneId.of("GMT")) + .toLocalDateTime(); + return Timestamp.valueOf(l).getTime() / 1000; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index d00cb1d1ed..6db8bd2fdd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -74,7 +74,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(14, deviceInfo.getTotalRAMMemory()); stmt.setDouble(15, deviceInfo.getAvailableRAMMemory()); stmt.setBoolean(16, deviceInfo.isPluggedIn()); - stmt.setLong(17, System.currentTimeMillis()); + stmt.setLong(17, DeviceManagementDAOUtil.getCurrentUTCTime()); stmt.setInt(18, enrolmentId); stmt.execute(); @@ -287,9 +287,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(9, deviceLocation.getCountry()); stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation)); if (deviceLocation.getUpdatedTime() == null) { - stmt.setLong(11, System.currentTimeMillis()); + stmt.setLong(11, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L); } else { - stmt.setLong(11, deviceLocation.getUpdatedTime().getTime()); + stmt.setLong(11, DeviceManagementDAOUtil.convertLocalTimeIntoUTC(deviceLocation.getUpdatedTime()) * 1000L); } stmt.setInt(12, enrollmentId); stmt.setDouble(13, deviceLocation.getAltitude()); @@ -330,7 +330,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(7, deviceLocation.getState()); stmt.setString(8, deviceLocation.getCountry()); stmt.setString(9, GeoHashGenerator.encodeGeohash(deviceLocation)); - stmt.setLong(10, System.currentTimeMillis()); + stmt.setLong(10, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L); stmt.setInt(11, deviceLocation.getDeviceId()); stmt.setInt(12, enrollmentId); stmt.execute(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index 80bcf8e1a4..badb223896 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -18,6 +18,9 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -34,6 +37,7 @@ import java.util.Date; import java.util.List; public class CommandOperationDAOImpl extends GenericOperationDAOImpl { + private static final Log log = LogFactory.getLog(CommandOperationDAOImpl.class); @Override public int addOperation(Operation operation) throws OperationManagementDAOException { @@ -45,8 +49,9 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { "INITIATED_BY, ENABLED) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setTimestamp(3, null); + stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); + log.info("------Time----- " + DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setBoolean(6, operation.isEnabled()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 397485a744..193a0244f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -46,14 +47,14 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; try { - operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString()); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setTimestamp(3, null); + stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index de92618c46..a9e050eb83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityHolder; import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping; @@ -72,8 +73,8 @@ public class GenericOperationDAOImpl implements OperationDAO { "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setTimestamp(3, null); + stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); @@ -98,7 +99,7 @@ public class GenericOperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; boolean isUpdated = false; try { - long time = System.currentTimeMillis() / 1000; + long time = DeviceManagementDAOUtil.getCurrentUTCTime(); Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=?, UPDATED_TIMESTAMP=? " + "WHERE ENROLMENT_ID=? and OPERATION_ID=?"); @@ -440,7 +441,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity = new Activity(); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); } @@ -456,7 +457,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + activityStatus.setUpdatedTimestamp(new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); } activityStatus.setResponses(operationResponses); @@ -556,7 +557,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -571,7 +572,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { @@ -595,7 +596,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -608,7 +609,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { responseId = rs.getInt("OP_RES_ID"); @@ -694,7 +695,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); } @@ -708,7 +709,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); if (rs.getBoolean("IS_LARGE_RESPONSE")) { largeResponseIDs.add(rs.getInt("OP_RES_ID")); } else { @@ -842,7 +843,7 @@ public class GenericOperationDAOImpl implements OperationDAO { enrolmentId = rs.getInt("ENROLMENT_ID"); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -855,7 +856,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new java.util.Date( + activityStatus.setUpdatedTimestamp(new Date( rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } @@ -878,7 +879,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activityStatus = new ActivityStatus(); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -890,7 +891,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new java.util.Date( + activityStatus.setUpdatedTimestamp(new Date( rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { @@ -1146,11 +1147,11 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); - if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + if (rs.getLong("RECEIVED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { - operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + operation.setReceivedTimeStamp(new Timestamp(rs.getLong("RECEIVED_TIMESTAMP") * 1000L).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); operation.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -1172,10 +1173,10 @@ public class GenericOperationDAOImpl implements OperationDAO { Operation operation = null; try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " + - "o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " + + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, o.OPERATION_CODE, " + + "om.ID AS OM_MAPPING_ID, " + "om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," + - "OPERATION_CODE, INITIATED_BY FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + "ON o.ID = om.OPERATION_ID "; stmt = conn.prepareStatement(sql); @@ -1188,16 +1189,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); } } catch (SQLException e) { @@ -1215,11 +1215,11 @@ public class GenericOperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; ResultSet rs = null; Operation operation; - List operations = new ArrayList<>(); + List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + - "o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, om.ID AS OM_MAPPING_ID," + + "om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; stmt = conn.prepareStatement(sql); @@ -1231,15 +1231,14 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(status); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); @@ -1264,7 +1263,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + - "o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + "om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + "o.CREATED_TIMESTAMP DESC LIMIT ?,?"; @@ -1279,15 +1278,14 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(status); OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); @@ -1311,8 +1309,8 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, o.INITIATED_BY, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " + - "FROM DM_OPERATION o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + + "o.OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC"; stmt = conn.prepareStatement(sql); @@ -1323,15 +1321,14 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operations.add(operation); } @@ -1348,7 +1345,7 @@ public class GenericOperationDAOImpl implements OperationDAO { public List getOperationsForDevice(int enrolmentId, PaginationRequest request) throws OperationManagementDAOException { Operation operation; - List operations = new ArrayList<>(); + List operations = new ArrayList(); String createdTo = null; String createdFrom = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); @@ -1366,75 +1363,74 @@ public class GenericOperationDAOImpl implements OperationDAO { Long updatedTo = request.getOperationLogFilters().getUpdatedDayTo(); List operationCode = request.getOperationLogFilters().getOperationCode(); List status = request.getOperationLogFilters().getStatus(); - StringBuilder sql = new StringBuilder("SELECT " + - "o.ID, " + - "TYPE, " + - "o.CREATED_TIMESTAMP, " + - "o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, " + - "o.INITIATED_BY, " + - "om.STATUS, " + - "om.ID AS OM_MAPPING_ID, " + - "om.UPDATED_TIMESTAMP " + - "FROM " + - "DM_OPERATION o " + - "INNER JOIN " + - "(SELECT dm.OPERATION_ID, " + - "dm.ID, " + - "dm.STATUS, " + - "dm.UPDATED_TIMESTAMP " + - "FROM " + - "DM_ENROLMENT_OP_MAPPING dm " + - "WHERE " + - "dm.ENROLMENT_ID = ?"); + String sql = "SELECT " + + "o.ID, " + + "TYPE, " + + "o.CREATED_TIMESTAMP, " + + "o.RECEIVED_TIMESTAMP, " + + "o.OPERATION_CODE, " + + "om.STATUS, " + + "om.ID AS OM_MAPPING_ID, " + + "om.UPDATED_TIMESTAMP " + + "FROM " + + "DM_OPERATION o " + + "INNER JOIN " + + "(SELECT dm.OPERATION_ID, " + + "dm.ID, " + + "dm.STATUS, " + + "dm.UPDATED_TIMESTAMP " + + "FROM " + + "DM_ENROLMENT_OP_MAPPING dm " + + "WHERE " + + "dm.ENROLMENT_ID = ?"; if (updatedFrom != null && updatedFrom != 0 && updatedTo != null && updatedTo != 0) { - sql.append(" AND dm.UPDATED_TIMESTAMP BETWEEN ? AND ?"); + sql = sql + " AND dm.UPDATED_TIMESTAMP BETWEEN ? AND ?"; isUpdatedDayProvided = true; } - sql.append(") om ON o.ID = om.OPERATION_ID "); + sql = sql + ") om ON o.ID = om.OPERATION_ID "; if (createdFrom != null && !createdFrom.isEmpty() && createdTo != null && !createdTo.isEmpty()) { - sql.append(" WHERE o.CREATED_TIMESTAMP BETWEEN ? AND ?"); + sql = sql + " WHERE o.CREATED_TIMESTAMP BETWEEN ? AND ?"; isCreatedDayProvided = true; } if ((isCreatedDayProvided) && (status != null && !status.isEmpty())) { int size = status.size(); - sql.append(" AND (om.STATUS = ? "); + sql = sql + " AND (om.STATUS = ? "; for (int i = 0; i < size - 1; i++) { - sql.append(" OR om.STATUS = ?"); + sql = sql + " OR om.STATUS = ?"; } - sql.append(")"); + sql = sql + ")"; isStatusProvided = true; } else if ((!isCreatedDayProvided) && (status != null && !status.isEmpty())) { int size = status.size(); - sql.append(" WHERE (om.STATUS = ? "); + sql = sql + " WHERE (om.STATUS = ? "; for (int i = 0; i < size - 1; i++) { - sql.append(" OR om.STATUS = ?"); + sql = sql + " OR om.STATUS = ?"; } - sql.append(")"); + sql = sql + ")"; isStatusProvided = true; } if ((isCreatedDayProvided || isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { int size = operationCode.size(); - sql.append(" AND (o.OPERATION_CODE = ? "); + sql = sql + " AND (o.OPERATION_CODE = ? "; for (int i = 0; i < size - 1; i++) { - sql.append(" OR o.OPERATION_CODE = ?"); + sql = sql + " OR o.OPERATION_CODE = ?"; } - sql.append(")"); + sql = sql + ")"; isOperationCodeProvided = true; } else if ((!isCreatedDayProvided && !isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { int size = operationCode.size(); - sql.append(" WHERE (o.OPERATION_CODE = ? "); + sql = sql + " WHERE (o.OPERATION_CODE = ? "; for (int i = 0; i < size - 1; i++) { - sql.append(" OR o.OPERATION_CODE = ?"); + sql = sql + " OR o.OPERATION_CODE = ?"; } - sql.append(")"); + sql = sql + ")"; isOperationCodeProvided = true; } - sql.append(" ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"); + sql = sql + " ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; try { Connection conn = OperationManagementDAOFactory.getConnection(); - try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) { + try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; stmt.setInt(paramIndex++, enrolmentId); if (isUpdatedDayProvided) { @@ -1446,13 +1442,15 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setString(paramIndex++, createdTo); } if (isStatusProvided) { - for (String s : status) { - stmt.setString(paramIndex++, s); + int size = status.size(); + for (int i = 0; i < size; i++) { + stmt.setString(paramIndex++, status.get(i)); } } if (isOperationCodeProvided) { - for (String s : operationCode) { - stmt.setString(paramIndex++, s); + int size = operationCode.size(); + for (int i = 0; i < size; i++) { + stmt.setString(paramIndex++, operationCode.get(i)); } } stmt.setInt(paramIndex++, request.getStartIndex()); @@ -1462,15 +1460,14 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); @@ -1597,7 +1594,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + "o.OPERATION_CODE, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1"); @@ -1610,16 +1607,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setType(OperationDAOUtil.getType(rs.getString("TYPE"))); operation.setId(rs.getInt("ID")); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.PENDING); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); } @@ -1640,10 +1636,10 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," + - " om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " + - "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " + - "FROM DM_OPERATION o WHERE o.TYPE = ?) o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID, " + + "om.UPDATED_TIMESTAMP FROM (SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " + + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; stmt = conn.prepareStatement(sql); @@ -1656,15 +1652,14 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); - operation.setInitiatedBy(rs.getString("INITIATED_BY")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index 39b6212e50..42ba7c7b28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -45,15 +46,15 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { int operationId = -1; try { - operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString()); operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setTimestamp(3, null); + stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 9f07007e3b..8e23d24067 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -42,15 +43,15 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { ByteArrayOutputStream bao = null; ObjectOutputStream oos = null; try { - operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(DeviceManagementDAOUtil.getCurrentUTCTime()).toString()); operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setTimestamp(3, null); + stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); @@ -117,7 +118,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { profileOperation = new ProfileOperation(); profileOperation.setCode(rs.getString("OPERATION_CODE")); profileOperation.setId(oppId); - profileOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP")); + profileOperation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); profileOperation.setId(oppId); profileOperation.setPayLoad(obj); } else { diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 5d5db38b2d..110ccdc606 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -57,8 +57,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW( COMMENT TEXT NOT NULL, ROOT_PARENT_ID INTEGER NOT NULL, IMMEDIATE_PARENT_ID INTEGER NOT NULL, - CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, - MODIFIED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + CREATED_AT BIGINT NOT NULL, + MODIFIED_AT BIGINT NOT NULL, RATING INTEGER NULL, USERNAME VARCHAR(45) NOT NULL, ACTIVE_REVIEW BOOLEAN NOT NULL DEFAULT TRUE, @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT TIMESTAMP NOT NULL, + UPDATED_AT BIGINT NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index a69b79b783..e11919b0a0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -99,8 +99,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT(15) NOT NULL, + RECEIVED_TIMESTAMP BIGINT(15) NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, From 10b8e0de53989e5661ff29cd92c7f69423220fdc Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 26 Nov 2021 23:03:57 +0530 Subject: [PATCH 6/8] Fix test failures --- .../core/operation/mgt/dao/impl/CommandOperationDAOImpl.java | 1 - .../src/test/resources/sql/h2.sql | 4 ++-- .../src/test/resources/sql-files/h2.sql | 4 ++-- .../src/test/resources/sql/CreateH2TestDB.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/application-mgt/h2.sql | 2 +- .../main/resources/dbscripts/cdm/application-mgt/mssql.sql | 2 +- .../resources/dbscripts/cdm/application-mgt/postgresql.sql | 2 +- .../src/main/resources/dbscripts/cdm/archival/mysql.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/h2.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/mssql.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/oracle.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/postgresql.sql | 2 +- 12 files changed, 18 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index badb223896..c96e20c4f1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -50,7 +50,6 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - log.info("------Time----- " + DeviceManagementDAOUtil.getCurrentUTCTime()); stmt.setLong(3, 0); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 2c846cb1af..cc69537e90 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -75,8 +75,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql index 7d7c1ece9c..ef684a6685 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql @@ -65,8 +65,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 7238d37790..4c59adb953 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -83,8 +83,8 @@ DROP TABLE IF EXISTS DM_OPERATION; CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index dcbebd74b4..150480f68d 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT TIMESTAMP NOT NULL, + UPDATED_AT BIGINT NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index 25fc47e38e..5d29525a8c 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -80,7 +80,7 @@ CREATE TABLE AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT DATETIME2(0) NOT NULL, + UPDATED_AT BIGINT NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON VARCHAR(max) DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index d871549d89..c799b03245 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT TIMESTAMP(0) NOT NULL, + UPDATED_AT BIGINT NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql index 659e22d110..7854ee1181 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql @@ -2,8 +2,8 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH ( ID INTEGER NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index f6894eb4ac..ed9ce41c7d 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -84,8 +84,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index c27f891445..f0cbcf2458 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -111,8 +111,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D CREATE TABLE DM_OPERATION ( ID INTEGER IDENTITY(1,1) NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP DATETIME2 NOT NULL, - RECEIVED_TIMESTAMP DATETIME2 NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index e2e4693bd2..00adba3500 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -173,8 +173,8 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_OPERATION ( ID NUMBER(10) NOT NULL, TYPE VARCHAR2(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR2(1000) NOT NULL, INITIATED_BY VARCHAR2(100) NULL, ENABLED NUMBER(10) DEFAULT 0 NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index bd8eb8771a..d2537af3a8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -93,7 +93,7 @@ CREATE SEQUENCE DM_OPERATION_seq; CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER DEFAULT NEXTVAL ('DM_OPERATION_seq') NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL, + CREATED_TIMESTAMP NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, From 23dcac5fa710f591dd9207c9df919a5dd24638b2 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 1 Dec 2021 11:53:37 +0530 Subject: [PATCH 7/8] Revert "Add timestamp issue fixes" This reverts commit 4691b1d7 --- .../GenericLifecycleStateDAOImpl.java | 9 +- .../dao/impl/review/GenericReviewDAOImpl.java | 15 +- .../mgt/core/impl/ReviewManagerImpl.java | 1 - .../core/impl/SubscriptionManagerImpl.java | 2 +- .../application/mgt/core/util/DAOUtil.java | 12 +- .../dao/util/DeviceManagementDAOUtil.java | 19 +- .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 8 +- .../mgt/dao/impl/CommandOperationDAOImpl.java | 8 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 7 +- .../mgt/dao/impl/GenericOperationDAOImpl.java | 187 +++++++++--------- .../mgt/dao/impl/PolicyOperationDAOImpl.java | 7 +- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 9 +- .../dbscripts/cdm/application-mgt/mysql.sql | 6 +- .../main/resources/dbscripts/cdm/mysql.sql | 4 +- 14 files changed, 139 insertions(+), 155 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index 2a68f4d7a6..ee90772205 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -161,13 +161,14 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif + "VALUES (?, ?, ?, ?, ?, ?, ?)"; try { Connection conn = this.getDBConnection(); - long timestamp = DAOUtil.getCurrentUTCTime(); + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, state.getCurrentState().toUpperCase()); stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setLong(5, timestamp); + stmt.setTimestamp(5, timestamp); stmt.setString(6, state.getReasonForChange()); stmt.setInt(7, appReleaseId); stmt.executeUpdate(); @@ -253,7 +254,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(new Timestamp(rs.getLong("UPDATED_AT"))); + lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); } } catch (SQLException e) { @@ -279,7 +280,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif LifecycleState lifecycleState = new LifecycleState(); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setPreviousState(rs.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedAt(new Timestamp(rs.getLong("UPDATED_AT") * 1000L)); + lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY")); lifecycleStates.add(lifecycleState); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java index 413d627b54..24052730b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java @@ -68,7 +68,8 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )"; try { int reviewId = -1; - long timestamp = DAOUtil.getCurrentUTCTime(); + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Connection conn = this.getDBConnection(); try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) { statement.setInt(1, tenantId); @@ -77,8 +78,8 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { statement.setInt(4, reviewDTO.getImmediateParentId()); statement.setInt(5, reviewDTO.getRating()); statement.setString(6, reviewDTO.getUsername()); - statement.setLong(7, timestamp); - statement.setLong(8, timestamp); + statement.setTimestamp(7, timestamp); + statement.setTimestamp(8, timestamp); statement.setInt(9, appReleaseId); statement.executeUpdate(); try (ResultSet rs = statement.getGeneratedKeys()) { @@ -157,17 +158,19 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { + "ACTIVE_REVIEW = ? " + "WHERE ID = ? AND TENANT_ID = ?"; try { - long timestamp = DAOUtil.getCurrentUTCTime(); + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + Connection connection = this.getDBConnection(); try (PreparedStatement statement = connection.prepareStatement(sql)){ statement.setString(1, reviewDTO.getContent()); statement.setInt(2, reviewDTO.getRating()); - statement.setLong(3, timestamp); + statement.setTimestamp(3, timestamp); statement.setBoolean(4, isActiveReview); statement.setInt(5, reviewId); statement.setInt(6, tenantId); if (statement.executeUpdate() == 1) { - reviewDTO.setModifiedAt(new Timestamp(timestamp * 1000)); + reviewDTO.setModifiedAt(timestamp); return reviewDTO; } return null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java index 2db6925dd8..92e281fd6b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ReviewManagerImpl.java @@ -46,7 +46,6 @@ import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAO import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; -import java.sql.Timestamp; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index b7d134a8c7..cdd18c5678 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -431,7 +431,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { * * @param applicationDTO Application DTO * @param params list of subscribers. This list can be of either - * {@link DeviceIdentifier} if {@param subType} is equal + * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal * to DEVICE or * {@link String} if {@param subType} is USER, ROLE or GROUP * @param subType subscription type. E.g. DEVICE, USER, ROLE, GROUP {@see { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java index def4c74d96..4950fe3c6e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/DAOUtil.java @@ -36,11 +36,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Timestamp; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -230,8 +226,8 @@ public class DAOUtil { ReviewDTO reviewDTO = new ReviewDTO(); reviewDTO.setId(rs.getInt("ID")); reviewDTO.setContent(rs.getString("COMMENT")); - reviewDTO.setCreatedAt(new Timestamp(rs.getLong("CREATED_AT") * 1000L)); - reviewDTO.setModifiedAt(new Timestamp(rs.getLong("MODIFIED_AT") * 1000L)); + reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); + reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); reviewDTO.setUsername(rs.getString("USERNAME")); @@ -308,8 +304,4 @@ public class DAOUtil { } } } - - public static long getCurrentUTCTime() { - return new Date().getTime() / 1000; - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 0c5f43668a..68e1b1dd1f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -17,9 +17,6 @@ */ package org.wso2.carbon.device.mgt.core.dao.util; -import java.sql.*; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,6 +36,10 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.naming.InitialContext; import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -261,7 +262,7 @@ public final class DeviceManagementDAOUtil { deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setUpdatedTime(new Date(rs.getLong("UPDATE_TIMESTAMP"))); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); return deviceInfo; } @@ -284,14 +285,4 @@ public final class DeviceManagementDAOUtil { return deviceLocationHistory; } - public static long getCurrentUTCTime() { - return new Date().getTime() / 1000; - } - - public static long convertLocalTimeIntoUTC(Date localDate) { - LocalDateTime l = localDate.toInstant() - .atZone(ZoneId.of("GMT")) - .toLocalDateTime(); - return Timestamp.valueOf(l).getTime() / 1000; - } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index 6db8bd2fdd..d00cb1d1ed 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -74,7 +74,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(14, deviceInfo.getTotalRAMMemory()); stmt.setDouble(15, deviceInfo.getAvailableRAMMemory()); stmt.setBoolean(16, deviceInfo.isPluggedIn()); - stmt.setLong(17, DeviceManagementDAOUtil.getCurrentUTCTime()); + stmt.setLong(17, System.currentTimeMillis()); stmt.setInt(18, enrolmentId); stmt.execute(); @@ -287,9 +287,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(9, deviceLocation.getCountry()); stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation)); if (deviceLocation.getUpdatedTime() == null) { - stmt.setLong(11, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L); + stmt.setLong(11, System.currentTimeMillis()); } else { - stmt.setLong(11, DeviceManagementDAOUtil.convertLocalTimeIntoUTC(deviceLocation.getUpdatedTime()) * 1000L); + stmt.setLong(11, deviceLocation.getUpdatedTime().getTime()); } stmt.setInt(12, enrollmentId); stmt.setDouble(13, deviceLocation.getAltitude()); @@ -330,7 +330,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(7, deviceLocation.getState()); stmt.setString(8, deviceLocation.getCountry()); stmt.setString(9, GeoHashGenerator.encodeGeohash(deviceLocation)); - stmt.setLong(10, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L); + stmt.setLong(10, System.currentTimeMillis()); stmt.setInt(11, deviceLocation.getDeviceId()); stmt.setInt(12, enrollmentId); stmt.execute(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index c96e20c4f1..80bcf8e1a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -18,9 +18,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -37,7 +34,6 @@ import java.util.Date; import java.util.List; public class CommandOperationDAOImpl extends GenericOperationDAOImpl { - private static final Log log = LogFactory.getLog(CommandOperationDAOImpl.class); @Override public int addOperation(Operation operation) throws OperationManagementDAOException { @@ -49,8 +45,8 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { "INITIATED_BY, ENABLED) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - stmt.setLong(3, 0); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setBoolean(6, operation.isEnabled()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 193a0244f8..397485a744 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -47,14 +46,14 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; try { - operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - stmt.setLong(3, 0); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index a9e050eb83..de92618c46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -28,7 +28,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityHolder; import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping; @@ -73,8 +72,8 @@ public class GenericOperationDAOImpl implements OperationDAO { "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - stmt.setLong(3, 0); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); @@ -99,7 +98,7 @@ public class GenericOperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; boolean isUpdated = false; try { - long time = DeviceManagementDAOUtil.getCurrentUTCTime(); + long time = System.currentTimeMillis() / 1000; Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=?, UPDATED_TIMESTAMP=? " + "WHERE ENROLMENT_ID=? and OPERATION_ID=?"); @@ -441,7 +440,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity = new Activity(); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); } @@ -457,7 +456,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); operationResponses.add(OperationDAOUtil.getOperationResponse(rs)); } activityStatus.setResponses(operationResponses); @@ -557,7 +556,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -572,7 +571,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { @@ -596,7 +595,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -609,7 +608,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { responseId = rs.getInt("OP_RES_ID"); @@ -695,7 +694,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setCreatedTimeStamp( - new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); } @@ -709,7 +708,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { activityStatus.setUpdatedTimestamp( - new Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); + new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); if (rs.getBoolean("IS_LARGE_RESPONSE")) { largeResponseIDs.add(rs.getInt("OP_RES_ID")); } else { @@ -843,7 +842,7 @@ public class GenericOperationDAOImpl implements OperationDAO { enrolmentId = rs.getInt("ENROLMENT_ID"); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); activity.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -856,7 +855,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new Date( + activityStatus.setUpdatedTimestamp(new java.util.Date( rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } @@ -879,7 +878,7 @@ public class GenericOperationDAOImpl implements OperationDAO { activityStatus = new ActivityStatus(); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); - activity.setCreatedTimeStamp(new Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); + activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCode(rs.getString("OPERATION_CODE")); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @@ -891,7 +890,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operationResponses = new ArrayList<>(); if (rs.getInt("UPDATED_TIMESTAMP") != 0) { - activityStatus.setUpdatedTimestamp(new Date( + activityStatus.setUpdatedTimestamp(new java.util.Date( rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); } if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { @@ -1147,11 +1146,11 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); - if (rs.getLong("RECEIVED_TIMESTAMP") == 0) { + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { operation.setReceivedTimeStamp(""); } else { - operation.setReceivedTimeStamp(new Timestamp(rs.getLong("RECEIVED_TIMESTAMP") * 1000L).toString()); + operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); } operation.setCode(rs.getString("OPERATION_CODE")); operation.setInitiatedBy(rs.getString("INITIATED_BY")); @@ -1173,10 +1172,10 @@ public class GenericOperationDAOImpl implements OperationDAO { Operation operation = null; try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, o.OPERATION_CODE, " + - "om.ID AS OM_MAPPING_ID, " + + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " + + "o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " + "om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," + - "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + + "OPERATION_CODE, INITIATED_BY FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + "ON o.ID = om.OPERATION_ID "; stmt = conn.prepareStatement(sql); @@ -1189,15 +1188,16 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); } } catch (SQLException e) { @@ -1215,11 +1215,11 @@ public class GenericOperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; ResultSet rs = null; Operation operation; - List operations = new ArrayList(); + List operations = new ArrayList<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, om.ID AS OM_MAPPING_ID," + - "om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + + "o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; stmt = conn.prepareStatement(sql); @@ -1231,14 +1231,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(status); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); @@ -1263,7 +1264,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + - "om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + "o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + "o.CREATED_TIMESTAMP DESC LIMIT ?,?"; @@ -1278,14 +1279,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(status); OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); @@ -1309,8 +1311,8 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + - "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + + "o.OPERATION_CODE, o.INITIATED_BY, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " + + "FROM DM_OPERATION o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC"; stmt = conn.prepareStatement(sql); @@ -1321,14 +1323,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operations.add(operation); } @@ -1345,7 +1348,7 @@ public class GenericOperationDAOImpl implements OperationDAO { public List getOperationsForDevice(int enrolmentId, PaginationRequest request) throws OperationManagementDAOException { Operation operation; - List operations = new ArrayList(); + List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); @@ -1363,74 +1366,75 @@ public class GenericOperationDAOImpl implements OperationDAO { Long updatedTo = request.getOperationLogFilters().getUpdatedDayTo(); List operationCode = request.getOperationLogFilters().getOperationCode(); List status = request.getOperationLogFilters().getStatus(); - String sql = "SELECT " + - "o.ID, " + - "TYPE, " + - "o.CREATED_TIMESTAMP, " + - "o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, " + - "om.STATUS, " + - "om.ID AS OM_MAPPING_ID, " + - "om.UPDATED_TIMESTAMP " + - "FROM " + - "DM_OPERATION o " + - "INNER JOIN " + - "(SELECT dm.OPERATION_ID, " + - "dm.ID, " + - "dm.STATUS, " + - "dm.UPDATED_TIMESTAMP " + - "FROM " + - "DM_ENROLMENT_OP_MAPPING dm " + - "WHERE " + - "dm.ENROLMENT_ID = ?"; + StringBuilder sql = new StringBuilder("SELECT " + + "o.ID, " + + "TYPE, " + + "o.CREATED_TIMESTAMP, " + + "o.RECEIVED_TIMESTAMP, " + + "o.OPERATION_CODE, " + + "o.INITIATED_BY, " + + "om.STATUS, " + + "om.ID AS OM_MAPPING_ID, " + + "om.UPDATED_TIMESTAMP " + + "FROM " + + "DM_OPERATION o " + + "INNER JOIN " + + "(SELECT dm.OPERATION_ID, " + + "dm.ID, " + + "dm.STATUS, " + + "dm.UPDATED_TIMESTAMP " + + "FROM " + + "DM_ENROLMENT_OP_MAPPING dm " + + "WHERE " + + "dm.ENROLMENT_ID = ?"); if (updatedFrom != null && updatedFrom != 0 && updatedTo != null && updatedTo != 0) { - sql = sql + " AND dm.UPDATED_TIMESTAMP BETWEEN ? AND ?"; + sql.append(" AND dm.UPDATED_TIMESTAMP BETWEEN ? AND ?"); isUpdatedDayProvided = true; } - sql = sql + ") om ON o.ID = om.OPERATION_ID "; + sql.append(") om ON o.ID = om.OPERATION_ID "); if (createdFrom != null && !createdFrom.isEmpty() && createdTo != null && !createdTo.isEmpty()) { - sql = sql + " WHERE o.CREATED_TIMESTAMP BETWEEN ? AND ?"; + sql.append(" WHERE o.CREATED_TIMESTAMP BETWEEN ? AND ?"); isCreatedDayProvided = true; } if ((isCreatedDayProvided) && (status != null && !status.isEmpty())) { int size = status.size(); - sql = sql + " AND (om.STATUS = ? "; + sql.append(" AND (om.STATUS = ? "); for (int i = 0; i < size - 1; i++) { - sql = sql + " OR om.STATUS = ?"; + sql.append(" OR om.STATUS = ?"); } - sql = sql + ")"; + sql.append(")"); isStatusProvided = true; } else if ((!isCreatedDayProvided) && (status != null && !status.isEmpty())) { int size = status.size(); - sql = sql + " WHERE (om.STATUS = ? "; + sql.append(" WHERE (om.STATUS = ? "); for (int i = 0; i < size - 1; i++) { - sql = sql + " OR om.STATUS = ?"; + sql.append(" OR om.STATUS = ?"); } - sql = sql + ")"; + sql.append(")"); isStatusProvided = true; } if ((isCreatedDayProvided || isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { int size = operationCode.size(); - sql = sql + " AND (o.OPERATION_CODE = ? "; + sql.append(" AND (o.OPERATION_CODE = ? "); for (int i = 0; i < size - 1; i++) { - sql = sql + " OR o.OPERATION_CODE = ?"; + sql.append(" OR o.OPERATION_CODE = ?"); } - sql = sql + ")"; + sql.append(")"); isOperationCodeProvided = true; } else if ((!isCreatedDayProvided && !isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { int size = operationCode.size(); - sql = sql + " WHERE (o.OPERATION_CODE = ? "; + sql.append(" WHERE (o.OPERATION_CODE = ? "); for (int i = 0; i < size - 1; i++) { - sql = sql + " OR o.OPERATION_CODE = ?"; + sql.append(" OR o.OPERATION_CODE = ?"); } - sql = sql + ")"; + sql.append(")"); isOperationCodeProvided = true; } - sql = sql + " ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; + sql.append(" ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"); try { Connection conn = OperationManagementDAOFactory.getConnection(); - try (PreparedStatement stmt = conn.prepareStatement(sql)) { + try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) { int paramIndex = 1; stmt.setInt(paramIndex++, enrolmentId); if (isUpdatedDayProvided) { @@ -1442,15 +1446,13 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setString(paramIndex++, createdTo); } if (isStatusProvided) { - int size = status.size(); - for (int i = 0; i < size; i++) { - stmt.setString(paramIndex++, status.get(i)); + for (String s : status) { + stmt.setString(paramIndex++, s); } } if (isOperationCodeProvided) { - int size = operationCode.size(); - for (int i = 0; i < size; i++) { - stmt.setString(paramIndex++, operationCode.get(i)); + for (String s : operationCode) { + stmt.setString(paramIndex++, s); } } stmt.setInt(paramIndex++, request.getStartIndex()); @@ -1460,14 +1462,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); @@ -1594,7 +1597,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + - "o.OPERATION_CODE, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + + "o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1"); @@ -1607,15 +1610,16 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setType(OperationDAOUtil.getType(rs.getString("TYPE"))); operation.setId(rs.getInt("ID")); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setStatus(Operation.Status.PENDING); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); } @@ -1636,10 +1640,10 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID, " + - "om.UPDATED_TIMESTAMP FROM (SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + - "FROM DM_OPERATION o WHERE o.TYPE = ?) o " + - "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," + + " om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " + + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " + + "FROM DM_OPERATION o WHERE o.TYPE = ?) o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; stmt = conn.prepareStatement(sql); @@ -1652,14 +1656,15 @@ public class GenericOperationDAOImpl implements OperationDAO { operation = new Operation(); operation.setId(rs.getInt("ID")); operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); - operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); if (rs.getLong("UPDATED_TIMESTAMP") == 0) { operation.setReceivedTimeStamp(""); } else { operation.setReceivedTimeStamp( - new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); + new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + operation.setInitiatedBy(rs.getString("INITIATED_BY")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index 42ba7c7b28..39b6212e50 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -46,15 +45,15 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { int operationId = -1; try { - operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - stmt.setLong(3, 0); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 8e23d24067..9f07007e3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; @@ -43,15 +42,15 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { ByteArrayOutputStream bao = null; ObjectOutputStream oos = null; try { - operation.setCreatedTimeStamp(new Timestamp(DeviceManagementDAOUtil.getCurrentUTCTime()).toString()); + operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); - stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); - stmt.setLong(3, 0); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); @@ -118,7 +117,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { profileOperation = new ProfileOperation(); profileOperation.setCode(rs.getString("OPERATION_CODE")); profileOperation.setId(oppId); - profileOperation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString()); + profileOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP")); profileOperation.setId(oppId); profileOperation.setPayLoad(obj); } else { diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 110ccdc606..5d5db38b2d 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -57,8 +57,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW( COMMENT TEXT NOT NULL, ROOT_PARENT_ID INTEGER NOT NULL, IMMEDIATE_PARENT_ID INTEGER NOT NULL, - CREATED_AT BIGINT NOT NULL, - MODIFIED_AT BIGINT NOT NULL, + CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + MODIFIED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, RATING INTEGER NULL, USERNAME VARCHAR(45) NOT NULL, ACTIVE_REVIEW BOOLEAN NOT NULL DEFAULT TRUE, @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT BIGINT NOT NULL, + UPDATED_AT TIMESTAMP NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index e11919b0a0..a69b79b783 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -99,8 +99,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP BIGINT(15) NOT NULL, - RECEIVED_TIMESTAMP BIGINT(15) NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, From 786f247adcdb990e8ca326196b70fd09b33a0f77 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 10 Dec 2021 01:57:34 +0530 Subject: [PATCH 8/8] Revert "Fix test failures" This reverts commit 10b8e0de --- .../src/test/resources/sql/h2.sql | 4 ++-- .../src/test/resources/sql-files/h2.sql | 4 ++-- .../src/test/resources/sql/CreateH2TestDB.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/application-mgt/h2.sql | 2 +- .../main/resources/dbscripts/cdm/application-mgt/mssql.sql | 2 +- .../resources/dbscripts/cdm/application-mgt/postgresql.sql | 2 +- .../src/main/resources/dbscripts/cdm/archival/mysql.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/h2.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/mssql.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/oracle.sql | 4 ++-- .../src/main/resources/dbscripts/cdm/postgresql.sql | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index cc69537e90..2c846cb1af 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -75,8 +75,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql index ef684a6685..7d7c1ece9c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql @@ -65,8 +65,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 4c59adb953..7238d37790 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -83,8 +83,8 @@ DROP TABLE IF EXISTS DM_OPERATION; CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 150480f68d..dcbebd74b4 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -79,7 +79,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT BIGINT NOT NULL, + UPDATED_AT TIMESTAMP NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index 5d29525a8c..25fc47e38e 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -80,7 +80,7 @@ CREATE TABLE AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT BIGINT NOT NULL, + UPDATED_AT DATETIME2(0) NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON VARCHAR(max) DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index c799b03245..d871549d89 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_LIFECYCLE_STATE( PREVIOUS_STATE VARCHAR(45) NOT NULL, TENANT_ID INTEGER NOT NULL, UPDATED_BY VARCHAR(100) NOT NULL, - UPDATED_AT BIGINT NOT NULL, + UPDATED_AT TIMESTAMP(0) NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, REASON TEXT DEFAULT NULL, PRIMARY KEY (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql index 7854ee1181..659e22d110 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql @@ -2,8 +2,8 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH ( ID INTEGER NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index ed9ce41c7d..f6894eb4ac 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -84,8 +84,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index f0cbcf2458..c27f891445 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -111,8 +111,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D CREATE TABLE DM_OPERATION ( ID INTEGER IDENTITY(1,1) NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP DATETIME2 NOT NULL, + RECEIVED_TIMESTAMP DATETIME2 NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 00adba3500..e2e4693bd2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -173,8 +173,8 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_OPERATION ( ID NUMBER(10) NOT NULL, TYPE VARCHAR2(50) NOT NULL, - CREATED_TIMESTAMP BIGINT NOT NULL, - RECEIVED_TIMESTAMP BIGINT NULL, + CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, OPERATION_CODE VARCHAR2(1000) NOT NULL, INITIATED_BY VARCHAR2(100) NULL, ENABLED NUMBER(10) DEFAULT 0 NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index d2537af3a8..bd8eb8771a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -93,7 +93,7 @@ CREATE SEQUENCE DM_OPERATION_seq; CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER DEFAULT NEXTVAL ('DM_OPERATION_seq') NOT NULL, TYPE VARCHAR(20) NOT NULL, - CREATED_TIMESTAMP NOT NULL, + CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, OPERATION_CODE VARCHAR(50) NOT NULL, INITIATED_BY VARCHAR(100) NULL,