Merge branch 'master' into 'master'

Add bundle Id getting method for iOS public apps

See merge request entgra/carbon-device-mgt!727
revert-70ac1926
Inosh Perara 4 years ago
commit bcff3f46ad

@ -25,6 +25,8 @@ import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -88,7 +90,13 @@ import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -125,9 +133,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
validateRequest(params, subType, action); validateRequest(params, subType, action);
//todo validate users, groups and roles //todo validate users, groups and roles
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType, params); ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), params);
applicationSubscriptionInfo.getDevices(), applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action); ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action);
applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers()); applicationInstallResponse.setErrorDeviceIdentifiers(applicationSubscriptionInfo.getErrorDeviceIdentifiers());
return applicationInstallResponse; return applicationInstallResponse;
@ -138,14 +148,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throws SubscriptionManagementException { throws SubscriptionManagementException {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ScheduledSubscriptionDTO existingEntry = subscriptionDAO.getPendingScheduledSubscriptionByTaskName( ScheduledSubscriptionDTO existingEntry = subscriptionDAO
subscriptionDTO.getTaskName()); .getPendingScheduledSubscriptionByTaskName(subscriptionDTO.getTaskName());
boolean transactionStatus; boolean transactionStatus;
if (existingEntry == null) { if (existingEntry == null) {
transactionStatus = subscriptionDAO.createScheduledSubscription(subscriptionDTO); transactionStatus = subscriptionDAO.createScheduledSubscription(subscriptionDTO);
} else { } else {
transactionStatus = subscriptionDAO.updateScheduledSubscription(existingEntry.getId(), transactionStatus = subscriptionDAO
subscriptionDTO.getScheduledAt(), subscriptionDTO.getScheduledBy()); .updateScheduledSubscription(existingEntry.getId(), subscriptionDTO.getScheduledAt(),
subscriptionDTO.getScheduledBy());
} }
if (!transactionStatus) { if (!transactionStatus) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -175,13 +186,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
return subscriptionDAO.getUUID(id, packageName); return subscriptionDAO.getUUID(id, packageName);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while checking the application is " + String msg = "Error occurred while checking the application is " + "subscribed one or not";
"subscribed one or not";
log.error(msg, e); log.error(msg, e);
throw new SubscriptionManagementException(msg, e); throw new SubscriptionManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection while checking the application is " + String msg = "Error occurred while observing the database connection while checking the application is "
"subscribed one or not"; + "subscribed one or not";
log.error(msg, e); log.error(msg, e);
throw new SubscriptionManagementException(msg, e); throw new SubscriptionManagementException(msg, e);
} finally { } finally {
@ -194,12 +204,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try { try {
// Cleaning up already executed, missed and failed tasks // Cleaning up already executed, missed and failed tasks
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
List<ScheduledSubscriptionDTO> taskList = subscriptionDAO.getScheduledSubscriptionByStatus( List<ScheduledSubscriptionDTO> taskList = subscriptionDAO
ExecutionStatus.EXECUTED, false); .getScheduledSubscriptionByStatus(ExecutionStatus.EXECUTED, false);
taskList.addAll(subscriptionDAO.getNonExecutedSubscriptions()); taskList.addAll(subscriptionDAO.getNonExecutedSubscriptions());
taskList.addAll(subscriptionDAO.getScheduledSubscriptionByStatus(ExecutionStatus.FAILED, false)); taskList.addAll(subscriptionDAO.getScheduledSubscriptionByStatus(ExecutionStatus.FAILED, false));
List<Integer> tasksToClean = taskList.stream().map(ScheduledSubscriptionDTO::getId).collect( List<Integer> tasksToClean = taskList.stream().map(ScheduledSubscriptionDTO::getId)
Collectors.toList()); .collect(Collectors.toList());
if (!subscriptionDAO.deleteScheduledSubscription(tasksToClean)) { if (!subscriptionDAO.deleteScheduledSubscription(tasksToClean)) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
@ -374,9 +384,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
AtomicBoolean isAppSubscribable = new AtomicBoolean(true); AtomicBoolean isAppSubscribable = new AtomicBoolean(true);
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) { for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
if (device.getId() == deviceSubscriptionDTO.getDeviceId() && if (device.getId() == deviceSubscriptionDTO.getDeviceId() && (
(Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus()) Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus())
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus()))) { || Operation.Status.IN_PROGRESS.toString()
.equals(deviceSubscriptionDTO.getStatus()))) {
isAppSubscribable.set(false); isAppSubscribable.set(false);
break; break;
} }
@ -410,12 +421,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* Gets Application subscribing info by using requesting params * Gets Application subscribing info by using requesting params
* *
* @param applicationDTO Application DTO * @param applicationDTO Application DTO
* @param params list of subscribers. This list can be of either * @param params list of subscribers. This list can be of either
* {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal * {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal
* to DEVICE or * to DEVICE or
* {@link String} if {@param subType} is USER, ROLE or GROUP * {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see { * @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see {
* @param <T> generic type of the method. * @param <T> generic type of the method.
* @return {@link ApplicationSubscriptionInfo} * @return {@link ApplicationSubscriptionInfo}
* @throws ApplicationManagementException if error occurred while getting Application subscription info * @throws ApplicationManagementException if error occurred while getting Application subscription info
*/ */
@ -456,28 +467,35 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
} }
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true));
}
} else { } else {
String msg = "Found invalid subscription type " + subType+ " to install application release" ; if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
log.error(msg); for (T param : params) {
throw new BadRequestException(msg); String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else {
if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true));
}
} else {
String msg =
"Found invalid subscription type " + subType + " to install application release";
log.error(msg);
throw new BadRequestException(msg);
}
}
}
} }
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE
@ -509,10 +527,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* This method is responsible to update subscription data for google enterprise install. * This method is responsible to update subscription data for google enterprise install.
* *
* @param applicationReleaseId Application release Id * @param applicationReleaseId Application release Id
* @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) * @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> appSubscribingDeviceIds, private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appSubscribingDeviceIds,
@ -556,10 +574,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* THis method is responsible to validate application install or uninstall request. * THis method is responsible to validate application install or uninstall request.
* *
* @param params params could be either list of {@link DeviceIdentifier} or list of username or list of group * @param params params could be either list of {@link DeviceIdentifier} or list of username or list of group
* names or list or role names. * names or list or role names.
* @param subType Subscription type. i.e DEVICE or USER or ROLE or GROUP * @param subType Subscription type. i.e DEVICE or USER or ROLE or GROUP
* @param action performing action. i.e Install or Uninstall * @param action performing action. i.e Install or Uninstall
* @throws BadRequestException if incompatible data is found with app install/uninstall request. * @throws BadRequestException if incompatible data is found with app install/uninstall request.
*/ */
private <T> void validateRequest(List<T> params, String subType, String action) throws BadRequestException { private <T> void validateRequest(List<T> params, String subType, String action) throws BadRequestException {
@ -572,14 +590,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
boolean isValidSubType = Arrays.stream(SubscriptionType.values()) boolean isValidSubType = Arrays.stream(SubscriptionType.values())
.anyMatch(sub -> sub.name().equalsIgnoreCase(subType)); .anyMatch(sub -> sub.name().equalsIgnoreCase(subType));
if (!isValidSubType) { if (!isValidSubType) {
String msg = "Found invalid subscription type " + subType+ " to subscribe application release" ; String msg = "Found invalid subscription type " + subType + " to subscribe application release";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
boolean isValidAction = Arrays.stream(SubAction.values()) boolean isValidAction = Arrays.stream(SubAction.values()).anyMatch(sub -> sub.name().equalsIgnoreCase(action));
.anyMatch(sub -> sub.name().equalsIgnoreCase(action));
if (!isValidAction) { if (!isValidAction) {
String msg = "Found invalid action " + action +" to perform on application release"; String msg = "Found invalid action " + action + " to perform on application release";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
@ -588,15 +605,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* This method perform given action (i.e APP INSTALL or APP UNINSTALL) on given set of devices. * This method perform given action (i.e APP INSTALL or APP UNINSTALL) on given set of devices.
* *
* @param deviceType Application supported device type. * @param deviceType Application supported device type.
* @param devices List of devices that action is triggered. * @param devices List of devices that action is triggered.
* @param applicationDTO Application data * @param applicationDTO Application data
* @param subType Subscription type (i.e USER, ROLE, GROUP or DEVICE) * @param subType Subscription type (i.e USER, ROLE, GROUP or DEVICE)
* @param subscribers Subscribers * @param subscribers Subscribers
* @param action Performing action. (i.e INSTALL or UNINSTALL) * @param action Performing action. (i.e INSTALL or UNINSTALL)
* @return {@link ApplicationInstallResponse} * @return {@link ApplicationInstallResponse}
* @throws ApplicationManagementException if error occured when adding operation on device or updating subscription * @throws ApplicationManagementException if error occured when adding operation on device or updating subscription
* data. * data.
*/ */
private ApplicationInstallResponse performActionOnDevices(String deviceType, List<Device> devices, private ApplicationInstallResponse performActionOnDevices(String deviceType, List<Device> devices,
ApplicationDTO applicationDTO, String subType, List<String> subscribers, String action) ApplicationDTO applicationDTO, String subType, List<String> subscribers, String action)
@ -615,12 +632,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
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()));
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { } else {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet())); deviceIdentifiers
ignoredDeviceIdentifiers .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet()));
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); ignoredDeviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
}
} }
if (deviceIdentifiers.isEmpty()) { if (deviceIdentifiers.isEmpty()) {
@ -664,7 +683,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* Filter given devices and davide given list of device into two sets, those are already application installed * Filter given devices and davide given list of device into two sets, those are already application installed
* devices and application installable devices. * devices and application installable devices.
* *
* @param devices List of {@link Device} * @param devices List of {@link Device}
* @param appReleaseId Application release id. * @param appReleaseId Application release id.
* @return {@link SubscribingDeviceIdHolder} * @return {@link SubscribingDeviceIdHolder}
* @throws ApplicationManagementException if error occured while getting device subscriptions for applicaion. * @throws ApplicationManagementException if error occured while getting device subscriptions for applicaion.
@ -689,18 +708,24 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus()) if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus())
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) { || Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId());
} else if (deviceSubscriptionDTO.isUnsubscribed()) { } else {
if (!Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) { if (deviceSubscriptionDTO.isUnsubscribed()) {
if (!Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) {
/*We can't ensure whether app is uninstalled successfully or not hence allow to perform both /*We can't ensure whether app is uninstalled successfully or not hence allow to perform both
install and uninstall operations*/ install and uninstall operations*/
subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppReUnInstallableDevices()
.put(deviceIdentifier, device.getId());
}
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} else {
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
} else {
subscribingDeviceIdHolder.getAppReInstallableDevices()
.put(deviceIdentifier, device.getId());
}
} }
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} else if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
} else {
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} }
} else { } else {
subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId());
@ -780,18 +805,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* This method is responsible to update subscription data. * This method is responsible to update subscription data.
* *
* @param applicationReleaseId Application release Id * @param applicationReleaseId Application release Id
* @param activities List of {@link Activity} * @param activities List of {@link Activity}
* @param subscribingDeviceIdHolder Subscribing device id holder. * @param subscribingDeviceIdHolder Subscribing device id holder.
* @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. ie INSTALL or UNINSTALL> * @param action performing action. ie 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 updateSubscriptions(int applicationReleaseId, List<Activity> activities, private void updateSubscriptions(int applicationReleaseId, List<Activity> activities,
SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType, SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> params, String subType, String action)
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();
try { try {
@ -809,15 +834,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribingDeviceIdHolder.getAppInstalledDevices())); subscribingDeviceIdHolder.getAppInstalledDevices()));
subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstallableDevices())); subscribingDeviceIdHolder.getAppInstallableDevices()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { } else {
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
subscribingDeviceIdHolder.getAppInstalledDevices())); subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subscribingDeviceIdHolder.getAppInstalledDevices()));
subscribingDeviceIdHolder.getAppReUnInstallableDevices())); subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppReUnInstallableDevices()));
}
} }
subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType, subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
if (!subUpdatingDeviceIds.isEmpty()) { if (!subUpdatingDeviceIds.isEmpty()) {
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType, subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
@ -832,8 +859,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when adding subscription data for application release ID: " String msg =
+ applicationReleaseId; "Error occurred when adding subscription data for application release ID: " + applicationReleaseId;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -842,7 +869,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String msg = "SQL Error occurred when adding new device subscription to application release which has ID: " String msg = "SQL Error occurred when adding new device subscription to application release which has ID: "
+ applicationReleaseId; + applicationReleaseId;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
@ -855,12 +882,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* is required to start DB transaction * is required to start DB transaction
* *
* @param applicationReleaseId Application release Id * @param applicationReleaseId Application release Id
* @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. ie INSTALL or UNINSTALL> * @param action performing action. ie INSTALL or UNINSTALL>
* @param tenantId Tenant Id * @param tenantId Tenant Id
* @param username Username * @param username Username
* @throws ApplicationManagementDAOException if error occurred while updating or inserting subscriber entities * @throws ApplicationManagementDAOException if error occurred while updating or inserting subscriber entities
*/ */
private void updateBulkSubscribers(int applicationReleaseId, List<String> params, String subType, String action, private void updateBulkSubscribers(int applicationReleaseId, List<String> params, String subType, String action,
@ -872,17 +899,22 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!params.isEmpty()) { if (!params.isEmpty()) {
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId, action); subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId, action);
} }
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else {
subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId); if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
params.removeAll(subscribedEntities); subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
if (!params.isEmpty()) { params.removeAll(subscribedEntities);
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId, action); if (!params.isEmpty()) {
} subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId, action);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { }
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId); } else {
params.removeAll(subscribedEntities); if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
if (!params.isEmpty()) { subscribedEntities = subscriptionDAO
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId, action); .getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
params.removeAll(subscribedEntities);
if (!params.isEmpty()) {
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId, action);
}
}
} }
} }
@ -895,25 +927,24 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* This method is responsible to get device IDs thta operation has added. * This method is responsible to get device IDs thta operation has added.
* *
* @param activity Activity * @param activity Activity
* @param deviceMap Device map, key is device identifier and value is primary key of device. * @param deviceMap Device map, key is device identifier and value is primary key of device.
* @return List of device primary keys * @return List of device primary keys
*/ */
private List<Integer> getOperationAddedDeviceIds(Activity activity, Map<DeviceIdentifier, Integer> deviceMap) { private List<Integer> getOperationAddedDeviceIds(Activity activity, Map<DeviceIdentifier, Integer> deviceMap) {
List<ActivityStatus> activityStatuses = activity.getActivityStatus(); List<ActivityStatus> activityStatuses = activity.getActivityStatus();
return activityStatuses.stream() return activityStatuses.stream().filter(status -> deviceMap.get(status.getDeviceIdentifier()) != null)
.filter(status -> deviceMap.get(status.getDeviceIdentifier()) != null)
.map(status -> deviceMap.get(status.getDeviceIdentifier())).collect(Collectors.toList()); .map(status -> deviceMap.get(status.getDeviceIdentifier())).collect(Collectors.toList());
} }
/** /**
* This method is responsible to get device subscription of particular application releasee for given set of devices. * This method is responsible to get device subscription of particular application releasee for given set of devices.
* *
* @param deviceIds Set of device Ids * @param deviceIds Set of device Ids
* @param appReleaseId Application release Id * @param appReleaseId Application release Id
* @return {@link HashMap} with key as device id and value as {@link DeviceSubscriptionDTO} * @return {@link HashMap} with key as device id and value as {@link DeviceSubscriptionDTO}
* @throws ApplicationManagementException if error occured while executing SQL query or if more than one data found * @throws ApplicationManagementException if error occured while executing SQL query or if more than one data found
* for a device id. * for a device id.
*/ */
private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId) private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -938,10 +969,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* This method is responsible to add operation on given devices. * This method is responsible to add operation on given devices.
* *
* @param applicationDTO application. * @param applicationDTO application.
* @param deviceIdentifierList list of device identifiers. * @param deviceIdentifierList list of device identifiers.
* @param deviceType device type * @param deviceType device type
* @param action action e.g :- INSTALL, UNINSTALL * @param action action e.g :- INSTALL, UNINSTALL
* @return {@link Activity} * @return {@link Activity}
* @throws ApplicationManagementException if found an invalid device. * @throws ApplicationManagementException if found an invalid device.
*/ */
@ -967,12 +998,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
/** /**
* This method constructs operation payload to install/uninstall an application. * This method constructs operation payload to install/uninstall an application.
* *
* @param deviceType Device type * @param deviceType Device type
* @param application {@link Application} data. * @param application {@link Application} data.
* @param action Action is either ININSTALL or UNINSTALL * @param action Action is either ININSTALL or UNINSTALL
* @return {@link Operation} * @return {@link Operation}
* @throws ApplicationManagementException if unknown application type is found to generate operation payload or * @throws ApplicationManagementException if unknown application type is found to generate operation payload or
* invalid action is found to generate operation payload. * invalid action is found to generate operation payload.
*/ */
private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action) private Operation generateOperationPayloadByDeviceType(String deviceType, Application application, String action)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -987,18 +1018,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
customApplication.setUrl(application.getApplicationReleases().get(0).getInstallerPath()); customApplication.setUrl(application.getApplicationReleases().get(0).getInstallerPath());
operation.setPayLoad(customApplication.toJSON()); operation.setPayLoad(customApplication.toJSON());
return operation; return operation;
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE);
CustomApplication customApplication = new CustomApplication();
customApplication.setType(application.getType());
customApplication.setAppIdentifier(application.getPackageName());
operation.setPayLoad(customApplication.toJSON());
return operation;
} else { } else {
String msg = "Invalid Action is found. Action: " + action; if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
log.error(msg); operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION);
throw new ApplicationManagementException(msg); operation.setType(Operation.Type.PROFILE);
CustomApplication customApplication = new CustomApplication();
customApplication.setType(application.getType());
customApplication.setAppIdentifier(application.getPackageName());
operation.setPayLoad(customApplication.toJSON());
return operation;
} else {
String msg = "Invalid Action is found. Action: " + action;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} }
} else { } else {
App app = new App(); App app = new App();
@ -1010,57 +1043,75 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
app.setName(application.getName()); app.setName(application.getName());
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
return MDMAndroidOperationUtil.createInstallAppOperation(app); return MDMAndroidOperationUtil.createInstallAppOperation(app);
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
return MDMAndroidOperationUtil.createAppUninstallOperation(app);
} else {
String msg = "Invalid Action is found. Action: " + action;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
String plistDownloadEndpoint =
APIUtil.getArtifactDownloadBaseURL() + MDMAppConstants.IOSConstants.PLIST
+ Constants.FORWARD_SLASH + application.getApplicationReleases().get(0)
.getUuid();
app.setType(mobileAppType);
app.setLocation(plistDownloadEndpoint);
app.setIconImage(application.getApplicationReleases().get(0).getIconPath());
Properties properties = new Properties();
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName());
properties.put(MDMAppConstants.IOSConstants.LABEL, application.getName());
properties.put(MDMAppConstants.IOSConstants.WEB_CLIP_URL,
application.getApplicationReleases().get(0).getInstallerPath());
app.setProperties(properties);
return MDMIOSOperationUtil.createInstallAppOperation(app);
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
app.setType(mobileAppType);
app.setIdentifier(application.getPackageName());
app.setLocation(application.getApplicationReleases().get(0).getInstallerPath());
return MDMIOSOperationUtil.createAppUninstallOperation(app);
} else { } else {
String msg = "Invalid Action is found. Action: " + action; if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
log.error(msg); return MDMAndroidOperationUtil.createAppUninstallOperation(app);
throw new ApplicationManagementException(msg); } else {
String msg = "Invalid Action is found. Action: " + action;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} }
} else if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) { } else {
app.setType(mobileAppType); if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
app.setIdentifier(application.getPackageName()); if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
app.setMetaData(application.getApplicationReleases().get(0).getMetaData()); String plistDownloadEndpoint =
app.setName(application.getInstallerName()); APIUtil.getArtifactDownloadBaseURL() + MDMAppConstants.IOSConstants.PLIST
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { + Constants.FORWARD_SLASH + application.getApplicationReleases().get(0)
return MDMWindowsOperationUtil.createInstallAppOperation(app); .getUuid();
app.setType(mobileAppType);
app.setLocation(plistDownloadEndpoint);
app.setIconImage(application.getApplicationReleases().get(0).getIconPath());
Properties properties = new Properties();
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, application.getPackageName());
properties.put(MDMAppConstants.IOSConstants.LABEL, application.getName());
properties.put(MDMAppConstants.IOSConstants.WEB_CLIP_URL,
application.getApplicationReleases().get(0).getInstallerPath());
app.setProperties(properties);
return MDMIOSOperationUtil.createInstallAppOperation(app);
} else {
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
if (ApplicationType.PUBLIC.toString().equals(mobileAppType.toString())) {
String bundleId = getBundleId(application.getPackageName());
if (bundleId == null) {
String msg = "Couldn't find the bundle Id for iOS public app uninstallation";
log.error(msg);
throw new ApplicationManagementException(msg);
}
application.setPackageName(bundleId);
}
app.setType(mobileAppType);
app.setIdentifier(application.getPackageName());
app.setLocation(application.getApplicationReleases().get(0).getInstallerPath());
return MDMIOSOperationUtil.createAppUninstallOperation(app);
} else {
String msg = "Invalid Action is found. Action: " + action;
log.error(msg);
throw new ApplicationManagementException(msg);
}
}
} else { } else {
String msg = "Invalid Action is found. Action: " + action; if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
log.error(msg); app.setType(mobileAppType);
throw new ApplicationManagementException(msg); app.setIdentifier(application.getPackageName());
app.setMetaData(application.getApplicationReleases().get(0).getMetaData());
app.setName(application.getInstallerName());
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
return MDMWindowsOperationUtil.createInstallAppOperation(app);
} else {
String msg = "Invalid Action is found. Action: " + action;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} else {
String msg = "Invalid device type is found. Device Type: " + deviceType;
log.error(msg);
throw new ApplicationManagementException(msg);
}
} }
} else {
String msg = "Invalid device type is found. Device Type: " + deviceType;
log.error(msg);
throw new ApplicationManagementException(msg);
} }
} }
} catch (UnknownApplicationTypeException e) { } catch (UnknownApplicationTypeException e) {
@ -1070,6 +1121,47 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
/**
* Get the bundle id of the iOS public application.
* @param appId Application Id
* @return {@link String} bundle Id
* @throws ApplicationManagementException if error occurred while getting the bundle if of the requesting public
* application
*/
private String getBundleId(String appId) throws ApplicationManagementException {
try {
URL url = new URL(Constants.APPLE_LOOKUP_URL + appId);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream responseStream = connection.getInputStream();
try (BufferedReader in = new BufferedReader(new InputStreamReader(responseStream))) {
StringBuilder response = new StringBuilder();
String readLine;
while ((readLine = in.readLine()) != null) {
response.append(readLine);
}
JSONObject obj = new JSONObject(response.toString());
JSONArray results = obj.getJSONArray("results");
for (int i = 0; i < results.length(); ++i) {
JSONObject result = results.getJSONObject(i);
if (StringUtils.isNotBlank(result.getString("bundleId"))) {
return result.getString("bundleId");
}
}
return null;
}
} catch (MalformedURLException e) {
String msg = "Error occurred while constructing to get iOS public app bundle Id.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (IOException e) {
String msg = "Error occurred while getting bundle Id of the iOS public app.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO) public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -1078,23 +1170,23 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try { try {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain); ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() String username =
.getRealmConfiguration().getAdminUserName() + Constants.ApplicationInstall.AT + tenantDomain; PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
.getAdminUserName() + Constants.ApplicationInstall.AT + tenantDomain;
AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username); AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username);
String requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + String requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
System.getProperty(Constants.ApplicationInstall.IOT_CORE_HOST) + .getProperty(Constants.ApplicationInstall.IOT_CORE_HOST) + Constants.ApplicationInstall.COLON
Constants.ApplicationInstall.COLON + + System.getProperty(Constants.ApplicationInstall.IOT_CORE_PORT)
System.getProperty(Constants.ApplicationInstall.IOT_CORE_PORT) + + Constants.ApplicationInstall.GOOGLE_APP_INSTALL_URL;
Constants.ApplicationInstall.GOOGLE_APP_INSTALL_URL;
Gson gson = new Gson(); Gson gson = new Gson();
String payload = gson.toJson(applicationPolicyDTO); String payload = gson.toJson(applicationPolicyDTO);
StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON,
, Constants.ApplicationInstall.ENCODING); Constants.ApplicationInstall.ENCODING);
httpClient = new HttpClient(); httpClient = new HttpClient();
request = new PostMethod(requestUrl); request = new PostMethod(requestUrl);
request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION,
, Constants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken()); Constants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken());
request.setRequestEntity(requestEntity); request.setRequestEntity(requestEntity);
httpClient.executeMethod(request); httpClient.executeMethod(request);
return request.getStatusCode(); return request.getStatusCode();
@ -1104,18 +1196,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (APIManagerException e) { } catch (APIManagerException e) {
String msg = "Error while retrieving access token for Android device" ; String msg = "Error while retrieving access token for Android device";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (HttpException e) { } catch (HttpException e) {
String msg = "Error while calling the app store to install enrollment app with id: " + String msg = "Error while calling the app store to install enrollment app with id: " + applicationPolicyDTO
applicationPolicyDTO.getApplicationDTO().getId() + .getApplicationDTO().getId() + " on device";
" on device";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (IOException e) { } catch (IOException e) {
String msg = "Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId() String msg =
+ " on device"; "Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId()
+ " on device";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
@ -1152,7 +1244,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
}); });
if (deviceIdList.isEmpty()){ if (deviceIdList.isEmpty()) {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(deviceIdList); paginationResult.setData(deviceIdList);
paginationResult.setRecordsFiltered(0); paginationResult.setRecordsFiltered(0);
@ -1162,11 +1254,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
//pass the device id list to device manager service method //pass the device id list to device manager service method
try { try {
PaginationResult deviceDetails = deviceManagementProviderService PaginationResult deviceDetails = deviceManagementProviderService
.getAppSubscribedDevices(offsetValue ,limitValue, deviceIdList, status); .getAppSubscribedDevices(offsetValue, limitValue, deviceIdList, status);
if (deviceDetails == null) { if (deviceDetails == null) {
String msg = "Couldn't found an subscribed devices details for device ids: " String msg = "Couldn't found an subscribed devices details for device ids: " + deviceIdList;
+ deviceIdList;
log.error(msg); log.error(msg);
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
@ -1178,13 +1269,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when get application release data for application" + String msg =
" release UUID: " + appUUID; "Error occurred when get application release data for application" + " release UUID: " + appUUID;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting device details that " + String msg = "DB Connection error occurred while getting device details that " + "given application id";
"given application id";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
@ -1200,8 +1290,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId);
.getAppWithRelatedRelease(appUUID, tenantId);
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
List<String> subscriptionList = new ArrayList<>(); List<String> subscriptionList = new ArrayList<>();
@ -1211,14 +1300,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscriptionList = subscriptionDAO subscriptionList = subscriptionDAO
.getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId); .getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId); count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId);
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else {
subscriptionList = subscriptionDAO if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId); subscriptionList = subscriptionDAO
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId); .getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId);
subscriptionList = subscriptionDAO } else {
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId); if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId); subscriptionList = subscriptionDAO
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId);
}
}
} }
paginationResult.setData(subscriptionList); paginationResult.setData(subscriptionList);
@ -1226,13 +1319,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
paginationResult.setRecordsTotal(count); paginationResult.setRecordsTotal(count);
return paginationResult; return paginationResult;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when get application release data for application" + String msg =
" release UUID: " + appUUID; "Error occurred when get application release data for application" + " release UUID: " + appUUID;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "DB Connection error occurred while getting category details that " + String msg = "DB Connection error occurred while getting category details that " + "given application id";
"given application id";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} finally { } finally {
@ -1315,8 +1407,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} }
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting application release data for application release UUID: " String msg =
+ appUUID; "Error occurred when getting application release data for application release UUID: " + appUUID;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {

@ -64,6 +64,7 @@ public class Constants {
public static final String TASK_NAME = "TASK_NAME"; public static final String TASK_NAME = "TASK_NAME";
public static final String SUBSCRIBED = "SUBSCRIBED"; public static final String SUBSCRIBED = "SUBSCRIBED";
public static final String UNSUBSCRIBED = "UNSUBSCRIBED"; public static final String UNSUBSCRIBED = "UNSUBSCRIBED";
public static final String APPLE_LOOKUP_URL = "https://itunes.apple.com/us/lookup?id=";
//App type constants related to window device type //App type constants related to window device type
public static final String MSI = "MSI"; public static final String MSI = "MSI";

Loading…
Cancel
Save