diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java index 7abd4d0ec50..06b0817ac1e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationInstallResponse.java @@ -36,7 +36,7 @@ public class ApplicationInstallResponse { value = "List of devices that either device identity is not exist or device type doesn't compatible with the supported device type of the .", dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]" ) - private List errorDevices; + private List errorDeviceIdentifiers; @ApiModelProperty( @@ -61,7 +61,7 @@ public class ApplicationInstallResponse { this.ignoredDeviceIdentifiers = ignoredDeviceIdentifiers; } - public List getErrorDevices() { return errorDevices; } + public List getErrorDeviceIdentifiers() { return errorDeviceIdentifiers; } - public void setErrorDevices(List errorDevices) { this.errorDevices = errorDevices; } + public void setErrorDeviceIdentifiers(List errorDeviceIdentifiers) { this.errorDeviceIdentifiers = errorDeviceIdentifiers; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 234cbc847f9..6a86f753b7c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -140,7 +140,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc try (ResultSet rs = stmt.getGeneratedKeys()){ List updatedDeviceSubIds = new ArrayList<>(); while (rs.next()) { - updatedDeviceSubIds.add(rs.getInt(1)); + updatedDeviceSubIds.add(rs.getInt("ID")); } return updatedDeviceSubIds; } @@ -402,7 +402,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { DeviceSubscriptionDTO deviceSubscriptionDTO = DAOUtil.constructDeviceSubscriptionDTO(rs); - deviceSubscriptionDTOHashMap.put(deviceSubscriptionDTO.getId(), deviceSubscriptionDTO); + if (deviceSubscriptionDTOHashMap.containsKey(deviceSubscriptionDTO.getDeviceId())){ + String msg = "There shouldn't be Device ids in multiple times in AP_DEVICE_SUBSCRIPTION " + + "table."; + log.error(msg); + throw new ApplicationManagementDAOException(msg); + } + deviceSubscriptionDTOHashMap.put(deviceSubscriptionDTO.getDeviceId(), deviceSubscriptionDTO); } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 40428d4a7ae..eaea262fe01 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -138,17 +138,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager { .isEmpty(deviceIdentifier.getType())) { log.warn("Found a device identifier which has either empty identity of the device or empty" + " device type. Hence ignoring the device identifier. "); + continue; } if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); if (!deviceType.getName().equals(deviceIdentifier.getType())) { - String msg = - "Found a device identifier which is not matched with the application device Type. " - + "Application device type is " + deviceType.getName() + " and the " - + "identifier of which has a " + "different device type is " - + deviceIdentifier.getId(); - log.warn(msg); + log.warn("Found a device identifier which is not matched with the supported device type " + + "of the application release which has UUID " + applicationUUID + " Application " + + "supported device type is " + deviceType.getName() + " and the " + + "identifier of which has a different device type is " + deviceIdentifier.getId()); errorDeviceIdentifiers.add(deviceIdentifier); + continue; } } devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); @@ -188,7 +188,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager { applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType, subscribers, action); } - applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers); + applicationInstallResponse.setErrorDeviceIdentifiers(errorDeviceIdentifiers); return applicationInstallResponse; } catch (DeviceManagementException e) { String msg = "Error occurred while getting devices of given users or given roles."; @@ -400,21 +400,23 @@ public class SubscriptionManagerImpl implements SubscriptionManager { entry.getKey(), action); activityList.add(activity); } - } else { - if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) { - List categories = getApplicationCategories(applicationDTO.getId()); - if (categories.contains("GooglePlaySyncedApp")) { - ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); - applicationPolicyDTO.setApplicationDTO(applicationDTO); - applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); - applicationPolicyDTO.setAction(action); - installEnrollmentApplications(applicationPolicyDTO); - } + } else if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) { + List categories = getApplicationCategories(applicationDTO.getId()); + if (categories.contains("GooglePlaySyncedApp")) { + ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); + applicationPolicyDTO.setApplicationDTO(applicationDTO); + applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); + applicationPolicyDTO.setAction(action); + installEnrollmentApplications(applicationPolicyDTO); } else { Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); activityList.add(activity); } + } else { + Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); + activityList.add(activity); } + ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); applicationInstallResponse.setActivities(activityList); applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers); @@ -600,16 +602,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager { } private List getOperationAddedDeviceIds(Activity activity, Map deviceMap) { - List deviceIds = new ArrayList<>(); List activityStatuses = activity.getActivityStatus(); - for (ActivityStatus status : activityStatuses) { - if (status.getStatus().equals(ActivityStatus.Status.PENDING)) { - deviceIds.add(deviceMap.get(status.getDeviceIdentifier())); - } - } - return deviceIds; + return activityStatuses.stream().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. + * + * @param deviceIds Set of device Ids + * @param appReleaseId Application release Id + * @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 + * for a device id. + */ private Map getDeviceSubscriptions(List deviceIds, int appReleaseId) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index f5f68286d97..62af127d182 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -34,7 +34,6 @@ import org.wso2.carbon.device.application.mgt.common.BasicUserInfoList; import org.wso2.carbon.device.application.mgt.common.RoleList; import org.wso2.carbon.device.application.mgt.common.DeviceGroupList; import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.application.mgt.common.SubscriptionType; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java index 3149ac5721d..9af578912c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/MobileAppTypes.java @@ -19,5 +19,5 @@ package org.wso2.carbon.device.mgt.common.app.mgt; public enum MobileAppTypes { - ENTERPRISE,WEBAPP,PUBLIC + ENTERPRISE,WEBAPP,PUBLIC,WEB_CLIP } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java index 37adcde87be..20d7fda28cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/MDMAndroidOperationUtil.java @@ -61,6 +61,7 @@ public class MDMAndroidOperationUtil { operation.setPayLoad(appStoreApplication.toJSON()); break; case WEBAPP: + case WEB_CLIP: WebApplication webApplication = new WebApplication(); webApplication.setUrl(application.getLocation()); webApplication.setName(application.getName()); @@ -101,6 +102,7 @@ public class MDMAndroidOperationUtil { operation.setPayLoad(appStoreApplication.toJSON()); break; case WEBAPP: + case WEB_CLIP: WebApplication webApplication = new WebApplication(); webApplication.setUrl(application.getLocation()); webApplication.setName(application.getName());