From 9b66b8e44cef9bf0f0ecdef6c03d5ede4a760cf9 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 4 Jun 2019 16:14:12 +0530 Subject: [PATCH] Fix issues in category updating functionality --- .../common/response/ApplicationRelease.java | 12 ----------- .../GenericApplicationDAOImpl.java | 4 ++-- .../application/mgt/core/util/APIUtil.java | 21 ++++++++++++++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java index 78be9b6bbc2..fe81d500deb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/response/ApplicationRelease.java @@ -81,10 +81,6 @@ public class ApplicationRelease { required = true) private String metaData; - @ApiModelProperty(name = "url", - value = "URL which is used for WEB-CLIP") - private String url; - @ApiModelProperty(name = "supportedOsVersions", value = "ApplicationDTO release supported OS versions") private String supportedOsVersions; @@ -125,14 +121,6 @@ public class ApplicationRelease { return metaData; } - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } 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/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 023a854cf1b..d3f79ab433e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -1036,8 +1036,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, categoryDTO.getCategoryName()); - stmt.setInt(1, categoryDTO.getId()); - stmt.setInt(2, tenantId); + stmt.setInt(2, categoryDTO.getId()); + stmt.setInt(3, tenantId); stmt.executeUpdate(); } } 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/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 74c49c11878..7611e08ca81 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -21,7 +21,9 @@ package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.validator.routines.UrlValidator; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.response.Application; @@ -280,10 +282,11 @@ public class APIUtil { throws BadRequestException, UnexpectedServerErrorException { Application application = new Application(); - //This is for handling web-apps - if (applicationDTO.getDeviceTypeId() > 0) { + if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); application.setDeviceType(deviceType.getName()); + } else { + application.setDeviceType("ANY"); } application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); @@ -306,8 +309,11 @@ public class APIUtil { .getArtifactDownloadEndpoint(); String basePath = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid() + Constants.FORWARD_SLASH; + List screenshotPaths = new ArrayList<>(); ApplicationRelease applicationRelease = new ApplicationRelease(); + UrlValidator urlValidator = new UrlValidator(); + applicationRelease.setDescription(applicationReleaseDTO.getDescription()); applicationRelease.setVersion(applicationReleaseDTO.getVersion()); applicationRelease.setUuid(applicationReleaseDTO.getUuid()); @@ -315,16 +321,21 @@ public class APIUtil { applicationRelease.setPrice(applicationReleaseDTO.getPrice()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setMetaData(applicationReleaseDTO.getMetaData()); - applicationRelease.setUrl(applicationReleaseDTO.getUrl()); applicationRelease.setCurrentStatus(applicationReleaseDTO.getCurrentState()); applicationRelease.setIsSharedWithAllTenants(applicationReleaseDTO.getIsSharedWithAllTenants()); applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions()); applicationRelease.setRating(applicationReleaseDTO.getRating()); - applicationRelease - .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); applicationRelease.setIconPath(basePath + applicationReleaseDTO.getIconName()); applicationRelease.setBannerPath(basePath + applicationReleaseDTO.getBannerName()); + if (urlValidator.isValid(applicationReleaseDTO.getInstallerName())){ + applicationRelease + .setInstallerPath(applicationReleaseDTO.getInstallerName()); + } else { + applicationRelease + .setInstallerPath(basePath + applicationReleaseDTO.getInstallerName()); + } + if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) { screenshotPaths.add(basePath + applicationReleaseDTO.getScreenshotName1()); }