Fix Search is not working in installation details in app store

geofence-revoke-fix
Nipuni Kavindya 5 months ago
parent 7c90b43485
commit 22f8497952

@ -60,6 +60,26 @@ public class CategorizedSubscriptionResult {
this.subscribedDevices = subscribedDevices; this.subscribedDevices = subscribedDevices;
} }
public CategorizedSubscriptionResult(List<DeviceSubscriptionData> devices, String tabActionStatus) {
switch (tabActionStatus) {
case "COMPLETED":
this.installedDevices = devices;
break;
case "PENDING":
this.pendingDevices = devices;
break;
case "ERROR":
this.errorDevices = devices;
break;
case "NEW":
this.newDevices = devices;
break;
case "SUBSCRIBED":
this.subscribedDevices = devices;
break;
}
}
public List<DeviceSubscriptionData> getInstalledDevices() { public List<DeviceSubscriptionData> getInstalledDevices() {
return installedDevices; return installedDevices;
} }
@ -100,4 +120,3 @@ public class CategorizedSubscriptionResult {
this.subscribedDevices = subscribedDevices; this.subscribedDevices = subscribedDevices;
} }
} }

@ -233,8 +233,9 @@ public interface SubscriptionManager {
* @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the group details * @throws ApplicationManagementException if an error occurs while fetching the group details
*/ */
List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) public List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus,
throws ApplicationManagementException; PaginationRequest request, int offset,
int limit) throws ApplicationManagementException;
/** /**
* Retrieves the user details associated with a given app release UUID. * Retrieves the user details associated with a given app release UUID.
@ -246,8 +247,8 @@ public interface SubscriptionManager {
* @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the user details * @throws ApplicationManagementException if an error occurs while fetching the user details
*/ */
List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, PaginationRequest request,
throws ApplicationManagementException; int offset, int limit) throws ApplicationManagementException;
/** /**
* Retrieves the Role details associated with a given app release UUID. * Retrieves the Role details associated with a given app release UUID.
@ -259,8 +260,8 @@ public interface SubscriptionManager {
* @return {@link SubscriptionsDTO} which contains the details of subscriptions. * @return {@link SubscriptionsDTO} which contains the details of subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the role details * @throws ApplicationManagementException if an error occurs while fetching the role details
*/ */
List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, PaginationRequest request,
throws ApplicationManagementException; int offset, int limit) throws ApplicationManagementException;
/** /**
* Retrieves the Device Subscription details associated with a given app release UUID. * Retrieves the Device Subscription details associated with a given app release UUID.
@ -272,8 +273,9 @@ public interface SubscriptionManager {
* @return {@link DeviceSubscriptionResponseDTO} which contains the details of device subscriptions. * @return {@link DeviceSubscriptionResponseDTO} which contains the details of device subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the device subscription details * @throws ApplicationManagementException if an error occurs while fetching the device subscription details
*/ */
DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID(String uuid, String subscriptionStatus,
throws ApplicationManagementException; PaginationRequest request, int offset,
int limit) throws ApplicationManagementException;
/** /**
* Retrieves the All Device details associated with a given app release UUID. * Retrieves the All Device details associated with a given app release UUID.
@ -285,8 +287,9 @@ public interface SubscriptionManager {
* @return {@link DeviceSubscriptionResponseDTO} which contains the details of device subscriptions. * @return {@link DeviceSubscriptionResponseDTO} which contains the details of device subscriptions.
* @throws ApplicationManagementException if an error occurs while fetching the subscription details * @throws ApplicationManagementException if an error occurs while fetching the subscription details
*/ */
DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID(String uuid, String subscriptionStatus,
throws ApplicationManagementException; PaginationRequest request, int offset,
int limit) throws ApplicationManagementException;
/** /**
* This method is responsible for retrieving device subscription details related to the given UUID. * This method is responsible for retrieving device subscription details related to the given UUID.

@ -390,12 +390,16 @@ public interface SubscriptionDAO {
* @param appReleaseId the appReleaseId of the application release. * @param appReleaseId the appReleaseId of the application release.
* @param unsubscribe the Status of the subscription. * @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant. * @param tenantId id of the current tenant.
* @param actionStatus Status of the action
* @param actionType type of the action
* @param actionTriggeredBy subscribed by
* @param deviceIds deviceIds deviceIds to retrieve data. * @param deviceIds deviceIds deviceIds to retrieve data.
* @return {@link DeviceOperationDTO} which contains the details of device subscriptions. * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails. * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/ */
List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId, List<Integer> deviceIds) List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
throws ApplicationManagementDAOException; List<Integer> deviceIds, String actionStatus, String actionType,
String actionTriggeredBy, String tabActionStatus) throws ApplicationManagementDAOException;
/** /**
* This method is used to get the details of device subscriptions related to a UUID. * This method is used to get the details of device subscriptions related to a UUID.
@ -403,13 +407,16 @@ public interface SubscriptionDAO {
* @param appReleaseId the appReleaseId of the application release. * @param appReleaseId the appReleaseId of the application release.
* @param unsubscribe the Status of the subscription. * @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant. * @param tenantId id of the current tenant.
* @param actionStatus Status of the action
* @param actionType type of the action
* @param actionTriggeredBy subscribed by
* @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 DeviceOperationDTO} which contains the details of device subscriptions. * @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails. * @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/ */
List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, int offset, int limit) List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, String actionStatus, String actionType,
throws ApplicationManagementDAOException; String actionTriggeredBy, int offset, int limit) throws ApplicationManagementDAOException;
/** /**
* This method is used to get the counts of all subscription types related to a UUID. * This method is used to get the counts of all subscription types related to a UUID.

@ -1911,8 +1911,9 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId, List<Integer> deviceIds) public List<DeviceSubscriptionDTO> getSubscriptionDetailsByDeviceIds(int appReleaseId, boolean unsubscribe, int tenantId,
throws ApplicationManagementDAOException { List<Integer> deviceIds, String actionStatus, String actionType,
String actionTriggeredBy, String tabActionStatus) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId log.debug("Getting device subscriptions for the application release id " + appReleaseId
+ " and device ids " + deviceIds + " from the database"); + " and device ids " + deviceIds + " from the database");
@ -1920,7 +1921,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP"; String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
String sql = "SELECT " StringBuilder sql = new StringBuilder("SELECT "
+ "DS.ID AS ID, " + "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, " + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
@ -1932,16 +1933,39 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "DS.DM_DEVICE_ID AS DEVICE_ID " + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ "FROM AP_DEVICE_SUBSCRIPTION DS " + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? AND DS.DM_DEVICE_ID IN (" + + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? AND DS.DM_DEVICE_ID IN (" +
deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") " deviceIds.stream().map(id -> "?").collect(Collectors.joining(",")) + ") ");
+ "ORDER BY " + subscriptionStatusTime + " DESC";
try (PreparedStatement ps = conn.prepareStatement(sql)) { if (actionStatus != null && !actionStatus.isEmpty()) {
ps.setInt(1, appReleaseId); sql.append(" AND DS.STATUS = ? ");
ps.setBoolean(2, unsubscribe); }
ps.setInt(3, tenantId); if (actionType != null && !actionType.isEmpty()) {
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
}
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
sql.append(" AND DS.SUBSCRIBED_BY LIKE ? ");
}
sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC");
try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
int paramIdx = 1;
ps.setInt(paramIdx++, appReleaseId);
ps.setBoolean(paramIdx++, unsubscribe);
ps.setInt(paramIdx++, tenantId);
for (int i = 0; i < deviceIds.size(); i++) { for (int i = 0; i < deviceIds.size(); i++) {
ps.setInt(4 + i, deviceIds.get(i)); ps.setInt(paramIdx++, deviceIds.get(i));
}
if (actionStatus != null && !actionStatus.isEmpty()) {
ps.setString(paramIdx++, actionStatus);
}
if (actionType != null && !actionType.isEmpty()) {
ps.setString(paramIdx++, actionType);
} }
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
}
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved device subscriptions for application release id " log.debug("Successfully retrieved device subscriptions for application release id "
@ -1980,6 +2004,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override @Override
public List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId, public List<DeviceSubscriptionDTO> getAllSubscriptionsDetails(int appReleaseId, boolean unsubscribe, int tenantId,
String actionStatus, String actionType, String actionTriggeredBy,
int offset, int limit) throws ApplicationManagementDAOException { int offset, int limit) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting device subscriptions for the application release id " + appReleaseId log.debug("Getting device subscriptions for the application release id " + appReleaseId
@ -1987,7 +2012,8 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP"; String subscriptionStatusTime = unsubscribe ? "DS.UNSUBSCRIBED_TIMESTAMP" : "DS.SUBSCRIBED_TIMESTAMP";
String sql = "SELECT " String actionTriggeredColumn = unsubscribe ? "DS.UNSUBSCRIBED_BY" : "DS.SUBSCRIBED_BY";
StringBuilder sql = new StringBuilder("SELECT "
+ "DS.ID AS ID, " + "DS.ID AS ID, "
+ "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, " + "DS.SUBSCRIBED_BY AS SUBSCRIBED_BY, "
+ "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, " + "DS.SUBSCRIBED_TIMESTAMP AS SUBSCRIBED_AT, "
@ -1995,21 +2021,45 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, " + "DS.UNSUBSCRIBED_BY AS UNSUBSCRIBED_BY, "
+ "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, " + "DS.UNSUBSCRIBED_TIMESTAMP AS UNSUBSCRIBED_AT, "
+ "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, " + "DS.ACTION_TRIGGERED_FROM AS ACTION_TRIGGERED_FROM, "
+ "DS.STATUS AS STATUS," + "DS.STATUS AS STATUS, "
+ "DS.DM_DEVICE_ID AS DEVICE_ID " + "DS.DM_DEVICE_ID AS DEVICE_ID "
+ "FROM AP_DEVICE_SUBSCRIPTION DS " + "FROM AP_DEVICE_SUBSCRIPTION DS "
+ "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID=? " + "WHERE DS.AP_APP_RELEASE_ID = ? AND DS.UNSUBSCRIBED = ? AND DS.TENANT_ID = ? ");
+ "ORDER BY " + subscriptionStatusTime + " DESC "
+ "LIMIT ? OFFSET ?"; if (actionStatus != null && !actionStatus.isEmpty()) {
sql.append(" AND DS.STATUS = ? ");
}
if (actionType != null && !actionType.isEmpty()) {
sql.append(" AND DS.ACTION_TRIGGERED_FROM = ? ");
}
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
sql.append(" AND ").append(actionTriggeredColumn).append(" LIKE ? ");
}
sql.append("ORDER BY ").append(subscriptionStatusTime).append(" DESC ")
.append("LIMIT ? OFFSET ?");
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement ps = conn.prepareStatement(sql)) { try (PreparedStatement ps = conn.prepareStatement(sql.toString())) {
ps.setInt(1, appReleaseId); int paramIdx = 1;
ps.setBoolean(2, unsubscribe); ps.setInt(paramIdx++, appReleaseId);
ps.setInt(3, tenantId); ps.setBoolean(paramIdx++, unsubscribe);
ps.setInt(4, limit); ps.setInt(paramIdx++, tenantId);
ps.setInt(5, offset);
if (actionStatus != null && !actionStatus.isEmpty()) {
ps.setString(paramIdx++, actionStatus);
}
if (actionType != null && !actionType.isEmpty()) {
ps.setString(paramIdx++, actionType);
}
if (actionTriggeredBy != null && !actionTriggeredBy.isEmpty()) {
ps.setString(paramIdx++, "%" + actionTriggeredBy + "%");
}
ps.setInt(paramIdx++, limit);
ps.setInt(paramIdx++, offset);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved device subscriptions for application release id " log.debug("Successfully retrieved device subscriptions for application release id "
@ -2040,7 +2090,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while while running SQL to get device subscription data for application ID: " + appReleaseId; String msg = "Error occurred while running SQL to get device subscription data for application ID: " + appReleaseId;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }

@ -1704,12 +1704,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, public List<SubscriptionsDTO> getGroupsSubscriptionDetailsByUUID(
int limit) throws ApplicationManagementException { String uuid, String subscriptionStatus, PaginationRequest request, int offset, int limit)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
String groupName;
String status;
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
@ -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 =
@ -1733,11 +1733,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
for (GroupSubscriptionDTO groupDetail : groupDetails) { for (GroupSubscriptionDTO groupDetail : groupDetails) {
groupName = groupDetail.getGroupName();
if (StringUtils.isNotBlank(request.getGroupName()) && !request.getGroupName().equals(groupDetail.getGroupName())) {
continue;
}
String groupName = StringUtils.isNotBlank(request.getGroupName()) ? request.getGroupName() : groupDetail.getGroupName();
// 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(), request.getOwner(),
request.getDeviceName(), request.getDeviceStatus(), offset, limit);
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO(); SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO();
groupDetailDTO.setId(groupDetailWithDevices.getGroupId()); groupDetailDTO.setId(groupDetailWithDevices.getGroupId());
@ -1760,24 +1767,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<Integer> deviceIds = groupDetailWithDevices.getDeviceIds(); List<Integer> deviceIds = groupDetailWithDevices.getDeviceIds();
Map<String, Integer> statusCounts = new HashMap<>(); Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0); statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0); statusCounts.put("ERROR", 0);
statusCounts.put("PENDING", 0);
statusCounts.put("NEW", 0); statusCounts.put("NEW", 0);
statusCounts.put("SUBSCRIBED", 0); statusCounts.put("SUBSCRIBED", 0);
for (Integer deviceId : deviceIds) {
// Get subscribed devices if unsubscribed devices are requested // Get subscribed devices if unsubscribed devices are requested
List<DeviceSubscriptionDTO> subscribedDeviceSubscriptions = new ArrayList<>(); List<DeviceSubscriptionDTO> deviceSubscriptions;
if (unsubscribe) { if (unsubscribe) {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds); appReleaseId, !unsubscribe, tenantId, deviceIds,
request.getActionStatus(), request.getActionType(), request.getActionTriggeredBy(), request.getTabActionStatus());
} else {
deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
groupDetail.getAppReleaseId(), false, tenantId, deviceIds,
request.getActionStatus(), request.getActionType(), request.getActionTriggeredBy(), request.getTabActionStatus());
} }
List<DeviceSubscriptionDTO> filteredDeviceSubscriptions = deviceSubscriptions.stream()
for (Integer deviceId : deviceIds) { .filter(subscription -> StringUtils.isBlank(request.getTabActionStatus()) || subscription.getStatus().equals(request.getTabActionStatus()))
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( .collect(Collectors.toList());
groupDetail.getAppReleaseId(), unsubscribe, tenantId, deviceIds);
boolean isNewDevice = true; boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) { for (DeviceSubscriptionDTO subscription : filteredDeviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) { if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId()); deviceDetail.setDeviceId(subscription.getDeviceId());
@ -1795,7 +1807,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setType(groupDetailWithDevices.getDeviceTypes().get(deviceId)); deviceDetail.setType(groupDetailWithDevices.getDeviceTypes().get(deviceId));
deviceDetail.setDeviceIdentifier(groupDetailWithDevices.getDeviceIdentifiers().get(deviceId)); deviceDetail.setDeviceIdentifier(groupDetailWithDevices.getDeviceIdentifiers().get(deviceId));
status = subscription.getStatus(); String status = subscription.getStatus();
switch (status) { switch (status) {
case "COMPLETED": case "COMPLETED":
installedDevices.add(deviceDetail); installedDevices.add(deviceDetail);
@ -1813,13 +1825,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
pendingDevices.add(deviceDetail); pendingDevices.add(deviceDetail);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1); statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break; break;
default:
newDevices.add(deviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
break;
} }
isNewDevice = false; isNewDevice = false;
} }
} }
if (isNewDevice) { if (isNewDevice) {
boolean isSubscribedDevice = false; boolean isSubscribedDevice = false;
for (DeviceSubscriptionDTO subscribedDevice : subscribedDeviceSubscriptions) { for (DeviceSubscriptionDTO subscribedDevice : deviceSubscriptions) {
if (subscribedDevice.getDeviceId() == deviceId) { if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
@ -1861,6 +1877,27 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage));
} }
List<DeviceSubscriptionData> requestedDevices = new ArrayList<>();
if (StringUtils.isNotBlank(request.getTabActionStatus())) {
switch (request.getTabActionStatus()) {
case "COMPLETED":
requestedDevices = installedDevices;
break;
case "PENDING":
requestedDevices = pendingDevices;
break;
case "ERROR":
requestedDevices = errorDevices;
break;
case "NEW":
requestedDevices = newDevices;
break;
case "SUBSCRIBED":
requestedDevices = subscribedDevices;
break;
}
groupDetailDTO.setDevices(new CategorizedSubscriptionResult(requestedDevices, request.getTabActionStatus()));
} else {
CategorizedSubscriptionResult categorizedSubscriptionResult; CategorizedSubscriptionResult categorizedSubscriptionResult;
if (subscribedDevices.isEmpty()) { if (subscribedDevices.isEmpty()) {
categorizedSubscriptionResult = categorizedSubscriptionResult =
@ -1870,8 +1907,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices);
} }
groupDetailDTO.setDevices(categorizedSubscriptionResult); groupDetailDTO.setDevices(categorizedSubscriptionResult);
}
groupDetailDTO.setStatusPercentages(statusPercentages); groupDetailDTO.setStatusPercentages(statusPercentages);
groupDetailsWithDevices.add(groupDetailDTO); groupDetailsWithDevices.add(groupDetailDTO);
} }
@ -1894,11 +1931,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) public List<SubscriptionsDTO> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus,
PaginationRequest request, int offset, int limit)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
String userName;
String status; String status;
try { try {
@ -1910,8 +1947,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 =
@ -1923,11 +1960,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (SubscriptionsDTO userSubscription : userSubscriptions) { for (SubscriptionsDTO userSubscription : userSubscriptions) {
userName = userSubscription.getName();
if (StringUtils.isNotBlank(request.getUserName()) && !request.getUserName().equals(userSubscription.getName())) {
continue;
}
String userName = StringUtils.isNotBlank(request.getUserName()) ? request.getUserName() : userSubscription.getName();
// 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(),
request.getOwner(), request.getDeviceName(), request.getDeviceStatus());
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO(); SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO();
userSubscriptionDTO.setName(userSubscription.getName()); userSubscriptionDTO.setName(userSubscription.getName());
@ -1958,21 +2001,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> subscribedDeviceSubscriptions = new ArrayList<>(); List<DeviceSubscriptionDTO> subscribedDeviceSubscriptions = new ArrayList<>();
if (unsubscribe) { if (unsubscribe) {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds); appReleaseId, !unsubscribe, tenantId, deviceIds, request.getActionStatus(), request.getActionType(),
request.getActionTriggeredBy(), request.getTabActionStatus());
} }
for (Integer deviceId : deviceIds) { for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
userSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds); userSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds, request.getActionStatus(), request.getActionType(),
request.getActionTriggeredBy(), request.getTabActionStatus());
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId, request.getOwner(), request.getDeviceName(),
request.getDeviceStatus());
if (ownerWithDeviceByDeviceId == null) {
continue;
}
boolean isNewDevice = true; boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) { for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) { if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId()); deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setSubId(subscription.getId()); deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setActionType(subscription.getActionTriggeredFrom()); deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setStatus(subscription.getStatus()); deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom()); deviceDetail.setActionType(subscription.getActionTriggeredFrom());
@ -1981,8 +2032,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(subscription.isUnsubscribed()); deviceDetail.setUnsubscribed(subscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp()); deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = subscription.getStatus(); status = subscription.getStatus();
switch (status) { switch (status) {
@ -2012,16 +2063,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) { if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId()); subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy()); subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail); subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true; isSubscribedDevice = true;
@ -2031,11 +2082,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) { if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId); newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail); newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1); statusCounts.put("NEW", statusCounts.get("NEW") + 1);
} }
@ -2050,20 +2101,42 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage));
} }
List<DeviceSubscriptionData> requestedDevices = new ArrayList<>();
if (StringUtils.isNotBlank(request.getTabActionStatus())) {
switch (request.getTabActionStatus()) {
case "COMPLETED":
requestedDevices = installedDevices;
break;
case "PENDING":
requestedDevices = pendingDevices;
break;
case "ERROR":
requestedDevices = errorDevices;
break;
case "NEW":
requestedDevices = newDevices;
break;
case "SUBSCRIBED":
requestedDevices = subscribedDevices;
break;
}
userSubscriptionDTO.setDevices(new CategorizedSubscriptionResult(requestedDevices, request.getTabActionStatus()));
} else {
CategorizedSubscriptionResult categorizedSubscriptionResult; CategorizedSubscriptionResult categorizedSubscriptionResult;
if (subscribedDevices.isEmpty()) { if (subscribedDevices.isEmpty()) {
categorizedSubscriptionResult = categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
} else { } else {
categorizedSubscriptionResult = categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices,
subscribedDevices);
} }
userSubscriptionDTO.setDevices(categorizedSubscriptionResult); userSubscriptionDTO.setDevices(categorizedSubscriptionResult);
userSubscriptionDTO.setStatusPercentages(statusPercentages); userSubscriptionDTO.setStatusPercentages(statusPercentages);
}
userSubscriptionsWithDevices.add(userSubscriptionDTO); userSubscriptionsWithDevices.add(userSubscriptionDTO);
} }
return userSubscriptionsWithDevices; return userSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid; String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid;
@ -2081,7 +2154,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus, int offset, int limit) public List<SubscriptionsDTO> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus,
PaginationRequest request, int offset, int limit)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
@ -2097,8 +2171,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 =
@ -2110,7 +2184,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService(); DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (SubscriptionsDTO roleSubscription : roleSubscriptions) { for (SubscriptionsDTO roleSubscription : roleSubscriptions) {
roleName = roleSubscription.getName();
roleName = StringUtils.isNotBlank(request.getRoleName()) ? request.getRoleName() : roleSubscription.getName();
SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO(); SubscriptionsDTO roleSubscriptionDTO = new SubscriptionsDTO();
roleSubscriptionDTO.setName(roleSubscription.getName()); roleSubscriptionDTO.setName(roleSubscription.getName());
@ -2139,7 +2214,8 @@ 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(),
request.getOwner(), request.getDeviceName(), request.getDeviceStatus());
} 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);
} }
@ -2150,13 +2226,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> subscribedDeviceSubscriptions = new ArrayList<>(); List<DeviceSubscriptionDTO> subscribedDeviceSubscriptions = new ArrayList<>();
if (unsubscribe) { if (unsubscribe) {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds); appReleaseId, !unsubscribe, tenantId, deviceIds, request.getActionStatus(), request.getActionType(),
request.getActionTriggeredBy(), request.getTabActionStatus());
}
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId, request.getOwner(), request.getDeviceName(),
request.getDeviceStatus());
if (ownerWithDeviceByDeviceId == null) {
continue;
} }
List<DeviceSubscriptionDTO> deviceSubscriptions; List<DeviceSubscriptionDTO> deviceSubscriptions;
try { try {
deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds( deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
roleSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds); roleSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds, request.getActionStatus(),
request.getActionType(), request.getActionTriggeredBy(), request.getTabActionStatus());
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving device subscriptions", e); throw new ApplicationManagementException("Error retrieving device subscriptions", e);
} }
@ -2166,9 +2249,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscription.getDeviceId() == deviceId) { if (deviceSubscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(deviceSubscription.getDeviceId()); deviceDetail.setDeviceId(deviceSubscription.getDeviceId());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom()); deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
deviceDetail.setStatus(deviceSubscription.getStatus()); deviceDetail.setStatus(deviceSubscription.getStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom()); deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
@ -2178,8 +2261,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(deviceSubscription.isUnsubscribed()); deviceDetail.setUnsubscribed(deviceSubscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(deviceSubscription.getUnsubscribedBy()); deviceDetail.setUnsubscribedBy(deviceSubscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(deviceSubscription.getUnsubscribedTimestamp()); deviceDetail.setUnsubscribedTimestamp(deviceSubscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = deviceSubscription.getStatus(); status = deviceSubscription.getStatus();
switch (status) { switch (status) {
@ -2209,16 +2292,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) { if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId()); subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId()); subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy()); subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp()); subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom()); subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus()); subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail); subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1); statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true; isSubscribedDevice = true;
@ -2228,11 +2311,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) { if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData(); DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId); newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames()); newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName()); newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus()); newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes()); newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers()); newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail); newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1); statusCounts.put("NEW", statusCounts.get("NEW") + 1);
} }
@ -2249,23 +2332,46 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage));
} }
List<DeviceSubscriptionData> requestedDevices = new ArrayList<>();
if (StringUtils.isNotBlank(request.getTabActionStatus())) {
switch (request.getTabActionStatus()) {
case "COMPLETED":
requestedDevices = installedDevices;
break;
case "PENDING":
requestedDevices = pendingDevices;
break;
case "ERROR":
requestedDevices = errorDevices;
break;
case "NEW":
requestedDevices = newDevices;
break;
case "SUBSCRIBED":
requestedDevices = subscribedDevices;
break;
}
roleSubscriptionDTO.setDevices(new CategorizedSubscriptionResult(requestedDevices, request.getTabActionStatus()));
} else {
CategorizedSubscriptionResult categorizedSubscriptionResult; CategorizedSubscriptionResult categorizedSubscriptionResult;
if (subscribedDevices.isEmpty()) { if (subscribedDevices.isEmpty()) {
categorizedSubscriptionResult = categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
} else { } else {
categorizedSubscriptionResult = categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices,
subscribedDevices);
} }
roleSubscriptionDTO.setDevices(categorizedSubscriptionResult); roleSubscriptionDTO.setDevices(categorizedSubscriptionResult);
roleSubscriptionDTO.setStatusPercentages(statusPercentages); roleSubscriptionDTO.setStatusPercentages(statusPercentages);
roleSubscriptionDTO.setDeviceCount(totalDevices); roleSubscriptionDTO.setDeviceCount(totalDevices);
}
roleSubscriptionsWithDevices.add(roleSubscriptionDTO); roleSubscriptionsWithDevices.add(roleSubscriptionDTO);
} }
return roleSubscriptionsWithDevices; return roleSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException | DeviceManagementDAOException e) {
String msg = "Error occurred in retrieving role subscriptions with devices"; String msg = "Error occurred in retrieving role subscriptions with devices";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
@ -2292,7 +2398,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID(String uuid, String subscriptionStatus, int offset, public DeviceSubscriptionResponseDTO getDeviceSubscriptionsDetailsByUUID(String uuid, String subscriptionStatus, PaginationRequest request, int offset,
int limit) throws ApplicationManagementException { int limit) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -2307,6 +2413,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 +2428,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
List<DeviceDetailsDTO> allDevices = List<DeviceDetailsDTO> allDevices =
deviceManagementProviderService.getDevicesByTenantId(tenantId); deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId(),
request.getOwner(), request.getDeviceStatus());
List<Integer> deviceIds = allDevices.stream() List<Integer> deviceIds = allDevices.stream()
.map(DeviceDetailsDTO::getDeviceId) .map(DeviceDetailsDTO::getDeviceId)
@ -2346,9 +2454,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
.collect(Collectors.toMap(DeviceDetailsDTO::getDeviceId, Function.identity())); .collect(Collectors.toMap(DeviceDetailsDTO::getDeviceId, Function.identity()));
List<DeviceSubscriptionDTO> allSubscriptionsForUnSubscribed = List<DeviceSubscriptionDTO> allSubscriptionsForUnSubscribed =
subscriptionDAO.getSubscriptionDetailsByDeviceIds(appReleaseId, !unsubscribe, tenantId, deviceIds); subscriptionDAO.getSubscriptionDetailsByDeviceIds(appReleaseId, !unsubscribe, tenantId, deviceIds, request.getActionStatus(),
request.getActionType(), request.getActionTriggeredBy(), request.getTabActionStatus());
List<DeviceSubscriptionDTO> allSubscriptionsForSubscribed = List<DeviceSubscriptionDTO> allSubscriptionsForSubscribed =
subscriptionDAO.getSubscriptionDetailsByDeviceIds(appReleaseId, unsubscribe, tenantId, deviceIds); subscriptionDAO.getSubscriptionDetailsByDeviceIds(appReleaseId, unsubscribe, tenantId, deviceIds, request.getActionStatus(),
request.getActionType(), request.getActionTriggeredBy(), request.getTabActionStatus());
Map<Integer, DeviceSubscriptionDTO> allSubscriptionForUnSubscribedMap = allSubscriptionsForUnSubscribed.stream() Map<Integer, DeviceSubscriptionDTO> allSubscriptionForUnSubscribedMap = allSubscriptionsForUnSubscribed.stream()
.collect(Collectors.toMap(DeviceSubscriptionDTO::getDeviceId, Function.identity())); .collect(Collectors.toMap(DeviceSubscriptionDTO::getDeviceId, Function.identity()));
Map<Integer, DeviceSubscriptionDTO> allSubscriptionForSubscribedMap = allSubscriptionsForSubscribed.stream() Map<Integer, DeviceSubscriptionDTO> allSubscriptionForSubscribedMap = allSubscriptionsForSubscribed.stream()
@ -2357,7 +2467,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for (DeviceDetailsDTO device : allDevices) { for (DeviceDetailsDTO device : allDevices) {
Integer deviceId = device.getDeviceId(); Integer deviceId = device.getDeviceId();
OwnerWithDeviceDTO ownerWithDevice = OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId); deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId, request.getOwner(), request.getDeviceName(),
request.getDeviceStatus());
if (ownerWithDevice == null) { if (ownerWithDevice == null) {
continue; continue;
} }
@ -2450,14 +2561,35 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage));
} }
CategorizedSubscriptionResult categorizedSubscriptionResult; List<DeviceSubscriptionData> requestedDevices = new ArrayList<>();
if (subscribedDevices.isEmpty()) { if (StringUtils.isNotBlank(request.getTabActionStatus())) {
categorizedSubscriptionResult = switch (request.getTabActionStatus()) {
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices); case "COMPLETED":
requestedDevices = installedDevices;
break;
case "PENDING":
requestedDevices = pendingDevices;
break;
case "ERROR":
requestedDevices = errorDevices;
break;
case "NEW":
requestedDevices = newDevices;
break;
case "SUBSCRIBED":
requestedDevices = subscribedDevices;
break;
}
} else { } else {
categorizedSubscriptionResult = requestedDevices.addAll(installedDevices);
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices); requestedDevices.addAll(pendingDevices);
requestedDevices.addAll(errorDevices);
requestedDevices.addAll(newDevices);
requestedDevices.addAll(subscribedDevices);
} }
CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices, subscribedDevices);
DeviceSubscriptionResponseDTO deviceSubscriptionResponse = DeviceSubscriptionResponseDTO deviceSubscriptionResponse =
new DeviceSubscriptionResponseDTO(totalDevices, statusPercentages, categorizedSubscriptionResult); new DeviceSubscriptionResponseDTO(totalDevices, statusPercentages, categorizedSubscriptionResult);
@ -2479,8 +2611,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, int offset, int limit) public DeviceSubscriptionResponseDTO getAllSubscriptionDetailsByUUID(String uuid, String subscriptionStatus, PaginationRequest request,
throws ApplicationManagementException { int offset, int limit) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed"); boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
@ -2493,10 +2625,12 @@ 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 =
subscriptionDAO.getAllSubscriptionsDetails(appReleaseId, unsubscribe, tenantId, offset, limit); subscriptionDAO.getAllSubscriptionsDetails(appReleaseId, unsubscribe, tenantId, request.getActionStatus(),
request.getActionType(), request.getActionTriggeredBy(), offset, limit);
// empty response for no subscriptions // empty response for no subscriptions
if (allSubscriptions.isEmpty()) { if (allSubscriptions.isEmpty()) {
@ -2522,12 +2656,14 @@ 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(), request.getOwner(),
request.getDeviceStatus());
for (DeviceDetailsDTO device : allDevices) { for (DeviceDetailsDTO device : allDevices) {
Integer deviceId = device.getDeviceId(); Integer deviceId = device.getDeviceId();
OwnerWithDeviceDTO ownerWithDevice = OwnerWithDeviceDTO ownerWithDevice =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId); deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId, request.getOwner(), request.getDeviceName(),
request.getDeviceStatus());
if (ownerWithDevice == null) { if (ownerWithDevice == null) {
continue; continue;
} }
@ -2590,6 +2726,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage)); statusPercentages.put(entry.getKey(), Double.valueOf(formattedPercentage));
} }
List<DeviceSubscriptionData> requestedDevices = new ArrayList<>();
if (StringUtils.isNotBlank(request.getTabActionStatus())) {
switch (request.getTabActionStatus()) {
case "COMPLETED":
requestedDevices = installedDevices;
break;
case "PENDING":
requestedDevices = pendingDevices;
break;
case "ERROR":
requestedDevices = errorDevices;
break;
case "NEW":
requestedDevices = newDevices;
break;
}
} else {
requestedDevices.addAll(installedDevices);
requestedDevices.addAll(pendingDevices);
requestedDevices.addAll(errorDevices);
requestedDevices.addAll(newDevices);
}
CategorizedSubscriptionResult categorizedSubscriptionResult = CategorizedSubscriptionResult categorizedSubscriptionResult =
new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices); new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices, newDevices);
DeviceSubscriptionResponseDTO result = DeviceSubscriptionResponseDTO result =

@ -41,6 +41,14 @@ public class PaginationRequest {
private Date since; private Date since;
private String filter; private String filter;
private String serialNumber; private String serialNumber;
private String groupName;
private String roleName;
private String userName;
private String deviceStatus;
private String tabActionStatus;
private String actionStatus;
private String actionType;
private String actionTriggeredBy;
private Map<String, String> customProperty = new HashMap<>(); private Map<String, String> customProperty = new HashMap<>();
private Map<String, Object> property = new HashMap<>(); private Map<String, Object> property = new HashMap<>();
private List<String> statusList = new ArrayList<>(); private List<String> statusList = new ArrayList<>();
@ -220,4 +228,68 @@ public class PaginationRequest {
+ this.ownership + "' Status '" + this.statusList + "' owner '" + this.owner + "' groupId: " + this.groupId + this.ownership + "' Status '" + this.statusList + "' owner '" + this.owner + "' groupId: " + this.groupId
+ " start index: " + this.startIndex + ", SortColumns: " + this.sortColumn; + " start index: " + this.startIndex + ", SortColumns: " + this.sortColumn;
} }
public String getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
public String getActionStatus() {
return actionStatus;
}
public void setActionStatus(String actionStatus) {
this.actionStatus = actionStatus;
}
public String getActionType() {
return actionType;
}
public void setActionType(String actionType) {
this.actionType = actionType;
}
public String getActionTriggeredBy() {
return actionTriggeredBy;
}
public void setActionTriggeredBy(String actionTriggeredBy) {
this.actionTriggeredBy = actionTriggeredBy;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getTabActionStatus() {
return tabActionStatus;
}
public void setTabActionStatus(String tabActionStatus) {
this.tabActionStatus = tabActionStatus;
}
} }

@ -101,29 +101,42 @@ 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
* @param deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @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,
String deviceOwner, String deviceName, String deviceStatus) throws DeviceManagementDAOException;
/** /**
* Retrieves a list of device IDs with owners and device status. * Retrieves a list of device IDs with owners and device status.
* *
* @param deviceId the deviceId of the device which user need to be retrieved * @param deviceId the deviceId of the device which user need to be retrieved
* @param tenantId the ID of the tenant * @param tenantId the ID of the tenant
* @param deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @return {@link OwnerWithDeviceDTO} which contains a list of devices * @return {@link OwnerWithDeviceDTO} which contains a list of devices
* @throws DeviceManagementDAOException if an error occurs while fetching the data * @throws DeviceManagementDAOException if an error occurs while fetching the data
*/ */
OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId) OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId, String deviceOwner, String deviceName, String deviceStatus)
throws DeviceManagementDAOException; throws DeviceManagementDAOException;
/** /**
* 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
* @param deviceOwner owner of the device
* @param deviceStatus status of the device
* @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, String deviceOwner,
String deviceStatus) throws DeviceManagementDAOException;
} }

@ -473,13 +473,19 @@ 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 deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @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, String deviceOwner, String deviceName, String deviceStatus, int offset, int limit)
throws GroupManagementDAOException; throws GroupManagementDAOException;
} }

@ -564,30 +564,73 @@ 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,
throws DeviceManagementDAOException { int deviceTypeId, String deviceOwner, String deviceName,
String deviceStatus) 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;
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 " + StringBuilder deviceFilters = new StringBuilder();
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
deviceFilters.append("?");
if (i < allowingDeviceStatuses.size() - 1) {
deviceFilters.append(",");
}
}
StringBuilder sql = new StringBuilder(
"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 + ")");
if (deviceOwner != null && !deviceOwner.isEmpty()) {
sql.append(" AND e.OWNER LIKE ?");
}
if (deviceName != null && !deviceName.isEmpty()) {
sql.append(" AND d.NAME LIKE ?");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
sql.append(" AND e.STATUS = ?");
}
try { try {
conn = this.getConnection(); conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
stmt.setString(1, owner); int index = 1;
stmt.setInt(2, tenantId); stmt.setString(index++, owner);
stmt.setInt(index++, tenantId);
stmt.setInt(index++, deviceTypeId);
for (String status : allowingDeviceStatuses) {
stmt.setString(index++, status);
}
if (deviceOwner != null && !deviceOwner.isEmpty()) {
stmt.setString(index++, "%" + deviceOwner + "%");
}
if (deviceName != null && !deviceName.isEmpty()) {
stmt.setString(index++, "%" + deviceName + "%");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
stmt.setString(index++, deviceStatus);
}
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {
if (ownerDetails.getUserName() == null) { if (ownerDetails.getUserName() == null) {
ownerDetails.setUserName(rs.getString("OWNER")); ownerDetails.setUserName(rs.getString("OWNER"));
}
ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS")); ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME")); ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
} ownerDetails.setDeviceTypes(rs.getString("DEVICE_TYPE"));
ownerDetails.setDeviceIdentifiers(rs.getString("DEVICE_IDENTIFICATION"));
deviceIds.add(rs.getInt("DEVICE_ID")); deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++; deviceCount++;
} }
@ -598,34 +641,61 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementDAOException(msg, e); throw new DeviceManagementDAOException(msg, e);
} }
ownerDetails.setDeviceIds(deviceIds); ownerDetails.setDeviceIds(deviceIds);
ownerDetails.setDeviceTypes("DEVICE_TYPE");
ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION");
ownerDetails.setDeviceCount(deviceCount); ownerDetails.setDeviceCount(deviceCount);
return ownerDetails; return ownerDetails;
} }
@Override @Override
public OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId) public OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, int tenantId, String deviceOwner, String deviceName,
throws DeviceManagementDAOException { String deviceStatus) throws DeviceManagementDAOException {
OwnerWithDeviceDTO deviceOwnerWithStatus = new OwnerWithDeviceDTO(); OwnerWithDeviceDTO deviceOwnerWithStatus = new OwnerWithDeviceDTO();
Connection conn = null; Connection conn = null;
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " + List<Integer> deviceIds = new ArrayList<>();
StringBuilder sql = new StringBuilder(
"SELECT e.DEVICE_ID, " +
"e.OWNER, " +
"e.STATUS AS DEVICE_STATUS, " +
"d.NAME AS DEVICE_NAME, " +
"e.DEVICE_TYPE, " +
"e.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.DEVICE_ID = ? AND e.TENANT_ID = ?"; "WHERE e.DEVICE_ID = ? AND e.TENANT_ID = ?");
if (deviceOwner != null && !deviceOwner.isEmpty()) {
sql.append(" AND e.OWNER LIKE ?");
}
if (deviceName != null && !deviceName.isEmpty()) {
sql.append(" AND d.NAME LIKE ?");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
sql.append(" AND e.STATUS = ?");
}
try { try {
conn = this.getConnection(); conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
stmt.setInt(1, deviceId); int paramIndex = 1;
stmt.setInt(2, tenantId); stmt.setInt(paramIndex++, deviceId);
stmt.setInt(paramIndex++, tenantId);
// Set filter parameters if provided
if (deviceOwner != null && !deviceOwner.isEmpty()) {
stmt.setString(paramIndex++, "%" + deviceOwner + "%");
}
if (deviceName != null && !deviceName.isEmpty()) {
stmt.setString(paramIndex++, "%" + deviceName + "%");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
stmt.setString(paramIndex++, deviceStatus);
}
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) { if (rs.next()) {
deviceOwnerWithStatus.setUserName(rs.getString("OWNER")); deviceOwnerWithStatus.setUserName(rs.getString("OWNER"));
deviceOwnerWithStatus.setDeviceStatus(rs.getString("DEVICE_STATUS")); deviceOwnerWithStatus.setDeviceStatus(rs.getString("DEVICE_STATUS"));
List<Integer> deviceIds = new ArrayList<>();
deviceIds.add(rs.getInt("DEVICE_ID")); deviceIds.add(rs.getInt("DEVICE_ID"));
deviceOwnerWithStatus.setDeviceIds(deviceIds); deviceOwnerWithStatus.setDeviceIds(deviceIds);
deviceOwnerWithStatus.setDeviceNames(rs.getString("DEVICE_NAME")); deviceOwnerWithStatus.setDeviceNames(rs.getString("DEVICE_NAME"));
@ -643,18 +713,51 @@ 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 { String deviceOwner, String deviceStatus) 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(",");
}
}
StringBuilder sql = new StringBuilder("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 = ?");
if (deviceOwner != null && !deviceOwner.isEmpty()) {
sql.append(" AND e.OWNER LIKE ?");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
sql.append(" AND e.STATUS = ?");
}
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.toString())) {
stmt.setInt(1, tenantId); int index = 1;
stmt.setInt(index++, tenantId);
for (String status : allowingDeviceStatuses) {
stmt.setString(index++, status);
}
stmt.setInt(index++, deviceTypeId);
if (deviceOwner != null && !deviceOwner.isEmpty()) {
stmt.setString(index++, "%" + deviceOwner + "%");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
stmt.setString(index++, deviceStatus);
}
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {

@ -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,
String deviceOwner, String deviceName, String deviceStatus, 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,7 +1455,15 @@ 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<>();
String sql = StringBuilder statusPlaceholders = new StringBuilder();
for (int i = 0; i < allowedStatuses.size(); i++) {
statusPlaceholders.append("?");
if (i < allowedStatuses.size() - 1) {
statusPlaceholders.append(",");
}
}
StringBuilder sql = new StringBuilder(
"SELECT " + "SELECT " +
" g.ID AS GROUP_ID, " + " g.ID AS GROUP_ID, " +
" g.GROUP_NAME, " + " g.GROUP_NAME, " +
@ -1473,16 +1482,45 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
"WHERE " + "WHERE " +
" g.GROUP_NAME = ? " + " g.GROUP_NAME = ? " +
" AND g.TENANT_ID = ? " + " AND g.TENANT_ID = ? " +
"LIMIT ? OFFSET ?"; " AND d.DEVICE_TYPE_ID = ? " +
" AND e.STATUS IN (" + statusPlaceholders + ")");
if (deviceOwner != null && !deviceOwner.isEmpty()) {
sql.append(" AND e.OWNER LIKE ?");
}
if (deviceName != null && !deviceName.isEmpty()) {
sql.append(" AND d.NAME LIKE ?");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
sql.append(" AND e.STATUS = ?");
}
sql.append(" 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.toString())) {
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);
}
if (deviceOwner != null && !deviceOwner.isEmpty()) {
stmt.setString(index++, "%" + deviceOwner + "%");
}
if (deviceName != null && !deviceName.isEmpty()) {
stmt.setString(index++, "%" + deviceName + "%");
}
if (deviceStatus != null && !deviceStatus.isEmpty()) {
stmt.setString(index++, deviceStatus);
}
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,6 +1538,7 @@ 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);
@ -1508,7 +1547,6 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
groupDetails.setDeviceTypes(deviceTypes); groupDetails.setDeviceTypes(deviceTypes);
groupDetails.setDeviceIdentifiers(deviceIdentifiers); groupDetails.setDeviceIdentifiers(deviceIdentifiers);
return groupDetails; return groupDetails;
}
} catch (SQLException e) { } catch (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);

@ -1082,27 +1082,40 @@ 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]
* @param deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @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, String deviceOwner, String deviceName, String deviceStatus)
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.
* *
* @param deviceId the deviceId of the device. * @param deviceId the deviceId of the device.
* @param deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @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 getOwnerWithDeviceByDeviceId(int deviceId) throws DeviceManagementDAOException; OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, String deviceOwner, String deviceName, String deviceStatus)
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.
* @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
* @param deviceOwner owner of the device
* @param deviceStatus status of the device
* @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, String deviceOwner, String deviceStatus)
throws DeviceManagementDAOException;
/** /**
* Get operation details by operation code. * Get operation details by operation code.

@ -5354,13 +5354,19 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException { public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId, String deviceOwner, String deviceName, String deviceStatus)
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, deviceOwner, deviceName, deviceStatus);
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);
@ -5384,13 +5390,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId) throws DeviceManagementDAOException { public OwnerWithDeviceDTO getOwnerWithDeviceByDeviceId(int deviceId, String deviceOwner, String deviceName, String deviceStatus)
throws DeviceManagementDAOException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
OwnerWithDeviceDTO deviceOwnerWithStatus; OwnerWithDeviceDTO deviceOwnerWithStatus;
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
deviceOwnerWithStatus = enrollmentDAO.getOwnerWithDeviceByDeviceId(deviceId, tenantId); deviceOwnerWithStatus = enrollmentDAO.getOwnerWithDeviceByDeviceId(deviceId, tenantId, deviceOwner, deviceName, deviceStatus);
if (deviceOwnerWithStatus == null) { if (deviceOwnerWithStatus == null) {
throw new DeviceManagementDAOException("No data found for device ID: " + deviceId); throw new DeviceManagementDAOException("No data found for device ID: " + deviceId);
} }
@ -5411,11 +5418,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException { public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, int deviceTypeId, String deviceOwner, String deviceStatus)
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, deviceOwner, deviceStatus);
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,16 @@ 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 deviceOwner owner of the device
* @param deviceName name of the device
* @param deviceStatus status of the device
* @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, String deviceOwner, String deviceName, String deviceStatus,
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.EnrolmentInfo;
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;
@ -1688,17 +1689,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
} }
@Override @Override
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit) public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, String deviceOwner, String deviceName, String deviceStatus,
throws GroupManagementException { int offset, int limit) 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, deviceOwner, deviceName, deviceStatus, 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…
Cancel
Save