use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO in project carbon-apimgt by wso2.
the class ImportUtils method extractAndDropOperationPoliciesFromURITemplate.
public static Map<String, List<OperationPolicy>> extractAndDropOperationPoliciesFromURITemplate(List<APIOperationsDTO> operationsDTO) {
Map<String, List<OperationPolicy>> operationPoliciesMap = new HashMap<>();
for (APIOperationsDTO dto : operationsDTO) {
String key = dto.getVerb() + ":" + dto.getTarget();
List<OperationPolicy> operationPolicies = OperationPolicyMappingUtil.fromDTOToAPIOperationPoliciesList(dto.getOperationPolicies());
if (!operationPolicies.isEmpty()) {
operationPoliciesMap.put(key, operationPolicies);
}
dto.setOperationPolicies(null);
}
return operationPoliciesMap;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method addWebsocketTopicMappings.
private static void addWebsocketTopicMappings(API api, APIDTO apidto) {
org.json.JSONObject endpointConfiguration = new org.json.JSONObject(api.getEndpointConfig());
String sandboxEndpointUrl = !endpointConfiguration.isNull(APIConstants.API_DATA_SANDBOX_ENDPOINTS) ? endpointConfiguration.getJSONObject(APIConstants.API_DATA_SANDBOX_ENDPOINTS).getString("url") : null;
String productionEndpointUrl = !endpointConfiguration.isNull(APIConstants.API_DATA_PRODUCTION_ENDPOINTS) ? endpointConfiguration.getJSONObject(APIConstants.API_DATA_PRODUCTION_ENDPOINTS).getString("url") : null;
Map<String, Map<String, String>> perTopicMappings = new HashMap<>();
for (APIOperationsDTO operation : apidto.getOperations()) {
String key = operation.getTarget();
String mapping = operation.getUriMapping() == null ? "" : Paths.get("/", operation.getUriMapping()).toString();
Map<String, String> endpoints = new HashMap<>();
if (sandboxEndpointUrl != null) {
endpoints.put(APIConstants.GATEWAY_ENV_TYPE_SANDBOX, sandboxEndpointUrl + mapping);
}
if (productionEndpointUrl != null) {
endpoints.put(APIConstants.GATEWAY_ENV_TYPE_PRODUCTION, productionEndpointUrl + mapping);
}
perTopicMappings.put(key, endpoints);
}
api.setWebSocketTopicMappingConfiguration(new WebSocketTopicMappingConfiguration(perTopicMappings));
addWebsocketTopicResourceKeys(api);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method getOperationsFromAPI.
/**
* Returns a set of operations from a API.
*
* @param api API object
* @return a set of operations from a given swagger definition
*/
private static List<APIOperationsDTO> getOperationsFromAPI(API api) {
Set<URITemplate> uriTemplates = api.getUriTemplates();
List<APIOperationsDTO> operationsDTOList = new ArrayList<>();
for (URITemplate uriTemplate : uriTemplates) {
APIOperationsDTO operationsDTO = getOperationFromURITemplate(uriTemplate);
if (api.getType().equals(APIConstants.API_TYPE_WS)) {
Map<String, String> wsUriMappings = api.getWsUriMapping();
if (wsUriMappings != null) {
String wsUriMapping = wsUriMappings.get(operationsDTO.getVerb() + "_" + operationsDTO.getTarget());
if (wsUriMapping != null) {
operationsDTO.setUriMapping(wsUriMapping);
}
}
}
operationsDTOList.add(operationsDTO);
}
return operationsDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method getOperationListWithOldData.
/**
* This method returns graphQL operations with the old data.
*
* @param uriTemplates uriTemplates
* @param operations operations
* @return operations
*/
public static List<APIOperationsDTO> getOperationListWithOldData(Set<URITemplate> uriTemplates, List<APIOperationsDTO> operations) {
for (APIOperationsDTO operation : operations) {
for (URITemplate uriTemplate : uriTemplates) {
if (operation.getVerb().equalsIgnoreCase(uriTemplate.getHTTPVerb()) && operation.getTarget().equalsIgnoreCase(uriTemplate.getUriTemplate())) {
operation.setThrottlingPolicy(uriTemplate.getThrottlingTier());
operation.setAuthType(uriTemplate.getAuthType());
operation.setScopes(uriTemplate.retrieveAllScopes().stream().map(Scope::getKey).collect(Collectors.toList()));
}
if (operation.getThrottlingPolicy() == null) {
operation.setThrottlingPolicy(APIConstants.UNLIMITED_TIER);
}
}
}
return operations;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method getURITemplates.
/**
* This method returns URI templates according to the given list of operations.
*
* @param operations List operations
* @return URI Templates
* @throws APIManagementException
*/
public static Set<URITemplate> getURITemplates(API model, List<APIOperationsDTO> operations) throws APIManagementException {
boolean isHttpVerbDefined = false;
Set<URITemplate> uriTemplates = new LinkedHashSet<>();
if (operations == null || operations.isEmpty()) {
operations = getDefaultOperationsList(model.getType());
}
for (APIOperationsDTO operation : operations) {
URITemplate template = new URITemplate();
String uriTempVal = operation.getTarget();
String httpVerb = operation.getVerb();
List<String> scopeList = operation.getScopes();
if (scopeList != null) {
for (String scopeKey : scopeList) {
for (Scope definedScope : model.getScopes()) {
if (definedScope.getKey().equalsIgnoreCase(scopeKey)) {
template.setScopes(definedScope);
template.setScope(definedScope);
break;
}
}
}
}
// AWS Lambda: set arn to URI template
String amznResourceName = operation.getAmznResourceName();
if (amznResourceName != null) {
template.setAmznResourceName(amznResourceName);
}
// Only continue for supported operations
if (APIConstants.SUPPORTED_METHODS.contains(httpVerb.toLowerCase()) || (APIConstants.GRAPHQL_SUPPORTED_METHOD_LIST.contains(httpVerb.toUpperCase())) || (APIConstants.WEBSUB_SUPPORTED_METHOD_LIST.contains(httpVerb.toUpperCase())) || (APIConstants.SSE_SUPPORTED_METHOD_LIST.contains(httpVerb.toUpperCase())) || (APIConstants.WS_SUPPORTED_METHOD_LIST.contains(httpVerb.toUpperCase()))) {
isHttpVerbDefined = true;
String authType = operation.getAuthType();
if (APIConstants.OASResourceAuthTypes.APPLICATION_OR_APPLICATION_USER.equals(authType)) {
authType = APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN;
} else if (APIConstants.OASResourceAuthTypes.APPLICATION_USER.equals(authType)) {
authType = APIConstants.AUTH_APPLICATION_USER_LEVEL_TOKEN;
} else if (APIConstants.OASResourceAuthTypes.NONE.equals(authType)) {
authType = APIConstants.AUTH_NO_AUTHENTICATION;
} else if (APIConstants.OASResourceAuthTypes.APPLICATION.equals(authType)) {
authType = APIConstants.AUTH_APPLICATION_LEVEL_TOKEN;
} else {
authType = APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN;
}
template.setThrottlingTier(operation.getThrottlingPolicy());
template.setThrottlingTiers(operation.getThrottlingPolicy());
template.setUriTemplate(uriTempVal);
template.setHTTPVerb(httpVerb.toUpperCase());
template.setHttpVerbs(httpVerb.toUpperCase());
template.setAuthType(authType);
template.setAuthTypes(authType);
if (operation.getOperationPolicies() != null) {
template.setOperationPolicies(OperationPolicyMappingUtil.fromDTOToAPIOperationPoliciesList(operation.getOperationPolicies()));
}
uriTemplates.add(template);
} else {
if (APIConstants.GRAPHQL_API.equals(model.getType())) {
handleException("The GRAPHQL operation Type '" + httpVerb + "' provided for operation '" + uriTempVal + "' is invalid");
} else if (APIConstants.API_TYPE_WEBSUB.equals(model.getType())) {
handleException("The WEBSUB operation Type '" + httpVerb + "' provided for operation '" + uriTempVal + "' is invalid");
} else if (APIConstants.API_TYPE_SSE.equals(model.getType())) {
handleException("The SSE operation Type '" + httpVerb + "' provided for operation '" + uriTempVal + "' is invalid");
} else if (APIConstants.API_TYPE_WS.equals(model.getType())) {
handleException("The WEBSOCKET operation Type '" + httpVerb + "' provided for operation '" + uriTempVal + "' is invalid");
} else {
handleException("The HTTP method '" + httpVerb + "' provided for resource '" + uriTempVal + "' is invalid");
}
}
if (!isHttpVerbDefined) {
if (APIConstants.GRAPHQL_API.equals(model.getType())) {
handleException("Operation '" + uriTempVal + "' has global parameters without " + "Operation Type");
} else if (APIConstants.API_TYPE_WEBSUB.equals(model.getType()) || APIConstants.API_TYPE_SSE.equals(model.getType())) {
handleException("Topic '" + uriTempVal + "' has global parameters without " + "Operation Type");
} else {
handleException("Resource '" + uriTempVal + "' has global parameters without " + "HTTP methods");
}
}
}
return uriTemplates;
}
Aggregations