Add timestamp issue fixes

4.x.x
Pahansith Gunathilake 3 years ago
parent cf4f45c89d
commit 4691b1d7bd

@ -161,14 +161,13 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
+ "VALUES (?, ?, ?, ?, ?, ?, ?)"; + "VALUES (?, ?, ?, ?, ?, ?, ?)";
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
Calendar calendar = Calendar.getInstance(); long timestamp = DAOUtil.getCurrentUTCTime();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, state.getCurrentState().toUpperCase()); stmt.setString(1, state.getCurrentState().toUpperCase());
stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setString(2, state.getPreviousState().toUpperCase());
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setString(4, state.getUpdatedBy()); stmt.setString(4, state.getUpdatedBy());
stmt.setTimestamp(5, timestamp); stmt.setLong(5, timestamp);
stmt.setString(6, state.getReasonForChange()); stmt.setString(6, state.getReasonForChange());
stmt.setInt(7, appReleaseId); stmt.setInt(7, appReleaseId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -254,7 +253,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
lifecycleState = new LifecycleState(); lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_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")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -280,7 +279,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
LifecycleState lifecycleState = new LifecycleState(); LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE")); lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUS_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")); lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState); lifecycleStates.add(lifecycleState);
} }

@ -68,8 +68,7 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )"; + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
try { try {
int reviewId = -1; int reviewId = -1;
Calendar calendar = Calendar.getInstance(); long timestamp = DAOUtil.getCurrentUTCTime();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) { try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) {
statement.setInt(1, tenantId); statement.setInt(1, tenantId);
@ -78,8 +77,8 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(4, reviewDTO.getImmediateParentId()); statement.setInt(4, reviewDTO.getImmediateParentId());
statement.setInt(5, reviewDTO.getRating()); statement.setInt(5, reviewDTO.getRating());
statement.setString(6, reviewDTO.getUsername()); statement.setString(6, reviewDTO.getUsername());
statement.setTimestamp(7, timestamp); statement.setLong(7, timestamp);
statement.setTimestamp(8, timestamp); statement.setLong(8, timestamp);
statement.setInt(9, appReleaseId); statement.setInt(9, appReleaseId);
statement.executeUpdate(); statement.executeUpdate();
try (ResultSet rs = statement.getGeneratedKeys()) { try (ResultSet rs = statement.getGeneratedKeys()) {
@ -158,19 +157,17 @@ public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "ACTIVE_REVIEW = ? " + "ACTIVE_REVIEW = ? "
+ "WHERE ID = ? AND TENANT_ID = ?"; + "WHERE ID = ? AND TENANT_ID = ?";
try { try {
Calendar calendar = Calendar.getInstance(); long timestamp = DAOUtil.getCurrentUTCTime();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection connection = this.getDBConnection(); Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)){ try (PreparedStatement statement = connection.prepareStatement(sql)){
statement.setString(1, reviewDTO.getContent()); statement.setString(1, reviewDTO.getContent());
statement.setInt(2, reviewDTO.getRating()); statement.setInt(2, reviewDTO.getRating());
statement.setTimestamp(3, timestamp); statement.setLong(3, timestamp);
statement.setBoolean(4, isActiveReview); statement.setBoolean(4, isActiveReview);
statement.setInt(5, reviewId); statement.setInt(5, reviewId);
statement.setInt(6, tenantId); statement.setInt(6, tenantId);
if (statement.executeUpdate() == 1) { if (statement.executeUpdate() == 1) {
reviewDTO.setModifiedAt(timestamp); reviewDTO.setModifiedAt(new Timestamp(timestamp * 1000));
return reviewDTO; return reviewDTO;
} }
return null; return null;

@ -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.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;

@ -431,7 +431,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* *
* @param applicationDTO Application DTO * @param applicationDTO Application DTO
* @param params list of subscribers. This list can be of either * @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 * to DEVICE or
* {@link String} if {@param subType} is USER, ROLE or GROUP * {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see { * @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see {

@ -36,7 +36,11 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -226,8 +230,8 @@ public class DAOUtil {
ReviewDTO reviewDTO = new ReviewDTO(); ReviewDTO reviewDTO = new ReviewDTO();
reviewDTO.setId(rs.getInt("ID")); reviewDTO.setId(rs.getInt("ID"));
reviewDTO.setContent(rs.getString("COMMENT")); reviewDTO.setContent(rs.getString("COMMENT"));
reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT")); reviewDTO.setCreatedAt(new Timestamp(rs.getLong("CREATED_AT") * 1000L));
reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); reviewDTO.setModifiedAt(new Timestamp(rs.getLong("MODIFIED_AT") * 1000L));
reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID")); reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID"));
reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID")); reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID"));
reviewDTO.setUsername(rs.getString("USERNAME")); reviewDTO.setUsername(rs.getString("USERNAME"));
@ -304,4 +308,8 @@ public class DAOUtil {
} }
} }
} }
public static long getCurrentUTCTime() {
return new Date().getTime() / 1000;
}
} }

@ -17,6 +17,9 @@
*/ */
package org.wso2.carbon.device.mgt.core.dao.util; 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 java.util.Date;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -36,10 +39,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.sql.DataSource; 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.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
@ -262,7 +261,7 @@ public final class DeviceManagementDAOUtil {
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); 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; return deviceInfo;
} }
@ -285,4 +284,14 @@ public final class DeviceManagementDAOUtil {
return deviceLocationHistory; 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;
}
} }

@ -74,7 +74,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setDouble(14, deviceInfo.getTotalRAMMemory()); stmt.setDouble(14, deviceInfo.getTotalRAMMemory());
stmt.setDouble(15, deviceInfo.getAvailableRAMMemory()); stmt.setDouble(15, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(16, deviceInfo.isPluggedIn()); stmt.setBoolean(16, deviceInfo.isPluggedIn());
stmt.setLong(17, System.currentTimeMillis()); stmt.setLong(17, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setInt(18, enrolmentId); stmt.setInt(18, enrolmentId);
stmt.execute(); stmt.execute();
@ -287,9 +287,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setString(9, deviceLocation.getCountry()); stmt.setString(9, deviceLocation.getCountry());
stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation)); stmt.setString(10, GeoHashGenerator.encodeGeohash(deviceLocation));
if (deviceLocation.getUpdatedTime() == null) { if (deviceLocation.getUpdatedTime() == null) {
stmt.setLong(11, System.currentTimeMillis()); stmt.setLong(11, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L);
} else { } else {
stmt.setLong(11, deviceLocation.getUpdatedTime().getTime()); stmt.setLong(11, DeviceManagementDAOUtil.convertLocalTimeIntoUTC(deviceLocation.getUpdatedTime()) * 1000L);
} }
stmt.setInt(12, enrollmentId); stmt.setInt(12, enrollmentId);
stmt.setDouble(13, deviceLocation.getAltitude()); stmt.setDouble(13, deviceLocation.getAltitude());
@ -330,7 +330,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setString(7, deviceLocation.getState()); stmt.setString(7, deviceLocation.getState());
stmt.setString(8, deviceLocation.getCountry()); stmt.setString(8, deviceLocation.getCountry());
stmt.setString(9, GeoHashGenerator.encodeGeohash(deviceLocation)); stmt.setString(9, GeoHashGenerator.encodeGeohash(deviceLocation));
stmt.setLong(10, System.currentTimeMillis()); stmt.setLong(10, DeviceManagementDAOUtil.getCurrentUTCTime() * 1000L);
stmt.setInt(11, deviceLocation.getDeviceId()); stmt.setInt(11, deviceLocation.getDeviceId());
stmt.setInt(12, enrollmentId); stmt.setInt(12, enrollmentId);
stmt.execute(); stmt.execute();

@ -18,6 +18,9 @@
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; 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.CommandOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
@ -34,6 +37,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
public class CommandOperationDAOImpl extends GenericOperationDAOImpl { public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
private static final Log log = LogFactory.getLog(CommandOperationDAOImpl.class);
@Override @Override
public int addOperation(Operation operation) throws OperationManagementDAOException { public int addOperation(Operation operation) throws OperationManagementDAOException {
@ -45,8 +49,9 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
"INITIATED_BY, ENABLED) VALUES (?, ?, ?, ?, ?, ?)"; "INITIATED_BY, ENABLED) VALUES (?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setTimestamp(3, null); log.info("------Time----- " + DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setLong(3, 0);
stmt.setString(4, operation.getCode()); stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy()); stmt.setString(5, operation.getInitiatedBy());
stmt.setBoolean(6, operation.isEnabled()); stmt.setBoolean(6, operation.isEnabled());

@ -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.Log;
import org.apache.commons.logging.LogFactory; 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.ConfigOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
@ -46,14 +47,14 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString());
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setTimestamp(3, null); stmt.setLong(3, 0);
stmt.setString(4, operation.getCode()); stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy()); stmt.setString(5, operation.getInitiatedBy());
stmt.setObject(6, operation); stmt.setObject(6, operation);

@ -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.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; 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.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.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
@ -72,8 +73,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
"INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setTimestamp(3, null); stmt.setLong(3, 0);
stmt.setString(4, operation.getCode()); stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy()); stmt.setString(5, operation.getInitiatedBy());
stmt.setObject(6, operation); stmt.setObject(6, operation);
@ -98,7 +99,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean isUpdated = false; boolean isUpdated = false;
try { try {
long time = System.currentTimeMillis() / 1000; long time = DeviceManagementDAOUtil.getCurrentUTCTime();
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=?, UPDATED_TIMESTAMP=? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS=?, UPDATED_TIMESTAMP=? " +
"WHERE ENROLMENT_ID=? and OPERATION_ID=?"); "WHERE ENROLMENT_ID=? and OPERATION_ID=?");
@ -440,7 +441,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity = new Activity(); activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); 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.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY")); activity.setInitiatedBy(rs.getString("INITIATED_BY"));
} }
@ -456,7 +457,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { 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)); operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
} }
activityStatus.setResponses(operationResponses); activityStatus.setResponses(operationResponses);
@ -556,7 +557,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY")); activity.setInitiatedBy(rs.getString("INITIATED_BY"));
@ -571,7 +572,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp( 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) { 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.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
@ -608,7 +609,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp( 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) { if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
responseId = rs.getInt("OP_RES_ID"); responseId = rs.getInt("OP_RES_ID");
@ -694,7 +695,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY")); activity.setInitiatedBy(rs.getString("INITIATED_BY"));
} }
@ -708,7 +709,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp( 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")) { if (rs.getBoolean("IS_LARGE_RESPONSE")) {
largeResponseIDs.add(rs.getInt("OP_RES_ID")); largeResponseIDs.add(rs.getInt("OP_RES_ID"));
} else { } else {
@ -842,7 +843,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
enrolmentId = rs.getInt("ENROLMENT_ID"); enrolmentId = rs.getInt("ENROLMENT_ID");
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); 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.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY")); activity.setInitiatedBy(rs.getString("INITIATED_BY"));
@ -855,7 +856,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(new java.util.Date( activityStatus.setUpdatedTimestamp(new Date(
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
} }
@ -878,7 +879,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activityStatus = new ActivityStatus(); activityStatus = new ActivityStatus();
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); 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.setCode(rs.getString("OPERATION_CODE"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
@ -890,7 +891,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) { if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(new java.util.Date( activityStatus.setUpdatedTimestamp(new Date(
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString()); rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
} }
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) { if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
@ -1146,11 +1147,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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.getTimestamp("RECEIVED_TIMESTAMP") == null) { if (rs.getLong("RECEIVED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY")); operation.setInitiatedBy(rs.getString("INITIATED_BY"));
@ -1172,10 +1173,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null; Operation operation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, o.OPERATION_CODE, " +
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " + "om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," + "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 " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID "; "ON o.ID = om.OPERATION_ID ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -1188,16 +1189,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
if (rs.getLong("UPDATED_TIMESTAMP") == 0) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -1215,11 +1215,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, om.ID AS OM_MAPPING_ID," +
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "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"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -1231,15 +1231,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(status); operation.setStatus(status);
OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation); operations.add(operation);
@ -1264,7 +1263,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + 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 " + "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 " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
"o.CREATED_TIMESTAMP DESC LIMIT ?,?"; "o.CREATED_TIMESTAMP DESC LIMIT ?,?";
@ -1279,15 +1278,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(status); operation.setStatus(status);
OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
@ -1311,8 +1309,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + 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 " + "o.OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"FROM DM_OPERATION o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC"; "ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -1323,15 +1321,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
operations.add(operation); operations.add(operation);
} }
@ -1348,7 +1345,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
public List<? extends Operation> getOperationsForDevice(int enrolmentId, PaginationRequest request) public List<? extends Operation> getOperationsForDevice(int enrolmentId, PaginationRequest request)
throws OperationManagementDAOException { throws OperationManagementDAOException {
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
String createdTo = null; String createdTo = null;
String createdFrom = null; String createdFrom = null;
DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 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(); Long updatedTo = request.getOperationLogFilters().getUpdatedDayTo();
List<String> operationCode = request.getOperationLogFilters().getOperationCode(); List<String> operationCode = request.getOperationLogFilters().getOperationCode();
List<String> status = request.getOperationLogFilters().getStatus(); List<String> status = request.getOperationLogFilters().getStatus();
StringBuilder sql = new StringBuilder("SELECT " + String sql = "SELECT " +
"o.ID, " + "o.ID, " +
"TYPE, " + "TYPE, " +
"o.CREATED_TIMESTAMP, " + "o.CREATED_TIMESTAMP, " +
"o.RECEIVED_TIMESTAMP, " + "o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE, " + "o.OPERATION_CODE, " +
"o.INITIATED_BY, " + "om.STATUS, " +
"om.STATUS, " + "om.ID AS OM_MAPPING_ID, " +
"om.ID AS OM_MAPPING_ID, " + "om.UPDATED_TIMESTAMP " +
"om.UPDATED_TIMESTAMP " + "FROM " +
"FROM " + "DM_OPERATION o " +
"DM_OPERATION o " + "INNER JOIN " +
"INNER JOIN " + "(SELECT dm.OPERATION_ID, " +
"(SELECT dm.OPERATION_ID, " + "dm.ID, " +
"dm.ID, " + "dm.STATUS, " +
"dm.STATUS, " + "dm.UPDATED_TIMESTAMP " +
"dm.UPDATED_TIMESTAMP " + "FROM " +
"FROM " + "DM_ENROLMENT_OP_MAPPING dm " +
"DM_ENROLMENT_OP_MAPPING dm " + "WHERE " +
"WHERE " + "dm.ENROLMENT_ID = ?";
"dm.ENROLMENT_ID = ?");
if (updatedFrom != null && updatedFrom != 0 && updatedTo != null && updatedTo != 0) { 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; 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()) { 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; isCreatedDayProvided = true;
} }
if ((isCreatedDayProvided) && (status != null && !status.isEmpty())) { if ((isCreatedDayProvided) && (status != null && !status.isEmpty())) {
int size = status.size(); int size = status.size();
sql.append(" AND (om.STATUS = ? "); sql = sql + " AND (om.STATUS = ? ";
for (int i = 0; i < size - 1; i++) { for (int i = 0; i < size - 1; i++) {
sql.append(" OR om.STATUS = ?"); sql = sql + " OR om.STATUS = ?";
} }
sql.append(")"); sql = sql + ")";
isStatusProvided = true; isStatusProvided = true;
} else if ((!isCreatedDayProvided) && (status != null && !status.isEmpty())) { } else if ((!isCreatedDayProvided) && (status != null && !status.isEmpty())) {
int size = status.size(); int size = status.size();
sql.append(" WHERE (om.STATUS = ? "); sql = sql + " WHERE (om.STATUS = ? ";
for (int i = 0; i < size - 1; i++) { for (int i = 0; i < size - 1; i++) {
sql.append(" OR om.STATUS = ?"); sql = sql + " OR om.STATUS = ?";
} }
sql.append(")"); sql = sql + ")";
isStatusProvided = true; isStatusProvided = true;
} }
if ((isCreatedDayProvided || isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { if ((isCreatedDayProvided || isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) {
int size = operationCode.size(); int size = operationCode.size();
sql.append(" AND (o.OPERATION_CODE = ? "); sql = sql + " AND (o.OPERATION_CODE = ? ";
for (int i = 0; i < size - 1; i++) { 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; isOperationCodeProvided = true;
} else if ((!isCreatedDayProvided && !isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) { } else if ((!isCreatedDayProvided && !isStatusProvided) && (operationCode != null && !operationCode.isEmpty())) {
int size = operationCode.size(); int size = operationCode.size();
sql.append(" WHERE (o.OPERATION_CODE = ? "); sql = sql + " WHERE (o.OPERATION_CODE = ? ";
for (int i = 0; i < size - 1; i++) { 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; isOperationCodeProvided = true;
} }
sql.append(" ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"); sql = sql + " ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?";
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndex = 1; int paramIndex = 1;
stmt.setInt(paramIndex++, enrolmentId); stmt.setInt(paramIndex++, enrolmentId);
if (isUpdatedDayProvided) { if (isUpdatedDayProvided) {
@ -1446,13 +1442,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setString(paramIndex++, createdTo); stmt.setString(paramIndex++, createdTo);
} }
if (isStatusProvided) { if (isStatusProvided) {
for (String s : status) { int size = status.size();
stmt.setString(paramIndex++, s); for (int i = 0; i < size; i++) {
stmt.setString(paramIndex++, status.get(i));
} }
} }
if (isOperationCodeProvided) { if (isOperationCodeProvided) {
for (String s : operationCode) { int size = operationCode.size();
stmt.setString(paramIndex++, s); for (int i = 0; i < size; i++) {
stmt.setString(paramIndex++, operationCode.get(i));
} }
} }
stmt.setInt(paramIndex++, request.getStartIndex()); stmt.setInt(paramIndex++, request.getStartIndex());
@ -1462,15 +1460,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation); operations.add(operation);
@ -1597,7 +1594,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + 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 " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "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"); "ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1");
@ -1610,16 +1607,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setType(OperationDAOUtil.getType(rs.getString("TYPE"))); operation.setType(OperationDAOUtil.getType(rs.getString("TYPE")));
operation.setId(rs.getInt("ID")); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
operation.setStatus(Operation.Status.PENDING); operation.setStatus(Operation.Status.PENDING);
OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
} }
@ -1640,10 +1636,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID, " +
" om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " + "om.UPDATED_TIMESTAMP FROM (SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "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"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -1656,15 +1652,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); 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) { if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp(""); operation.setReceivedTimeStamp("");
} else { } else {
operation.setReceivedTimeStamp( 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.setCode(rs.getString("OPERATION_CODE"));
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
operations.add(operation); operations.add(operation);
} }

@ -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.Log;
import org.apache.commons.logging.LogFactory; 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.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
@ -45,15 +46,15 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
int operationId = -1; int operationId = -1;
try { try {
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString());
operation.setEnabled(true); operation.setEnabled(true);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setTimestamp(3, null); stmt.setLong(3, 0);
stmt.setString(4, operation.getCode()); stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy()); stmt.setString(5, operation.getInitiatedBy());

@ -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.Log;
import org.apache.commons.logging.LogFactory; 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.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
@ -42,15 +43,15 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
ByteArrayOutputStream bao = null; ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
try { try {
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); operation.setCreatedTimeStamp(new Timestamp(DeviceManagementDAOUtil.getCurrentUTCTime()).toString());
operation.setEnabled(true); operation.setEnabled(true);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString()); stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime())); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
stmt.setTimestamp(3, null); stmt.setLong(3, 0);
stmt.setString(4, operation.getCode()); stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy()); stmt.setString(5, operation.getInitiatedBy());
@ -117,7 +118,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
profileOperation = new ProfileOperation(); profileOperation = new ProfileOperation();
profileOperation.setCode(rs.getString("OPERATION_CODE")); profileOperation.setCode(rs.getString("OPERATION_CODE"));
profileOperation.setId(oppId); profileOperation.setId(oppId);
profileOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP")); profileOperation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
profileOperation.setId(oppId); profileOperation.setId(oppId);
profileOperation.setPayLoad(obj); profileOperation.setPayLoad(obj);
} else { } else {

@ -57,8 +57,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW(
COMMENT TEXT NOT NULL, COMMENT TEXT NOT NULL,
ROOT_PARENT_ID INTEGER NOT NULL, ROOT_PARENT_ID INTEGER NOT NULL,
IMMEDIATE_PARENT_ID INTEGER NOT NULL, IMMEDIATE_PARENT_ID INTEGER NOT NULL,
CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, CREATED_AT BIGINT NOT NULL,
MODIFIED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, MODIFIED_AT BIGINT NOT NULL,
RATING INTEGER NULL, RATING INTEGER NULL,
USERNAME VARCHAR(45) NOT NULL, USERNAME VARCHAR(45) NOT NULL,
ACTIVE_REVIEW BOOLEAN NOT NULL DEFAULT TRUE, 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, PREVIOUS_STATE VARCHAR(45) NOT NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
UPDATED_BY VARCHAR(100) 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, AP_APP_RELEASE_ID INTEGER NOT NULL,
REASON TEXT DEFAULT NULL, REASON TEXT DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),

@ -99,8 +99,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
TYPE VARCHAR(20) NOT NULL, TYPE VARCHAR(20) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL, CREATED_TIMESTAMP BIGINT(15) NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL, RECEIVED_TIMESTAMP BIGINT(15) NULL,
OPERATION_CODE VARCHAR(50) NOT NULL, OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL, INITIATED_BY VARCHAR(100) NULL,
OPERATION_DETAILS BLOB DEFAULT NULL, OPERATION_DETAILS BLOB DEFAULT NULL,

Loading…
Cancel
Save