From 23dcac5fa710f591dd9207c9df919a5dd24638b2 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 1 Dec 2021 11:53:37 +0530 Subject: [PATCH] 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,