Post api publishing observer implementation

remotes/1731000850486189418/master
Lasantha Dharmakeerthi 9 months ago
commit c8cf4b86ca

@ -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();

@ -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();
}

@ -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<PostApiPublishingObsever> postApiPublishingObseverList = new ArrayList<>();
private APIPublisherDataHolder() {
}
@ -179,4 +183,16 @@ public class APIPublisherDataHolder {
public void setMetadataManagementService(MetadataManagementService metadataManagementService) {
this.metadataManagementService = metadataManagementService;
}
public List<PostApiPublishingObsever> getPostApiPublishingObseverList() {
return postApiPublishingObseverList;
}
public void addPostApiPublishingObseverList(PostApiPublishingObsever postApiPublishingObseverList) {
this.postApiPublishingObseverList.add(postApiPublishingObseverList);
}
public void removePostApiPublishingObseverList(PostApiPublishingObsever postApiPublishingObsever) {
this.postApiPublishingObseverList.remove(postApiPublishingObsever);
}
}

@ -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);
}
}

Loading…
Cancel
Save