mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request 'Fix deleted,removed devices appearing in subscription table' (#447) from prathabanKavin/device-mgt-core:removeddevicefix into master
Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/447
This commit is contained in:
commit
090c5d22df
@ -1720,8 +1720,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new NotFoundException(msg);
|
throw new NotFoundException(msg);
|
||||||
}
|
}
|
||||||
|
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
|
||||||
int appReleaseId = applicationReleaseDTO.getId();
|
int appReleaseId = applicationReleaseDTO.getId();
|
||||||
|
|
||||||
List<SubscriptionsDTO> groupDetailsWithDevices = new ArrayList<>();
|
List<SubscriptionsDTO> groupDetailsWithDevices = new ArrayList<>();
|
||||||
|
|
||||||
List<GroupSubscriptionDTO> groupDetails =
|
List<GroupSubscriptionDTO> groupDetails =
|
||||||
@ -1737,7 +1737,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
|
|
||||||
// Retrieve group details and device IDs for the group using the service layer
|
// Retrieve group details and device IDs for the group using the service layer
|
||||||
GroupDetailsDTO groupDetailWithDevices =
|
GroupDetailsDTO groupDetailWithDevices =
|
||||||
groupManagementProviderService.getGroupDetailsWithDevices(groupName, offset, limit);
|
groupManagementProviderService.getGroupDetailsWithDevices(groupName, applicationDTO.getDeviceTypeId(),
|
||||||
|
offset, limit);
|
||||||
|
|
||||||
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO();
|
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO();
|
||||||
groupDetailDTO.setId(groupDetailWithDevices.getGroupId());
|
groupDetailDTO.setId(groupDetailWithDevices.getGroupId());
|
||||||
@ -1910,8 +1911,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new NotFoundException(msg);
|
throw new NotFoundException(msg);
|
||||||
}
|
}
|
||||||
|
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
|
||||||
int appReleaseId = applicationReleaseDTO.getId();
|
int appReleaseId = applicationReleaseDTO.getId();
|
||||||
|
|
||||||
List<SubscriptionsDTO> userSubscriptionsWithDevices = new ArrayList<>();
|
List<SubscriptionsDTO> userSubscriptionsWithDevices = new ArrayList<>();
|
||||||
|
|
||||||
List<SubscriptionsDTO> userSubscriptions =
|
List<SubscriptionsDTO> userSubscriptions =
|
||||||
@ -1927,7 +1928,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
|
|
||||||
// Retrieve owner details and device IDs for the user using the service layer
|
// Retrieve owner details and device IDs for the user using the service layer
|
||||||
OwnerWithDeviceDTO ownerDetailsWithDevices =
|
OwnerWithDeviceDTO ownerDetailsWithDevices =
|
||||||
deviceManagementProviderService.getOwnersWithDeviceIds(userName);
|
deviceManagementProviderService.getOwnersWithDeviceIds(userName, applicationDTO.getDeviceTypeId());
|
||||||
|
|
||||||
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO();
|
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO();
|
||||||
userSubscriptionDTO.setName(userSubscription.getName());
|
userSubscriptionDTO.setName(userSubscription.getName());
|
||||||
@ -2097,8 +2098,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new NotFoundException(msg);
|
throw new NotFoundException(msg);
|
||||||
}
|
}
|
||||||
|
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
|
||||||
int appReleaseId = applicationReleaseDTO.getId();
|
int appReleaseId = applicationReleaseDTO.getId();
|
||||||
|
|
||||||
List<SubscriptionsDTO> roleSubscriptionsWithDevices = new ArrayList<>();
|
List<SubscriptionsDTO> roleSubscriptionsWithDevices = new ArrayList<>();
|
||||||
|
|
||||||
List<SubscriptionsDTO> roleSubscriptions =
|
List<SubscriptionsDTO> roleSubscriptions =
|
||||||
@ -2139,7 +2140,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
for (String user : users) {
|
for (String user : users) {
|
||||||
OwnerWithDeviceDTO ownerDetailsWithDevices;
|
OwnerWithDeviceDTO ownerDetailsWithDevices;
|
||||||
try {
|
try {
|
||||||
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user);
|
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user, applicationDTO.getDeviceTypeId());
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e);
|
throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e);
|
||||||
}
|
}
|
||||||
@ -2307,6 +2308,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new NotFoundException(msg);
|
throw new NotFoundException(msg);
|
||||||
}
|
}
|
||||||
|
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
|
||||||
int appReleaseId = applicationReleaseDTO.getId();
|
int appReleaseId = applicationReleaseDTO.getId();
|
||||||
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
|
||||||
@ -2321,7 +2323,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<DeviceDetailsDTO> allDevices =
|
List<DeviceDetailsDTO> allDevices =
|
||||||
deviceManagementProviderService.getDevicesByTenantId(tenantId);
|
deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId());
|
||||||
|
|
||||||
List<Integer> deviceIds = allDevices.stream()
|
List<Integer> deviceIds = allDevices.stream()
|
||||||
.map(DeviceDetailsDTO::getDeviceId)
|
.map(DeviceDetailsDTO::getDeviceId)
|
||||||
@ -2493,6 +2495,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new NotFoundException(msg);
|
throw new NotFoundException(msg);
|
||||||
}
|
}
|
||||||
|
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
|
||||||
int appReleaseId = applicationReleaseDTO.getId();
|
int appReleaseId = applicationReleaseDTO.getId();
|
||||||
|
|
||||||
List<DeviceSubscriptionDTO> allSubscriptions =
|
List<DeviceSubscriptionDTO> allSubscriptions =
|
||||||
@ -2522,7 +2525,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
statusCounts.put("NEW", 0);
|
statusCounts.put("NEW", 0);
|
||||||
|
|
||||||
List<DeviceDetailsDTO> allDevices =
|
List<DeviceDetailsDTO> allDevices =
|
||||||
deviceManagementProviderService.getDevicesByTenantId(tenantId);
|
deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId());
|
||||||
|
|
||||||
for (DeviceDetailsDTO device : allDevices) {
|
for (DeviceDetailsDTO device : allDevices) {
|
||||||
Integer deviceId = device.getDeviceId();
|
Integer deviceId = device.getDeviceId();
|
||||||
|
|||||||
@ -101,11 +101,13 @@ public interface EnrollmentDAO {
|
|||||||
* Retrieves owners and the list of device IDs related to an owner.
|
* Retrieves owners and the list of device IDs related to an owner.
|
||||||
*
|
*
|
||||||
* @param owner the owner whose device IDs need to be retrieved
|
* @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
|
* @param tenantId the ID of the tenant
|
||||||
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
|
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
|
||||||
* @throws DeviceManagementDAOException if an error occurs while fetching the data
|
* @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, int deviceTypeId)
|
||||||
|
throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a list of device IDs with owners and device status.
|
* Retrieves a list of device IDs with owners and device status.
|
||||||
@ -122,8 +124,11 @@ public interface EnrollmentDAO {
|
|||||||
* Retrieves owners and the list of device IDs with device status.
|
* Retrieves owners and the list of device IDs with device status.
|
||||||
*
|
*
|
||||||
* @param tenantId the ID of the tenant
|
* @param tenantId the ID of the tenant
|
||||||
|
* @param allowingDeviceStatuses the allowed device statuses of devices
|
||||||
|
* @param deviceTypeId the device type id
|
||||||
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
|
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
|
||||||
* @throws DeviceManagementDAOException if an error occurs while fetching the data
|
* @throws DeviceManagementDAOException if an error occurs while fetching the data
|
||||||
*/
|
*/
|
||||||
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException;
|
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, List<String> allowingDeviceStatuses, int deviceTypeId)
|
||||||
|
throws DeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -473,13 +473,16 @@ public interface GroupDAO {
|
|||||||
* Get group details and list of device IDs related to the group.
|
* Get group details and list of device IDs related to the group.
|
||||||
*
|
*
|
||||||
* @param groupName Group name
|
* @param groupName Group name
|
||||||
|
* @param allowingDeviceStatuses the statuses of devices
|
||||||
|
* @param deviceTypeId the device type id
|
||||||
* @param tenantId Tenant ID
|
* @param tenantId Tenant ID
|
||||||
* @param offset the offset for the data set
|
* @param offset the offset for the data set
|
||||||
* @param limit the limit for the data set
|
* @param limit the limit for the data set
|
||||||
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
|
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
|
||||||
* @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
|
* @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
|
||||||
*/
|
*/
|
||||||
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit)
|
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List<String> allowingDeviceStatuses, int deviceTypeId,
|
||||||
|
int tenantId, int offset, int limit)
|
||||||
throws GroupManagementDAOException;
|
throws GroupManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -564,23 +564,35 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId)
|
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List<String> allowingDeviceStatuses, int tenantId, int deviceTypeId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
|
OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
|
||||||
List<Integer> deviceIds = new ArrayList<>();
|
List<Integer> deviceIds = new ArrayList<>();
|
||||||
int deviceCount = 0;
|
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 " +
|
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 " +
|
"FROM DM_ENROLMENT e " +
|
||||||
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
|
"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 d.DEVICE_TYPE_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
stmt.setString(1, owner);
|
stmt.setString(1, owner);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setInt(3, deviceTypeId);
|
||||||
|
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
|
||||||
|
stmt.setString(4 + i, allowingDeviceStatuses.get(i));
|
||||||
|
}
|
||||||
try (ResultSet rs = stmt.executeQuery()) {
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (ownerDetails.getUserName() == null) {
|
if (ownerDetails.getUserName() == null) {
|
||||||
@ -643,18 +655,36 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId)
|
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, List<String> allowingDeviceStatuses, int deviceTypeId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
List<DeviceDetailsDTO> devices = new ArrayList<>();
|
List<DeviceDetailsDTO> devices = new ArrayList<>();
|
||||||
String sql = "SELECT DEVICE_ID, OWNER, STATUS, DEVICE_TYPE, DEVICE_IDENTIFICATION " +
|
if (allowingDeviceStatuses.isEmpty()) {
|
||||||
"FROM DM_ENROLMENT " +
|
return devices;
|
||||||
"WHERE TENANT_ID = ?";
|
}
|
||||||
|
|
||||||
|
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, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " +
|
||||||
|
"FROM DM_ENROLMENT e " +
|
||||||
|
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
|
||||||
|
"WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ") AND d.DEVICE_TYPE_ID = ?";
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
stmt.setInt(1, tenantId);
|
int index = 1;
|
||||||
|
stmt.setInt(index++, tenantId);
|
||||||
|
for (String status : allowingDeviceStatuses) {
|
||||||
|
stmt.setString(index++, status);
|
||||||
|
}
|
||||||
|
stmt.setInt(index++, deviceTypeId);
|
||||||
|
|
||||||
try (ResultSet rs = stmt.executeQuery()) {
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -675,5 +705,4 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1441,7 +1441,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit)
|
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List<String> allowedStatuses, int deviceTypeId,
|
||||||
|
int tenantId, int offset, int limit)
|
||||||
throws GroupManagementDAOException {
|
throws GroupManagementDAOException {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
|
log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
|
||||||
@ -1454,6 +1455,14 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
Map<Integer, String> deviceTypes = new HashMap<>();
|
Map<Integer, String> deviceTypes = new HashMap<>();
|
||||||
Map<Integer, String> deviceIdentifiers = new HashMap<>();
|
Map<Integer, String> deviceIdentifiers = new HashMap<>();
|
||||||
|
|
||||||
|
StringBuilder deviceFilters = new StringBuilder();
|
||||||
|
for (int i = 0; i < allowedStatuses.size(); i++) {
|
||||||
|
deviceFilters.append("?");
|
||||||
|
if (i < allowedStatuses.size() - 1) {
|
||||||
|
deviceFilters.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String sql =
|
String sql =
|
||||||
"SELECT " +
|
"SELECT " +
|
||||||
" g.ID AS GROUP_ID, " +
|
" g.ID AS GROUP_ID, " +
|
||||||
@ -1473,16 +1482,23 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
"WHERE " +
|
"WHERE " +
|
||||||
" g.GROUP_NAME = ? " +
|
" g.GROUP_NAME = ? " +
|
||||||
" AND g.TENANT_ID = ? " +
|
" AND g.TENANT_ID = ? " +
|
||||||
|
" AND d.DEVICE_TYPE_ID = ? " +
|
||||||
|
" AND e.STATUS IN (" + deviceFilters.toString() + ") " +
|
||||||
"LIMIT ? OFFSET ?";
|
"LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = GroupManagementDAOFactory.getConnection();
|
conn = GroupManagementDAOFactory.getConnection();
|
||||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
stmt.setString(1, groupName);
|
int index = 1;
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setString(index++, groupName);
|
||||||
stmt.setInt(3, limit);
|
stmt.setInt(index++, tenantId);
|
||||||
stmt.setInt(4, offset);
|
stmt.setInt(index++, deviceTypeId);
|
||||||
|
for (String status : allowedStatuses) {
|
||||||
|
stmt.setString(index++, status);
|
||||||
|
}
|
||||||
|
stmt.setInt(index++, limit);
|
||||||
|
stmt.setInt(index++, offset);
|
||||||
|
|
||||||
try (ResultSet rs = stmt.executeQuery()) {
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -1500,19 +1516,19 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
deviceIdentifiers.put(deviceId, rs.getString("DEVICE_IDENTIFICATION"));
|
deviceIdentifiers.put(deviceId, rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groupDetails.setDeviceIds(deviceIds);
|
groupDetails.setDeviceIds(deviceIds);
|
||||||
groupDetails.setDeviceCount(deviceIds.size());
|
groupDetails.setDeviceCount(deviceIds.size());
|
||||||
groupDetails.setDeviceOwners(deviceOwners);
|
groupDetails.setDeviceOwners(deviceOwners);
|
||||||
groupDetails.setDeviceStatuses(deviceStatuses);
|
groupDetails.setDeviceStatuses(deviceStatuses);
|
||||||
groupDetails.setDeviceNames(deviceNames);
|
groupDetails.setDeviceNames(deviceNames);
|
||||||
groupDetails.setDeviceTypes(deviceTypes);
|
groupDetails.setDeviceTypes(deviceTypes);
|
||||||
groupDetails.setDeviceIdentifiers(deviceIdentifiers);
|
groupDetails.setDeviceIdentifiers(deviceIdentifiers);
|
||||||
return groupDetails;
|
return groupDetails;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new GroupManagementDAOException(msg, e);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new GroupManagementDAOException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1082,10 +1082,11 @@ public interface DeviceManagementProviderService {
|
|||||||
* Get owner details and device IDs for a given owner and tenant.
|
* Get owner details and device IDs for a given owner and tenant.
|
||||||
*
|
*
|
||||||
* @param owner the name of the owner.
|
* @param owner the name of the owner.
|
||||||
|
* @param deviceTypeId the device type id
|
||||||
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user.
|
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user.
|
||||||
* @throws DeviceManagementException if an error occurs while fetching owner details.
|
* @throws DeviceManagementException if an error occurs while fetching owner details.
|
||||||
*/
|
*/
|
||||||
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException;
|
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get owner details and device IDs for a given owner and tenant.
|
* Get owner details and device IDs for a given owner and tenant.
|
||||||
@ -1099,10 +1100,11 @@ public interface DeviceManagementProviderService {
|
|||||||
/**
|
/**
|
||||||
* Get owner details and device IDs for a given owner and tenant.
|
* Get owner details and device IDs for a given owner and tenant.
|
||||||
* @param tenantId the tenant id which devices need to be retried
|
* @param tenantId the tenant id which devices need to be retried
|
||||||
|
* @param deviceTypeId the device type id
|
||||||
* @return {@link DeviceDetailsDTO} which contains devices details.
|
* @return {@link DeviceDetailsDTO} which contains devices details.
|
||||||
* @throws DeviceManagementException if an error occurs while fetching owner details.
|
* @throws DeviceManagementException if an error occurs while fetching owner details.
|
||||||
*/
|
*/
|
||||||
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException;
|
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get operation details by operation code.
|
* Get operation details by operation code.
|
||||||
|
|||||||
@ -5354,13 +5354,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException {
|
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
OwnerWithDeviceDTO ownerWithDeviceDTO;
|
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 {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, tenantId);
|
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId, deviceTypeId);
|
||||||
if (ownerWithDeviceDTO == null) {
|
if (ownerWithDeviceDTO == null) {
|
||||||
String msg = "No data found for owner: " + owner;
|
String msg = "No data found for owner: " + owner;
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -5411,11 +5416,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException {
|
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException {
|
||||||
List<DeviceDetailsDTO> devices;
|
List<DeviceDetailsDTO> devices;
|
||||||
|
List<String> allowingDeviceStatuses = new ArrayList<>();
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
devices = enrollmentDAO.getDevicesByTenantId(tenantId);
|
devices = enrollmentDAO.getDevicesByTenantId(tenantId, allowingDeviceStatuses, deviceTypeId);
|
||||||
if (devices == null || devices.isEmpty()) {
|
if (devices == null || devices.isEmpty()) {
|
||||||
String msg = "No devices found for tenant ID: " + tenantId;
|
String msg = "No devices found for tenant ID: " + tenantId;
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
|
|||||||
@ -377,11 +377,12 @@ public interface GroupManagementProviderService {
|
|||||||
* Get group details and device IDs for a given group name.
|
* Get group details and device IDs for a given group name.
|
||||||
*
|
*
|
||||||
* @param groupName the name of the group.
|
* @param groupName the name of the group.
|
||||||
|
* @param deviceTypeId the device type id
|
||||||
* @param offset the offset for the data set
|
* @param offset the offset for the data set
|
||||||
* @param limit the limit for the data set
|
* @param limit the limit for the data set
|
||||||
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
|
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
|
||||||
* @throws GroupManagementException if an error occurs while fetching group details.
|
* @throws GroupManagementException if an error occurs while fetching group details.
|
||||||
*/
|
*/
|
||||||
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit) throws GroupManagementException;
|
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit) throws GroupManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.device.mgt.core.service;
|
package io.entgra.device.mgt.core.device.mgt.core.service;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.*;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
|
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants;
|
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
|
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
|
||||||
@ -39,13 +40,8 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.CarbonConstants;
|
import org.wso2.carbon.CarbonConstants;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.Device;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
||||||
@ -1688,17 +1684,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit)
|
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit)
|
||||||
throws GroupManagementException {
|
throws GroupManagementException {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Retrieving group details and device IDs for group: " + groupName);
|
log.debug("Retrieving group details and device IDs for group: " + groupName);
|
||||||
}
|
}
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
GroupDetailsDTO groupDetailsWithDevices;
|
GroupDetailsDTO groupDetailsWithDevices;
|
||||||
|
List<String> allowingDeviceStatuses = new ArrayList<>();
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
|
||||||
|
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GroupManagementDAOFactory.openConnection();
|
GroupManagementDAOFactory.openConnection();
|
||||||
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, tenantId, offset, limit);
|
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses,
|
||||||
|
deviceTypeId, tenantId, offset, limit);
|
||||||
} catch (GroupManagementDAOException | SQLException e) {
|
} catch (GroupManagementDAOException | SQLException e) {
|
||||||
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
|
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user