Fix the device information delete issue

revert-70aa11f8
geethkokila 7 years ago
parent 7dd3f29ff7
commit 54fc0be69f

@ -128,9 +128,12 @@ public interface UserManagementAdminService {
@Path("/{username}/devices")
@DELETE
@Path("/{username}/devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_DELETE,
value = "Delete a users associated devices.",
@ -186,6 +189,8 @@ public interface UserManagementAdminService {
//DELETE devices/type/virtual_firealarm/id/us06ww93auzp
@DELETE
@Path("/type/{device-type}/id/{device-id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
consumes = MediaType.APPLICATION_JSON,

@ -19,6 +19,8 @@
package org.wso2.carbon.device.mgt.core.privacy.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
@ -34,6 +36,8 @@ import java.util.List;
public class PrivacyComplianceDAOImpl implements PrivacyComplianceDAO {
private static final Log log = LogFactory.getLog(PrivacyComplianceDAOImpl.class);
@Override
public List<DeviceEnrollmentMapping> getDevicesOfUser(String username, int tenantId) throws PrivacyComplianceDAOException {
@ -43,16 +47,16 @@ public class PrivacyComplianceDAOImpl implements PrivacyComplianceDAO {
List<DeviceEnrollmentMapping> deviceIds = new ArrayList<>();
try {
conn = this.getConnection();
String sql = "SELECT * FROM DM_ENROLMENT WHERE OWNER = ? AND TENANT_ID = ? ORDER BY DEVICE_ID";
String sql = "SELECT * FROM DM_ENROLMENT WHERE OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
rs = stmt.executeQuery();
while (rs.next()) {
DeviceEnrollmentMapping mapping = new DeviceEnrollmentMapping();
mapping.setDeviceId(rs.getInt("DEVICE_ID"));
mapping.setEnrolmentId(rs.getInt("ENROLMENT_ID"));
mapping.setEnrolmentId(rs.getInt("ID"));
deviceIds.add(mapping);
}
if (deviceIds.isEmpty()) {
@ -102,7 +106,9 @@ public class PrivacyComplianceDAOImpl implements PrivacyComplianceDAO {
stmt.executeUpdate();
} catch (SQLException e) {
throw new PrivacyComplianceDAOException("Error occurred while deleting the device enrolments", e);
String msg = "Error occurred while deleting the device enrolments";
log.error(msg, e);
throw new PrivacyComplianceDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}

@ -58,6 +58,10 @@ public class PrivacyComplianceProviderImpl implements PrivacyComplianceProvider
DeviceManagementDAOFactory.beginTransaction();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceEnrollmentMapping> enrollmentMappings = complianceDAO.getDevicesOfUser(username, tenantId);
if(enrollmentMappings == null || enrollmentMappings.isEmpty()){
log.info("No enrolments found with the user..!");
return;
}
Map<Integer, List<Integer>> deviceMap = new HashMap<>();
int x = -1;
for (DeviceEnrollmentMapping m : enrollmentMappings) {
@ -79,7 +83,7 @@ public class PrivacyComplianceProviderImpl implements PrivacyComplianceProvider
complianceDAO.deleteDeviceDetails(deviceId, enrolmentId);
complianceDAO.deleteDeviceProperties(deviceId, enrolmentId, tenantId);
complianceDAO.deleteDeviceLocation(deviceId, enrolmentId);
complianceDAO.deleteDeviceEnrollments(deviceId, enrolmentId);
complianceDAO.deleteDeviceEnrollments(deviceId, tenantId);
}
complianceDAO.deleteDevice(deviceId, tenantId);
}
@ -116,6 +120,8 @@ public class PrivacyComplianceProviderImpl implements PrivacyComplianceProvider
complianceDAO.deleteDeviceDetails(device.getId(), device.getEnrolmentInfo().getId());
complianceDAO.deleteDeviceProperties(device.getId(), device.getEnrolmentInfo().getId(), tenantId);
complianceDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId());
complianceDAO.deleteDeviceEnrollments(device.getId(), tenantId);
complianceDAO.deleteDevice(device.getId(), tenantId);
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();

Loading…
Cancel
Save