From db325a637ec477336e97640fd7aecef31967954d Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Sat, 5 Aug 2017 14:53:32 +0530 Subject: [PATCH] Truncating applist version if length greater than allowed length (#881) In this commit, the application version is truncated if the version length is greater than the maximum allowed length in the database level. --- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 4 ++++ .../device/mgt/core/DeviceManagementConstants.java | 1 + .../app/mgt/ApplicationManagerProviderServiceImpl.java | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 7b0ddcda4f0..493dfa5f668 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -158,6 +158,10 @@ org.wso2.carbon.identity.framework org.wso2.carbon.user.mgt + + commons-lang + commons-lang + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index af07800f3df..38d57956267 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -87,6 +87,7 @@ public final class DeviceManagementConstants { public static final class OperationAttributes { private OperationAttributes() {throw new AssertionError(); } public static final String ACTIVITY = "ACTIVITY_"; + public static final int APPLIST_VERSION_MAX_LENGTH = 50; } public static final class PushNotifications { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index bf078a7b56d..37ee12f0546 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.app.mgt; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; @@ -31,6 +32,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.mgt.core.dao.ApplicationMappingDAO; @@ -225,6 +227,14 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem List applicationIds = new ArrayList<>(); for (Application application : applications) { + /* + Truncating the application version if length of the version is greater than maximum allowed length. + */ + if (application.getVersion().length() > + DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH) { + application.setVersion(StringUtils.abbreviate(application.getVersion(), + DeviceManagementConstants.OperationAttributes.APPLIST_VERSION_MAX_LENGTH)); + } if (!installedAppList.contains(application)) { installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), application.getVersion(), tenantId);