|
|
@ -319,7 +319,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public <T> void performEntAppInstall(String applicationUUID, List<T> params, String subType)
|
|
|
|
public <T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Google Ent app Install operation is received to application which has UUID "
|
|
|
|
log.debug("Google Ent app Install operation is received to application which has UUID "
|
|
|
@ -358,8 +358,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
List<String> subscribers = new ArrayList<>();
|
|
|
|
List<String> subscribers = new ArrayList<>();
|
|
|
|
List<Integer> appInstallingDeviceIds;
|
|
|
|
List<Integer> appSubscribingDeviceIds;
|
|
|
|
List<Integer> appReInstallingDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> appReSubscribingDeviceIds = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
//todo validate users, groups and roles
|
|
|
|
//todo validate users, groups and roles
|
|
|
@ -409,14 +409,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
appInstallingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appInstallingDeviceIds,
|
|
|
|
|
|
|
|
applicationReleaseId);
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription: deviceSubscriptions.entrySet()){
|
|
|
|
|
|
|
|
appReInstallingDeviceIds.add(deviceSubscription.getKey());
|
|
|
|
|
|
|
|
appInstallingDeviceIds.remove(deviceSubscription.getKey());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*If subscription type is not device we need to crete device identifiers object list by referring retrieved
|
|
|
|
/*If subscription type is not device we need to crete device identifiers object list by referring retrieved
|
|
|
|
list of devices.*/
|
|
|
|
list of devices.*/
|
|
|
|
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
|
|
|
|
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
|
|
|
@ -436,11 +428,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
|
|
|
|
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
|
|
|
|
applicationPolicyDTO.setApplicationDTO(applicationDTO);
|
|
|
|
applicationPolicyDTO.setApplicationDTO(applicationDTO);
|
|
|
|
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
|
|
|
|
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
|
|
|
|
applicationPolicyDTO.setAction(SubAction.INSTALL.toString());
|
|
|
|
applicationPolicyDTO.setAction(action);
|
|
|
|
installEnrollmentApplications(applicationPolicyDTO);
|
|
|
|
installEnrollmentApplications(applicationPolicyDTO);
|
|
|
|
|
|
|
|
|
|
|
|
updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds,
|
|
|
|
appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
subscribers, subType);
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds,
|
|
|
|
|
|
|
|
applicationReleaseId);
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription: deviceSubscriptions.entrySet()){
|
|
|
|
|
|
|
|
appReSubscribingDeviceIds.add(deviceSubscription.getKey());
|
|
|
|
|
|
|
|
appSubscribingDeviceIds.remove(deviceSubscription.getKey());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateSubscriptionsForEntInstall(applicationReleaseId, appSubscribingDeviceIds, appReSubscribingDeviceIds,
|
|
|
|
|
|
|
|
subscribers, subType, action);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error occurred while getting devices of given users or given roles.";
|
|
|
|
String msg = "Error occurred while getting devices of given users or given roles.";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
@ -459,10 +459,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
* @param params subscribers. If subscription is performed via user, group or role, params is a list of
|
|
|
|
* @param params subscribers. If subscription is performed via user, group or role, params is a list of
|
|
|
|
* {@link String}
|
|
|
|
* {@link String}
|
|
|
|
* @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE
|
|
|
|
* @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE
|
|
|
|
|
|
|
|
* @param action Performing action. (i.e INSTALL or UNINSTALL)
|
|
|
|
* @throws ApplicationManagementException if error occurred while getting or updating subscription data.
|
|
|
|
* @throws ApplicationManagementException if error occurred while getting or updating subscription data.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appInstallingDeviceIds,
|
|
|
|
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appSubscribingDeviceIds,
|
|
|
|
List<Integer> appReInstallingDeviceIds, List<String> params, String subType)
|
|
|
|
List<Integer> appReSubscribingDeviceIds, List<String> params, String subType, String action)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
@ -470,11 +471,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
List<String> subscribedEntities = new ArrayList<>();
|
|
|
|
List<String> subscribedEntities = new ArrayList<>();
|
|
|
|
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
|
|
|
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
|
|
|
subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
|
|
|
|
subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
|
|
|
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
|
|
|
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
|
|
|
subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId);
|
|
|
|
subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
|
|
|
|
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
|
|
|
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
|
|
|
subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
|
|
|
|
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
@ -484,17 +485,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
if (!subscribedEntities.isEmpty()) {
|
|
|
|
if (!subscribedEntities.isEmpty()) {
|
|
|
|
subscriptionDAO
|
|
|
|
subscriptionDAO
|
|
|
|
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
SubAction.INSTALL.toString());
|
|
|
|
action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!appInstallingDeviceIds.isEmpty()) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action) && !appSubscribingDeviceIds.isEmpty()) {
|
|
|
|
subscriptionDAO.addDeviceSubscription(username, appInstallingDeviceIds, subType,
|
|
|
|
subscriptionDAO.addDeviceSubscription(username, appSubscribingDeviceIds, subType,
|
|
|
|
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
|
|
|
|
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!appReInstallingDeviceIds.isEmpty()) {
|
|
|
|
if (!appReSubscribingDeviceIds.isEmpty()) {
|
|
|
|
subscriptionDAO
|
|
|
|
subscriptionDAO.updateDeviceSubscription(username, appReSubscribingDeviceIds, action, subType,
|
|
|
|
.updateDeviceSubscription(username, appReInstallingDeviceIds, SubAction.INSTALL.toString(),
|
|
|
|
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
|
|
|
|
subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
@ -578,10 +578,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
|
|
|
|
ignoredDeviceIdentifiers
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
|
|
|
|
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
|
|
|
|
|
|
|
|
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
|
|
|
|
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
|
|
|
|
|
|
|
|
deviceIdentifiers
|
|
|
|
|
|
|
|
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet()));
|
|
|
|
ignoredDeviceIdentifiers
|
|
|
|
ignoredDeviceIdentifiers
|
|
|
|
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
|
|
|
|
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -636,10 +637,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices, int appReleaseId)
|
|
|
|
private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices, int appReleaseId)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
Map<DeviceIdentifier, Integer> appInstalledDevices = new HashMap<>();
|
|
|
|
|
|
|
|
Map<DeviceIdentifier, Integer> appInstallableDevices = new HashMap<>();
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
|
|
|
|
Map<DeviceIdentifier, Integer> appReInstallableDevices = new HashMap<>();
|
|
|
|
subscribingDeviceIdHolder.setAppInstallableDevices(new HashMap<>());
|
|
|
|
Map<DeviceIdentifier, Integer> skippedDevices = new HashMap<>();
|
|
|
|
subscribingDeviceIdHolder.setAppInstalledDevices(new HashMap<>());
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setAppReInstallableDevices(new HashMap<>());
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setAppReUnInstallableDevices(new HashMap<>());
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setSkippedDevices(new HashMap<>());
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> deviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
List<Integer> deviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
//get device subscriptions for given device id list.
|
|
|
|
//get device subscriptions for given device id list.
|
|
|
@ -650,23 +654,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
if (deviceSubscriptionDTO != null) {
|
|
|
|
if (deviceSubscriptionDTO != null) {
|
|
|
|
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
|
|
|
|
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
|
|
|
|
.equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
.equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
appInstalledDevices.put(deviceIdentifier, device.getId());
|
|
|
|
subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
|
|
|
|
|
|
|
|
} else if (deviceSubscriptionDTO.isUnsubscribed() && !Operation.Status.COMPLETED.toString()
|
|
|
|
|
|
|
|
.equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId());
|
|
|
|
} else if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus())
|
|
|
|
} else if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus())
|
|
|
|
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
skippedDevices.put(deviceIdentifier, device.getId());
|
|
|
|
subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
appReInstallableDevices.put(deviceIdentifier, device.getId());
|
|
|
|
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
appInstallableDevices.put(deviceIdentifier, device.getId());
|
|
|
|
subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setAppInstallableDevices(appInstallableDevices);
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setAppInstalledDevices(appInstalledDevices);
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setAppReInstallableDevices(appReInstallableDevices);
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setSkippedDevices(skippedDevices);
|
|
|
|
|
|
|
|
return subscribingDeviceIdHolder;
|
|
|
|
return subscribingDeviceIdHolder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -756,7 +757,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
|
|
|
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
|
|
|
List<String> subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
|
|
|
|
List<String> subscribedEntities = subscriptionDAO
|
|
|
|
|
|
|
|
.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
|
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
@ -764,7 +766,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
action);
|
|
|
|
action);
|
|
|
|
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
|
|
|
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
|
|
|
List<String> subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId);
|
|
|
|
List<String> subscribedEntities = subscriptionDAO
|
|
|
|
|
|
|
|
.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
|
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
@ -772,7 +775,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
|
|
|
action);
|
|
|
|
action);
|
|
|
|
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
|
|
|
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
|
|
|
List<String> subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
|
|
|
|
List<String> subscribedEntities = subscriptionDAO
|
|
|
|
|
|
|
|
.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
params.removeAll(subscribedEntities);
|
|
|
|
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
|
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
|
|
|
@ -785,11 +789,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
|
|
|
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
|
|
|
List<Integer> subUpdatingDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> subUpdatingDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> subInsertingDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> subInsertingDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> deviceSubIds = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
|
|
|
|
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
|
|
|
|
subscribingDeviceIdHolder.getAppReInstallableDevices()));
|
|
|
|
subscribingDeviceIdHolder.getAppReInstallableDevices()));
|
|
|
|
|
|
|
|
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.getAppInstalledDevices()));
|
|
|
|
subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
|
|
|
|
subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
|
|
|
|
subscribingDeviceIdHolder.getAppInstallableDevices()));
|
|
|
|
subscribingDeviceIdHolder.getAppInstallableDevices()));
|
|
|
|
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
|
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
|
|
@ -797,19 +802,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
subscribingDeviceIdHolder.getAppInstalledDevices()));
|
|
|
|
subscribingDeviceIdHolder.getAppInstalledDevices()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> subscribingDevices = subscriptionDAO
|
|
|
|
subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType,
|
|
|
|
.addDeviceSubscription(username, subInsertingDeviceIds, subType,
|
|
|
|
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
|
|
|
|
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!subUpdatingDeviceIds.isEmpty()) {
|
|
|
|
if (!subUpdatingDeviceIds.isEmpty()) {
|
|
|
|
deviceSubIds.addAll(subscriptionDAO
|
|
|
|
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
|
|
|
|
.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
subUpdatingDeviceIds.addAll(subInsertingDeviceIds);
|
|
|
|
|
|
|
|
if (!subUpdatingDeviceIds.isEmpty()) {
|
|
|
|
|
|
|
|
List<Integer> deviceSubIds = new ArrayList<>(
|
|
|
|
|
|
|
|
subscriptionDAO.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
|
|
|
|
|
|
|
|
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceSubIds.addAll(subscribingDevices);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
@ -1059,14 +1063,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
.getDeviceSubscriptions(applicationReleaseId, tenantId);
|
|
|
|
.getDeviceSubscriptions(applicationReleaseId, tenantId);
|
|
|
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
|
|
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
|
|
|
String msg = "Couldn't found an subscribed devices for application release id: "
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
+ applicationReleaseId;
|
|
|
|
paginationResult.setData(new ArrayList<>());
|
|
|
|
log.info(msg);
|
|
|
|
paginationResult.setRecordsFiltered(0);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(0);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Integer> deviceIdList = new ArrayList<>();
|
|
|
|
List<Integer> deviceIdList = new ArrayList<>();
|
|
|
|
for (DeviceSubscriptionDTO deviceIds : deviceSubscriptionDTOS) {
|
|
|
|
deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
|
|
|
|
deviceIdList.add(deviceIds.getDeviceId());
|
|
|
|
if ((!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
|
|
|
|
}
|
|
|
|
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) || (deviceSubscriptionDTO.isUnsubscribed()
|
|
|
|
|
|
|
|
&& !Operation.Status.COMPLETED.toString()
|
|
|
|
|
|
|
|
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus()))) {
|
|
|
|
|
|
|
|
deviceIdList.add(deviceSubscriptionDTO.getDeviceId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceIdList.isEmpty()){
|
|
|
|
if (deviceIdList.isEmpty()){
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
@ -1109,7 +1120,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID, String subType)
|
|
|
|
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -1178,18 +1189,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
.getDeviceSubscriptions(applicationReleaseId, tenantId);
|
|
|
|
.getDeviceSubscriptions(applicationReleaseId, tenantId);
|
|
|
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
|
|
|
if (deviceSubscriptionDTOS.isEmpty()) {
|
|
|
|
String msg = "Couldn't found an subscribed devices for application release id: " + applicationReleaseId;
|
|
|
|
|
|
|
|
log.info(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (deviceIdList.isEmpty()) {
|
|
|
|
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
paginationResult.setData(deviceIdList);
|
|
|
|
paginationResult.setData(new ArrayList<>());
|
|
|
|
paginationResult.setRecordsFiltered(0);
|
|
|
|
paginationResult.setRecordsFiltered(0);
|
|
|
|
paginationResult.setRecordsTotal(0);
|
|
|
|
paginationResult.setRecordsTotal(0);
|
|
|
|
return paginationResult;
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//pass the device id list to device manager service method
|
|
|
|
//pass the device id list to device manager service method
|
|
|
|
PaginationResult paginationResult = deviceManagementProviderService
|
|
|
|
PaginationResult paginationResult = deviceManagementProviderService
|
|
|
|