Skip to content

Commit

Permalink
Add devportal rest api changes for API Chat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 committed Mar 23, 2024
1 parent 5971afb commit 5292151
Show file tree
Hide file tree
Showing 22 changed files with 684 additions and 819 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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 org.wso2.carbon.apimgt.api.model;

import org.json.simple.JSONArray;

public class APIChatAPISpec {
private String serviceUrl = null;

Check warning on line 24 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java#L23-L24

Added lines #L23 - L24 were not covered by tests
private JSONArray tools;

public String getServiceUrl() {
return serviceUrl;

Check warning on line 28 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java#L28

Added line #L28 was not covered by tests
}

public void setServiceUrl(String serviceUrl) {
this.serviceUrl = serviceUrl;
}

Check warning on line 33 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java#L32-L33

Added lines #L32 - L33 were not covered by tests

public JSONArray getTools() {
return tools;

Check warning on line 36 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java#L36

Added line #L36 was not covered by tests
}

public void setTools(JSONArray tools) {
this.tools = tools;
}

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatAPISpec.java#L40-L41

Added lines #L40 - L41 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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 org.wso2.carbon.apimgt.api.model;

public class APIChatExecutionResponse {
private Integer code = null;
private String path = null;
private Object headers = null;
private Object body = null;

Check warning on line 25 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L21-L25

Added lines #L21 - L25 were not covered by tests

public Integer getCode() {
return code;

Check warning on line 28 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L28

Added line #L28 was not covered by tests
}

public void setCode(Integer code) {
this.code = code;
}

Check warning on line 33 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L32-L33

Added lines #L32 - L33 were not covered by tests

public String getPath() {
return path;

Check warning on line 36 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L36

Added line #L36 was not covered by tests
}

public void setPath(String path) {
this.path = path;
}

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L40-L41

Added lines #L40 - L41 were not covered by tests

public Object getHeaders() {
return headers;

Check warning on line 44 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L44

Added line #L44 was not covered by tests
}

public void setHeaders(Object headers) {
this.headers = headers;
}

Check warning on line 49 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L48-L49

Added lines #L48 - L49 were not covered by tests

public Object getBody() {
return body;

Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L52

Added line #L52 was not covered by tests
}

public void setBody(Object body) {
this.body = body;
}

Check warning on line 57 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatExecutionResponse.java#L56-L57

Added lines #L56 - L57 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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 org.wso2.carbon.apimgt.api.model;

/**
* Details related to API Chat test execution
*/
public class APIChatTestExecutionInfo {
private APIChatExecutionResponse response = null;

Check warning on line 25 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java#L24-L25

Added lines #L24 - L25 were not covered by tests

public APIChatExecutionResponse getResponse() {
return response;

Check warning on line 28 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java#L28

Added line #L28 was not covered by tests
}

public void setResponse(APIChatExecutionResponse response) {
this.response = response;
}

Check warning on line 33 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestExecutionInfo.java#L32-L33

Added lines #L32 - L33 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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 org.wso2.carbon.apimgt.api.model;

import org.json.simple.JSONObject;

/**
* Details related to API Chat test initialization
*/
public class APIChatTestInitializerInfo {
private String command = null;
private APIChatAPISpec apiSpec = null;

Check warning on line 28 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java#L26-L28

Added lines #L26 - L28 were not covered by tests

public String getCommand() {
return command;

Check warning on line 31 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java#L31

Added line #L31 was not covered by tests
}

public void setCommand(String command) {
this.command = command;
}

Check warning on line 36 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java#L35-L36

Added lines #L35 - L36 were not covered by tests

public APIChatAPISpec getApiSpec() {
return apiSpec;

Check warning on line 39 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java#L39

Added line #L39 was not covered by tests
}

public void setApiSpec(APIChatAPISpec apiSpec) {
this.apiSpec = apiSpec;
}

Check warning on line 44 in components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/APIChatTestInitializerInfo.java#L43-L44

Added lines #L43 - L44 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,21 @@ public final class APIConstants {
public static final String CNF = "cnf";

// Constants related to AI features: API chat and Marketplace Assistant
public static final String API_CHAT = "APIChat.";
public static final String API_CHAT_ENABLED = API_CHAT + "Enabled";
public static final String API_CHAT_AUTH_TOKEN = API_CHAT + "AuthToken";
public static final String API_CHAT_ENDPOINT = API_CHAT + "Endpoint";
public static final String API_CHAT_PREPARE_RESOURCE = "/prepare"; // "/api-chat/prepare"
public static final String API_CHAT_EXECUTE_RESOURCE = "/chat"; // "/api-chat/chat"
public static class AI {

public static final String API_CHAT = "APIChat.";
public static final String API_CHAT_ENABLED = API_CHAT + "Enabled";
public static final String API_CHAT_AUTH_TOKEN = API_CHAT + "AuthToken";
public static final String API_CHAT_ENDPOINT = API_CHAT + "Endpoint";
public static final String API_CHAT_PREPARE_RESOURCE = "/prepare";
public static final String API_CHAT_EXECUTE_RESOURCE = "/chat";
public static final String API_CHAT_ACTION_PREPARE = "PREPARE";
public static final String API_CHAT_ACTION_EXECUTE = "EXECUTE";

private AI() {

Check warning on line 516 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.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/APIConstants.java#L516

Added line #L516 was not covered by tests

}

Check warning on line 518 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.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/APIConstants.java#L518

Added line #L518 was not covered by tests
}

//documentation rxt

Expand Down Expand Up @@ -1260,7 +1269,7 @@ public static class ApplicationStatus {
public static final String DELETE_PENDING = "DELETE_PENDING";
}

public static class APIRevisionStatus {
public static class APIRevisionStatus { //

public static final String API_REVISION_CREATED = "CREATED";
public static final String API_REVISION_APPROVED = "APPROVED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3310,8 +3310,8 @@ public String getOpenAPIDefinition(String apiId, String organization) throws API

@Override
public String invokeApiChatExecute(String apiChatRequestId, String requestPayload) throws APIManagementException {
return APIUtil.invokeAIService(APIConstants.API_CHAT_ENDPOINT,
APIConstants.API_CHAT_AUTH_TOKEN, APIConstants.API_CHAT_EXECUTE_RESOURCE, requestPayload,
return APIUtil.invokeAIService(APIConstants.AI.API_CHAT_ENDPOINT,

Check warning on line 3313 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.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/APIConsumerImpl.java#L3313

Added line #L3313 was not covered by tests
APIConstants.AI.API_CHAT_AUTH_TOKEN, APIConstants.AI.API_CHAT_EXECUTE_RESOURCE, requestPayload,
apiChatRequestId);
}

Expand All @@ -3320,8 +3320,9 @@ public String invokeApiChatPrepare(String apiId, String apiChatRequestId, String
throws APIManagementException {
String swaggerDefinition = getOpenAPIDefinition(apiId, organization);
String payload = "{\"openapi\": " + swaggerDefinition + "}";
String prepareResponse = APIUtil.invokeAIService(APIConstants.API_CHAT_ENDPOINT,
APIConstants.API_CHAT_AUTH_TOKEN, APIConstants.API_CHAT_PREPARE_RESOURCE, payload, apiChatRequestId);
String prepareResponse = APIUtil.invokeAIService(APIConstants.AI.API_CHAT_ENDPOINT,

Check warning on line 3323 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.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/APIConsumerImpl.java#L3321-L3323

Added lines #L3321 - L3323 were not covered by tests
APIConstants.AI.API_CHAT_AUTH_TOKEN, APIConstants.AI.API_CHAT_PREPARE_RESOURCE, payload,
apiChatRequestId);
return prepareResponse;

Check warning on line 3326 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.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/APIConsumerImpl.java#L3326

Added line #L3326 was not covered by tests
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10378,14 +10378,9 @@ public static String getScopesAsString(Set<Scope> scopes) {
* @return returns true if API Chat feature is enabled, false if disabled.
*/
public static boolean isApiChatEnabled() {

APIManagerConfiguration config = ServiceReferenceHolder.getInstance().
getAPIManagerConfigurationService().getAPIManagerConfiguration();
String isApiChatEnabled = config.getFirstProperty(APIConstants.API_CHAT_ENABLED);
if (isApiChatEnabled == null) {
return false;
}

String isApiChatEnabled = config.getFirstProperty(APIConstants.AI.API_CHAT_ENABLED);
return Boolean.parseBoolean(isApiChatEnabled);
}

Expand All @@ -10398,8 +10393,8 @@ public static boolean isApiChatEnabled() {
public static boolean isAuthTokenProvidedForAIFeatures() {
APIManagerConfiguration config = ServiceReferenceHolder.getInstance().
getAPIManagerConfigurationService().getAPIManagerConfiguration();
String authToken = config.getFirstProperty(APIConstants.API_CHAT_AUTH_TOKEN);
if (authToken == null || authToken.equals("")) {
String authToken = config.getFirstProperty(APIConstants.AI.API_CHAT_AUTH_TOKEN);
if (StringUtils.isEmpty(authToken)) {
return false;
}
return true;

Check warning on line 10400 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.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/utils/APIUtil.java#L10397-L10400

Added lines #L10397 - L10400 were not covered by tests
Expand Down
Loading

0 comments on commit 5292151

Please sign in to comment.