|
|
@ -56,6 +56,7 @@ 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.sql.Timestamp;
|
|
|
|
|
|
|
|
import java.sql.Statement;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -1560,9 +1561,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
ps.setInt(index++, tenantId);
|
|
|
|
ps.setInt(index++, tenantId);
|
|
|
|
ps.setInt(index, tenantId);
|
|
|
|
ps.setInt(index, tenantId);
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
|
|
devices.add(DeviceManagementDAOUtil.loadDevice(rs));
|
|
|
|
devices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1573,368 +1573,460 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteDevice(DeviceIdentifier deviceIdentifier, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
@Override
|
|
|
|
String deviceIdentifierId = deviceIdentifier.getId();
|
|
|
|
public void deleteDevices(List<String> deviceIdentifiers, List<Integer> deviceIds, List<Integer> enrollmentIds)
|
|
|
|
String deviceType = deviceIdentifier.getType();
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
int deviceId = getDeviceId(conn, deviceIdentifier, tenantId);
|
|
|
|
if (enrollmentIds.isEmpty()) {
|
|
|
|
if (deviceId == -1) {
|
|
|
|
String msg = "Enrollments not found for the devices: " + deviceIdentifiers;
|
|
|
|
String msg = "Device " + deviceIdentifierId + " of type " + deviceType + " is not found";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new DeviceManagementDAOException(msg);
|
|
|
|
throw new DeviceManagementDAOException(msg);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
List<Integer> enrollmentIds = getEnrollmentIds(conn, deviceId, tenantId);
|
|
|
|
removeDeviceDetail(conn, deviceIds);
|
|
|
|
if (enrollmentIds == null || enrollmentIds.isEmpty()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
String msg = "Enrollments not found for the device " + deviceIdentifierId + " of type "
|
|
|
|
log.debug("Successfully removed device detail data of devices: " + deviceIdentifiers);
|
|
|
|
+ deviceType;
|
|
|
|
}
|
|
|
|
log.error(msg);
|
|
|
|
removeDeviceLocation(conn, deviceIds);
|
|
|
|
throw new DeviceManagementDAOException(msg);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
} else {
|
|
|
|
log.debug("Successfully removed device location data of devices: " + deviceIdentifiers);
|
|
|
|
removeDeviceDetail(conn, deviceId);
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeDeviceInfo(conn, deviceIds);
|
|
|
|
log.debug("Successfully removed device detail data of device " + deviceIdentifierId
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
log.debug("Successfully removed device info data of devices: " + deviceIdentifiers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeDeviceLocation(conn, deviceId);
|
|
|
|
removeDeviceNotification(conn, deviceIds);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Successfully removed device location data of device " + deviceIdentifierId
|
|
|
|
log.debug("Successfully removed device notification data of devices: " + deviceIdentifiers);
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeDeviceApplicationMapping(conn, deviceIds);
|
|
|
|
removeDeviceInfo(conn, deviceId);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Successfully removed device application mapping data of devices: "
|
|
|
|
log.debug("Successfully removed device info data of device " + deviceIdentifierId
|
|
|
|
+ deviceIdentifiers);
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeDevicePolicyApplied(conn, deviceIds);
|
|
|
|
removeDeviceNotification(conn, deviceId);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Successfully removed device applied policy data of devices: " + deviceIdentifiers);
|
|
|
|
log.debug("Successfully removed device notification data of device " + deviceIdentifierId
|
|
|
|
}
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
removeDevicePolicy(conn, deviceIds);
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeDeviceApplicationMapping(conn, deviceId);
|
|
|
|
log.debug("Successfully removed device policy data of devices: " + deviceIdentifiers);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Successfully removed device application mapping data of device "
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
+ deviceIdentifierId + " of type " + deviceType);
|
|
|
|
log.debug("Starting to remove " + enrollmentIds.size() + " enrollment data of devices with " +
|
|
|
|
}
|
|
|
|
"identifiers: " + deviceIdentifiers);
|
|
|
|
removeDevicePolicyApplied(conn, deviceId);
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeEnrollmentDeviceDetail(conn, enrollmentIds);
|
|
|
|
log.debug("Successfully removed device applied policy data of device " + deviceIdentifierId
|
|
|
|
removeEnrollmentDeviceLocation(conn, enrollmentIds);
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
removeEnrollmentDeviceInfo(conn, enrollmentIds);
|
|
|
|
}
|
|
|
|
removeEnrollmentDeviceApplicationMapping(conn, enrollmentIds);
|
|
|
|
removeDevicePolicy(conn, deviceId);
|
|
|
|
removeDeviceOperationResponse(conn, enrollmentIds);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeEnrollmentOperationMapping(conn, enrollmentIds);
|
|
|
|
log.debug("Successfully removed device policy data of device " + deviceIdentifierId
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
log.debug("Successfully removed enrollment device details, enrollment device location," +
|
|
|
|
}
|
|
|
|
"enrollment device info, enrollment device application mapping, " +
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
"enrollment device operation response, enrollment operation mapping data of " +
|
|
|
|
log.debug("Starting to remove " + enrollmentIds.size() + " enrollment data of device "
|
|
|
|
"devices with identifiers: " + deviceIdentifiers);
|
|
|
|
+ deviceIdentifierId + " of type " + deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeDeviceEnrollment(conn, deviceIds);
|
|
|
|
for (Integer enrollmentId : enrollmentIds) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeEnrollmentDeviceDetail(conn, enrollmentId);
|
|
|
|
log.debug("Successfully removed device enrollment data of devices: " + deviceIdentifiers);
|
|
|
|
removeEnrollmentDeviceLocation(conn, enrollmentId);
|
|
|
|
}
|
|
|
|
removeEnrollmentDeviceInfo(conn, enrollmentId);
|
|
|
|
removeDeviceGroupMapping(conn, deviceIds);
|
|
|
|
removeEnrollmentDeviceApplicationMapping(conn, enrollmentId);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
removeDeviceOperationResponse(conn, enrollmentId);
|
|
|
|
log.debug("Successfully removed device group mapping data of devices: " + deviceIdentifiers);
|
|
|
|
removeEnrollmentOperationMapping(conn, enrollmentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeDevice(conn, deviceIds);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Successfully removed enrollment device details, enrollment device location, " +
|
|
|
|
log.debug("Successfully permanently deleted the device of devices: " + deviceIdentifiers);
|
|
|
|
"enrollment device info, enrollment device application mapping, " +
|
|
|
|
|
|
|
|
"enrollment device operation response, enrollment operation mapping data of device "
|
|
|
|
|
|
|
|
+ deviceIdentifierId + " of type " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removeDeviceEnrollment(conn, deviceId);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Successfully removed device enrollment data of device " + deviceIdentifierId
|
|
|
|
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removeDeviceGroupMapping(conn, deviceId);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Successfully removed device group mapping data of device " + deviceIdentifierId
|
|
|
|
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removeDevice(conn, deviceId);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Successfully permanently deleted the device of device " + deviceIdentifierId
|
|
|
|
|
|
|
|
+ " of type " + deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while deleting the device " + deviceIdentifierId
|
|
|
|
String msg ="Error occurred while deleting the devices: " + deviceIdentifiers;
|
|
|
|
+ " of type " + deviceType, e);
|
|
|
|
log.error(msg,e);
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getDeviceId(Connection conn, DeviceIdentifier deviceIdentifier, int tenantId)
|
|
|
|
/***
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_DETAIL table
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* @param conn Connection object
|
|
|
|
ResultSet rs = null;
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
int deviceId = -1;
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceDetail(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "SELECT ID FROM DM_DEVICE WHERE DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setString(1, deviceIdentifier.getId());
|
|
|
|
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
deviceId = rs.getInt("ID");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving device id of the device", e);
|
|
|
|
String msg = "Error occurred while removing device details.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceId;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Integer> getEnrollmentIds(Connection conn, int deviceId, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_LOCATION table
|
|
|
|
ResultSet rs = null;
|
|
|
|
* @param conn Connection object
|
|
|
|
List<Integer> enrollmentIds = new ArrayList<>();
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceLocation(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "SELECT ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
enrollmentIds.add(rs.getInt("ID"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving enrollment id of the device", e);
|
|
|
|
String msg = "Error occurred while obtaining locations of devices.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return enrollmentIds;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceDetail(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_INFO table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceInfo(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device detail", e);
|
|
|
|
String msg = "Error occurred while removing device info.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceLocation(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_NOTIFICATION table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceNotification(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_NOTIFICATION WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device location", e);
|
|
|
|
String msg = "Error occurred while removing device notifications.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceInfo(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_APPLICATION_MAPPING table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceApplicationMapping(Connection conn, List<Integer> deviceIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device info", e);
|
|
|
|
String msg = "Error occurred while removing device application mapping";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceNotification(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_POLICY_APPLIED table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDevicePolicyApplied(Connection conn, List<Integer> deviceIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_NOTIFICATION WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device notification", e);
|
|
|
|
String msg = "Error occurred while removing policies applied on devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceApplicationMapping(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_POLICY table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDevicePolicy(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device application mapping", e);
|
|
|
|
String msg = "Error occurred while removing policies of devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDevicePolicyApplied(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_DEVICE_DETAIL table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceDetail(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device policy applied", e);
|
|
|
|
String msg = "Error occurred while removing enrollment details of devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDevicePolicy(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_DEVICE_LOCATION table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceLocation(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_POLICY WHERE DEVICE_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device policy", e);
|
|
|
|
String msg = "Error occurred while removing enrollment locations of devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceDetail(Connection conn, int enrollmentId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_DEVICE_INFO table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceInfo(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_INFO WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE ENROLMENT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing enrollment device detail", e);
|
|
|
|
String msg = "Error occurred while removing enrollment info of devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceLocation(Connection conn, int enrollmentId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_DEVICE_APPLICATION_MAPPING table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceApplicationMapping(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE ENROLMENT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing enrollment device location", e);
|
|
|
|
String msg = "Error occurred while removing enrollment device application mapping";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceInfo(Connection conn, int enrollmentId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_DEVICE_OPERATION_RESPONSE table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceOperationResponse(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_INFO WHERE ENROLMENT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing enrollment device info", e);
|
|
|
|
String msg = "Error occurred while removing device operation response";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeEnrollmentDeviceApplicationMapping(Connection conn, int enrollmentId)
|
|
|
|
/***
|
|
|
|
|
|
|
|
* This method removes records of a given list of enrollments from the DM_ENROLMENT_OP_MAPPING table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeEnrollmentOperationMapping(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE ENROLMENT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing enrollment device application " +
|
|
|
|
String msg = "Error occurred while removing enrollment operation mapping";
|
|
|
|
"mapping", e);
|
|
|
|
log.error(msg, e);
|
|
|
|
} finally {
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceOperationResponse(Connection conn, int enrollmentId) throws DeviceManagementDAOException {
|
|
|
|
/***
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
* This method removes records of a given list of enrollments from the DM_ENROLMENT table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param enrollmentIds list of enrollment ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceEnrollment(Connection conn, List<Integer> enrollmentIds)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?";
|
|
|
|
executeBatchOperation(conn, sql, enrollmentIds);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device operation response", e);
|
|
|
|
String msg = "Error occurred while removing enrollments of devices";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE_GROUP_MAP table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDeviceGroupMapping(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while removing device group mapping";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
|
|
* This method removes records of a given list of devices from the DM_DEVICE table
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param deviceIds list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException if deletion fails
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void removeDevice(Connection conn, List<Integer> deviceIds) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
String sql = "DELETE FROM DM_DEVICE WHERE ID = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
executeBatchOperation(conn, sql, deviceIds);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while removing devices.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
|
|
|
* This method executes batch operations for a given list of primary keys
|
|
|
|
|
|
|
|
* where the statement only has one param of type int, following the given pattern:
|
|
|
|
|
|
|
|
* DELETE FROM TABLE WHERE ID = ?
|
|
|
|
|
|
|
|
* @param sql SQL statement
|
|
|
|
|
|
|
|
* @param conn Connection object
|
|
|
|
|
|
|
|
* @param identifiers list of device ids (primary keys)
|
|
|
|
|
|
|
|
* @throws SQLException if deletion fails.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void executeBatchOperation(Connection conn, String sql, List<Integer> identifiers) throws SQLException {
|
|
|
|
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
|
|
|
|
|
|
|
if (conn.getMetaData().supportsBatchUpdates()) {
|
|
|
|
|
|
|
|
for (int identifier : identifiers) {
|
|
|
|
|
|
|
|
ps.setInt(1, identifier);
|
|
|
|
|
|
|
|
ps.addBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i : ps.executeBatch()) {
|
|
|
|
|
|
|
|
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (int enrollmentId : identifiers) {
|
|
|
|
|
|
|
|
ps.setInt(1, enrollmentId);
|
|
|
|
|
|
|
|
if (ps.executeUpdate() == 0) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeEnrollmentOperationMapping(Connection conn, int enrollmentId)
|
|
|
|
private int getDeviceId(Connection conn, DeviceIdentifier deviceIdentifier, int tenantId)
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int deviceId = -1;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ?";
|
|
|
|
String sql = "SELECT ID FROM DM_DEVICE WHERE DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, enrollmentId);
|
|
|
|
stmt.setString(1, deviceIdentifier.getId());
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
deviceId = rs.getInt("ID");
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing enrollment operation mapping", e);
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving device id of the device", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceEnrollment(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
public boolean transferDevice(String deviceType, String deviceIdentifier, String owner, int destinationTenantId)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException, SQLException {
|
|
|
|
|
|
|
|
Connection conn = this.getConnection();
|
|
|
|
|
|
|
|
int deviceId = getDeviceId(conn, new DeviceIdentifier(deviceIdentifier, deviceType), -1234);
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ?";
|
|
|
|
String sql = "UPDATE DM_DEVICE SET TENANT_ID = ? WHERE ID = ? AND TENANT_ID = -1234";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, destinationTenantId);
|
|
|
|
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device enrollment", e);
|
|
|
|
conn.rollback();
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDeviceGroupMapping(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE_GROUP_MAP WHERE DEVICE_ID = ?";
|
|
|
|
String sql = "UPDATE DM_DEVICE_PROPERTIES SET TENANT_ID = ? " +
|
|
|
|
|
|
|
|
"WHERE DEVICE_TYPE_NAME = ? AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = -1234";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, destinationTenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, deviceType);
|
|
|
|
|
|
|
|
stmt.setString(3, deviceIdentifier);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device group mapping", e);
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void removeDevice(Connection conn, int deviceId) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String sql = "DELETE FROM DM_DEVICE WHERE ID = ?";
|
|
|
|
String sql = "UPDATE DM_ENROLMENT SET TENANT_ID = ?, OWNER = ? WHERE DEVICE_ID = ? AND TENANT_ID = -1234";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, destinationTenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, owner);
|
|
|
|
|
|
|
|
stmt.setInt(3, deviceId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device", e);
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while removing device", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|