From 8bdffc90c6291d565de2e3132017902a6cf83b21 Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Wed, 2 Feb 2022 13:25:20 +0530 Subject: [PATCH 1/2] Add query param to publish an app directly --- .../common/services/ApplicationManager.java | 9 +++--- .../mgt/core/impl/ApplicationManagerImpl.java | 31 ++++++++++++------- .../management/ApplicationManagementTest.java | 11 ++++--- .../ApplicationManagementPublisherAPI.java | 20 ++++++++++++ ...ApplicationManagementPublisherAPIImpl.java | 16 ++++++---- 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java index 5e77584b9a..c3080d4092 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java @@ -51,19 +51,20 @@ public interface ApplicationManager { * * @param applicationWrapper Application that need to be created. * @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc. + * @param isPublished checks if application should be published * @return {@link Application} * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} */ - Application createEntApp(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) + Application createEntApp(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException; - Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) + Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException; - Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) + Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException; - Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) + Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException; /** diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 82405ee2fe..8f484b383e 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -135,7 +135,7 @@ ApplicationManagerImpl implements ApplicationManager { @Override public Application createEntApp(ApplicationWrapper applicationWrapper, - ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Ent. Application create request is received. Application name: " + applicationWrapper.getName() + " Device type: " + applicationWrapper.getDeviceType()); @@ -149,11 +149,11 @@ ApplicationManagerImpl implements ApplicationManager { applicationWrapper.getDeviceType(), tenantId, false); applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); - return addAppDataIntoDB(applicationDTO, tenantId); + return addAppDataIntoDB(applicationDTO, tenantId, isPublished); } @Override - public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) + public Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException { if (log.isDebugEnabled()) { log.debug("Web clip create request is received. App name: " + webAppWrapper.getName() + " Device type: " @@ -175,11 +175,11 @@ ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } //insert application data into database - return addAppDataIntoDB(applicationDTO, tenantId); + return addAppDataIntoDB(applicationDTO, tenantId, isPublished); } @Override - public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact) + public Application createPublicApp(PublicAppWrapper publicAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -231,11 +231,11 @@ ApplicationManagerImpl implements ApplicationManager { throw new ApplicationManagementException(msg, e); } //insert application data into database - return addAppDataIntoDB(applicationDTO, tenantId); + return addAppDataIntoDB(applicationDTO, tenantId, isPublished); } @Override - public Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact) + public Application createCustomApp(CustomAppWrapper customAppWrapper, ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -282,7 +282,7 @@ ApplicationManagerImpl implements ApplicationManager { applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact, tenantId); applicationDTO.getApplicationReleaseDTOs().clear(); applicationDTO.getApplicationReleaseDTOs().add(applicationReleaseDTO); - return addAppDataIntoDB(applicationDTO, tenantId); + return addAppDataIntoDB(applicationDTO, tenantId, isPublished); } catch (ResourceManagementException e) { String msg = "Error occurred while uploading application artifact into the server. Application name: " + customAppWrapper.getName() + " Device type: " + customAppWrapper.getDeviceType(); @@ -872,7 +872,7 @@ ApplicationManagerImpl implements ApplicationManager { * @return {@link Application} * @throws ApplicationManagementException which throws if error occurs while during application management. */ - private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementException { + private Application addAppDataIntoDB(ApplicationDTO applicationDTO, int tenantId, boolean isPublished) throws ApplicationManagementException { ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); List unrestrictedRoles = applicationDTO.getUnrestrictedRoles(); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); @@ -939,11 +939,18 @@ ApplicationManagerImpl implements ApplicationManager { if (log.isDebugEnabled()) { log.debug("Creating a new release. App Id:" + appId); } - String initialLifecycleState = lifecycleStateManager.getInitialState(); - applicationReleaseDTO.setCurrentState(initialLifecycleState); + + String lifeCycleState; + if(isPublished){ + lifeCycleState = lifecycleStateManager.getInstallableState(); + } else { + lifeCycleState = lifecycleStateManager.getInitialState(); + } + + applicationReleaseDTO.setCurrentState(lifeCycleState); applicationReleaseDTO = this.applicationReleaseDAO .createRelease(applicationReleaseDTO, appId, tenantId); - LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, initialLifecycleState); + LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); applicationReleaseEntities.add(applicationReleaseDTO); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/test/java/io/entgra/application/mgt/core/management/ApplicationManagementTest.java b/components/application-mgt/io.entgra.application.mgt.core/src/test/java/io/entgra/application/mgt/core/management/ApplicationManagementTest.java index 998e10e5b1..bab8ef199e 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/test/java/io/entgra/application/mgt/core/management/ApplicationManagementTest.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/test/java/io/entgra/application/mgt/core/management/ApplicationManagementTest.java @@ -41,7 +41,6 @@ import io.entgra.application.mgt.core.dto.ApplicationsDTO; import io.entgra.application.mgt.core.impl.ApplicationManagerImpl; import io.entgra.application.mgt.core.internal.DataHolder; import io.entgra.application.mgt.core.util.ConnectionManagerUtil; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; @@ -121,9 +120,8 @@ public class ApplicationManagementTest extends BaseTestCase { screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); applicationArtifact.setScreenshots(screenshots); - ApplicationManager manager = new ApplicationManagerImpl(); - manager.createEntApp(applicationWrapper, applicationArtifact); + manager.createEntApp(applicationWrapper, applicationArtifact, false); } @DataProvider(name = "applicationIdDataProvider") @@ -140,7 +138,12 @@ public class ApplicationManagementTest extends BaseTestCase { public static Object[][] uuidDataProvider() { return new Object[][] {{"TEST_APP_UUID"}}; } - + + @Test(enabled = false) + public void createApplicationAndPublish(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact, boolean isPublish) throws ApplicationManagementException { + + } + @Test(enabled = false) public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 1cd1411da3..3f37f9252a 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -319,6 +319,11 @@ public interface ApplicationManagementPublisherAPI { value = "The application that need to be created.", required = true) @Multipart("application") ApplicationWrapper application, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("is-Published") boolean isPublished, @ApiParam( name = "binaryFile", value = "Binary file of uploading application", @@ -388,6 +393,11 @@ public interface ApplicationManagementPublisherAPI { value = "The web app that need to be created.", required = true) @Multipart("webapp") WebAppWrapper webAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("is-Published") boolean isPublished, @ApiParam( name = "icon", value = "Icon of the uploading web app", @@ -452,6 +462,11 @@ public interface ApplicationManagementPublisherAPI { value = "The public app that need to be created.", required = true) @Multipart("public-app") PublicAppWrapper publicAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("is-Published") boolean isPublished, @ApiParam( name = "icon", value = "Icon of the uploading public app", @@ -514,6 +529,11 @@ public interface ApplicationManagementPublisherAPI { value = "The application that need to be created.", required = true) @Multipart("application") CustomAppWrapper customAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("is-Published") boolean isPublished, @ApiParam( name = "binaryFile", value = "Binary file of uploading application", diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 8b156bbf9d..ee41b8b976 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -173,6 +173,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Path("/ent-app") public Response createEntApp( @Multipart("application") ApplicationWrapper applicationWrapper, + @QueryParam("is-published") boolean isPublished, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @Multipart(value = "banner", required = false) Attachment bannerFile, @@ -190,7 +191,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem // Created new Ent App Application application = applicationManager.createEntApp(applicationWrapper, - constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); + constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList), isPublished); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { @@ -218,6 +219,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Path("/web-app") public Response createWebApp( @Multipart("webapp") WebAppWrapper webAppWrapper, + @QueryParam("is-published") boolean isPublished, @Multipart("icon") Attachment iconFile, @Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart("screenshot1") Attachment screenshot1, @@ -233,7 +235,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem // Created new Web App Application application = applicationManager.createWebClip(webAppWrapper, - constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); + constructApplicationArtifact(null, iconFile, bannerFile, attachmentList), isPublished); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { @@ -255,12 +257,13 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } - + @POST @Consumes({"multipart/mixed", MediaType.MULTIPART_FORM_DATA}) @Path("/public-app") public Response createPubApp( @Multipart("public-app") PublicAppWrapper publicAppWrapper, + @QueryParam("is-published") boolean isPublished, @Multipart("icon") Attachment iconFile, @Multipart(value = "banner", required = false) Attachment bannerFile, @Multipart("screenshot1") Attachment screenshot1, @@ -276,11 +279,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem // Created new Public App Application application = applicationManager.createPublicApp(publicAppWrapper, - constructApplicationArtifact(null, iconFile, bannerFile, attachmentList)); + constructApplicationArtifact(null, iconFile, bannerFile, attachmentList), isPublished); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { - String msg = "Web app creation is failed"; + String msg = "Public app creation is failed"; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } @@ -304,6 +307,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Path("/custom-app") public Response createCustomApp( @Multipart("application") CustomAppWrapper customAppWrapper, + @QueryParam("is-published") boolean isPublished, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @Multipart(value = "banner", required = false) Attachment bannerFile, @@ -321,7 +325,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem // Created new Custom App Application application = applicationManager.createCustomApp(customAppWrapper, - constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); + constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList), isPublished); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { From 1186c9e292ef0b38a81326aa45ee96e826043ebf Mon Sep 17 00:00:00 2001 From: Gimhan-minion Date: Thu, 10 Feb 2022 17:06:21 +0530 Subject: [PATCH 2/2] Add query param to publish an enterprise release directly --- .../common/services/ApplicationManager.java | 17 +++- .../mgt/core/impl/ApplicationManagerImpl.java | 97 ++++++++++++++++--- .../ApplicationManagementPublisherAPI.java | 5 + ...ApplicationManagementPublisherAPIImpl.java | 3 +- 4 files changed, 106 insertions(+), 16 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java index c3080d4092..018f9af7d9 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/ApplicationManager.java @@ -180,7 +180,18 @@ public interface ApplicationManager { */ ApplicationRelease changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger) throws ApplicationManagementException; - + + /** + * To get all the releases of a particular ApplicationDTO. + * + * @param applicationReleaseDTO of the ApplicationDTO Release. + * @param lifecycleChanger Lifecycle changer that contains the action and the reason for the change. + * @throws ApplicationManagementException ApplicationDTO Management Exception. + * @return + */ + ApplicationRelease changeLifecycleState(ApplicationReleaseDTO applicationReleaseDTO, LifecycleChanger lifecycleChanger) + throws ApplicationManagementException; + /** * To update release images such as icons, banner and screenshots. * @@ -208,10 +219,11 @@ public interface ApplicationManager { * * @param applicationId ID of the ApplicationDTO * @param entAppReleaseWrapper ApplicatonRelease that need to be be created. + * @param isPublished checks if application should be published * @return the unique id of the application release, if the application release succeeded else -1 */ ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper, - ApplicationArtifact applicationArtifact) throws ApplicationManagementException; + ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException; /*** * @@ -305,5 +317,4 @@ public interface ApplicationManager { String getPlistArtifact(String uuid) throws ApplicationManagementException; List getReleaseByPackageNames(List packageIds) throws ApplicationManagementException; - } diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 8f484b383e..599576f7b3 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -940,18 +940,23 @@ ApplicationManagerImpl implements ApplicationManager { log.debug("Creating a new release. App Id:" + appId); } - String lifeCycleState; - if(isPublished){ - lifeCycleState = lifecycleStateManager.getInstallableState(); - } else { - lifeCycleState = lifecycleStateManager.getInitialState(); - } + String lifeCycleState = lifecycleStateManager.getInitialState(); + String[] publishStates= {"IN-REVIEW", "APPROVED", "PUBLISHED"}; applicationReleaseDTO.setCurrentState(lifeCycleState); - applicationReleaseDTO = this.applicationReleaseDAO - .createRelease(applicationReleaseDTO, appId, tenantId); + applicationReleaseDTO = this.applicationReleaseDAO.createRelease(applicationReleaseDTO, appId, tenantId); LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + + if(isPublished){ + for (String state: publishStates) { + LifecycleChanger lifecycleChanger = new LifecycleChanger(); + lifecycleChanger.setAction(state); + lifecycleChanger.setReason("Updated to " + state); + this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger); + } + } + applicationReleaseEntities.add(applicationReleaseDTO); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); Application application = APIUtil.appDtoToAppResponse(applicationDTO); @@ -1011,7 +1016,7 @@ ApplicationManagerImpl implements ApplicationManager { @Override public ApplicationRelease createEntAppRelease(int applicationId, EntAppReleaseWrapper entAppReleaseWrapper, - ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + ApplicationArtifact applicationArtifact, boolean isPublished) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { log.debug("Application release creating request is received for the application id: " + applicationId); @@ -1037,15 +1042,28 @@ ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts( APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(), tenantId, true); + try { ConnectionManagerUtil.beginDBTransaction(); - String initialstate = lifecycleStateManager.getInitialState(); - applicationReleaseDTO.setCurrentState(initialstate); - LifecycleState lifecycleState = getLifecycleStateInstance(initialstate, initialstate); + String lifeCycleState = lifecycleStateManager.getInitialState(); + String[] publishStates= {"IN-REVIEW", "APPROVED", "PUBLISHED"}; + + applicationReleaseDTO.setCurrentState(lifeCycleState); + LifecycleState lifecycleState = getLifecycleStateInstance(lifeCycleState, lifeCycleState); applicationReleaseDTO = this.applicationReleaseDAO .createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId); this.lifecycleStateDAO .addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + + if(isPublished){ + for (String state: publishStates) { + LifecycleChanger lifecycleChanger = new LifecycleChanger(); + lifecycleChanger.setAction(state); + lifecycleChanger.setReason("Updated to " + state); + this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger); + } + } + ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO); ConnectionManagerUtil.commitDBTransaction(); return applicationRelease; @@ -1890,6 +1908,61 @@ ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.closeDBConnection(); } } + + public ApplicationRelease changeLifecycleState(ApplicationReleaseDTO applicationReleaseDTO, LifecycleChanger lifecycleChanger) throws ApplicationManagementException { + + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + if (lifecycleChanger == null || StringUtils.isEmpty(lifecycleChanger.getAction())) { + String msg = "The Action is null or empty. Please verify the request."; + log.error(msg); + throw new BadRequestException(msg); + } + + try{ + if (lifecycleStateManager + .isValidStateChange(applicationReleaseDTO.getCurrentState(), lifecycleChanger.getAction(), userName, + tenantId)) { + if (lifecycleStateManager.isInstallableState(lifecycleChanger.getAction()) && applicationReleaseDAO + .hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(), + lifecycleStateManager.getInstallableState(), tenantId)) { + String msg = "Installable application release is already registered for the application. " + + "Therefore it is not permitted to change the lifecycle state from " + + applicationReleaseDTO.getCurrentState() + " to " + lifecycleChanger.getAction(); + log.error(msg); + throw new ForbiddenException(msg); + } + LifecycleState lifecycleState = new LifecycleState(); + lifecycleState.setCurrentState(lifecycleChanger.getAction()); + lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState()); + lifecycleState.setUpdatedBy(userName); + lifecycleState.setReasonForChange(lifecycleChanger.getReason()); + applicationReleaseDTO.setCurrentState(lifecycleChanger.getAction()); + if (this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId) == null) { + String msg = "Application release updating is failed/."; + log.error(msg); + throw new ApplicationManagementException(msg); + } + this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); + return APIUtil.releaseDtoToRelease(applicationReleaseDTO); + } else { + String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'" + + " to '" + lifecycleChanger.getAction() + "'"; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred when accessing application release data of application release which has the " + + "application release UUID: " + applicationReleaseDTO.getUuid(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } catch (LifeCycleManagementDAOException e) { + String msg = "Failed to add lifecycle state for Application release UUID: " + applicationReleaseDTO.getUuid(); + log.error(msg, e); + throw new ApplicationManagementException(msg, e); + } + } + @Override public void addApplicationCategories(List categories) throws ApplicationManagementException { diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 3f37f9252a..772ac1a33d 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -613,6 +613,11 @@ public interface ApplicationManagementPublisherAPI { value = "The application release that need to be created.", required = true) @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("is-Published") boolean isPublished, @ApiParam( name = "binaryFile", value = "Binary file of uploading application", diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index ee41b8b976..155348284f 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -355,6 +355,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @PathParam("deviceType") String deviceType, @PathParam("appId") int appId, @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, + @QueryParam("is-published") boolean isPublished, @Multipart("binaryFile") Attachment binaryFile, @Multipart("icon") Attachment iconFile, @Multipart(value = "banner", required = false) Attachment bannerFile, @@ -370,7 +371,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem // Created new Ent App release ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper, - constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList)); + constructApplicationArtifact(binaryFile, iconFile, bannerFile, attachmentList), isPublished); if (release != null) { return Response.status(Response.Status.CREATED).entity(release).build(); } else {