From 4aa42aed6ff646533d3127c8f83fe050cab1da21 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Sat, 8 Jun 2019 23:28:21 +0530 Subject: [PATCH] Improve app release adding method --- .../mgt/common/services/ApplicationManager.java | 2 +- .../mgt/core/impl/ApplicationManagerImpl.java | 12 ++++++++++-- .../impl/ApplicationManagementPublisherAPIImpl.java | 11 ++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) 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 ffc0620581..e40d28e89c 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 @@ -192,7 +192,7 @@ public interface ApplicationManager { * @param applicationReleaseWrapper ApplicatonRelease that need to be be created. * @return the unique id of the application release, if the application release succeeded else -1 */ - ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, + ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; /*** 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 2bfa6a5159..6b223428d0 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 @@ -740,16 +740,24 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, + public ApplicationRelease createEntAppRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ApplicationRelease applicationRelease; if (log.isDebugEnabled()) { - log.debug("ApplicationDTO release request is received for the application id: " + applicationId); + log.debug("Application release creating request is received for the application id: " + applicationId); } ApplicationDTO applicationDTO = getApplication(applicationId); try { + if (!ApplicationType.ENTERPRISE.toString().equals(applicationDTO.getType())) { + String msg = + "It is possible to add new application release for " + ApplicationType.ENTERPRISE.toString() + + " app type. But you are requesting to add new application release for " + + applicationDTO.getType() + " app type."; + log.error(msg); + throw new BadRequestException(msg); + } ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper, applicationDTO, applicationArtifact); ConnectionManagerUtil.beginDBTransaction(); 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 8ef252d4de..a9c639b2ad 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 @@ -143,6 +143,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @PathParam("uuid") String uuid) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { + //todo return application ApplicationRelease applicationRelease = applicationManager.getApplicationReleaseByUUID(uuid); if (applicationRelease == null){ String msg = "Application release is in the end state of the application lifecycle flow."; @@ -186,7 +187,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); - // Created new application entry + // Created new Ent App Application application = applicationManager.createApplication(applicationWrapper, constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); if (application != null) { @@ -224,7 +225,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateReleaseCreatingRequest(webAppWrapper.getWebAppReleaseWrappers().get(0)); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); - // Created new application entry + // Created new Web App Application application = applicationManager.createWebClip(webAppWrapper, constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); if (application != null) { @@ -262,7 +263,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateReleaseCreatingRequest(publicAppWrapper.getPublicAppReleaseWrappers().get(0)); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); - // Created new application entry + // Created new Public App Application application = applicationManager.createPublicApp(publicAppWrapper, constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); if (application != null) { @@ -302,8 +303,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem applicationManager.validateBinaryArtifact(binaryFile); applicationManager.validateImageArtifacts(iconFile, bannerFile, attachmentList); - // Created new application release - ApplicationRelease release = applicationManager.createRelease(appId, applicationReleaseWrapper, + // Created new Ent App release + ApplicationRelease release = applicationManager.createEntAppRelease(appId, applicationReleaseWrapper, constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); if (release != null) { return Response.status(Response.Status.CREATED).entity(release).build();