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;
}
Aggregations