Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

...

14 Commits

Author SHA1 Message Date
Nipuni Kavindya 1e3d5cc9b5 Merge branch 'appm_improvement' of https://repository.entgra.net/community/device-mgt-core into appm
6 months ago
Nipuni Kavindya 0742d467db Modify Get data according to Subscribed or Unsubscribed statuses
6 months ago
Kavin Prathaban 1ea3a44859 Modify methods to categorize device subscriptions
6 months ago
Nipuni Kavindya b3c2c8a524 Modify Get data according to Subscribed or Unsubscribed statuses
6 months ago
Nipuni Kavindya 0ea302bf94 Get data according to Subscribed or Unsubscribed statuses in Role base subscriptions
6 months ago
Nipuni Kavindya 6373357cfe Get data according to Subscribed or Unsubscribed statuses
6 months ago
Nipuni Kavindya 15c3906d36 Feature to manage subscription type base subscriptions and Installation Percentage Calculation based on groups, users
6 months ago
Nipuni Kavindya d2adbd54e8 Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core
6 months ago
Nipuni Kavindya 30cb23ecb3 Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core
6 months ago
Nipuni Kavindya b336150eb8 Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core
7 months ago
Nipuni Kavindya 321b8ffe67 Merge branch 'master' of https://repository.entgra.net/community/device-mgt-core
7 months ago
Nipuni Kavindya 539ec8bec6 Merge remote-tracking branch 'origin/master'
7 months ago
Gimhan Wijayawardana 4d11b4a657 Implement multi value (status) filtering for getting activity details
7 months ago
Gimhan Wijayawardana 84d948a532 Implement multi value (status) filtering for getting activity details
7 months ago

@ -0,0 +1,41 @@
package io.entgra.device.mgt.core.application.mgt.common;
import java.util.List;
public class CategorizedSubscriptionResult {
private List<DeviceSubscriptionData> installedDevices;
private List<DeviceSubscriptionData> pendingDevices;
private List<DeviceSubscriptionData> errorDevices;
public CategorizedSubscriptionResult(List<DeviceSubscriptionData> installedDevices,
List<DeviceSubscriptionData> pendingDevices,
List<DeviceSubscriptionData> errorDevices) {
this.installedDevices = installedDevices;
this.pendingDevices = pendingDevices;
this.errorDevices = errorDevices;
}
public List<DeviceSubscriptionData> getInstalledDevices() {
return installedDevices;
}
public void setInstalledDevices(List<DeviceSubscriptionData> installedDevices) {
this.installedDevices = installedDevices;
}
public List<DeviceSubscriptionData> getPendingDevices() {
return pendingDevices;
}
public void setPendingDevices(List<DeviceSubscriptionData> pendingDevices) {
this.pendingDevices = pendingDevices;
}
public List<DeviceSubscriptionData> getErrorDevices() {
return errorDevices;
}
public void setErrorDevices(List<DeviceSubscriptionData> errorDevices) {
this.errorDevices = errorDevices;
}
}

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.application.mgt.common.services;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
@ -30,6 +31,7 @@ import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
@ -194,7 +196,7 @@ public interface SubscriptionManager {
* application release for given UUID, if an error occurred while getting device details of subscribed device ids,
* if an error occurred while getting subscription details of given application release UUID.
*/
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action, String installedVersion)
CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action, String installedVersion)
throws ApplicationManagementException;
/***
@ -217,4 +219,41 @@ public interface SubscriptionManager {
* @throws {@link SubscriptionManagementException} Exception of the subscription management
*/
Activity getOperationAppDetails(String id) throws SubscriptionManagementException;
/**
* Retrieves the group details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing group details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<Map<String, Object>> getGroupsSubDetailsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException;
/**
* Retrieves the user details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing user details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<Map<String, Object>> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException;
/**
* Retrieves the Role details associated with a given app release UUID.
*
* @param uuid the UUID of the app release
* @return a list of maps containing role details and their associated devices
* @throws ApplicationManagementException if an error occurs while fetching the group details
*/
List<Map<String, Object>> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException;
/**
* This method is responsible for retrieving device subscription details related to the given UUID.
*
* @param uuid the UUID of the application release.
* @return List of device subscription details.
* @throws SubscriptionManagementException if there is an error while fetching the details.
*/
List<Map<String, Object>> getDeviceSubscriptionsOperationsByUUID(String uuid) throws ApplicationManagementException;
}

@ -312,4 +312,47 @@ public interface SubscriptionDAO {
* @throws ApplicationManagementDAOException thrown if an error occurs while deleting data
*/
void deleteScheduledSubscriptionByTenant(int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of groups related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return groupDetails - list of group details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment fails.
*/
List<Map<String, Object>> getGroupsSubByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of user subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return userSubscriptions - list of user subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<Map<String, Object>> getUserSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of role subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param unsubscribe the Status of the subscription.
* @param tenantId id of the current tenant.
* @return roleSubscriptions - list of role subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<Map<String, Object>> getRoleSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the details of device subscriptions related to a UUID.
*
* @param uuid the UUID of the application release.
* @param tenantId id of the current tenant.
* @return deviceSubscriptions - list of device subscription details related to the UUID.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<Map<String, Object>> getDeviceSubscriptionsOperationsByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException;
}

@ -1635,4 +1635,219 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<Map<String, Object>> getGroupsSubByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get groups related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<Map<String, Object>> groupDetails = new ArrayList<>();
String sql = "SELECT GS.GROUP_NAME, GS.SUBSCRIBED_BY, GS.SUBSCRIBED_TIMESTAMP, GS.UNSUBSCRIBED, " +
"GS.UNSUBSCRIBED_BY, GS.UNSUBSCRIBED_TIMESTAMP, GS.AP_APP_RELEASE_ID " +
"FROM AP_GROUP_SUBSCRIPTION GS " +
"JOIN AP_APP_RELEASE AR ON GS.AP_APP_RELEASE_ID = AR.ID " +
"WHERE AR.UUID = ? AND GS.UNSUBSCRIBED = ? AND AR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String groupName = rs.getString("GROUP_NAME");
String subscribedBy = rs.getString("SUBSCRIBED_BY");
String subscribedTimestamp = rs.getString("SUBSCRIBED_TIMESTAMP");
boolean unsubscribed = rs.getBoolean("UNSUBSCRIBED");
String unsubscribedBy = rs.getString("UNSUBSCRIBED_BY");
String unsubscribedTimestamp = rs.getString("UNSUBSCRIBED_TIMESTAMP");
int appReleaseId = rs.getInt("AP_APP_RELEASE_ID");
Map<String, Object> groupDetail = new HashMap<>();
groupDetail.put("GroupName", groupName);
groupDetail.put("SubscribedBy", subscribedBy);
groupDetail.put("SubscribedTimestamp", subscribedTimestamp);
groupDetail.put("Unsubscribed", unsubscribed);
groupDetail.put("UnsubscribedBy", unsubscribedBy);
groupDetail.put("UnsubscribedTimestamp", unsubscribedTimestamp);
groupDetail.put("AppReleaseId", appReleaseId);
groupDetails.add(groupDetail);
}
}
return groupDetails;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get groups for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting groups for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<Map<String, Object>> getUserSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get user subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<Map<String, Object>> userSubscriptions = new ArrayList<>();
String sql = "SELECT US.USER_NAME, US.SUBSCRIBED_BY, US.SUBSCRIBED_TIMESTAMP, US.UNSUBSCRIBED, " +
"US.UNSUBSCRIBED_BY, US.UNSUBSCRIBED_TIMESTAMP, US.AP_APP_RELEASE_ID, AR.UUID " +
"FROM AP_USER_SUBSCRIPTION US " +
"JOIN AP_APP_RELEASE AR ON US.AP_APP_RELEASE_ID = AR.ID " +
"WHERE AR.UUID = ? AND US.UNSUBSCRIBED = ? AND AR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String userName = rs.getString("USER_NAME");
String subscribedBy = rs.getString("SUBSCRIBED_BY");
Timestamp subscribedTimestamp = rs.getTimestamp("SUBSCRIBED_TIMESTAMP");
boolean unsubscribed = rs.getBoolean("UNSUBSCRIBED");
String unsubscribedBy = rs.getString("UNSUBSCRIBED_BY");
Timestamp unsubscribedTimestamp = rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP");
int appReleaseId = rs.getInt("AP_APP_RELEASE_ID");
Map<String, Object> userSubscription = new HashMap<>();
userSubscription.put("UserName", userName);
userSubscription.put("SubscribedBy", subscribedBy);
userSubscription.put("SubscribedTimestamp", subscribedTimestamp);
userSubscription.put("Unsubscribed", unsubscribed);
userSubscription.put("UnsubscribedBy", unsubscribedBy);
userSubscription.put("UnsubscribedTimestamp", unsubscribedTimestamp);
userSubscription.put("AppReleaseId", appReleaseId);
userSubscriptions.add(userSubscription);
}
}
return userSubscriptions;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get user subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting user subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<Map<String, Object>> getRoleSubscriptionsByUUID(String uuid, boolean unsubscribe, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get role subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<Map<String, Object>> roleSubscriptions = new ArrayList<>();
String sql = "SELECT ARS.ROLE_NAME, ARS.SUBSCRIBED_BY, ARS.SUBSCRIBED_TIMESTAMP, ARS.UNSUBSCRIBED, " +
"ARS.UNSUBSCRIBED_BY, ARS.UNSUBSCRIBED_TIMESTAMP, ARS.AP_APP_RELEASE_ID " +
"FROM AP_ROLE_SUBSCRIPTION ARS " +
"JOIN AP_APP_RELEASE AAR ON ARS.AP_APP_RELEASE_ID = AAR.ID " +
"WHERE AAR.UUID = ? AND ARS.UNSUBSCRIBED = ? AND AAR.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setBoolean(2, unsubscribe);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String roleName = rs.getString("ROLE_NAME");
String subscribedBy = rs.getString("SUBSCRIBED_BY");
Timestamp subscribedTimestamp = rs.getTimestamp("SUBSCRIBED_TIMESTAMP");
boolean unsubscribed = rs.getBoolean("UNSUBSCRIBED");
String unsubscribedBy = rs.getString("UNSUBSCRIBED_BY");
Timestamp unsubscribedTimestamp = rs.getTimestamp("UNSUBSCRIBED_TIMESTAMP");
int appReleaseId = rs.getInt("AP_APP_RELEASE_ID");
Map<String, Object> roleSubscription = new HashMap<>();
roleSubscription.put("RoleName", roleName);
roleSubscription.put("SubscribedBy", subscribedBy);
roleSubscription.put("SubscribedTimestamp", subscribedTimestamp);
roleSubscription.put("Unsubscribed", unsubscribed);
roleSubscription.put("UnsubscribedBy", unsubscribedBy);
roleSubscription.put("UnsubscribedTimestamp", unsubscribedTimestamp);
roleSubscription.put("AppReleaseId", appReleaseId);
roleSubscriptions.add(roleSubscription);
}
}
return roleSubscriptions;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get role subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting role subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public List<Map<String, Object>> getDeviceSubscriptionsOperationsByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get device subscriptions related to the given UUID.");
}
try {
Connection conn = this.getDBConnection();
List<Map<String, Object>> deviceSubscriptions = new ArrayList<>();
String sql = "SELECT " +
" aar.UUID, " +
" ads.DM_DEVICE_ID, " +
" aasom.OPERATION_ID, " +
" ads.STATUS, " +
" ads.ACTION_TRIGGERED_FROM, " +
" ads.SUBSCRIBED_TIMESTAMP AS ACTION_TRIGGERED_AT, " +
" ads.AP_APP_RELEASE_ID " +
"FROM AP_APP_SUB_OP_MAPPING aasom " +
"JOIN AP_DEVICE_SUBSCRIPTION ads ON aasom.AP_DEVICE_SUBSCRIPTION_ID = ads.ID " +
"JOIN AP_APP_RELEASE aar ON ads.AP_APP_RELEASE_ID = aar.ID " +
"WHERE aar.UUID = ? AND aar.TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, uuid);
ps.setInt(2, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
int deviceId = rs.getInt("DM_DEVICE_ID");
String retrievedUUID = rs.getString("UUID");
String status = rs.getString("STATUS");
int operationId = rs.getInt("OPERATION_ID");
String actionTriggeredFrom = rs.getString("ACTION_TRIGGERED_FROM");
Timestamp actionTriggeredAt = rs.getTimestamp("ACTION_TRIGGERED_AT");
int appReleaseId = rs.getInt("AP_APP_RELEASE_ID");
Map<String, Object> deviceSubscription = new HashMap<>();
deviceSubscription.put("DeviceId", deviceId);
deviceSubscription.put("UUID", retrievedUUID);
deviceSubscription.put("Status", status);
deviceSubscription.put("OperationId", operationId);
deviceSubscription.put("ActionTriggeredFrom", actionTriggeredFrom);
deviceSubscription.put("ActionTriggeredAt", actionTriggeredAt);
deviceSubscription.put("AppReleaseId", appReleaseId);
deviceSubscriptions.add(deviceSubscription);
}
}
}
return deviceSubscriptions;
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get device subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting device subscriptions for the given UUID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -19,17 +19,29 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
import io.entgra.device.mgt.core.application.mgt.common.CategorizedSubscriptionResult;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.SubAction;
import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
@ -45,15 +57,6 @@ import org.json.JSONObject;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationSubscriptionInfo;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
import io.entgra.device.mgt.core.application.mgt.common.DeviceSubscriptionData;
import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes;
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
import io.entgra.device.mgt.core.application.mgt.common.SubAction;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.SubscribingDeviceIdHolder;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationPolicyDTO;
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
@ -99,6 +102,7 @@ import io.entgra.device.mgt.core.device.mgt.core.util.MDMIOSOperationUtil;
import io.entgra.device.mgt.core.device.mgt.core.util.MDMWindowsOperationUtil;
import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import javax.ws.rs.core.MediaType;
import java.io.BufferedReader;
@ -1505,16 +1509,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
String action, String installedVersion) throws ApplicationManagementException {
public CategorizedSubscriptionResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
String action, String installedVersion) throws ApplicationManagementException {
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<DeviceSubscriptionData> installedDevices = new ArrayList<>();
List<DeviceSubscriptionData> pendingDevices = new ArrayList<>();
List<DeviceSubscriptionData> errorDevices = new ArrayList<>();
if (offsetValue < 0 || limitValue <= 0) {
String msg = "Found incompatible values for offset and limit. Hence please check the request and resend. "
+ "Offset " + offsetValue + " limit " + limitValue;
String msg = "Found incompatible values for offset and limit. Hence please check the request and resend. " +
"Offset " + offsetValue + " limit " + limitValue;
log.error(msg);
throw new BadRequestException(msg);
}
@ -1532,31 +1539,25 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId, actionStatus, action);
if (deviceSubscriptionDTOS.isEmpty()) {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
return new CategorizedSubscriptionResult(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
}
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
Map<Integer,String> currentVersionsMap = subscriptionDAO.getCurrentInstalledAppVersion(applicationDTO.getId(),deviceIdList, installedVersion);
Map<Integer, String> currentVersionsMap = subscriptionDAO.getCurrentInstalledAppVersion(applicationDTO.getId(), deviceIdList, installedVersion);
try {
//pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices
(request, deviceIdList);
List<DeviceSubscriptionData> deviceSubscriptionDataList = new ArrayList<>();
// Pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices(request, deviceIdList);
if (!paginationResult.getData().isEmpty()) {
List<Device> devices = (List<Device>) paginationResult.getData();
for (Device device : devices) {
if(installedVersion != null && !installedVersion.isEmpty() && !currentVersionsMap.containsKey(device.getId())){
if (installedVersion != null && !installedVersion.isEmpty() && !currentVersionsMap.containsKey(device.getId())) {
continue;
}
DeviceSubscriptionData deviceSubscriptionData = new DeviceSubscriptionData();
if(currentVersionsMap.containsKey(device.getId())){
if (currentVersionsMap.containsKey(device.getId())) {
deviceSubscriptionData.setCurrentInstalledVersion(currentVersionsMap.get(device.getId()));
}else{
} else {
deviceSubscriptionData.setCurrentInstalledVersion("-");
}
for (DeviceSubscriptionDTO subscription : deviceSubscriptionDTOS) {
@ -1565,39 +1566,51 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscription.isUnsubscribed()) {
deviceSubscriptionData.setAction(Constants.UNSUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getUnsubscribedBy());
deviceSubscriptionData
.setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp().getTime() / 1000);
deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getUnsubscribedTimestamp().getTime() / 1000);
} else {
deviceSubscriptionData.setAction(Constants.SUBSCRIBED);
deviceSubscriptionData.setActionTriggeredBy(subscription.getSubscribedBy());
deviceSubscriptionData
.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp().getTime() / 1000);
deviceSubscriptionData.setActionTriggeredTimestamp(subscription.getSubscribedTimestamp().getTime() / 1000);
}
deviceSubscriptionData.setActionType(subscription.getActionTriggeredFrom());
deviceSubscriptionData.setStatus(subscription.getStatus());
deviceSubscriptionData.setSubId(subscription.getId());
deviceSubscriptionDataList.add(deviceSubscriptionData);
// Categorize the subscription data based on its status
switch (subscription.getStatus()) {
case "COMPLETED":
installedDevices.add(deviceSubscriptionData);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceSubscriptionData);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceSubscriptionData);
break;
}
break;
}
}
}
}
paginationResult.setData(deviceSubscriptionDataList);
return paginationResult;
return new CategorizedSubscriptionResult(installedDevices, pendingDevices, errorDevices);
} catch (DeviceManagementException e) {
String msg = "service error occurred while getting device data from the device management service. "
+ "Device ids " + deviceIdList;
String msg = "Service error occurred while getting device data from the device management service. " +
"Device ids " + deviceIdList;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred when getting application release data for application release UUID: " + appUUID;
String msg = "Error occurred when getting application release data for application release UUID: " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while trying to get subscription data of application which has "
+ "application release UUID " + appUUID;
String msg = "DB Connection error occurred while trying to get subscription data of application which has " +
"application release UUID " + appUUID;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
@ -1675,4 +1688,419 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
public List<Map<String, Object>> getGroupsSubDetailsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
try {
ConnectionManagerUtil.openDBConnection();
List<Map<String, Object>> groupDetailsWithDevices = new ArrayList<>();
List<Map<String, Object>> groupDetails = subscriptionDAO.getGroupsSubByUUID(uuid, unsubscribe, tenantId);
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
for (Map<String, Object> groupDetail : groupDetails) {
String groupName = (String) groupDetail.get("GroupName");
// Retrieve group details and device IDs for the group using the service layer
Map<String, Object> groupDetailWithDevices = groupManagementProviderService.getGroupDetailsWithDeviceIds(groupName);
// map to hold the response data
Map<String, Object> groupDetailMap = new HashMap<>();
groupDetailMap.put("GroupID", groupDetailWithDevices.get("GroupID"));
groupDetailMap.put("GroupName", groupDetail.get("GroupName"));
groupDetailMap.put("GroupOwner", groupDetailWithDevices.get("GroupOwner"));
groupDetailMap.put("SubscribedBy", groupDetail.get("SubscribedBy"));
groupDetailMap.put("SubscribedTimestamp", groupDetail.get("SubscribedTimestamp"));
groupDetailMap.put("Unsubscribed", groupDetail.get("Unsubscribed"));
groupDetailMap.put("UnsubscribedBy", groupDetail.get("UnsubscribedBy"));
groupDetailMap.put("UnsubscribedTimestamp", groupDetail.get("UnsubscribedTimestamp"));
groupDetailMap.put("AppReleaseId", groupDetail.get("AppReleaseId"));
groupDetailMap.put("DeviceCount", groupDetailWithDevices.get("DeviceCount"));
// Fetch device subscriptions for each device ID in the group
List<Map<String, Object>> pendingDevices = new ArrayList<>();
List<Map<String, Object>> installedDevices = new ArrayList<>();
List<Map<String, Object>> errorDevices = new ArrayList<>();
List<Map<String, Object>> newDevices = new ArrayList<>();
List<Integer> deviceIds = (List<Integer>) groupDetailWithDevices.get("DeviceIds");
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptions(
(Integer) groupDetail.get("AppReleaseId"), tenantId, null, null);
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
Map<String, Object> deviceDetailMap = new HashMap<>();
deviceDetailMap.put("DeviceID", subscription.getDeviceId());
// deviceDetailMap.put("Status", subscription.getStatus()); // if need to get the real status
String status = subscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetailMap);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetailMap);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetailMap);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
Map<String, Object> newDeviceDetailMap = new HashMap<>();
newDeviceDetailMap.put("DeviceID", deviceId);
newDevices.add(newDeviceDetailMap);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
int totalDevices = deviceIds.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
Map<String, Object> devicesMap = new HashMap<>();
devicesMap.put("PendingDevices", pendingDevices);
devicesMap.put("InstalledDevices", installedDevices);
devicesMap.put("ErrorDevices", errorDevices);
devicesMap.put("NewDevices", newDevices);
groupDetailMap.put("Devices", devicesMap);
groupDetailMap.put("StatusPercentages", statusPercentages);
groupDetailsWithDevices.add(groupDetailMap);
}
return groupDetailsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while fetching groups and devices for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while fetching groups and devices for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (GroupManagementException e) {
String msg = "Error occurred while fetching group details and device IDs: " + e.getMessage();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public List<Map<String, Object>> getUserSubscriptionsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
try {
ConnectionManagerUtil.openDBConnection();
List<Map<String, Object>> userSubscriptions = subscriptionDAO.getUserSubscriptionsByUUID(uuid, unsubscribe, tenantId);
List<Map<String, Object>> userSubscriptionsWithDevices = new ArrayList<>();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (Map<String, Object> userSubscription : userSubscriptions) {
String userName = (String) userSubscription.get("UserName");
// Retrieve owner details and device IDs for the user using the service layer
Map<String, Object> ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(userName);
Map<String, Object> userSubscriptionMap = new HashMap<>();
userSubscriptionMap.put("UserName", userSubscription.get("UserName"));
userSubscriptionMap.put("SubscribedBy", userSubscription.get("SubscribedBy"));
userSubscriptionMap.put("SubscribedTimestamp", userSubscription.get("SubscribedTimestamp"));
userSubscriptionMap.put("Unsubscribed", userSubscription.get("Unsubscribed"));
userSubscriptionMap.put("UnsubscribedBy", userSubscription.get("UnsubscribedBy"));
userSubscriptionMap.put("UnsubscribedTimestamp", userSubscription.get("UnsubscribedTimestamp"));
userSubscriptionMap.put("AppReleaseId", userSubscription.get("AppReleaseId"));
userSubscriptionMap.put("DeviceCount", ownerDetailsWithDevices.get("DeviceCount"));
// Fetch device subscriptions for each device ID associated with the user
List<Map<String, Object>> pendingDevices = new ArrayList<>();
List<Map<String, Object>> installedDevices = new ArrayList<>();
List<Map<String, Object>> errorDevices = new ArrayList<>();
List<Map<String, Object>> newDevices = new ArrayList<>();
List<Integer> deviceIds = (List<Integer>) ownerDetailsWithDevices.get("DeviceIds");
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptions(
(Integer) userSubscription.get("AppReleaseId"), tenantId, null, null);
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
Map<String, Object> deviceDetailMap = new HashMap<>();
deviceDetailMap.put("DeviceID", subscription.getDeviceId());
// deviceDetailMap.put("Status", subscription.getStatus());
String status = subscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetailMap);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetailMap);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetailMap);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
Map<String, Object> newDeviceDetailMap = new HashMap<>();
newDeviceDetailMap.put("DeviceID", deviceId);
newDevices.add(newDeviceDetailMap);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
int totalDevices = deviceIds.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
Map<String, Object> devicesMap = new HashMap<>();
devicesMap.put("PendingDevices", pendingDevices);
devicesMap.put("InstalledDevices", installedDevices);
devicesMap.put("ErrorDevices", errorDevices);
devicesMap.put("NewDevices", newDevices);
userSubscriptionMap.put("Devices", devicesMap);
userSubscriptionMap.put("StatusPercentages", statusPercentages);
userSubscriptionsWithDevices.add(userSubscriptionMap);
}
return userSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting user subscriptions for the application release UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting user subscriptions for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
throw new RuntimeException(e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public List<Map<String, Object>> getRoleSubscriptionsByUUID(String uuid, String subscriptionStatus) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean unsubscribe = subscriptionStatus.equals("unsubscribed");
try {
ConnectionManagerUtil.openDBConnection();
List<Map<String, Object>> roleSubscriptions = subscriptionDAO.getRoleSubscriptionsByUUID(uuid, unsubscribe, tenantId);
List<Map<String, Object>> roleSubscriptionsWithDevices = new ArrayList<>();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
for (Map<String, Object> roleSubscription : roleSubscriptions) {
String roleName = (String) roleSubscription.get("RoleName");
Map<String, Object> roleSubscriptionMap = new HashMap<>();
roleSubscriptionMap.put("RoleName", roleName);
roleSubscriptionMap.put("SubscribedBy", roleSubscription.get("SubscribedBy"));
roleSubscriptionMap.put("SubscribedTimestamp", roleSubscription.get("SubscribedTimestamp"));
roleSubscriptionMap.put("Unsubscribed", roleSubscription.get("Unsubscribed"));
roleSubscriptionMap.put("UnsubscribedBy", roleSubscription.get("UnsubscribedBy"));
roleSubscriptionMap.put("UnsubscribedTimestamp", roleSubscription.get("UnsubscribedTimestamp"));
roleSubscriptionMap.put("AppReleaseId", roleSubscription.get("AppReleaseId"));
List<Map<String, Object>> pendingDevices = new ArrayList<>();
List<Map<String, Object>> installedDevices = new ArrayList<>();
List<Map<String, Object>> errorDevices = new ArrayList<>();
List<Map<String, Object>> newDevices = new ArrayList<>();
Map<String, Integer> statusCounts = new HashMap<>();
statusCounts.put("PENDING", 0);
statusCounts.put("COMPLETED", 0);
statusCounts.put("ERROR", 0);
statusCounts.put("NEW", 0);
List<String> users = this.getUsersForRole(roleName);
for (String user : users) {
// Retrieve owner details and device IDs for the user using the service layer
Map<String, Object> ownerDetailsWithDevices;
try {
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user);
} catch (DeviceManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e);
}
// Fetch device subscriptions for each device ID associated with the user
List<Integer> deviceIds = (List<Integer>) ownerDetailsWithDevices.get("DeviceIds");
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions;
try {
deviceSubscriptions = subscriptionDAO.getDeviceSubscriptions(
(Integer) roleSubscription.get("AppReleaseId"), tenantId, null, null);
} catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving device subscriptions", e);
}
boolean isNewDevice = true;
for (DeviceSubscriptionDTO deviceSubscription : deviceSubscriptions) {
if (deviceSubscription.getDeviceId() == deviceId) {
Map<String, Object> deviceDetailMap = new HashMap<>();
deviceDetailMap.put("DeviceID", deviceSubscription.getDeviceId());
// deviceDetailMap.put("Status", deviceSubscription.getStatus());
String status = deviceSubscription.getStatus();
switch (status) {
case "COMPLETED":
installedDevices.add(deviceDetailMap);
statusCounts.put("COMPLETED", statusCounts.get("COMPLETED") + 1);
break;
case "ERROR":
case "INVALID":
case "UNAUTHORIZED":
errorDevices.add(deviceDetailMap);
statusCounts.put("ERROR", statusCounts.get("ERROR") + 1);
break;
case "IN_PROGRESS":
case "PENDING":
case "REPEATED":
pendingDevices.add(deviceDetailMap);
statusCounts.put("PENDING", statusCounts.get("PENDING") + 1);
break;
}
isNewDevice = false;
}
}
if (isNewDevice) {
Map<String, Object> newDeviceDetailMap = new HashMap<>();
newDeviceDetailMap.put("DeviceID", deviceId);
newDevices.add(newDeviceDetailMap);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
}
}
int totalDevices = pendingDevices.size() + installedDevices.size() + errorDevices.size() + newDevices.size();
Map<String, Double> statusPercentages = new HashMap<>();
for (Map.Entry<String, Integer> entry : statusCounts.entrySet()) {
double percentage = totalDevices == 0 ? 0.0 : ((double) entry.getValue() / totalDevices) * 100;
statusPercentages.put(entry.getKey(), percentage);
}
Map<String, Object> devicesMap = new HashMap<>();
devicesMap.put("PendingDevices", pendingDevices);
devicesMap.put("InstalledDevices", installedDevices);
devicesMap.put("ErrorDevices", errorDevices);
devicesMap.put("NewDevices", newDevices);
roleSubscriptionMap.put("Devices", devicesMap);
roleSubscriptionMap.put("StatusPercentages", statusPercentages);
roleSubscriptionMap.put("DeviceCount", totalDevices);
roleSubscriptionsWithDevices.add(roleSubscriptionMap);
}
return roleSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred in retrieving role subscriptions with devices";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while retrieving the database connection";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving users for role";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
// Get user list for each role
public List<String> getUsersForRole(String roleName) throws UserStoreException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
int tenantId = ctx.getTenantId();
UserStoreManager userStoreManager = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
String[] users = userStoreManager.getUserListOfRole(roleName);
return Arrays.asList(users);
}
@Override
public List<Map<String, Object>> getDeviceSubscriptionsOperationsByUUID(String uuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (uuid == null || uuid.isEmpty()) {
throw new IllegalArgumentException("UUID cannot be null or empty.");
}
try {
ConnectionManagerUtil.openDBConnection();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<Map<String, Object>> deviceSubscriptions = subscriptionDAO.getDeviceSubscriptionsOperationsByUUID(uuid, tenantId);
for (Map<String, Object> deviceSubscription : deviceSubscriptions) {
Integer operationId = (Integer) deviceSubscription.get("OperationId");
if (operationId != null) {
Map<String, Object> operationDetails = deviceManagementProviderService.getOperationDetailsById(operationId);
if (operationDetails != null) {
deviceSubscription.put("OperationCode", operationDetails.get("OperationCode"));
deviceSubscription.put("OperationDetails", operationDetails.get("OperationDetails"));
deviceSubscription.put("OperationProperties", operationDetails.get("OperationProperties"));
}
}
}
return deviceSubscriptions;
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while retrieving device subscriptions for UUID: " + uuid;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while retrieving the database connection";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (OperationManagementException e) {
throw new RuntimeException(e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
}

@ -24,6 +24,7 @@ import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo.Status;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
public interface EnrollmentDAO {
@ -94,5 +95,13 @@ public interface EnrollmentDAO {
*/
boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException;
/**
* Retrieves owners and the list of device IDs related to an owner.
*
* @param owner the owner whose device IDs need to be retrieved
* @param tenantId the ID of the tenant
* @return a map containing owner details, device IDs, and device count
* @throws DeviceManagementDAOException if an error occurs while fetching the data
*/
Map<String, Object> getOwnersWithDeviceIds(String owner, int tenantId) throws DeviceManagementDAOException;
}

@ -469,4 +469,14 @@ public interface GroupDAO {
List<String> groupNames)
throws GroupManagementDAOException;
/**
* Get group details and list of device IDs related to the group.
*
* @param groupName Group name
* @param tenantId Tenant ID
* @return A map containing group details and a list of device IDs
* @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
*/
Map<String, Object> getGroupDetailsWithDeviceIds(String groupName, int tenantId) throws GroupManagementDAOException;
}

@ -33,9 +33,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
@ -557,4 +555,36 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
return enrolmentInfo;
}
@Override
public Map<String, Object> getOwnersWithDeviceIds(String owner, int tenantId) throws DeviceManagementDAOException {
Map<String, Object> ownerDetails = new HashMap<>();
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
String sql = "SELECT DEVICE_ID, OWNER FROM DM_ENROLMENT WHERE OWNER = ? AND TENANT_ID = ?";
try (Connection conn = this.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, owner);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (ownerDetails.isEmpty()) {
ownerDetails.put("UserName", rs.getString("OWNER"));
}
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++;
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving owners and device IDs for owner: " + owner, e);
}
ownerDetails.put("DeviceIds", deviceIds);
ownerDetails.put("DeviceCount", deviceCount);
return ownerDetails;
}
}

@ -1437,4 +1437,45 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
return groupUnassignedDeviceList;
}
@Override
public Map<String, Object> getGroupDetailsWithDeviceIds(String groupName, int tenantId) throws GroupManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
}
Map<String, Object> groupDetails = new HashMap<>();
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
String sql = "SELECT g.ID AS GROUP_ID, g.GROUP_NAME, g.OWNER, dgm.DEVICE_ID "
+ "FROM DM_GROUP g "
+ "JOIN DM_DEVICE_GROUP_MAP dgm ON g.ID = dgm.GROUP_ID "
+ "WHERE g.GROUP_NAME = ? AND g.TENANT_ID = ?";
try (Connection conn = GroupManagementDAOFactory.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, groupName);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (groupDetails.isEmpty()) {
groupDetails.put("GroupID", rs.getInt("GROUP_ID"));
groupDetails.put("GroupName", rs.getString("GROUP_NAME"));
groupDetails.put("GroupOwner", rs.getString("OWNER"));
}
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++;
}
}
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while retrieving group details and device IDs for group: " + groupName, e);
}
groupDetails.put("DeviceIds", deviceIds);
groupDetails.put("DeviceCount", deviceCount);
return groupDetails;
}
}

@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationResponse;
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.DeviceActivity;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.OperationMapping;
@ -124,4 +125,6 @@ public interface OperationDAO {
int getDeviceActivitiesCount(ActivityPaginationRequest activityPaginationRequest)
throws OperationManagementDAOException;
Map<String, Object> getOperationDetailsById(int operationId, int tenantId) throws OperationManagementDAOException;
}

@ -17,6 +17,8 @@
*/
package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -2774,4 +2776,36 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
return 0;
}
@Override
public Map<String, Object> getOperationDetailsById(int operationId, int tenantId) throws OperationManagementDAOException {
Map<String, Object> operationDetails = new HashMap<>();
String sql = "SELECT ID, OPERATION_CODE, OPERATION_DETAILS, OPERATION_PROPERTIES " +
"FROM DM_OPERATION " +
"WHERE ID = ? AND TENANT_ID = ?";
try (Connection conn = OperationManagementDAOFactory.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, operationId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
String opCode = rs.getString("OPERATION_CODE");
byte[] opDetails = rs.getBytes("OPERATION_DETAILS");
byte[] opProperties = rs.getBytes("OPERATION_PROPERTIES");
operationDetails.put("OperationId", operationId);
operationDetails.put("OperationCode", opCode);
operationDetails.put("OperationDetails", opDetails);
operationDetails.put("OperationProperties", opProperties);
}
}
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while retrieving operation details for operation ID: " + operationId, e);
}
return operationDetails;
}
}

@ -1073,4 +1073,22 @@ public interface DeviceManagementProviderService {
List<Device> getEnrolledDevicesSince(Date since) throws DeviceManagementException;
List<Device> getEnrolledDevicesPriorTo(Date before) throws DeviceManagementException;
void deleteDeviceDataByTenantDomain(String tenantDomain) throws DeviceManagementException;
/**
* Get owner details and device IDs for a given owner and tenant.
*
* @param owner the name of the owner.
* @return a map containing owner details (Owner, DeviceIds, DeviceCount).
* @throws DeviceManagementException if an error occurs while fetching owner details.
*/
Map<String, Object> getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException;
/**
* Get operation details by operation code.
*
* @param operationId the id of the operation.
* @return Map containing operation ID, operation code, operation details, and operation properties.
* @throws OperationManagementException if an error occurs while fetching the operation details.
*/
Map<String, Object> getOperationDetailsById(int operationId) throws OperationManagementException;
}

@ -22,6 +22,8 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl;
@ -120,6 +122,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceStatusDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceTypeDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.EnrollmentDAO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationDAO;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceInformationManager;
@ -173,6 +176,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
private final DeviceDAO deviceDAO;
private final DeviceTypeDAO deviceTypeDAO;
private final EnrollmentDAO enrollmentDAO;
private final OperationDAO operationDAO;
private final ApplicationDAO applicationDAO;
private MetadataDAO metadataDAO;
private final DeviceStatusDAO deviceStatusDAO;
@ -185,6 +189,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
this.operationDAO = OperationManagementDAOFactory.getOperationDAO();
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
this.deviceStatusDAO = DeviceManagementDAOFactory.getDeviceStatusDAO();
this.tenantDao = DeviceManagementDAOFactory.getTenantDAO();
@ -5339,4 +5344,51 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public Map<String, Object> getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Map<String, Object> getOwnersWithWithDevices;
try {
DeviceManagementDAOFactory.openConnection();
getOwnersWithWithDevices = this.enrollmentDAO.getOwnersWithDeviceIds(owner, tenantId);
} catch (DeviceManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving device IDs for owner: " + owner;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
// Add device count to the returned map
if (getOwnersWithWithDevices != null) {
List<Integer> deviceIds = (List<Integer>) getOwnersWithWithDevices.get("DeviceIds");
if (deviceIds != null) {
getOwnersWithWithDevices.put("DeviceCount", deviceIds.size());
} else {
getOwnersWithWithDevices.put("DeviceCount", 0);
}
}
return getOwnersWithWithDevices;
}
@Override
public Map<String, Object> getOperationDetailsById(int operationId) throws OperationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Map<String, Object> operationDetails;
try {
OperationManagementDAOFactory.openConnection();
operationDetails = this.operationDAO.getOperationDetailsById(operationId, tenantId);
} catch (SQLException | OperationManagementDAOException e) {
String msg = "Error occurred while retrieving operation details for operation ID: " + operationId;
log.error(msg, e);
throw new OperationManagementException(msg, e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
return operationDetails;
}
}

@ -34,6 +34,7 @@ import org.wso2.carbon.user.api.AuthorizationManager;
import org.wso2.carbon.user.api.UserStoreManager;
import java.util.List;
import java.util.Map;
/**
* Interface for Group Management Services
@ -371,4 +372,14 @@ public interface GroupManagementProviderService {
DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException;
DeviceGroup getUserOwnGroup(int groupId, boolean requireGroupProps, int depth) throws GroupManagementException;
/**
* Get group details and device IDs for a given group name.
*
* @param groupName the name of the group.
* @return a map containing group details and device IDs.
* @throws GroupManagementException if an error occurs while fetching group details.
*/
Map<String, Object> getGroupDetailsWithDeviceIds(String groupName) throws GroupManagementException;
}

@ -1629,6 +1629,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
createGroupWithChildren(nextParentGroup, childrenGroups, requireGroupProps, tenantId, depth, counter);
}
}
@Override
public DeviceTypesOfGroups getDeviceTypesOfGroups(List<String> identifiers) throws GroupManagementException {
DeviceTypesOfGroups deviceTypesOfGroups = new DeviceTypesOfGroups();
@ -1685,4 +1686,37 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return deviceTypesOfGroups;
}
@Override
public Map<String, Object> getGroupDetailsWithDeviceIds(String groupName) throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Retrieving group details and device IDs for group: " + groupName);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<String, Object> groupDetailsWithDevices;
try {
GroupManagementDAOFactory.openConnection();
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDeviceIds(groupName, tenantId);
} catch (GroupManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally {
GroupManagementDAOFactory.closeConnection();
}
// Add device count to the returned map
if (groupDetailsWithDevices != null) {
List<Integer> deviceIds = (List<Integer>) groupDetailsWithDevices.get("DeviceIds");
if (deviceIds != null) {
groupDetailsWithDevices.put("DeviceCount", deviceIds.size());
} else {
groupDetailsWithDevices.put("DeviceCount", 0);
}
}
return groupDetailsWithDevices;
}
}

Loading…
Cancel
Save