Search in sources :

Example 16 with GraphqlComplexityInfo

use of org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdGraphqlPoliciesComplexityGet.

/**
 * Get complexity details of a given API
 *
 * @param apiId          apiId
 * @param messageContext message context
 * @return Response with complexity details of the GraphQL API
 */
@Override
public Response apisApiIdGraphqlPoliciesComplexityGet(String apiId, MessageContext messageContext) {
    try {
        APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        API api = apiConsumer.getLightweightAPIByUUID(apiId, organization);
        if (APIConstants.GRAPHQL_API.equals(api.getType())) {
            GraphqlComplexityInfo graphqlComplexityInfo = apiConsumer.getComplexityDetails(apiId);
            GraphQLQueryComplexityInfoDTO graphQLQueryComplexityInfoDTO = GraphqlQueryAnalysisMappingUtil.fromGraphqlComplexityInfotoDTO(graphqlComplexityInfo);
            return Response.ok().entity(graphQLQueryComplexityInfoDTO).build();
        } else {
            throw new APIManagementException(ExceptionCodes.API_NOT_GRAPHQL);
        }
    } catch (APIManagementException e) {
        // to expose the existence of the resource
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving complexity details of API : " + apiId, e, log);
        } else {
            String msg = "Error while retrieving complexity details of API " + apiId;
            RestApiUtil.handleInternalServerError(msg, e, log);
        }
    }
    return null;
}
Also used : GraphqlComplexityInfo(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) API(org.wso2.carbon.apimgt.api.model.API) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer)

Aggregations

GraphqlComplexityInfo (org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 CustomComplexityDetails (org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails)7 ArrayList (java.util.ArrayList)6 API (org.wso2.carbon.apimgt.api.model.API)6 Gson (com.google.gson.Gson)4 GraphQLQueryComplexityInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO)4 JsonElement (com.google.gson.JsonElement)3 IOException (java.io.IOException)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)3 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 JSONObject (org.json.simple.JSONObject)2 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)2 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)2 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)2 GsonBuilder (com.google.gson.GsonBuilder)1