From e1a5ae11641a68ffa824d334c478d2d7d6739093 Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 12 May 2020 17:16:24 +0530 Subject: [PATCH] Fix app name validation issue for webclip --- .../mgt/core/impl/ApplicationManagerImpl.java | 21 ++++++++++++------- .../application/mgt/core/util/Constants.java | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 0fde607bba..55ddd7d3f3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1894,16 +1894,23 @@ public class ApplicationManagerImpl implements ApplicationManager { DeviceManagementProviderService deviceManagementProviderService = DataHolder.getInstance() .getDeviceManagementService(); try { - DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); - if (deviceType == null) { - String msg = "Device type doesn't exist. Hence check the application name existence with valid " - + "device type name."; - log.error(msg); - throw new BadRequestException(msg); + int deviceTypeId; + if (!deviceTypeName.equals(Constants.ALL)) { + DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); + deviceTypeId = deviceType.getId(); + if (deviceType == null) { + String msg = "Device type doesn't exist. Hence check the application name existence with valid " + + "device type name."; + log.error(msg); + throw new BadRequestException(msg); + } + } else { + //For web-clips device type = 'ALL' + deviceTypeId = 0; } try { ConnectionManagerUtil.openDBConnection(); - if (applicationDAO.isExistingAppName(appName, deviceType.getId(), tenantId)) { + if (applicationDAO.isExistingAppName(appName, deviceTypeId, tenantId)) { return true; } } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java index e29959b427..11ca234e1a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java @@ -48,6 +48,7 @@ public class Constants { public static final String FORWARD_SLASH = "/"; public static final String ANY = "ANY"; public static final String DEFAULT_PCK_NAME = "default.app.com"; + public static final String ALL = "ALL"; public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id="; public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";