forked from community/device-mgt-core
This is has an api to delete device of users when they requestrevert-70aa11f8
parent
1d605d0921
commit
8cf1bd996c
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
public class PrivacyComplianceException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3127931192903344297L;
|
||||||
|
|
||||||
|
public PrivacyComplianceException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.privacy.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.impl.DeviceEnrollmentMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PrivacyComplianceDAO {
|
||||||
|
|
||||||
|
List<DeviceEnrollmentMapping> getDevicesOfUser(String username, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDevice(int deviceId, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceEnrollments(int deviceId, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceEnrollments(int deviceId, int enrolmentId, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceDetails(int deviceId, int enrolmentId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceApplications(int deviceId, int enrolmentId, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceProperties(int deviceId, int enrolmentId, int tenantId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceLocation(int deviceId, int enrolmentId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void updateDeviceOperationResponses(int enrolmentId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteDeviceOperationDetails(int enrolmentId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
void deleteOperationEnrolmentMappings(int enrolmentId) throws PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.privacy.dao;
|
||||||
|
|
||||||
|
public class PrivacyComplianceDAOException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3127931192903344297L;
|
||||||
|
|
||||||
|
public PrivacyComplianceDAOException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceDAOException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceDAOException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceDAOException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivacyComplianceDAOException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,280 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.privacy.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.dao.PrivacyComplianceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.dao.PrivacyComplianceDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.impl.DeviceEnrollmentMapping;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PrivacyComplianceDAOImpl implements PrivacyComplianceDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceEnrollmentMapping> getDevicesOfUser(String username, int tenantId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<DeviceEnrollmentMapping> deviceIds = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "SELECT * FROM DM_ENROLMENT WHERE OWNER = ? AND TENANT_ID = ? ORDER BY DEVICE_ID";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setString(1, username);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
DeviceEnrollmentMapping mapping = new DeviceEnrollmentMapping();
|
||||||
|
mapping.setDeviceId(rs.getInt("DEVICE_ID"));
|
||||||
|
mapping.setEnrolmentId(rs.getInt("ENROLMENT_ID"));
|
||||||
|
deviceIds.add(mapping);
|
||||||
|
}
|
||||||
|
if (deviceIds.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return deviceIds;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while retrieving device ids " +
|
||||||
|
"related to the given user.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDevice(int deviceId, int tenantId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the devices", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceEnrollments(int deviceId, int tenantId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device enrolments", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceEnrollments(int deviceId, int enrolmentId, int tenantId)
|
||||||
|
throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setInt(3, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device enrolments", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceDetails(int deviceId, int enrolmentId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE_DETAIL WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device details.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceApplications(int deviceId, int enrolmentId, int tenantId)
|
||||||
|
throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? " +
|
||||||
|
"AND ENROLMENT_ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device applications.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceProperties(int deviceId, int enrolmentId, int tenantId)
|
||||||
|
throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE_INFO WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device information.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceLocation(int deviceId, int enrolmentId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device location.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDeviceOperationResponses(int enrolmentId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "UPDATE DM_DEVICE_OPERATION_RESPONSE SET OPERATION_RESPONSE = ? WHERE ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setNull(1, java.sql.Types.BLOB);
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device information.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceOperationDetails(int enrolmentId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device information.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteOperationEnrolmentMappings(int enrolmentId) throws PrivacyComplianceDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, enrolmentId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PrivacyComplianceDAOException("Error occurred while deleting the device information.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws SQLException {
|
||||||
|
return DeviceManagementDAOFactory.getConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.privacy.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
|
public class DeviceEnrollmentMapping {
|
||||||
|
|
||||||
|
private int deviceId;
|
||||||
|
private int enrolmentId;
|
||||||
|
private DeviceIdentifier deviceIdentifier;
|
||||||
|
private int tenantId;
|
||||||
|
|
||||||
|
public int getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceId(int deviceId) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnrolmentId() {
|
||||||
|
return enrolmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnrolmentId(int enrolmentId) {
|
||||||
|
this.enrolmentId = enrolmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceIdentifier getDeviceIdentifier() {
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
|
||||||
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.privacy.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PrivacyComplianceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.PrivacyComplianceProvider;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.dao.PrivacyComplianceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.privacy.dao.PrivacyComplianceDAOException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PrivacyComplianceProviderImpl implements PrivacyComplianceProvider {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(PrivacyComplianceProviderImpl.class);
|
||||||
|
|
||||||
|
PrivacyComplianceDAO complianceDAO;
|
||||||
|
|
||||||
|
public PrivacyComplianceProviderImpl() {
|
||||||
|
complianceDAO = DeviceManagementDAOFactory.getPrivacyComplianceDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDevicesOfUser(String username) throws PrivacyComplianceException {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleting the requested users.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
List<DeviceEnrollmentMapping> enrollmentMappings = complianceDAO.getDevicesOfUser(username, tenantId);
|
||||||
|
Map<Integer, List<Integer>> deviceMap = new HashMap<>();
|
||||||
|
int x = -1;
|
||||||
|
for (DeviceEnrollmentMapping m : enrollmentMappings) {
|
||||||
|
if (m.getDeviceId() != x) {
|
||||||
|
x = m.getDeviceId();
|
||||||
|
List<Integer> enrolments = new ArrayList<>();
|
||||||
|
enrolments.add(m.getEnrolmentId());
|
||||||
|
deviceMap.put(m.getDeviceId(), enrolments);
|
||||||
|
} else {
|
||||||
|
deviceMap.get(m.getDeviceId()).add(m.getEnrolmentId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int deviceId : deviceMap.keySet()) {
|
||||||
|
List<Integer> enrollmentIds = deviceMap.get(deviceId);
|
||||||
|
for (Integer enrolmentId : enrollmentIds) {
|
||||||
|
complianceDAO.deleteDeviceOperationDetails(enrolmentId);
|
||||||
|
complianceDAO.deleteOperationEnrolmentMappings(enrolmentId);
|
||||||
|
complianceDAO.deleteDeviceApplications(deviceId, enrolmentId, tenantId);
|
||||||
|
complianceDAO.deleteDeviceDetails(deviceId, enrolmentId);
|
||||||
|
complianceDAO.deleteDeviceProperties(deviceId, enrolmentId, tenantId);
|
||||||
|
complianceDAO.deleteDeviceLocation(deviceId, enrolmentId);
|
||||||
|
complianceDAO.deleteDeviceEnrollments(deviceId, enrolmentId);
|
||||||
|
}
|
||||||
|
complianceDAO.deleteDevice(deviceId, tenantId);
|
||||||
|
}
|
||||||
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PrivacyComplianceDAOException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while deleting the devices and details of the given user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PrivacyComplianceException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Database error occurred while deleting the devices and details of the given user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PrivacyComplianceException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
log.info("Requested users device has been successfully removed..!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteDeviceDetails(DeviceIdentifier deviceIdentifier) throws PrivacyComplianceException {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleting the requested device details.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Device device = this.getDevice(deviceIdentifier);
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
|
complianceDAO.deleteDeviceOperationDetails(device.getEnrolmentInfo().getId());
|
||||||
|
complianceDAO.deleteOperationEnrolmentMappings(device.getEnrolmentInfo().getId());
|
||||||
|
complianceDAO.deleteDeviceApplications(device.getId(), device.getEnrolmentInfo().getId(), tenantId);
|
||||||
|
complianceDAO.deleteDeviceDetails(device.getId(), device.getEnrolmentInfo().getId());
|
||||||
|
complianceDAO.deleteDeviceProperties(device.getId(), device.getEnrolmentInfo().getId(), tenantId);
|
||||||
|
complianceDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId());
|
||||||
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Database error occurred while deleting the device details.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PrivacyComplianceException(msg, e);
|
||||||
|
} catch (PrivacyComplianceDAOException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while deleting the device details.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PrivacyComplianceException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Device getDevice(DeviceIdentifier deviceId) throws PrivacyComplianceException {
|
||||||
|
try {
|
||||||
|
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId, false);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new PrivacyComplianceException(
|
||||||
|
"Error occurred while retrieving device info.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue