|
|
@ -20,18 +20,11 @@ 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.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
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.ProfileOperation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -48,13 +41,12 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
"INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, OPERATION_CODE) " +
|
|
|
|
"INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " +
|
|
|
|
"VALUES (?, ?, ?, ?,?)");
|
|
|
|
"VALUES (?, ?, ?, ?)");
|
|
|
|
stmt.setString(1, operation.getType().toString());
|
|
|
|
stmt.setString(1, operation.getType().toString());
|
|
|
|
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(3, null);
|
|
|
|
stmt.setTimestamp(3, null);
|
|
|
|
stmt.setString(4, Operation.Status.PENDING.toString());
|
|
|
|
stmt.setString(4, operation.getCode());
|
|
|
|
stmt.setString(5, operation.getCode());
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.getGeneratedKeys();
|
|
|
|
rs = stmt.getGeneratedKeys();
|
|
|
@ -76,12 +68,11 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? " +
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " +
|
|
|
|
"WHERE O.ID=?");
|
|
|
|
"WHERE O.ID=?");
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setString(2, operation.getStatus().toString());
|
|
|
|
stmt.setInt(2, operation.getId());
|
|
|
|
stmt.setInt(3, operation.getId());
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -114,30 +105,16 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation = null;
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE," +
|
|
|
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
|
|
|
" po.OPERATION_DETAILS, co.ENABLED from" +
|
|
|
|
"DM_OPERATION WHERE id=?";
|
|
|
|
" (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, OPERATION_CODE FROM " +
|
|
|
|
|
|
|
|
" DM_OPERATION WHERE id=?) o" +
|
|
|
|
|
|
|
|
" LEFT OUTER JOIN DM_PROFILE_OPERATION po on o.ID=po.OPERATION_ID" +
|
|
|
|
|
|
|
|
" LEFT OUTER JOIN DM_COMMAND_OPERATION co on co.OPERATION_ID=o.ID";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
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")));
|
|
|
@ -147,19 +124,9 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
|
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
String errorMsg = "IO Error occurred while de serialize the profile operation object";
|
|
|
|
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
|
|
|
String errorMsg = "Class not found error occurred while de serialize the profile operation object";
|
|
|
|
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '"
|
|
|
|
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '"
|
|
|
|
+ id;
|
|
|
|
+ id;
|
|
|
@ -179,19 +146,13 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation = null;
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE," +
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " +
|
|
|
|
" po.OPERATION_DETAILS,co.ENABLED from " +
|
|
|
|
" From (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
|
|
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
|
|
|
|
"DM_DEVICE_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.DEVICE_ID=?) om " +
|
|
|
|
"DM_DEVICE_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.DEVICE_ID=?) om " +
|
|
|
|
"ON o.ID = om.OPERATION_ID " +
|
|
|
|
"ON o.ID = om.OPERATION_ID ";
|
|
|
|
"LEFT OUTER JOIN DM_PROFILE_OPERATION po on o.ID = po.OPERATION_ID " +
|
|
|
|
|
|
|
|
"LEFT OUTER JOIN DM_COMMAND_OPERATION co on co.OPERATION_ID=o.ID";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
@ -200,37 +161,17 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
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(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
|
|
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
|
|
|
|
|
|
"device:" + deviceId + "' with id '" + operationId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
|
|
|
String errorMsg =
|
|
|
|
|
|
|
|
"class not found error occurred while de serializing the profile operation available for " +
|
|
|
|
|
|
|
|
"the device:" + deviceId + "' with id '" + operationId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
"' with id '" + operationId;
|
|
|
|
"' with id '" + operationId;
|
|
|
@ -251,62 +192,34 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
|
|
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
|
|
|
"po.OPERATION_DETAILS,co.ENABLED from " +
|
|
|
|
"FROM DM_OPERATION o " +
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
|
|
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " +
|
|
|
|
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION po ON " +
|
|
|
|
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, status.toString());
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
stmt.setString(2, status.toString());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
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(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
if (rs.getObject("ENABLED") != null) {
|
|
|
|
|
|
|
|
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operationList.add(operation);
|
|
|
|
operationList.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
|
|
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
|
|
|
|
|
|
"device:" + deviceId + "' and status '" + status.toString();
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
|
|
|
String errorMsg =
|
|
|
|
|
|
|
|
"class not found error occurred while de serializing the profile operation available for " +
|
|
|
|
|
|
|
|
"the device:" + deviceId + "' with status '" + status.toString();
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
"' with status '" + status.toString();
|
|
|
|
"' with status '" + status.toString();
|
|
|
@ -327,19 +240,14 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
|
|
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
|
|
|
"po.OPERATION_DETAILS,co.ENABLED from " +
|
|
|
|
"OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " +
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
|
|
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION) o " +
|
|
|
|
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION po ON " +
|
|
|
|
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
@ -347,38 +255,19 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
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(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
}
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
operationList.add(operation);
|
|
|
|
operationList.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
|
|
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
|
|
|
|
|
|
"device:" + deviceId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
|
|
|
String errorMsg =
|
|
|
|
|
|
|
|
"class not found error occurred while de serializing the profile operation available for " +
|
|
|
|
|
|
|
|
"the device:" + deviceId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
"' with status '";
|
|
|
|
"' with status '";
|
|
|
@ -392,115 +281,76 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
|
|
|
|
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream byteArrayInputStream;
|
|
|
|
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE,"+
|
|
|
|
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP " +
|
|
|
|
"po.OPERATION_DETAILS,co.ENABLED from "+
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION o " +
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS,"+
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o "+
|
|
|
|
"where dm.DEVICE_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " +
|
|
|
|
"LEFT OUTER JOIN DM_PROFILE_OPERATION po ON "+
|
|
|
|
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
|
|
|
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.setString(2, Operation.Status.PENDING.toString());
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setString(1, status.toString());
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
byteArrayInputStream = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(byteArrayInputStream);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operation = new Operation();
|
|
|
|
operation = new Operation();
|
|
|
|
|
|
|
|
operation.setType(this.getType(rs.getString("TYPE")));
|
|
|
|
|
|
|
|
operation.setStatus(this.getStatus(rs.getString("STATUS")));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operationList.add(operation);
|
|
|
|
return operation;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
|
|
|
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
|
|
|
|
|
|
"status:" + status.toString();
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
|
|
|
String errorMsg =
|
|
|
|
|
|
|
|
"class not found error occurred while de serializing the profile operation available for " +
|
|
|
|
|
|
|
|
"the status:" + status.toString();
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the status:'" +
|
|
|
|
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
|
|
|
status.toString();
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
|
|
|
|
public List<? extends Operation> getOperationsByDeviceStatusAndType(int deviceId,
|
|
|
|
|
|
|
|
Operation.Status status,Operation.Type type) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
ObjectInputStream ois;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM "+
|
|
|
|
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
|
|
|
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
|
|
|
"po.OPERATION_DETAILS,co.ENABLED from " +
|
|
|
|
"FROM DM_OPERATION o WHERE o.TYPE=?) o " +
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
|
|
|
|
|
|
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " +
|
|
|
|
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION " +
|
|
|
|
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"po ON " +
|
|
|
|
|
|
|
|
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " +
|
|
|
|
|
|
|
|
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setString(1, Operation.Status.PENDING.toString());
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setString(1, type.toString());
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
|
|
|
|
stmt.setString(3, status.toString());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
|
|
|
|
|
|
byte[] operationDetails;
|
|
|
|
|
|
|
|
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
|
|
|
|
operation = (ProfileOperation) ois.readObject();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operation = new Operation();
|
|
|
|
operation = new Operation();
|
|
|
|
operation.setType(this.getType(rs.getString("TYPE")));
|
|
|
|
|
|
|
|
operation.setStatus(this.getStatus(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
@ -508,29 +358,18 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
if (rs.getObject("ENABLED") != null) {
|
|
|
|
operationList.add(operation);
|
|
|
|
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operation;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (IOException ex) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
|
|
|
String errorMsg = "IO error occurred while de serializing the next profile operation available for the " +
|
|
|
|
"' with status '" + status.toString();
|
|
|
|
"device:" + deviceId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException ex) {
|
|
|
|
|
|
|
|
String errorMsg = "class not found error occurred while de serializing the profile operation available " +
|
|
|
|
|
|
|
|
"for the device:" + deviceId;
|
|
|
|
|
|
|
|
log.error(errorMsg);
|
|
|
|
log.error(errorMsg);
|
|
|
|
throw new OperationManagementDAOException(errorMsg, ex);
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
|
|
|
|
}catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return operationList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Operation.Status getStatus(String status) {
|
|
|
|
private Operation.Status getStatus(String status) {
|
|
|
|