From 22f4da908f096123d31b8501873fc3eb47c4d1a2 Mon Sep 17 00:00:00 2001 From: Dharmakeerthi Lasantha Date: Thu, 1 Jun 2023 17:13:51 +0530 Subject: [PATCH] Add Consumer REST API integration --- .../pom.xml | 6 ++++ ...ApplicationManagerExtensionDataHolder.java | 10 ++++++ ...ationManagerExtensionServiceComponent.java | 32 +++++++++++++++++++ .../internal/PublisherRESTAPIDataHolder.java | 11 +++++++ .../PublisherRESTAPIServiceComponent.java | 3 +- 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml index 9968446869..d9a1370d00 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml @@ -74,6 +74,11 @@ io.entgra.device.mgt.core.identity.jwt.client.extension provided + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.apimgt.extension.rest.api + + @@ -121,6 +126,7 @@ io.entgra.device.mgt.core.identity.jwt.client.extension.dto, io.entgra.device.mgt.core.identity.jwt.client.extension.exception, io.entgra.device.mgt.core.identity.jwt.client.extension.service, + io.entgra.device.mgt.core.apimgt.extension.rest.api, org.wso2.carbon.registry.core.exceptions;version="[1.0,2)", org.wso2.carbon.registry.core.service;version="[1.0,2)", org.wso2.carbon.registry.indexing.service;version="${carbon.registry.imp.pkg.version.range}", diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java index 8a4cf4f1a6..893e17034b 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.apimgt.application.extension.internal; import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProviderService; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices; import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.registry.core.service.TenantRegistryLoader; @@ -35,6 +36,7 @@ public class APIApplicationManagerExtensionDataHolder { private TenantRegistryLoader tenantRegistryLoader; private TenantIndexingLoader indexLoader; private JWTClientManagerService jwtClientManagerService; + private ConsumerRESTAPIServices consumerRESTAPIServices; private APIApplicationManagerExtensionDataHolder() { } @@ -103,4 +105,12 @@ public class APIApplicationManagerExtensionDataHolder { public void setJwtClientManagerService(JWTClientManagerService jwtClientManagerService) { this.jwtClientManagerService = jwtClientManagerService; } + + public ConsumerRESTAPIServices getConsumerRESTAPIServices() { + return consumerRESTAPIServices; + } + + public void setConsumerRESTAPIServices(ConsumerRESTAPIServices consumerRESTAPIServices) { + this.consumerRESTAPIServices = consumerRESTAPIServices; + } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java index 53dccb67d8..9e9166d11a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java @@ -17,6 +17,7 @@ */ package io.entgra.device.mgt.core.apimgt.application.extension.internal; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; @@ -48,6 +49,12 @@ import org.wso2.carbon.user.core.service.RealmService; * policy="dynamic" * bind="setRealmService" * unbind="unsetRealmService" + * @scr.reference name="io.entgra.device.mgt.core.apimgt.extension.rest.api" + * interface="io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices" + * cardinality="0..1" + * policy="dynamic" + * bind="setConsumerRESTAPIServices" + * unbind="unsetConsumerRESTAPIServices" */ public class APIApplicationManagerExtensionServiceComponent { @@ -113,4 +120,29 @@ public class APIApplicationManagerExtensionServiceComponent { } APIApplicationManagerExtensionDataHolder.getInstance().setRealmService(null); } + + /** + * Sets APIM Consumer REST API service. + * + * @param consumerRESTAPIServices An instance of ConsumerRESTAPIServices + */ + protected void setConsumerRESTAPIServices(ConsumerRESTAPIServices consumerRESTAPIServices) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + APIApplicationManagerExtensionDataHolder.getInstance().setConsumerRESTAPIServices(consumerRESTAPIServices); + } + + /** + * Unset APIM Consumer REST API service + * + * @param consumerRESTAPIServices An instance of ConsumerRESTAPIServices + */ + protected void unsetConsumerRESTAPIServices(ConsumerRESTAPIServices consumerRESTAPIServices) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + APIApplicationManagerExtensionDataHolder.getInstance().setConsumerRESTAPIServices(null); + } + } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java index 9a53757b0b..4995df95ef 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.internal; import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; public class PublisherRESTAPIDataHolder { @@ -26,6 +27,8 @@ public class PublisherRESTAPIDataHolder { private APIApplicationServices apiApplicationServices; private APIManagerConfigurationService apiManagerConfigurationService; + private ConsumerRESTAPIServices consumerRESTAPIServices; + private static PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); private PublisherRESTAPIDataHolder() { @@ -54,4 +57,12 @@ public class PublisherRESTAPIDataHolder { return apiManagerConfigurationService; } + public ConsumerRESTAPIServices getConsumerRESTAPIServices() { + return consumerRESTAPIServices; + } + + public void setConsumerRESTAPIServices(ConsumerRESTAPIServices consumerRESTAPIServices) { + this.consumerRESTAPIServices = consumerRESTAPIServices; + } + } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java index 86cb5109e3..cb5c992664 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java @@ -40,7 +40,7 @@ import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; */ public class PublisherRESTAPIServiceComponent { - private static Log log = LogFactory.getLog(PublisherRESTAPIServiceComponent.class); + private static final Log log = LogFactory.getLog(PublisherRESTAPIServiceComponent.class); protected void activate(ComponentContext componentContext) { if (log.isDebugEnabled()) { @@ -55,6 +55,7 @@ public class PublisherRESTAPIServiceComponent { ConsumerRESTAPIServices consumerRESTAPIServices = new ConsumerRESTAPIServicesImpl(); bundleContext.registerService(ConsumerRESTAPIServices.class.getName(), consumerRESTAPIServices, null); + PublisherRESTAPIDataHolder.getInstance().setConsumerRESTAPIServices(consumerRESTAPIServices); if (log.isDebugEnabled()) { log.debug("API Application bundle has been successfully initialized");