diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java index 244cc99b06..e039259b92 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -90,6 +90,15 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { } catch (APIManagerPublisherException e) { log.error("failed to update scope role mapping.", e); } + + // execute after api publishing + for (PostApiPublishingObsever observer : APIPublisherDataHolder.getInstance().getPostApiPublishingObseverList()) { + if (log.isDebugEnabled()) { + log.debug("Executing " + observer.getClass().getName()); + } + observer.execute(); + } + log.info("Finish executing PostApiPublishingObsevers"); } }); t.start(); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/PostApiPublishingObsever.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/PostApiPublishingObsever.java new file mode 100644 index 0000000000..392e780300 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/PostApiPublishingObsever.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.entgra.device.mgt.core.apimgt.webapp.publisher; + +public interface PostApiPublishingObsever { + void execute(); + +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java index 4f8e5599bf..d00f50e35f 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java @@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServi import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig; import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService; +import io.entgra.device.mgt.core.apimgt.webapp.publisher.PostApiPublishingObsever; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.registry.core.service.RegistryService; @@ -32,9 +33,11 @@ import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.tenant.TenantManager; import org.wso2.carbon.utils.ConfigurationContextService; -import java.util.HashMap; import java.util.Map; import java.util.Stack; +import java.util.List; +import java.util.ArrayList; + public class APIPublisherDataHolder { @@ -52,6 +55,7 @@ public class APIPublisherDataHolder { private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder(); + private List postApiPublishingObseverList = new ArrayList<>(); private APIPublisherDataHolder() { } @@ -179,4 +183,16 @@ public class APIPublisherDataHolder { public void setMetadataManagementService(MetadataManagementService metadataManagementService) { this.metadataManagementService = metadataManagementService; } + + public List getPostApiPublishingObseverList() { + return postApiPublishingObseverList; + } + + public void addPostApiPublishingObseverList(PostApiPublishingObsever postApiPublishingObseverList) { + this.postApiPublishingObseverList.add(postApiPublishingObseverList); + } + + public void removePostApiPublishingObseverList(PostApiPublishingObsever postApiPublishingObsever) { + this.postApiPublishingObseverList.remove(postApiPublishingObsever); + } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java index 7427bd930f..62684c2215 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java @@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal; import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService; +import io.entgra.device.mgt.core.apimgt.webapp.publisher.PostApiPublishingObsever; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; @@ -66,6 +67,12 @@ import java.util.HashMap; * policy="dynamic" * bind="setMetaDataMgtService" * unbind="unsetMetaDataMgtService" + * @scr.reference name="postApiPublishingObsever" + * interface="io.entgra.device.mgt.core.apimgt.webapp.publisher.PostApiPublishingObsever" + * cardinality="0..n" + * policy="dynamic" + * bind="setPostApiPublishingObsever" + * unbind="unsetPostApiPublishingObsever" */ public class APIPublisherServiceComponent { @@ -176,4 +183,18 @@ public class APIPublisherServiceComponent { APIPublisherDataHolder.getInstance().setMetadataManagementService(null); } + protected void setPostApiPublishingObsever(PostApiPublishingObsever postApiPublishingObsever) { + if (log.isDebugEnabled()) { + log.debug("Setting PostApiPublishingObsever"); + } + APIPublisherDataHolder.getInstance().addPostApiPublishingObseverList(postApiPublishingObsever); + } + + protected void unsetPostApiPublishingObsever(PostApiPublishingObsever postApiPublishingObsever) { + if (log.isDebugEnabled()) { + log.debug("Unsetting PostApiPublishingObsever"); + } + APIPublisherDataHolder.getInstance().removePostApiPublishingObseverList(postApiPublishingObsever); + } + }