From 28bc9f3a77463fb920debd82daabeda41e9e4d47 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 4 Jun 2019 15:28:15 +0530 Subject: [PATCH] Improve web clip registering in APPM --- .../mgt/common/ApplicationType.java | 2 +- .../common/services/ApplicationManager.java | 4 +- ...Wrapper.java => WebAppReleaseWrapper.java} | 23 +++++++- ...WebClipWrapper.java => WebAppWrapper.java} | 31 ++++++++--- .../GenericApplicationDAOImpl.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 54 +++++++++---------- .../application/mgt/core/util/APIUtil.java | 49 +++++++++-------- .../mgt/handler/util/HandlerUtil.java | 8 +++ .../ApplicationManagementPublisherAPI.java | 4 +- ...ApplicationManagementPublisherAPIImpl.java | 10 ++-- .../dbscripts/cdm/application-mgt/h2.sql | 2 +- 11 files changed, 121 insertions(+), 68 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/{WebClipReleaseWrapper.java => WebAppReleaseWrapper.java} (81%) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/{WebClipWrapper.java => WebAppWrapper.java} (78%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java index 3b0049e51a..289e36938e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationType.java @@ -23,6 +23,6 @@ package org.wso2.carbon.device.application.mgt.common; * Application Types. */ public enum ApplicationType { - ENTERPRISE, PUBLIC, WEB, WEB_CLIP + ENTERPRISE, PUBLIC, WEB_APP, WEB_CLIP } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index a0979e449c..ce66315c1d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -35,7 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.response.Tag; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; @@ -54,7 +54,7 @@ public interface ApplicationManager { Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException, RequestValidatingException; - Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java similarity index 81% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java index 8187eda76b..9cf11f2374 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppReleaseWrapper.java @@ -19,17 +19,22 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; + +//todo add version attribute @ApiModel(value = "ApplicationReleaseDTO", description = "This class holds the details when releasing an ApplicationDTO to application store") -public class WebClipReleaseWrapper { +public class WebAppReleaseWrapper { @ApiModelProperty(name = "description", value = "Description of the web clip release") + @NotNull private String description; @ApiModelProperty(name = "releaseType", value = "Release type of the web clip release", required = true, example = "alpha, beta etc") + @NotNull private String releaseType; @ApiModelProperty(name = "price", @@ -40,6 +45,7 @@ public class WebClipReleaseWrapper { @ApiModelProperty(name = "isSharedWithAllTenants", value = "If web clip release is shared with all tenants it is equal to 1 otherwise 0", required = true) + @NotNull private boolean isSharedWithAllTenants; @ApiModelProperty(name = "metaData", @@ -47,8 +53,15 @@ public class WebClipReleaseWrapper { required = true) private String metaData; + @ApiModelProperty(name = "version", + value = "Version of the web app release.", + required = true) + @NotNull + private String version; + @ApiModelProperty(name = "url", value = "URL which is used for WEB-CLIP") + @NotNull private String url; public String getReleaseType() { @@ -94,4 +107,12 @@ public class WebClipReleaseWrapper { public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } + + public boolean isSharedWithAllTenants() { return isSharedWithAllTenants; } + + public void setSharedWithAllTenants(boolean sharedWithAllTenants) { isSharedWithAllTenants = sharedWithAllTenants; } + + public String getVersion() { return version; } + + public void setVersion(String version) { this.version = version; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java similarity index 78% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java index b5c1b5ce42..1c5bba1d20 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebClipWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/WebAppWrapper.java @@ -19,33 +19,45 @@ package org.wso2.carbon.device.application.mgt.common.wrapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; import java.util.List; -@ApiModel(value = "WebClipWrapper", description = "WebClipWrapper represents an ApplicationDTO in ApplicationDTO Store") -public class WebClipWrapper { +@ApiModel(value = "WebAppWrapper", description = "WebAppWrapper represents an ApplicationDTO in ApplicationDTO Store") +public class WebAppWrapper { @ApiModelProperty(name = "name", value = "Name of the web clip", required = true) + @NotNull private String name; @ApiModelProperty(name = "description", value = "Description of the web clip", required = true) + @NotNull private String description; @ApiModelProperty(name = "categories", value = "List of Categories", required = true, example = "Educational, Gaming, Travel, Entertainment etc") + @NotNull private List categories; @ApiModelProperty(name = "subType", value = "Subscription method of the web clip", required = true, example = "PAID, FREE") + @NotNull private String subMethod; + @ApiModelProperty(name = "Web App Type", + value = "Type of the web app", + required = true, + example = "WEB_APP, WEB_CLIP") + @NotNull + private String type; + @ApiModelProperty(name = "paymentCurrency", value = "Payment currency of the web clip", required = true, @@ -54,16 +66,19 @@ public class WebClipWrapper { @ApiModelProperty(name = "tags", value = "List of tags") + @NotNull private List tags; @ApiModelProperty(name = "unrestrictedRoles", value = "List of roles that users should have to view the web clip") + @NotNull private List unrestrictedRoles; @ApiModelProperty(name = "applicationReleaseWrappers", value = "List of web clip releases", required = true) - private List webClipReleaseWrappers; + @NotNull + private List webAppReleaseWrappers; public String getName() { return name; @@ -87,10 +102,10 @@ public class WebClipWrapper { public void setDescription(String description) { this.description = description; } - public List getWebClipReleaseWrappers() { return webClipReleaseWrappers; } + public List getWebAppReleaseWrappers() { return webAppReleaseWrappers; } - public void setWebClipReleaseWrappers(List webClipReleaseWrappers) { - this.webClipReleaseWrappers = webClipReleaseWrappers; } + public void setWebAppReleaseWrappers(List webAppReleaseWrappers) { + this.webAppReleaseWrappers = webAppReleaseWrappers; } public List getCategories() { return categories; } @@ -99,4 +114,8 @@ public class WebClipWrapper { public String getSubMethod() { return subMethod; } public void setSubMethod(String subMethod) { this.subMethod = subMethod; } + + public String getType() { return type; } + + public void setType(String type) { this.type = type; } } 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 e98096d865..023a854cf1 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 @@ -1028,7 +1028,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Connection conn; String sql = "UPDATE " + "AP_APP_CATEGORY cat " + - "SET cat.CATEGORY_NAME = ? " + + "SET cat.CATEGORY = ? " + "WHERE " + "cat.ID = ? AND " + "cat.TENANT_ID = ?"; 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 a0152321d3..55859fd127 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 @@ -58,8 +58,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; @@ -622,7 +622,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application createWebClip(WebClipWrapper webClipWrapper, ApplicationArtifact applicationArtifact) + public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); @@ -632,7 +632,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } List categoryIds; - ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webClipWrapper); + ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); List tags = applicationDTO.getTags(); List categories = applicationDTO.getAppCategories(); @@ -645,7 +645,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { String msg = "Error occurred while getting data which is related to application. application name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); throw new ApplicationManagementException(msg, e); } finally { @@ -665,7 +665,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); } catch (ResourceManagementException e) { - String msg = "Error Occured when uploading artifacts of the application: " + webClipWrapper.getName(); + String msg = "Error Occured when uploading artifacts of the application: " + webAppWrapper.getName(); log.error(msg); throw new ApplicationManagementException(msg, e); } @@ -748,7 +748,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (LifeCycleManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = - "Error occurred while adding lifecycle state. application name: " + webClipWrapper.getName() + "."; + "Error occurred while adding lifecycle state. application name: " + webAppWrapper.getName() + "."; log.error(msg); try { applicationStorageManager.deleteAllApplicationReleaseArtifacts( @@ -764,13 +764,13 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Error occurred while adding application or application release. application name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); throw new ApplicationManagementException(msg, e); } catch (LifecycleManagementException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred when getting initial lifecycle state. application name: " + webClipWrapper + String msg = "Error occurred when getting initial lifecycle state. application name: " + webAppWrapper .getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); @@ -782,7 +782,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (VisibilityManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); String msg = - "Error occurred while adding unrestricted roles. application name: " + webClipWrapper.getName() + "Error occurred while adding unrestricted roles. application name: " + webAppWrapper.getName() + "."; log.error(msg); deleteApplicationArtifacts(Collections.singletonList(applicationReleaseDTO.getAppHashValue())); @@ -2489,37 +2489,37 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - } else if (param instanceof WebClipWrapper) { - WebClipWrapper webClipWrapper = (WebClipWrapper) param; - if (StringUtils.isEmpty(webClipWrapper.getName())) { + } else if (param instanceof WebAppWrapper) { + WebAppWrapper webAppWrapper = (WebAppWrapper) param; + if (StringUtils.isEmpty(webAppWrapper.getName())) { String msg = "Web Clip name cannot be empty."; log.error(msg); throw new BadRequestException(msg); } - if (webClipWrapper.getCategories() == null) { + if (webAppWrapper.getCategories() == null) { String msg = "Web Clip category can't be null."; log.error(msg); throw new BadRequestException(msg); } - if (webClipWrapper.getCategories().isEmpty()) { + if (webAppWrapper.getCategories().isEmpty()) { String msg = "Web clip category can't be empty."; log.error(msg); throw new BadRequestException(msg); } - List webClipReleaseWrappers; - webClipReleaseWrappers = webClipWrapper.getWebClipReleaseWrappers(); + List webAppReleaseWrappers; + webAppReleaseWrappers = webAppWrapper.getWebAppReleaseWrappers(); - if (webClipReleaseWrappers == null || webClipReleaseWrappers.size() != 1) { + if (webAppReleaseWrappers == null || webAppReleaseWrappers.size() != 1) { String msg = "Invalid web clip creating request. Web clip creating request must have single " - + "web clip release. Web clip name:" + webClipWrapper.getName() + "."; + + "web clip release. Web clip name:" + webAppWrapper.getName() + "."; log.error(msg); throw new BadRequestException(msg); } try { ConnectionManagerUtil.openDBConnection(); - List unrestrictedRoles = webClipWrapper.getUnrestrictedRoles(); + List unrestrictedRoles = webAppWrapper.getUnrestrictedRoles(); if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { if (!isValidRestrictedRole(unrestrictedRoles)) { @@ -2538,7 +2538,7 @@ public class ApplicationManagerImpl implements ApplicationManager { Filter filter = new Filter(); filter.setFullMatch(true); - filter.setAppName(webClipWrapper.getName().trim()); + filter.setAppName(webAppWrapper.getName().trim()); filter.setOffset(0); filter.setLimit(1); List applicationList = applicationDAO.getApplications(filter, -1, tenantId); @@ -2551,7 +2551,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } List registeredCategories = this.applicationDAO.getAllCategories(tenantId); - List appCategories = webClipWrapper.getCategories(); + List appCategories = webAppWrapper.getCategories(); if (registeredCategories.isEmpty()) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -2583,7 +2583,7 @@ public class ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } catch (ApplicationManagementDAOException e) { String msg = "Error occurred while getting data which is related to web clip. web clip name: " - + webClipWrapper.getName() + "."; + + webAppWrapper.getName() + "."; log.error(msg); throw new ApplicationManagementException(msg, e); } catch (UserStoreException e) { @@ -2614,16 +2614,16 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } - } if (param instanceof WebClipReleaseWrapper){ - WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; + } if (param instanceof WebAppReleaseWrapper){ + WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; UrlValidator urlValidator = new UrlValidator(); if (StringUtils - .isEmpty(webClipReleaseWrapper.getUrl())){ + .isEmpty(webAppReleaseWrapper.getUrl())){ String msg = "URL should't be null for the application release creating request for application type WEB_CLIP"; log.error(msg); throw new BadRequestException(msg); } - if (!urlValidator.isValid(webClipReleaseWrapper.getUrl())){ + if (!urlValidator.isValid(webAppReleaseWrapper.getUrl())){ String msg = "Request payload contains an invalid Web Clip URL."; log.error(msg); throw new BadRequestException(msg); 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 47f95cf0e6..74c49c1187 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 @@ -30,8 +30,8 @@ import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipReleaseWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppReleaseWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; @@ -235,16 +235,17 @@ public class APIUtil { List applicationReleaseEntities = applicationWrapper.getApplicationReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - } else if (param instanceof WebClipWrapper){ - WebClipWrapper webClipWrapper = (WebClipWrapper) param; - applicationDTO.setName(webClipWrapper.getName()); - applicationDTO.setDescription(webClipWrapper.getDescription()); - applicationDTO.setAppCategories(webClipWrapper.getCategories()); - applicationDTO.setSubType(webClipWrapper.getSubMethod()); - applicationDTO.setPaymentCurrency(webClipWrapper.getPaymentCurrency()); - applicationDTO.setTags(webClipWrapper.getTags()); - applicationDTO.setUnrestrictedRoles(webClipWrapper.getUnrestrictedRoles()); - List applicationReleaseEntities = webClipWrapper.getWebClipReleaseWrappers() + } else if (param instanceof WebAppWrapper){ + WebAppWrapper webAppWrapper = (WebAppWrapper) param; + applicationDTO.setName(webAppWrapper.getName()); + applicationDTO.setDescription(webAppWrapper.getDescription()); + applicationDTO.setAppCategories(webAppWrapper.getCategories()); + applicationDTO.setSubType(webAppWrapper.getSubMethod()); + applicationDTO.setPaymentCurrency(webAppWrapper.getPaymentCurrency()); + applicationDTO.setType(webAppWrapper.getType()); + applicationDTO.setTags(webAppWrapper.getTags()); + applicationDTO.setUnrestrictedRoles(webAppWrapper.getUnrestrictedRoles()); + List applicationReleaseEntities = webAppWrapper.getWebAppReleaseWrappers() .stream().map(APIUtil::releaseWrapperToReleaseDTO).collect(Collectors.toList()); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); } @@ -262,14 +263,15 @@ public class APIUtil { applicationReleaseDTO.setIsSharedWithAllTenants(applicationReleaseWrapper.getIsSharedWithAllTenants()); applicationReleaseDTO.setMetaData(applicationReleaseWrapper.getMetaData()); applicationReleaseDTO.setSupportedOsVersions(applicationReleaseWrapper.getSupportedOsVersions()); - } else if (param instanceof WebClipReleaseWrapper){ - WebClipReleaseWrapper webClipReleaseWrapper = (WebClipReleaseWrapper) param; - applicationReleaseDTO.setDescription(webClipReleaseWrapper.getDescription()); - applicationReleaseDTO.setReleaseType(webClipReleaseWrapper.getReleaseType()); - applicationReleaseDTO.setPrice(webClipReleaseWrapper.getPrice()); - applicationReleaseDTO.setInstallerName(webClipReleaseWrapper.getUrl()); - applicationReleaseDTO.setIsSharedWithAllTenants(webClipReleaseWrapper.getIsSharedWithAllTenants()); - applicationReleaseDTO.setMetaData(webClipReleaseWrapper.getMetaData()); + } else if (param instanceof WebAppReleaseWrapper){ + WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param; + applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription()); + applicationReleaseDTO.setReleaseType(webAppReleaseWrapper.getReleaseType()); + applicationReleaseDTO.setVersion(webAppReleaseWrapper.getVersion()); + applicationReleaseDTO.setPrice(webAppReleaseWrapper.getPrice()); + applicationReleaseDTO.setInstallerName(webAppReleaseWrapper.getUrl()); + applicationReleaseDTO.setIsSharedWithAllTenants(webAppReleaseWrapper.getIsSharedWithAllTenants()); + applicationReleaseDTO.setMetaData(webAppReleaseWrapper.getMetaData()); } return applicationReleaseDTO; } @@ -278,7 +280,11 @@ public class APIUtil { throws BadRequestException, UnexpectedServerErrorException { Application application = new Application(); - DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + //This is for handling web-apps + if (applicationDTO.getDeviceTypeId() > 0) { + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + application.setDeviceType(deviceType.getName()); + } application.setId(applicationDTO.getId()); application.setName(applicationDTO.getName()); application.setDescription(applicationDTO.getDescription()); @@ -288,7 +294,6 @@ public class APIUtil { application.setPaymentCurrency(applicationDTO.getPaymentCurrency()); application.setTags(applicationDTO.getTags()); application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles()); - application.setDeviceType(deviceType.getName()); application.setRating(applicationDTO.getAppRating()); List applicationReleases = applicationDTO.getApplicationReleaseDTOs() .stream().map(APIUtil::releaseDtoToRelease).collect(Collectors.toList()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java index cf14b96651..e49659c980 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.handler/src/main/java/org/wso2/carbon/device/application/mgt/handler/util/HandlerUtil.java @@ -24,8 +24,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.json.JSONException; @@ -60,6 +62,12 @@ public class HandlerUtil { } else if (httpMethod instanceof HttpGet) { HttpGet method = (HttpGet) httpMethod; response = client.execute(method); + } else if (httpMethod instanceof HttpPut) { + HttpPut method = (HttpPut) httpMethod; + response = client.execute(method); + } else if (httpMethod instanceof HttpDelete) { + HttpDelete method = (HttpDelete) httpMethod; + response = client.execute(method); } ProxyResponse proxyResponse = new ProxyResponse(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 2aef9d23af..aa97ff0243 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -42,7 +42,7 @@ import org.wso2.carbon.device.application.mgt.common.response.ApplicationRelease import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; import java.util.List; import javax.validation.Valid; @@ -375,7 +375,7 @@ public interface ApplicationManagementPublisherAPI { name = "webapp", value = "The web app that need to be created.", required = true) - @Multipart("webapp") WebClipWrapper webClipWrapper, + @Multipart("webapp") WebAppWrapper webAppWrapper, @ApiParam( name = "icon", value = "Icon of the uploading web app", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index d2e696944e..323f476b7a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationReleaseWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationUpdateWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ApplicationWrapper; -import org.wso2.carbon.device.application.mgt.common.wrapper.WebClipWrapper; +import org.wso2.carbon.device.application.mgt.common.wrapper.WebAppWrapper; 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.UnexpectedServerErrorException; @@ -209,7 +209,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes("multipart/mixed") @Path("/web-app") public Response createWebApp( - @Multipart("webapp") WebClipWrapper webClipWrapper, + @Multipart("webapp") WebAppWrapper webAppWrapper, @Multipart("icon") Attachment iconFile, @Multipart("banner") Attachment bannerFile, @Multipart("screenshot1") Attachment screenshot1, @@ -218,12 +218,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem ApplicationManager applicationManager = APIUtil.getApplicationManager(); List attachmentList = constructAttachmentList(screenshot1, screenshot2, screenshot3); try { - applicationManager.validateAppCreatingRequest(webClipWrapper); - applicationManager.validateReleaseCreatingRequest(webClipWrapper.getWebClipReleaseWrappers().get(0)); + applicationManager.validateAppCreatingRequest(webAppWrapper); + applicationManager.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0)); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); // Created new application entry - Application application = applicationManager.createWebClip(webClipWrapper, + Application application = applicationManager.createWebClip(webAppWrapper, constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index e0d12e9289..b2816cb5f1 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS AP_APP_RELEASE( APP_HASH_VALUE VARCHAR(1000) NOT NULL, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, APP_META_INFO CLOB NULL DEFAULT NULL, - SUPPORTED_OS_VERSIONS VARCHAR(45) NOT NULL, + SUPPORTED_OS_VERSIONS VARCHAR(45) NULL DEFAULT NULL, RATING DOUBLE NULL DEFAULT NULL, CURRENT_STATE VARCHAR(45) NOT NULL, RATED_USERS INTEGER NULL,