Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJaI committed Jan 3, 2025
1 parent efeb3bc commit d571f43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,10 @@ EnvironmentPropertiesDTO getEnvironmentSpecificAPIProperties(String apiUuid, Str
void setOperationPoliciesToURITemplates(String apiId, Set<URITemplate> 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
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5313,7 +5313,7 @@ public String getProductPolicyType(OperationPolicy policy, String apiUUID,
return getPolicyType(policy, apiOperationPolicyIdToClonedPolicyIdMap);

Check warning on line 5313 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5309-L5313

Added lines #L5309 - L5313 were not covered by tests
}

public API addPolicyTypeFieldToApi(API api) throws APIManagementException {
public void populatePolicyTypeInAPI(API api) throws APIManagementException {

Map<String, String> apiOperationPolicyIdToClonedPolicyIdMap = getClonedAPISpecificOperationPolicyIdsList(api.getUuid());
Set<URITemplate> uriTemplates = api.getUriTemplates();

Check warning on line 5319 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5318-L5319

Added lines #L5318 - L5319 were not covered by tests
Expand All @@ -5336,11 +5336,9 @@ public API addPolicyTypeFieldToApi(API api) throws APIManagementException {
}

Check warning on line 5336 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5334-L5336

Added lines #L5334 - L5336 were not covered by tests
}
api.setApiPolicies(apiPolicies);

return api;
}

Check warning on line 5339 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5338-L5339

Added lines #L5338 - L5339 were not covered by tests

public APIProduct addPolicyTypeFieldToApiProduct(APIProduct product) throws APIManagementException {
public void populatePolicyTypeInApiProduct(APIProduct product) throws APIManagementException {

Map<String, String> apiProductOperationPolicyIdToClonedPolicyIdMap =
getClonedAPISpecificOperationPolicyIdsList(product.getUuid());
Expand All @@ -5359,7 +5357,6 @@ public APIProduct addPolicyTypeFieldToApiProduct(APIProduct product) throws APIM
resource.setUriTemplate(uriTemplate);
}
product.setProductResources(productResources);
return product;
}

Check warning on line 5360 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5356-L5360

Added lines #L5356 - L5360 were not covered by tests

@Override
Expand Down Expand Up @@ -5404,7 +5401,7 @@ public API getAPIbyUUID(String uuid, String organization) throws APIManagementEx
populateApiInfo(api);
populateSubtypeConfiguration(api);
populateDefaultVersion(api);
api = addPolicyTypeFieldToApi(api);
populatePolicyTypeInAPI(api);

Check warning on line 5404 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5404

Added line #L5404 was not covered by tests
return api;
} else {
String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
Expand Down Expand Up @@ -5584,7 +5581,7 @@ public APIProduct getAPIProductbyUUID(String uuid, String organization) throws A
if (migrationEnabled == null) {
populateDefaultVersion(product);
}
product = addPolicyTypeFieldToApiProduct(product);
populatePolicyTypeInApiProduct(product);

Check warning on line 5584 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L5584

Added line #L5584 was not covered by tests
return product;
} else {
String msg = "Failed to get API Product. API Product artifact corresponding to artifactId " + uuid
Expand Down Expand Up @@ -7176,18 +7173,18 @@ 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();

Check warning on line 7181 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L7181

Added line #L7181 was not covered by tests
OperationPolicyData existingOperationPolicy;

String policyId = null;

Check warning on line 7184 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L7184

Added line #L7184 was not covered by tests
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);

Check warning on line 7189 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L7189

Added line #L7189 was not covered by tests
} else if (policyType.equalsIgnoreCase(ImportExportConstants.POLICY_TYPE_COMMON)) {
Expand Down Expand Up @@ -7221,8 +7218,7 @@ public String importOperationPolicyOfGivenType(OperationPolicyData importedPolic
policyId = addAPISpecificOperationPolicy(importedPolicyData.getApiUUID(), importedPolicyData,

Check warning on line 7218 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L7214-L7218

Added lines #L7214 - L7218 were not covered by tests
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. " +

Check warning on line 7221 in components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java#L7221

Added line #L7221 was not covered by tests
"A new policy created with ID " + policyId);
}
}
Expand Down

0 comments on commit d571f43

Please sign in to comment.