|
|
|
@ -19,17 +19,28 @@
|
|
|
|
|
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.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 +56,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;
|
|
|
|
@ -1505,16 +1507,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
|
|
|
|
|
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,20 +1537,14 @@ 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);
|
|
|
|
|
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();
|
|
|
|
@ -1565,39 +1564,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 {
|
|
|
|
|