use of org.wso2.carbon.apimgt.api.model.URITemplate in project carbon-apimgt by wso2.
the class APIMappingUtil method fromURITemplateListToOprationList.
/**
* Converts a List object of URITemplates into APIOperations DTO List.
*
* @param uriTemplateList uriTemplateList
* @return List of APIOperationsDTO object
*/
public static List<APIOperationsDTO> fromURITemplateListToOprationList(List<URITemplate> uriTemplateList) {
int index = 0;
List<APIOperationsDTO> operations = new ArrayList<>();
for (URITemplate uriTemplate : uriTemplateList) {
uriTemplate.setId((index++));
operations.add(fromURITemplateToOperationList(uriTemplate));
}
return operations;
}
use of org.wso2.carbon.apimgt.api.model.URITemplate in project carbon-apimgt by wso2.
the class SharedScopeMappingUtil method fromSharedScopeUsageToDTO.
/**
* Converts SharedScopeUsage object into SharedScopeUsageDTO object.
*
* @param sharedScopeUsage SharedScopeUsage object
* @return SharedScopeUsageDTO object
*/
public static SharedScopeUsageDTO fromSharedScopeUsageToDTO(SharedScopeUsage sharedScopeUsage) {
SharedScopeUsageDTO sharedScopeUsageDTO = new SharedScopeUsageDTO();
sharedScopeUsageDTO.setId(sharedScopeUsage.getId());
sharedScopeUsageDTO.setName(sharedScopeUsage.getName());
List<SharedScopeUsedAPIInfoDTO> usedAPIInfoDTOList = new ArrayList<>();
for (API api : sharedScopeUsage.getApis()) {
APIIdentifier apiIdentifier = api.getId();
SharedScopeUsedAPIInfoDTO usedAPIInfoDTO = new SharedScopeUsedAPIInfoDTO();
usedAPIInfoDTO.setName(apiIdentifier.getName());
usedAPIInfoDTO.setVersion(apiIdentifier.getVersion());
usedAPIInfoDTO.setProvider(apiIdentifier.getProviderName());
usedAPIInfoDTO.setContext(api.getContext());
List<SharedScopeUsedAPIResourceInfoDTO> usedAPIResourceInfoDTOList = new ArrayList<>();
for (URITemplate uriTemplate : api.getUriTemplates()) {
SharedScopeUsedAPIResourceInfoDTO usedAPIResourceInfoDTO = new SharedScopeUsedAPIResourceInfoDTO();
usedAPIResourceInfoDTO.setTarget(uriTemplate.getUriTemplate());
usedAPIResourceInfoDTO.setVerb(uriTemplate.getHTTPVerb());
usedAPIResourceInfoDTOList.add(usedAPIResourceInfoDTO);
}
usedAPIInfoDTO.setUsedResourceList(usedAPIResourceInfoDTOList);
usedAPIInfoDTOList.add(usedAPIInfoDTO);
}
sharedScopeUsageDTO.setUsedApiList(usedAPIInfoDTOList);
return sharedScopeUsageDTO;
}
use of org.wso2.carbon.apimgt.api.model.URITemplate in project carbon-apimgt by wso2.
the class SynapsePolicyAggregator method generatePolicySequenceForUriTemplateSet.
public static String generatePolicySequenceForUriTemplateSet(Set<URITemplate> uriTemplates, String sequenceName, String flow, String pathToAchieve) throws APIManagementException, IOException {
List<Object> caseList = new ArrayList<>();
for (URITemplate template : uriTemplates) {
populatePolicyCaseList(template, pathToAchieve, flow, caseList);
}
if (caseList.size() != 0) {
Map<String, Object> configMap = new HashMap<>();
configMap.put("sequence_name", sequenceName);
configMap.put("case_list", caseList);
if (APIConstants.OPERATION_SEQUENCE_TYPE_FAULT.equals(flow)) {
configMap.put("fault_sequence", true);
}
String operationPolicyTemplate = FileUtil.readFileToString(POLICY_SEQUENCE_TEMPLATE_LOCATION).replace("\\", // Removing escape characters from the template
"");
return renderPolicyTemplate(operationPolicyTemplate, configMap);
} else {
return "";
}
}
use of org.wso2.carbon.apimgt.api.model.URITemplate in project carbon-apimgt by wso2.
the class ImportUtils method validateOperationPolicies.
public static Set<URITemplate> validateOperationPolicies(API api, APIProvider provider, String extractedFolderPath, Map<String, List<OperationPolicy>> extractedPoliciesMap, String tenantDomain) {
String policyDirectory = extractedFolderPath + File.separator + ImportExportConstants.POLICIES_DIRECTORY;
Set<URITemplate> uriTemplates = api.getUriTemplates();
for (URITemplate uriTemplate : uriTemplates) {
String key = uriTemplate.getHTTPVerb() + ":" + uriTemplate.getUriTemplate();
if (extractedPoliciesMap.containsKey(key)) {
List<OperationPolicy> operationPolicies = extractedPoliciesMap.get(key);
List<OperationPolicy> validatedOperationPolicies = new ArrayList<>();
if (operationPolicies != null && !operationPolicies.isEmpty()) {
for (OperationPolicy policy : operationPolicies) {
try {
OperationPolicySpecification policySpec = getOperationPolicySpecificationFromFile(policyDirectory, policy.getPolicyName());
OperationPolicyData operationPolicyData = new OperationPolicyData();
operationPolicyData.setSpecification(policySpec);
operationPolicyData.setOrganization(tenantDomain);
operationPolicyData.setApiUUID(api.getUuid());
OperationPolicyDefinition synapseDefinition = APIUtil.getOperationPolicyDefinitionFromFile(policyDirectory, policy.getPolicyName(), APIConstants.SYNAPSE_POLICY_DEFINITION_EXTENSION);
if (synapseDefinition != null) {
synapseDefinition.setGatewayType(OperationPolicyDefinition.GatewayType.Synapse);
operationPolicyData.setSynapsePolicyDefinition(synapseDefinition);
}
OperationPolicyDefinition ccDefinition = APIUtil.getOperationPolicyDefinitionFromFile(policyDirectory, policy.getPolicyName(), APIConstants.CC_POLICY_DEFINITION_EXTENSION);
if (ccDefinition != null) {
ccDefinition.setGatewayType(OperationPolicyDefinition.GatewayType.ChoreoConnect);
operationPolicyData.setCcPolicyDefinition(ccDefinition);
}
operationPolicyData.setMd5Hash(APIUtil.getMd5OfOperationPolicy(operationPolicyData));
String policyID = provider.importOperationPolicy(operationPolicyData, tenantDomain);
policy.setPolicyId(policyID);
validatedOperationPolicies.add(policy);
} catch (APIManagementException e) {
log.error(e);
}
}
}
uriTemplate.setOperationPolicies(validatedOperationPolicies);
}
}
return uriTemplates;
}
use of org.wso2.carbon.apimgt.api.model.URITemplate in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getUsedProductResources.
/**
* Get resources of an API that are reused by API Products
*
* @param api API
* @return List of resources reused by API Products
*/
private List<APIResource> getUsedProductResources(API api) {
List<APIResource> usedProductResources = new ArrayList<>();
Set<URITemplate> uriTemplates = api.getUriTemplates();
for (URITemplate uriTemplate : uriTemplates) {
// If existing URITemplate is used by any API Products
if (!uriTemplate.retrieveUsedByProducts().isEmpty()) {
APIResource apiResource = new APIResource(uriTemplate.getHTTPVerb(), uriTemplate.getUriTemplate());
usedProductResources.add(apiResource);
}
}
return usedProductResources;
}
Aggregations