Add bundle Id getting method for iOS public apps

revert-70ac1926
tcdlpds@gmail.com 4 years ago
parent 5cbe5a65cc
commit 1c47ff56ab

@ -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;
} }
@ -456,29 +467,36 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
} }
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { } else {
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
for (T param : params) { for (T param : params) {
String username = (String) param; String username = (String) param;
subscribers.add(username); subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username)); devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
} }
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
for (T param : params) { for (T param : params) {
String roleName = (String) param; String roleName = (String) param;
subscribers.add(roleName); subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName)); devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
} }
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else {
if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
for (T param : params) { for (T param : params) {
String groupName = (String) param; String groupName = (String) param;
subscribers.add(groupName); subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true)); devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName, true));
} }
} else { } else {
String msg = "Found invalid subscription type " + subType+ " to install application release" ; String msg =
"Found invalid subscription type " + subType + " to install application release";
log.error(msg); log.error(msg);
throw new BadRequestException(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
.toString().equals(subType)) { .toString().equals(subType)) {
@ -576,8 +594,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
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);
@ -615,13 +632,15 @@ 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 {
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
deviceIdentifiers deviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet())); .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet()));
ignoredDeviceIdentifiers ignoredDeviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
} }
}
if (deviceIdentifiers.isEmpty()) { if (deviceIdentifiers.isEmpty()) {
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
@ -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 (deviceSubscriptionDTO.isUnsubscribed()) {
if (!Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) { 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()); subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} else if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString() } else {
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) { .equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
} else { } else {
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppReInstallableDevices()
.put(deviceIdentifier, device.getId());
}
}
} }
} else { } else {
subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId());
@ -790,8 +815,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* @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,12 +834,14 @@ 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 {
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstalledDevices())); subscribingDeviceIdHolder.getAppInstalledDevices()));
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppReUnInstallableDevices())); subscribingDeviceIdHolder.getAppReUnInstallableDevices()));
} }
}
subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType, subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, 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) {
@ -872,19 +899,24 @@ 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 {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId); subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
if (!params.isEmpty()) { if (!params.isEmpty()) {
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId, action); subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId, action);
} }
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else {
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId); if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO
.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
if (!params.isEmpty()) { if (!params.isEmpty()) {
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId, action); subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId, action);
} }
} }
}
}
if (!subscribedEntities.isEmpty()) { if (!subscribedEntities.isEmpty()) {
subscriptionDAO subscriptionDAO
@ -901,8 +933,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
*/ */
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());
} }
@ -987,7 +1018,8 @@ 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)) { } else {
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
CustomApplication customApplication = new CustomApplication(); CustomApplication customApplication = new CustomApplication();
@ -1000,6 +1032,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
}
} else { } else {
App app = new App(); App app = new App();
MobileAppTypes mobileAppType = MobileAppTypes.valueOf(application.getType()); MobileAppTypes mobileAppType = MobileAppTypes.valueOf(application.getType());
@ -1010,14 +1043,17 @@ 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)) { } else {
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
return MDMAndroidOperationUtil.createAppUninstallOperation(app); return MDMAndroidOperationUtil.createAppUninstallOperation(app);
} else { } else {
String msg = "Invalid Action is found. Action: " + action; String msg = "Invalid Action is found. Action: " + action;
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) { }
} else {
if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
String plistDownloadEndpoint = String plistDownloadEndpoint =
APIUtil.getArtifactDownloadBaseURL() + MDMAppConstants.IOSConstants.PLIST APIUtil.getArtifactDownloadBaseURL() + MDMAppConstants.IOSConstants.PLIST
@ -1035,7 +1071,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
application.getApplicationReleases().get(0).getInstallerPath()); application.getApplicationReleases().get(0).getInstallerPath());
app.setProperties(properties); app.setProperties(properties);
return MDMIOSOperationUtil.createInstallAppOperation(app); return MDMIOSOperationUtil.createInstallAppOperation(app);
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { } 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.setType(mobileAppType);
app.setIdentifier(application.getPackageName()); app.setIdentifier(application.getPackageName());
app.setLocation(application.getApplicationReleases().get(0).getInstallerPath()); app.setLocation(application.getApplicationReleases().get(0).getInstallerPath());
@ -1045,7 +1092,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
} else if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) { }
} else {
if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
app.setType(mobileAppType); app.setType(mobileAppType);
app.setIdentifier(application.getPackageName()); app.setIdentifier(application.getPackageName());
app.setMetaData(application.getApplicationReleases().get(0).getMetaData()); app.setMetaData(application.getApplicationReleases().get(0).getMetaData());
@ -1063,6 +1112,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
} }
}
}
} catch (UnknownApplicationTypeException e) { } catch (UnknownApplicationTypeException e) {
String msg = "Unknown Application type is found."; String msg = "Unknown Application type is found.";
log.error(msg, e); log.error(msg, 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();
@ -1108,13 +1200,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
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 =
"Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId()
+ " on device"; + " on device";
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
@ -1165,8 +1257,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
.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,28 +1300,31 @@ 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 {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO subscriptionList = subscriptionDAO
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId); .getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId); count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else {
if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO subscriptionList = subscriptionDAO
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId); .getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId); count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId);
} }
}
}
paginationResult.setData(subscriptionList); paginationResult.setData(subscriptionList);
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
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