Skip to content

Commit

Permalink
Merge pull request #12355 from Thenujan-Nagaratnam/marketplace-assist…
Browse files Browse the repository at this point in the history
…ant-ai

Marketplace assistant
  • Loading branch information
Arshardh authored Mar 23, 2024
2 parents 1ab51af + 16dd85c commit 6984829
Show file tree
Hide file tree
Showing 27 changed files with 1,683 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ private AI() {
public static final String FIRST_NAME = DEFAULT_CARBON_DIALECT + "/givenname";
public static final String LAST_NAME = DEFAULT_CARBON_DIALECT + "/lastname";

// constants for marketplace assistant
public static final String MARKETPLACE_ASSISTANT = "MarketplaceAssistant";
public static final String MARKETPLACE_ASSISTANT_ENABLED = "Enabled";
public static final String MARKETPLACE_ASSISTANT_AUTH_TOKEN = "AuthToken";
public static final String MARKETPLACE_ASSISTANT_ENDPOINT = "Endpoint";
public static final String MARKETPLACE_ASSISTANT_CHAT_RESOURCE = "ChatResource";
public static final String MARKETPLACE_ASSISTANT_PUBLISH_API_RESOURCE = "ApiPublishResource";
public static final String MARKETPLACE_ASSISTANT_DELETE_API_RESOURCE = "ApiDeleteResource";
public static final String MARKETPLACE_ASSISTANT_API_COUNT_RESOURCE = "ApiCountResource";


//Overview constants for CORS configuration
public static final String API_OVERVIEW_CORS_CONFIGURATION = "overview_corsConfiguration";
//Registry lifecycle related info
Expand Down Expand Up @@ -1695,6 +1706,34 @@ private ConfigParameters() {
public static final String API_DATA_URL = "url";
public static final String API_UUID = "apiUUID";


public static final String UUID = "uuid";
public static final String API_SPEC_TYPE = "api_type";
public static final String API_SPEC_NAME = "api_name";
public static final String TENANT_DOMAIN = "tenant_domain";
public static final String QUERY = "query";
public static final String HISTORY = "history";
public static final String VERSION = "version";
public static final String DESCRIPTION = "description";

public static final String DEMOTE_TO_CREATED= "Demote to Created";
public static final String BLOCK = "Block";
public static final String DEPRECATE = "Deprecate";
public static final String PUBLISH = "Publish";
public static final String DEPLOY_AS_A_PROTOTYPE = "Deploy as a Prototype";
public static final String REPUBLISH = "Re-Publish";

public static final String API_SPEC_TYPE_REST = "api_spec";
public static final String API_SPEC_TYPE_GRAPHQL = "sdl_schema";
public static final String API_SPEC_TYPE_ASYNC = "async_spec";
public static final String API_TYPE_HTTP = "HTTP";
public static final String API_TYPE_WEBHOOK = "WEBHOOK";

public static final String API_TYPE_REST = "REST";

public static final String API_TYPE_GRAPHQL = "GRAPHQL";
public static final String API_TYPE_ASYNC = "ASYNC";

public static final String TRANSPORT_URL_IN = "TransportInURL";

// mock response generation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.wso2.carbon.apimgt.api.model.Environment;
import org.wso2.carbon.apimgt.api.model.VHost;
import org.wso2.carbon.apimgt.common.gateway.configdto.HttpClientConfigurationDTO;
import org.wso2.carbon.apimgt.impl.ai.MarketplaceAssistantConfigurationDto;
import org.wso2.carbon.apimgt.common.gateway.dto.ClaimMappingDto;
import org.wso2.carbon.apimgt.common.gateway.dto.JWKSConfigurationDTO;
import org.wso2.carbon.apimgt.common.gateway.dto.TokenIssuerDto;
Expand Down Expand Up @@ -107,6 +108,7 @@ public class APIManagerConfiguration {
private JSONArray applicationAttributes = new JSONArray();
private CacheInvalidationConfiguration cacheInvalidationConfiguration;


private HttpClientConfigurationDTO httpClientConfiguration;

private RecommendationEnvironment recommendationEnvironment;
Expand All @@ -116,6 +118,8 @@ public class APIManagerConfiguration {
private boolean initialized;
private ThrottleProperties throttleProperties = new ThrottleProperties();
private ExtendedJWTConfigurationDto jwtConfigurationDto = new ExtendedJWTConfigurationDto();
private static MarketplaceAssistantConfigurationDto marketplaceAssistantConfigurationDto = new MarketplaceAssistantConfigurationDto();

private WorkflowProperties workflowProperties = new WorkflowProperties();
private Map<String, Environment> apiGatewayEnvironments = new LinkedHashMap<String, Environment>();
private static Properties realtimeNotifierProperties;
Expand Down Expand Up @@ -160,6 +164,11 @@ public static boolean isTokenRevocationEnabled() {
return !tokenRevocationClassName.isEmpty();
}

public MarketplaceAssistantConfigurationDto getMarketplaceAssistantConfigurationDto() {

return marketplaceAssistantConfigurationDto;
}

private Set<APIStore> externalAPIStores = new HashSet<APIStore>();
private EventHubConfigurationDto eventHubConfigurationDto;
private MonetizationConfigurationDto monetizationConfigurationDto = new MonetizationConfigurationDto();
Expand Down Expand Up @@ -624,6 +633,8 @@ private void readChildElements(OMElement serverConfig,
jsonObject.put(APIConstants.CustomPropertyAttributes.REQUIRED, isRequired);
customProperties.add(jsonObject);
}
} else if (APIConstants.MARKETPLACE_ASSISTANT.equals(localName)) {
setMarketplaceAssistantConfiguration(element);
}
readChildElements(element, nameStack);
nameStack.pop();
Expand Down Expand Up @@ -2326,4 +2337,46 @@ public HttpClientConfigurationDTO getHttpClientConfiguration() {
public void setHttpClientConfiguration(HttpClientConfigurationDTO httpClientConfiguration) {
this.httpClientConfiguration = httpClientConfiguration;
}

public void setMarketplaceAssistantConfiguration(OMElement omElement){
OMElement marketplaceAssistantEnableElement =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_ENABLED));
if (marketplaceAssistantEnableElement != null) {
marketplaceAssistantConfigurationDto.setEnabled(Boolean.parseBoolean(marketplaceAssistantEnableElement.getText()));
}
if (marketplaceAssistantConfigurationDto.isEnabled()) {
OMElement marketplaceAssistantEndpoint =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_ENDPOINT));

Check warning on line 2349 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2348-L2349

Added lines #L2348 - L2349 were not covered by tests
if (marketplaceAssistantEndpoint != null) {
marketplaceAssistantConfigurationDto.setEndpoint(marketplaceAssistantEndpoint.getText());

Check warning on line 2351 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2351

Added line #L2351 was not covered by tests
}
OMElement marketplaceAssistantToken =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_AUTH_TOKEN));

Check warning on line 2354 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2353-L2354

Added lines #L2353 - L2354 were not covered by tests

if (marketplaceAssistantToken != null) {
String AccessToken = MiscellaneousUtil.resolve(marketplaceAssistantToken, secretResolver);
marketplaceAssistantConfigurationDto.setAccessToken(AccessToken);

Check warning on line 2358 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2357-L2358

Added lines #L2357 - L2358 were not covered by tests
}
OMElement marketplaceAssistantApiCountResource =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_API_COUNT_RESOURCE));

Check warning on line 2361 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2360-L2361

Added lines #L2360 - L2361 were not covered by tests
if (marketplaceAssistantApiCountResource != null) {
marketplaceAssistantConfigurationDto.setApiCountResource(marketplaceAssistantApiCountResource.getText());

Check warning on line 2363 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2363

Added line #L2363 was not covered by tests
}
OMElement marketplaceAssistantApiDeleteResource =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_DELETE_API_RESOURCE));

Check warning on line 2366 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2365-L2366

Added lines #L2365 - L2366 were not covered by tests
if (marketplaceAssistantApiDeleteResource != null) {
marketplaceAssistantConfigurationDto.setApiDeleteResource(marketplaceAssistantApiDeleteResource.getText());

Check warning on line 2368 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2368

Added line #L2368 was not covered by tests
}
OMElement marketplaceAssistantApiPublishResource =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_PUBLISH_API_RESOURCE));

Check warning on line 2371 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2370-L2371

Added lines #L2370 - L2371 were not covered by tests
if (marketplaceAssistantApiPublishResource != null) {
marketplaceAssistantConfigurationDto.setApiPublishResource(marketplaceAssistantApiPublishResource.getText());

Check warning on line 2373 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2373

Added line #L2373 was not covered by tests
}
OMElement marketplaceAssistantChatResource =
omElement.getFirstChildWithName(new QName(APIConstants.MARKETPLACE_ASSISTANT_CHAT_RESOURCE));

Check warning on line 2376 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2375-L2376

Added lines #L2375 - L2376 were not covered by tests
if (marketplaceAssistantChatResource != null) {
marketplaceAssistantConfigurationDto.setChatResource(marketplaceAssistantChatResource.getText());

Check warning on line 2378 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java#L2378

Added line #L2378 was not covered by tests
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ public void deleteAPI(String apiUuid, String organization) throws APIManagementE
APIConstants.EventType.API_DELETE.name(), tenantId, organization, api.getId().getApiName(), apiId,
api.getUuid(), api.getId().getVersion(), api.getType(), api.getContext(),
APIUtil.replaceEmailDomainBack(api.getId().getProviderName()),
api.getStatus(), api.getApiSecurity());
api.getStatus(), api.getApiSecurity(), api.getStatus(), api.getVisibility());
APIUtil.sendNotification(apiEvent, APIConstants.NotifierType.API.name());
} else {
log.debug("Event has not published to gateways due to API id has failed to retrieve from DB for API "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.wso2.carbon.apimgt.impl.ai;

public class MarketplaceAssistantConfigurationDto {

private String AccessToken;
private String Endpoint;
private String ApiPublishResource;
private String ChatResource;
private String ApiDeleteResource;
private String ApiCountResource;
private boolean isEnabled;



public String getAccessToken() {
return AccessToken;

Check warning on line 16 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L16

Added line #L16 was not covered by tests
}

public void setAccessToken(String AccessToken) {
this.AccessToken = AccessToken;
}

Check warning on line 21 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L20-L21

Added lines #L20 - L21 were not covered by tests

public String getEndpoint() {
return Endpoint;

Check warning on line 24 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L24

Added line #L24 was not covered by tests
}

public void setEndpoint(String Endpoint) {
this.Endpoint = Endpoint;
}

Check warning on line 29 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L28-L29

Added lines #L28 - L29 were not covered by tests

public String getApiPublishResource() {
return ApiPublishResource;

Check warning on line 32 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L32

Added line #L32 was not covered by tests
}

public void setApiPublishResource(String ApiPublishResource) {
this.ApiPublishResource = ApiPublishResource;
}

Check warning on line 37 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L36-L37

Added lines #L36 - L37 were not covered by tests

public String getChatResource() {
return ChatResource;

Check warning on line 40 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L40

Added line #L40 was not covered by tests
}

public void setChatResource(String ChatResource) {
this.ChatResource = ChatResource;
}

Check warning on line 45 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L44-L45

Added lines #L44 - L45 were not covered by tests

public String getApiDeleteResource() {
return ApiDeleteResource;

Check warning on line 48 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L48

Added line #L48 was not covered by tests
}

public void setApiDeleteResource(String ApiDeleteResource) {
this.ApiDeleteResource = ApiDeleteResource;
}

Check warning on line 53 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L52-L53

Added lines #L52 - L53 were not covered by tests

public String getApiCountResource() {
return ApiCountResource;

Check warning on line 56 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L56

Added line #L56 was not covered by tests
}

public void setApiCountResource(String ApiCountResource) {
this.ApiCountResource = ApiCountResource;
}

Check warning on line 61 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ai/MarketplaceAssistantConfigurationDto.java#L60-L61

Added lines #L60 - L61 were not covered by tests

public boolean isEnabled() {
return isEnabled;
}

public void setEnabled(boolean Enabled) {
this.isEnabled = Enabled;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.wso2.carbon.apimgt.impl.notifier.ScopesNotifier;
import org.wso2.carbon.apimgt.impl.notifier.SubscriptionsNotifier;
import org.wso2.carbon.apimgt.impl.notifier.KeyTemplateNotifier;
import org.wso2.carbon.apimgt.impl.notifier.MarketplaceAssistantApiPublisherNotifier;
import org.wso2.carbon.apimgt.impl.observers.APIStatusObserverList;
import org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer;
import org.wso2.carbon.apimgt.impl.observers.KeyMgtConfigDeployer;
Expand Down Expand Up @@ -201,6 +202,8 @@ protected void activate(ComponentContext componentContext) throws Exception {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
configuration.load(filePath);

boolean isMarketplaceAssistantEnabled = configuration.getMarketplaceAssistantConfigurationDto().isEnabled();

//Registering Notifiers
bundleContext.registerService(Notifier.class.getName(), new SubscriptionsNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApisNotifier(), null);
Expand All @@ -216,6 +219,9 @@ protected void activate(ComponentContext componentContext) throws Exception {
bundleContext.registerService(Notifier.class.getName(),new KeyTemplateNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new CorrelationConfigNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new GatewayPolicyNotifier(), null);
if (isMarketplaceAssistantEnabled) {
bundleContext.registerService(Notifier.class.getName(), new MarketplaceAssistantApiPublisherNotifier(), null);

Check warning on line 223 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponent.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/internal/APIManagerComponent.java#L223

Added line #L223 was not covered by tests
}
APIManagerConfigurationServiceImpl configurationService = new APIManagerConfigurationServiceImpl(configuration);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(configurationService);
APIMgtDBUtil.initialize();
Expand Down Expand Up @@ -1097,4 +1103,3 @@ protected void unsetWorkflowTaskService(WorkflowTaskService workflowTaskService)
ServiceReferenceHolder.getInstance().setWorkflowTaskService(null);
}
}

Loading

0 comments on commit 6984829

Please sign in to comment.