Fix user,role removed devices

remotes/1721635363905829615/tmp_refs/heads/master
prathabanKavin 4 months ago
parent 9f8f25d310
commit f9cea050ae

@ -101,11 +101,12 @@ public interface EnrollmentDAO {
* Retrieves owners and the list of device IDs related to an owner.
*
* @param owner the owner whose device IDs need to be retrieved
* @param allowingDeviceStatuses statuses of devices need to be retrieved
* @param tenantId the ID of the tenant
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
* @throws DeviceManagementDAOException if an error occurs while fetching the data
*/
OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId) throws DeviceManagementDAOException;
OwnerWithDeviceDTO getOwnersWithDevices(String owner, List<String> allowingDeviceStatuses, int tenantId) throws DeviceManagementDAOException;
/**
* Retrieves a list of device IDs with owners and device status.

@ -564,23 +564,34 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
}
@Override
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId)
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List<String> allowingDeviceStatuses, int tenantId)
throws DeviceManagementDAOException {
Connection conn = null;
OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
StringBuilder deviceFilters = new StringBuilder();
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
deviceFilters.append("?");
if (i < allowingDeviceStatuses.size() - 1) {
deviceFilters.append(",");
}
}
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME, e.DEVICE_TYPE AS DEVICE_TYPE, e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " +
"FROM DM_ENROLMENT e " +
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE e.OWNER = ? AND e.TENANT_ID = ?";
"WHERE e.OWNER = ? AND e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, owner);
stmt.setInt(2, tenantId);
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
stmt.setString(3 + i, allowingDeviceStatuses.get(i));
}
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (ownerDetails.getUserName() == null) {

@ -5358,9 +5358,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
OwnerWithDeviceDTO ownerWithDeviceDTO;
List<String> allowingDeviceStatuses = new ArrayList<>();
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
try {
DeviceManagementDAOFactory.openConnection();
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, tenantId);
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId);
if (ownerWithDeviceDTO == null) {
String msg = "No data found for owner: " + owner;
log.error(msg);

Loading…
Cancel
Save