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 12346507da..82e78096b1 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 @@ -50,10 +50,11 @@ public interface ApplicationManager { * * @param appId application id of the application to which the release should be created * @param releaseWrapper {@link EntAppReleaseWrapper} of the release to be created + * @param isPublished If the app should be added in PUBLISHED state instead of initial state * @return Created application release bean * @throws ApplicationManagementException if any error occurred while creating the application */ - ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper) + ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper, boolean isPublished) throws ApplicationManagementException; /** @@ -61,10 +62,11 @@ public interface ApplicationManager { * * @param appId application id of the application to which the release should be created * @param releaseWrapper {@link WebAppReleaseWrapper} of the release to be created + * @param isPublished If the app should be added in PUBLISHED state instead of initial state * @return Created application release bean * @throws ApplicationManagementException if any error occurred while creating the application */ - ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper) + ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper, boolean isPublished) throws ApplicationManagementException, ResourceManagementException; /** @@ -72,10 +74,11 @@ public interface ApplicationManager { * * @param appId application id of the application to which the release should be created * @param releaseWrapper {@link PublicAppReleaseWrapper} of the release to be created + * @param isPublished If the app should be added in PUBLISHED state instead of initial state * @return Created application release bean * @throws ApplicationManagementException if any error occurred while creating the application */ - ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper) + ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper, boolean isPublished) throws ApplicationManagementException, ResourceManagementException; /** @@ -83,10 +86,11 @@ public interface ApplicationManager { * * @param appId application id of the application to which the release should be created * @param releaseWrapper {@link CustomAppReleaseWrapper} of the release to be created + * @param isPublished If the app should be added in PUBLISHED state instead of initial state * @return Created application release bean * @throws ApplicationManagementException if any error occurred while creating the application */ - ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper) + ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper, boolean isPublished) throws ResourceManagementException, ApplicationManagementException; /** @@ -113,21 +117,23 @@ public interface ApplicationManager { * required to do the validation of request and check the existence of application releaseDTO. * * @param applicationDTO Application DTO object. + * @param isPublished Wether the app should be added in PUBLISHED state instead of initial state * @return {@link Application} * @throws ApplicationManagementException which throws if error occurs while during application management. */ - Application addAppDataIntoDB(ApplicationDTO applicationDTO) throws + Application addAppDataIntoDB(ApplicationDTO applicationDTO, boolean isPublished) throws ApplicationManagementException; /** * This method is responsible for handling application creation * * @param app Application wrapper object which depends on the application type + * @param isPublished If the app should be created in PUBLISHED state * @param Application wrapper class which depends on the application type * @return Created application bean * @throws ApplicationManagementException if any error occurred while creating the application */ - Application createApplication(T app) throws ApplicationManagementException; + Application createApplication(T app, boolean isPublished) throws ApplicationManagementException; /** * Add an application to favourites * @param appId id of the application @@ -249,10 +255,11 @@ public interface ApplicationManager { * @param applicationDTO ApplicationDTO of the release * @param applicationReleaseDTO ApplicatonRelease that need to be be created. * @param type {@link ApplicationType} + * @param isPublished if the app should be added in PUBLISHED state instead of initial state * @return the unique id of the application release, if the application release succeeded else -1 */ ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO, - ApplicationType type) + ApplicationType type, boolean isPublished) throws ApplicationManagementException; /** diff --git a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/SPApplicationManager.java b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/SPApplicationManager.java index 433fa5ff12..bd4b1dd015 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/SPApplicationManager.java +++ b/components/application-mgt/io.entgra.application.mgt.common/src/main/java/io/entgra/application/mgt/common/services/SPApplicationManager.java @@ -131,11 +131,12 @@ public interface SPApplicationManager { * @param identityServerId id of the identity server to which the created application should be mapped * @param spId uid of the service provder to which the created application should be mapped * @param Application wrapper class which depends on application type (PUBLIC, ENTERPRISE & etc) + * @param isPublished If the app should be added in PUBLISHED state instead of initial state * @return Application bean of the created application * @throws ApplicationManagementException if errors while creating and mapping the application * @throws RequestValidatingException if app contains any invalid payload */ - Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException, RequestValidatingException; + Application createSPApplication(T app, int identityServerId, String spId, boolean isPublished) throws ApplicationManagementException, RequestValidatingException; /** * Validates application ids of the applications that should be attached 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 375924a036..b7fce45b1a 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 @@ -138,11 +138,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application createApplication(T app) throws ApplicationManagementException { + public Application createApplication(T app, boolean isPublished) throws ApplicationManagementException { ApplicationDTO applicationDTO = uploadReleaseArtifactIfExist(app); try { ConnectionManagerUtil.beginDBTransaction(); - Application application = addAppDataIntoDB(applicationDTO); + Application application = addAppDataIntoDB(applicationDTO, isPublished); ConnectionManagerUtil.commitDBTransaction(); return application; } catch (DBConnectionException e) { @@ -167,7 +167,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper) + public ApplicationRelease createEntAppRelease(int appId, EntAppReleaseWrapper releaseWrapper, boolean isPublished) throws ApplicationManagementException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationArtifact artifact = ApplicationManagementUtil.constructApplicationArtifact(releaseWrapper.getIcon(), releaseWrapper.getScreenshots(), @@ -177,7 +177,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); releaseDTO = uploadEntAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName(), true); try { - return createRelease(applicationDTO, releaseDTO, ApplicationType.ENTERPRISE); + return createRelease(applicationDTO, releaseDTO, ApplicationType.ENTERPRISE, isPublished); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating ent app release for application with the name: " + applicationDTO.getName(); log.error(msg, e); @@ -187,7 +187,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper) + public ApplicationRelease createWebAppRelease(int appId, WebAppReleaseWrapper releaseWrapper, boolean isPublished) throws ApplicationManagementException, ResourceManagementException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationDTO applicationDTO = applicationManager.getApplication(appId); @@ -196,7 +196,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); releaseDTO = uploadWebAppReleaseArtifacts(releaseDTO, artifact); try { - return createRelease(applicationDTO, releaseDTO, ApplicationType.WEB_CLIP); + return createRelease(applicationDTO, releaseDTO, ApplicationType.WEB_CLIP, isPublished); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating web app release for application with the name: " + applicationDTO.getName(); log.error(msg, e); @@ -206,7 +206,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper) throws + public ApplicationRelease createPubAppRelease(int appId, PublicAppReleaseWrapper releaseWrapper, boolean isPublished) throws ResourceManagementException, ApplicationManagementException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationDTO applicationDTO = applicationManager.getApplication(appId); @@ -216,7 +216,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); releaseDTO = uploadPubAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName()); try { - return createRelease(applicationDTO, releaseDTO, ApplicationType.PUBLIC); + return createRelease(applicationDTO, releaseDTO, ApplicationType.PUBLIC, isPublished); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating ent public release for application with the name: " + applicationDTO.getName(); log.error(msg, e); @@ -226,7 +226,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper) + public ApplicationRelease createCustomAppRelease(int appId, CustomAppReleaseWrapper releaseWrapper, boolean isPublished) throws ResourceManagementException, ApplicationManagementException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationDTO applicationDTO = applicationManager.getApplication(appId); @@ -236,7 +236,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationReleaseDTO releaseDTO = APIUtil.releaseWrapperToReleaseDTO(releaseWrapper); releaseDTO = uploadCustomAppReleaseArtifacts(releaseDTO, artifact, deviceType.getName()); try { - return createRelease(applicationDTO, releaseDTO, ApplicationType.CUSTOM); + return createRelease(applicationDTO, releaseDTO, ApplicationType.CUSTOM, isPublished); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating custom app release for application with the name: " + applicationDTO.getName(); log.error(msg, e); @@ -1192,7 +1192,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application addAppDataIntoDB(ApplicationDTO applicationDTO) throws + public Application addAppDataIntoDB(ApplicationDTO applicationDTO, boolean isPublished) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); ApplicationReleaseDTO applicationReleaseDTO = null; @@ -1258,12 +1258,21 @@ public class ApplicationManagerImpl implements ApplicationManager { } List applicationReleaseEntities = new ArrayList<>(); if (applicationReleaseDTO != null) { - String initialLifecycleState = lifecycleStateManager.getInitialState(); - applicationReleaseDTO.setCurrentState(initialLifecycleState); - applicationReleaseDTO = this.applicationReleaseDAO - .createRelease(applicationReleaseDTO, appId, tenantId); - LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState, initialLifecycleState); + String lifeCycleState = lifecycleStateManager.getInitialState(); + String[] publishStates= {"IN-REVIEW", "APPROVED", "PUBLISHED"}; + + applicationReleaseDTO.setCurrentState(lifeCycleState); + 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.setId(appId); @@ -1296,7 +1305,7 @@ public class ApplicationManagerImpl implements ApplicationManager { @Override public ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO, - ApplicationType type) + ApplicationType type, boolean isPublished) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { @@ -1322,13 +1331,23 @@ public class ApplicationManagerImpl implements ApplicationManager { 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; diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SPApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SPApplicationManagerImpl.java index 6f8fd98198..8382f428b5 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SPApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/SPApplicationManagerImpl.java @@ -650,7 +650,7 @@ public class SPApplicationManagerImpl implements SPApplicationManager { } @Override - public Application createSPApplication(T app, int identityServerId, String spId) throws ApplicationManagementException { + public Application createSPApplication(T app, int identityServerId, String spId, boolean isPublished) throws ApplicationManagementException { validateServiceProviderUID(identityServerId, spId); ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance(); ApplicationDTO applicationDTO = applicationManager.uploadReleaseArtifactIfExist(app); @@ -660,7 +660,7 @@ public class SPApplicationManagerImpl implements SPApplicationManager { } try { ConnectionManagerUtil.beginDBTransaction(); - Application createdApp = applicationManager.addAppDataIntoDB(applicationDTO); + Application createdApp = applicationManager.addAppDataIntoDB(applicationDTO, isPublished); attachCreatedSPApplication(createdApp, identityServerId, spId); ConnectionManagerUtil.commitDBTransaction(); return createdApp; 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 9d51887beb..5d9f59bd21 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 @@ -121,7 +121,7 @@ public class ApplicationManagementTest extends BaseTestCase { applicationArtifact.setScreenshots(screenshots); ApplicationManager manager = new ApplicationManagerImpl(); - manager.createApplication(applicationWrapper); + manager.createApplication(applicationWrapper, false); } @DataProvider(name = "applicationIdDataProvider") 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 23ca981b00..5abce176c6 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 @@ -317,7 +317,12 @@ public interface ApplicationManagementPublisherAPI { name = "application", value = "The application that need to be created.", required = true) - ApplicationWrapper application); + ApplicationWrapper application, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished); @POST @Path("/web-app") @@ -356,7 +361,12 @@ public interface ApplicationManagementPublisherAPI { name = "webapp", value = "The web app that need to be created.", required = true) - WebAppWrapper webAppWrapper + WebAppWrapper webAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -396,7 +406,12 @@ public interface ApplicationManagementPublisherAPI { name = "public-app", value = "The public app that need to be created.", required = true) - PublicAppWrapper publicAppWrapper + PublicAppWrapper publicAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -436,7 +451,12 @@ public interface ApplicationManagementPublisherAPI { name = "application", value = "The application that need to be created.", required = true) - CustomAppWrapper customAppWrapper + CustomAppWrapper customAppWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -486,7 +506,12 @@ public interface ApplicationManagementPublisherAPI { name = "applicationRelease", value = "The application release that need to be created.", required = true) - EntAppReleaseWrapper entAppReleaseWrapper + EntAppReleaseWrapper entAppReleaseWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -536,7 +561,12 @@ public interface ApplicationManagementPublisherAPI { name = "applicationRelease", value = "The application release that need to be created.", required = true) - PublicAppReleaseWrapper publicAppReleaseWrapper + PublicAppReleaseWrapper publicAppReleaseWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -581,7 +611,12 @@ public interface ApplicationManagementPublisherAPI { name = "applicationRelease", value = "The application release that need to be created.", required = true) - WebAppReleaseWrapper webAppReleaseWrapper + WebAppReleaseWrapper webAppReleaseWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @POST @@ -631,7 +666,12 @@ public interface ApplicationManagementPublisherAPI { name = "applicationRelease", value = "The application release that need to be created.", required = true) - CustomAppReleaseWrapper customAppReleaseWrapper + CustomAppReleaseWrapper customAppReleaseWrapper, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished ); @PUT diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/SPApplicationService.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/SPApplicationService.java index 3b521eec5c..995c892aa5 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/SPApplicationService.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/SPApplicationService.java @@ -24,6 +24,7 @@ import io.entgra.application.mgt.common.wrapper.PublicAppWrapper; import io.entgra.application.mgt.common.wrapper.WebAppWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Info; @@ -311,7 +312,12 @@ public interface SPApplicationService { } ) Response createEntApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app); + @PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished); /** * This method is used to register an APIM application for tenant domain. @@ -332,7 +338,12 @@ public interface SPApplicationService { } ) Response createPubApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app); + @PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished); @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app") @POST @@ -350,7 +361,12 @@ public interface SPApplicationService { } ) Response createWebApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app); + @PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished); @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app") @POST @@ -368,5 +384,10 @@ public interface SPApplicationService { } ) Response createCustomApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app); + @PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app, + @ApiParam( + name = "isPublished", + value = "Published state of the application" + ) + @QueryParam("isPublished") boolean isPublished); } 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 f17e2e973d..078af292d9 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 @@ -169,9 +169,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes(MediaType.APPLICATION_JSON) @Path("/ent-app") public Response createEntApp( - ApplicationWrapper applicationWrapper) { + ApplicationWrapper applicationWrapper, @QueryParam("is-published") boolean isPublished) { try { - return createApplication(applicationWrapper); + return createApplication(applicationWrapper, isPublished); } catch (BadRequestException e) { String msg = "Found incompatible payload with ent. app creating request."; log.error(msg, e); @@ -191,9 +191,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes(MediaType.APPLICATION_JSON) @Path("/web-app") public Response createWebApp( - WebAppWrapper webAppWrapper) { + WebAppWrapper webAppWrapper, @QueryParam("is-published") boolean isPublished) { try { - return createApplication(webAppWrapper); + return createApplication(webAppWrapper, isPublished); } catch (BadRequestException e) { String msg = "Found incompatible payload with web app creating request."; log.error(msg, e); @@ -213,9 +213,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes(MediaType.APPLICATION_JSON) @Path("/public-app") public Response createPubApp( - PublicAppWrapper publicAppWrapper) { + PublicAppWrapper publicAppWrapper, @QueryParam("is-published") boolean isPublished) { try { - return createApplication(publicAppWrapper); + return createApplication(publicAppWrapper, isPublished); } catch (BadRequestException e) { String msg = "Found incompatible payload with pub app creating request."; log.error(msg, e); @@ -235,9 +235,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Consumes(MediaType.APPLICATION_JSON) @Path("/custom-app") public Response createCustomApp( - CustomAppWrapper customAppWrapper) { + CustomAppWrapper customAppWrapper, @QueryParam("is-published") boolean isPublished) { try { - return createApplication(customAppWrapper); + return createApplication(customAppWrapper, isPublished); } catch (BadRequestException e) { String msg = "Found incompatible payload with custom app creating request."; log.error(msg, e); @@ -259,11 +259,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem public Response createEntAppRelease( @PathParam("deviceType") String deviceTypeName, @PathParam("appId") int appId, - EntAppReleaseWrapper entAppReleaseWrapper) { + EntAppReleaseWrapper entAppReleaseWrapper, + @QueryParam("isPublished") boolean isPublished) { try { ApplicationManager applicationManager = APIUtil.getApplicationManager(); applicationManager.validateEntAppReleaseCreatingRequest(entAppReleaseWrapper, deviceTypeName); - ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper); + ApplicationRelease release = applicationManager.createEntAppRelease(appId, entAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(release).build(); } catch (RequestValidatingException e) { String msg = "Error occurred while validating binaryArtifact"; @@ -283,12 +284,12 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem public Response createPubAppRelease( @PathParam("deviceType") String deviceTypeName, @PathParam("appId") int appId, - PublicAppReleaseWrapper publicAppReleaseWrapper) { + PublicAppReleaseWrapper publicAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) { try { ApplicationManager applicationManager = APIUtil.getApplicationManager(); applicationManager.validatePublicAppReleaseCreatingRequest(publicAppReleaseWrapper, deviceTypeName); - ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper); + ApplicationRelease applicationRelease = applicationManager.createPubAppRelease(appId, publicAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); } catch (ApplicationManagementException e) { String msg = "Error occurred while creating application release for the application with the id " + appId; @@ -311,11 +312,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem @Override public Response createWebAppRelease( @PathParam("appId") int appId, - WebAppReleaseWrapper webAppReleaseWrapper) { + WebAppReleaseWrapper webAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) { try { ApplicationManager applicationManager = APIUtil.getApplicationManager(); applicationManager.validateWebAppReleaseCreatingRequest(webAppReleaseWrapper); - ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper); + ApplicationRelease applicationRelease= applicationManager.createWebAppRelease(appId, webAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(applicationRelease).build(); } catch (ResourceManagementException e) { String msg = "Error occurred while uploading application release artifacts"; @@ -339,11 +340,11 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem public Response createCustomAppRelease( @PathParam("deviceType") String deviceTypeName, @PathParam("appId") int appId, - CustomAppReleaseWrapper customAppReleaseWrapper) { + CustomAppReleaseWrapper customAppReleaseWrapper, @QueryParam("isPublished") boolean isPublished) { try { ApplicationManager applicationManager = APIUtil.getApplicationManager(); applicationManager.validateCustomAppReleaseCreatingRequest(customAppReleaseWrapper, deviceTypeName); - ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper); + ApplicationRelease release = applicationManager.createCustomAppRelease(appId, customAppReleaseWrapper, isPublished); return Response.status(Response.Status.CREATED).entity(release).build(); } catch (RequestValidatingException e) { String msg = "Error occurred while validating binaryArtifact"; @@ -864,10 +865,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } } - public Response createApplication(T appWrapper) throws ApplicationManagementException, RequestValidatingException { + public Response createApplication(T appWrapper, boolean isPublished) throws ApplicationManagementException, RequestValidatingException { ApplicationManager applicationManager = APIUtil.getApplicationManager(); applicationManager.validateAppCreatingRequest(appWrapper); - Application application = applicationManager.createApplication(appWrapper); + Application application = applicationManager.createApplication(appWrapper, isPublished); if (application != null) { return Response.status(Response.Status.CREATED).entity(application).build(); } else { diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java index cceefb6c18..ec197dd47f 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/SPApplicationServiceImpl.java @@ -294,32 +294,36 @@ public class SPApplicationServiceImpl implements SPApplicationService { @POST @Override public Response createEntApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app) { - return createSPApplication(identityServerId, serviceProviderId, app); + @PathParam("service-provider-id") String serviceProviderId, ApplicationWrapper app, + @QueryParam("isPublished") boolean isPublished) { + return createSPApplication(identityServerId, serviceProviderId, app, isPublished); } @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/public-app") @POST @Override public Response createPubApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app) { - return createSPApplication(identityServerId, serviceProviderId, app); + @PathParam("service-provider-id") String serviceProviderId, PublicAppWrapper app, + @QueryParam("isPublished") boolean isPublished) { + return createSPApplication(identityServerId, serviceProviderId, app, isPublished); } @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/web-app") @POST @Override public Response createWebApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app) { - return createSPApplication(identityServerId, serviceProviderId, app); + @PathParam("service-provider-id") String serviceProviderId, WebAppWrapper app, + @QueryParam("isPublished") boolean isPublished) { + return createSPApplication(identityServerId, serviceProviderId, app, isPublished); } @Path("/{identity-server-id}/service-provider/{service-provider-id}/create/custom-app") @POST @Override public Response createCustomApp(@PathParam("identity-server-id") int identityServerId, - @PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app) { - return createSPApplication(identityServerId, serviceProviderId, app); + @PathParam("service-provider-id") String serviceProviderId, CustomAppWrapper app, + @QueryParam("isPublished") boolean isPublished) { + return createSPApplication(identityServerId, serviceProviderId, app, isPublished); } /** @@ -331,10 +335,10 @@ public class SPApplicationServiceImpl implements SPApplicationService { * @param application wrapper class * @return Response */ - private Response createSPApplication(int identityServerId, String spUID, T appWrapper) { + private Response createSPApplication(int identityServerId, String spUID, T appWrapper, boolean isPublished) { try { SPApplicationManager spApplicationManager = APIUtil.getSPApplicationManager(); - Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, spUID); + Application createdApp = spApplicationManager.createSPApplication(appWrapper, identityServerId, spUID, isPublished); return Response.status(Response.Status.CREATED).entity(createdApp).build(); } catch (NotFoundException e) { String msg = "No identity server exist with the id " + identityServerId;