diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java index b797aed8c8ab..69157976272c 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java @@ -1543,8 +1543,10 @@ EnvironmentPropertiesDTO getEnvironmentSpecificAPIProperties(String apiUuid, Str void setOperationPoliciesToURITemplates(String apiId, Set uriTemplates) throws APIManagementException; /** - * Import an operation policy from the API CTL project. This will either create a new API specific policy, - * update existing API specific policy or return the policyID of existing policy if policy content is not changed. + * Import an operation policy from the API CTL project which is exported from a product version prior to the update + * level which introduced to have an API and a Common policy with identical names and versions. + * This will either create a new API specific policy, update existing API specific policy or return the + * policyID of existing policy if policy content is not changed. * * @param operationPolicyData Operation Policy Data * @param organization Organization name @@ -1553,6 +1555,18 @@ EnvironmentPropertiesDTO getEnvironmentSpecificAPIProperties(String apiUuid, Str */ String importOperationPolicy(OperationPolicyData operationPolicyData, String organization) throws APIManagementException; + + /** + * Import an operation policy of a given policy type, from the API CTL project. + * This will either create a new API specific policy, update existing API specific policy or return the + * policyID of existing policy if policy content is not changed. + * + * @param operationPolicyData Operation Policy Data + * @param organization Organization name + * @param policyType Policy Type + * @return UUID of the imported operation policy + * @throws APIManagementException + */ String importOperationPolicyOfGivenType(OperationPolicyData operationPolicyData, String policyType, String organization) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java index 7fc417294384..56c49000dd28 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/OperationPolicy.java @@ -109,7 +109,8 @@ public boolean equals(Object o) { if (o instanceof OperationPolicy) { OperationPolicy policyObj = (OperationPolicy) o; return Objects.equals(policyName, policyObj.policyName) && Objects.equals(policyVersion, - policyObj.policyVersion) && Objects.equals(direction, policyObj.direction) && policyType.equals(policyObj.policyType) && Objects.equals( + policyObj.policyVersion) && Objects.equals(direction, policyObj.direction) + && policyType.equals(policyObj.policyType) && Objects.equals( parameters, policyObj.parameters) && Objects.equals(policyId, policyObj.policyId); } return false; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java index 90e35b7e5020..b8e6ef74ae4d 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java @@ -5281,6 +5281,13 @@ public String getSecuritySchemeOfAPI(String uuid, String organization) throws AP } } + /** + * + * @param policy + * @param apiOperationPolicyIdToClonedPolicyIdMap + * @return + * @throws APIManagementException + */ public String getPolicyType(OperationPolicy policy, Map apiOperationPolicyIdToClonedPolicyIdMap) throws APIManagementException { String policyType = null; @@ -5313,7 +5320,7 @@ public String getProductPolicyType(OperationPolicy policy, String apiUUID, return getPolicyType(policy, apiOperationPolicyIdToClonedPolicyIdMap); } - public API addPolicyTypeFieldToApi(API api) throws APIManagementException { + public void populatePolicyTypeInAPI(API api) throws APIManagementException { Map apiOperationPolicyIdToClonedPolicyIdMap = getClonedAPISpecificOperationPolicyIdsList(api.getUuid()); Set uriTemplates = api.getUriTemplates(); @@ -5336,11 +5343,9 @@ public API addPolicyTypeFieldToApi(API api) throws APIManagementException { } } api.setApiPolicies(apiPolicies); - - return api; } - public APIProduct addPolicyTypeFieldToApiProduct(APIProduct product) throws APIManagementException { + public void populatePolicyTypeInApiProduct(APIProduct product) throws APIManagementException { Map apiProductOperationPolicyIdToClonedPolicyIdMap = getClonedAPISpecificOperationPolicyIdsList(product.getUuid()); @@ -5359,7 +5364,6 @@ public APIProduct addPolicyTypeFieldToApiProduct(APIProduct product) throws APIM resource.setUriTemplate(uriTemplate); } product.setProductResources(productResources); - return product; } @Override @@ -5404,7 +5408,7 @@ public API getAPIbyUUID(String uuid, String organization) throws APIManagementEx populateApiInfo(api); populateSubtypeConfiguration(api); populateDefaultVersion(api); - api = addPolicyTypeFieldToApi(api); + populatePolicyTypeInAPI(api); return api; } else { String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist"; @@ -5584,7 +5588,7 @@ public APIProduct getAPIProductbyUUID(String uuid, String organization) throws A if (migrationEnabled == null) { populateDefaultVersion(product); } - product = addPolicyTypeFieldToApiProduct(product); + populatePolicyTypeInApiProduct(product); return product; } else { String msg = "Failed to get API Product. API Product artifact corresponding to artifactId " + uuid @@ -7114,7 +7118,7 @@ public void setOperationPoliciesToURITemplates(String apiId, Set ur * If there aren't any existing policies, a new API specific policy will be created. * * @param importedPolicyData Imported policy - * @param organization Organization name + * @param organization Organization name * @return corrosponding policy ID for imported data * @throws APIManagementException if failed to delete APIRevision */ @@ -7176,23 +7180,23 @@ public String importOperationPolicy(OperationPolicyData importedPolicyData, Stri return policyId; } + @Override public String importOperationPolicyOfGivenType(OperationPolicyData importedPolicyData, String policyType, - String organization) - throws APIManagementException { + String organization) throws APIManagementException { OperationPolicySpecification importedSpec = importedPolicyData.getSpecification(); OperationPolicyData existingOperationPolicy; String policyId = null; if (policyType == null) { - /*To handle scenarios where api is exported from a previous U2 version. API and Common policies with same name - and same version is not supported there + /*To handle scenarios where api is exported from a previous U2 version. API and Common policies with + same name and same version is not supported there */ policyId = importOperationPolicy(importedPolicyData, organization); } else if (policyType.equalsIgnoreCase(ImportExportConstants.POLICY_TYPE_COMMON)) { existingOperationPolicy = getCommonOperationPolicyByPolicyName(importedSpec.getName(), - importedSpec.getVersion(),organization, false); + importedSpec.getVersion(), organization, false); if (existingOperationPolicy != null) { if (existingOperationPolicy.getMd5Hash().equals(importedPolicyData.getMd5Hash())) { @@ -7221,8 +7225,7 @@ public String importOperationPolicyOfGivenType(OperationPolicyData importedPolic policyId = addAPISpecificOperationPolicy(importedPolicyData.getApiUUID(), importedPolicyData, organization); if (log.isDebugEnabled()) { - log.debug( - "There aren't any existing common policy for the imported policy. " + + log.debug("There is no common policy currently available for the imported policy. " + "A new policy created with ID " + policyId); } }