Search in sources :

Example 71 with URITemplate

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;
}
Also used : APIOperationsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO) ArrayList(java.util.ArrayList) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate)

Example 72 with URITemplate

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;
}
Also used : SharedScopeUsedAPIResourceInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIResourceInfoDTO) ArrayList(java.util.ArrayList) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SharedScopeUsageDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsageDTO) SharedScopeUsedAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SharedScopeUsedAPIInfoDTO)

Example 73 with URITemplate

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 "";
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate)

Example 74 with URITemplate

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;
}
Also used : OperationPolicyData(org.wso2.carbon.apimgt.api.model.OperationPolicyData) OperationPolicyDefinition(org.wso2.carbon.apimgt.api.model.OperationPolicyDefinition) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OperationPolicy(org.wso2.carbon.apimgt.api.model.OperationPolicy) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) ArrayList(java.util.ArrayList) OperationPolicySpecification(org.wso2.carbon.apimgt.api.model.OperationPolicySpecification)

Example 75 with URITemplate

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;
}
Also used : APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) ArrayList(java.util.ArrayList) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate)

Aggregations

URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)122 HashMap (java.util.HashMap)71 ArrayList (java.util.ArrayList)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)42 Scope (org.wso2.carbon.apimgt.api.model.Scope)41 API (org.wso2.carbon.apimgt.api.model.API)38 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)38 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)37 HashSet (java.util.HashSet)36 LinkedHashSet (java.util.LinkedHashSet)28 PreparedStatement (java.sql.PreparedStatement)25 ResultSet (java.sql.ResultSet)23 API (org.wso2.carbon.apimgt.core.models.API)22 Map (java.util.Map)21 Tier (org.wso2.carbon.apimgt.api.model.Tier)21 Connection (java.sql.Connection)20 OperationPolicy (org.wso2.carbon.apimgt.api.model.OperationPolicy)20 LinkedHashMap (java.util.LinkedHashMap)19 List (java.util.List)19 SQLException (java.sql.SQLException)16