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 23, 2025
1 parent efeb3bc commit 721993b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 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 @@ -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<String, String> apiOperationPolicyIdToClonedPolicyIdMap)
throws APIManagementException {
String policyType = null;
Expand Down Expand Up @@ -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<String, String> apiOperationPolicyIdToClonedPolicyIdMap = getClonedAPISpecificOperationPolicyIdsList(api.getUuid());
Set<URITemplate> uriTemplates = api.getUriTemplates();
Expand All @@ -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<String, String> apiProductOperationPolicyIdToClonedPolicyIdMap =
getClonedAPISpecificOperationPolicyIdsList(product.getUuid());
Expand All @@ -5359,7 +5364,6 @@ public APIProduct addPolicyTypeFieldToApiProduct(APIProduct product) throws APIM
resource.setUriTemplate(uriTemplate);
}
product.setProductResources(productResources);
return product;
}

@Override
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -7114,7 +7118,7 @@ public void setOperationPoliciesToURITemplates(String apiId, Set<URITemplate> 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
*/
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 721993b

Please sign in to comment.