Skip to content

Commit

Permalink
Adding migration related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranyaKavishani committed Dec 6, 2023
1 parent aa0668d commit b74d446
Show file tree
Hide file tree
Showing 15 changed files with 658 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ public interface APIManager {
*/
boolean isContextExist(String context, String organization) throws APIManagementException;


/**
* Checks whether the given API Product context is already registered in the system for API products
*
* @param context A String representing an API product context
* @param contextWithVersion A String representing an API context appended with the version
* @param organization Organization
* @return true if the context already exists and false otherwise
* @throws APIManagementException if failed to check the context availability
*/
boolean isContextExistForAPIProducts(String context, String contextWithVersion, String organization)
throws APIManagementException;

/**
/**
* Checks whether the given API name is already registered in the system
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class APIProduct implements Serializable {
* Used to set the workflow status in lifecycle state change workflow
*/
private String workflowStatus = null;
private Boolean isDefaultVersion = null;
private Boolean isDefaultVersion = true;
private boolean isPublishedDefaultVersion = false;
public APIProduct(){}

Expand Down Expand Up @@ -202,6 +202,7 @@ public void setDefaultVersion(Boolean isDefaultVersion) {
public void setAsPublishedDefaultVersion(boolean value) {
isPublishedDefaultVersion = value;
}

public Boolean isDefaultVersion() {
return isDefaultVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ public enum RegistryResourceTypesForUI {
public static final String ENABLE_STORE = "enableStore";

//api-product related constants
public static final String API_PRODUCT_VERSION = "1.0.0";
public static final String API_PRODUCT_VERSION_1_0_0 = "1.0.0";
public static final String API_IDENTIFIER_TYPE = "API";
public static final String API_PRODUCT_IDENTIFIER_TYPE = "API Product";
public static final String[] API_SUPPORTED_TYPE_LIST = {"HTTP", "WS", "SOAPTOREST", "GRAPHQL", "SOAP", "WEBSUB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3636,6 +3636,7 @@ public ApiTypeWrapper getAPIorAPIProductByUUID(String uuid, String organization)
apiProduct.setID(new APIProductIdentifier(devPortalApi.getProviderName(),
devPortalApi.getApiName(), devPortalApi.getVersion()));
populateAPIProductInformation(uuid, organization, apiProduct);
populateDefaultVersion(apiProduct);
populateAPIStatus(apiProduct);
apiProduct = addTiersToAPI(apiProduct, organization);
return new ApiTypeWrapper(apiProduct);
Expand Down Expand Up @@ -3798,6 +3799,12 @@ public API getLightweightAPIByUUID(String uuid, String organization) throws APIM
}
}

@Override
public boolean isContextExistForAPIProducts(String context, String contextWithVersion, String organization)
throws APIManagementException {
return false;
}

/**
* Used to retrieve API/API Products without performing the visibility permission checks
* @param uuid
Expand All @@ -3816,7 +3823,7 @@ private ApiTypeWrapper getAPIorAPIProductByUUIDWithoutPermissionCheck(String uui
apiProduct.setID(new APIProductIdentifier(devPortalApi.getProviderName(), devPortalApi.getApiName(),
devPortalApi.getVersion()));
populateAPIProductInformation(uuid, organization, apiProduct);

populateDefaultVersion(apiProduct);
return new ApiTypeWrapper(apiProduct);
} else {
API api = APIMapper.INSTANCE.toApi(devPortalApi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,17 @@ private String getDefaultVersion(Identifier apiid) throws APIManagementException
}


public String getPublishedDefaultVersion(Identifier apiid) throws APIManagementException {
public String getPublishedDefaultVersion(Identifier apiId) throws APIManagementException {

String defaultVersion = null;
try {
defaultVersion = apiMgtDAO.getPublishedDefaultVersion(apiid);
if (apiId instanceof APIIdentifier) {
defaultVersion = apiMgtDAO.getPublishedDefaultVersion((APIIdentifier) apiId);
} else if (apiId instanceof APIProductIdentifier) {
defaultVersion = apiMgtDAO.getPublishedDefaultVersion((APIProductIdentifier) apiId);
}
} catch (APIManagementException e) {
handleException("Error while getting published default version :" + apiid.getName(), e);
handleException("Error while getting published default version :" + apiId.getName(), e);
}
return defaultVersion;
}
Expand Down Expand Up @@ -4305,6 +4309,7 @@ public Map<API, List<APIProductResource>> updateAPIProduct(APIProduct product)
Map<API, List<APIProductResource>> apiToProductResourceMapping = new HashMap<>();
//validate resources and set api identifiers and resource ids to product
List<APIProductResource> resources = product.getProductResources();
String publishedDefaultVersion = getPublishedDefaultVersion(product.getId());
String prevDefaultVersion = getDefaultVersion(product.getId());
for (APIProductResource apiProductResource : resources) {
API api;
Expand Down Expand Up @@ -4395,8 +4400,6 @@ public Map<API, List<APIProductResource>> updateAPIProduct(APIProduct product)
product.setDefaultVersion(true);
}
apiMgtDAO.updateAPIProduct(product, userNameWithoutChange);

String publishedDefaultVersion = getPublishedDefaultVersion(product.getId());
if (publishedDefaultVersion != null && product.isPublishedDefaultVersion() && !product.getId().getVersion()
.equals(publishedDefaultVersion)) {
sendUpdateEventToPreviousDefaultVersion(product.getId().getProviderName(), product.getId().getName(),
Expand Down Expand Up @@ -5070,13 +5073,6 @@ private void populateAPIStatus(API api) throws APIManagementException {
}
}

private void populateDefaultVersion(APIProduct apiProduct) throws APIManagementException {
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(apiProduct);
apiMgtDAO.setDefaultVersion(apiTypeWrapper);
apiProduct.setDefaultVersion(apiTypeWrapper.getDefaultVersion());
apiProduct.setAsPublishedDefaultVersion(apiTypeWrapper.getPublishedDefaultVersion());
}


private void populateAPIStatus(APIProduct apiProduct) throws APIManagementException {
if (apiProduct.isRevision()) {
Expand Down Expand Up @@ -5238,6 +5234,12 @@ public API getLightweightAPIByUUID(String uuid, String organization) throws APIM
}
}

@Override
public boolean isContextExistForAPIProducts(String context, String contextWithVersion, String organization)
throws APIManagementException {
return apiMgtDAO.isContextExistForAPIProducts(context, contextWithVersion, organization);
}

@Override
public List<APIResource> getUsedProductResources(String uuid) throws APIManagementException {
List<APIResource> usedProductResources = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ protected String getTenantDomain(Identifier identifier) {
}

protected void populateDefaultVersion(API api) throws APIManagementException {
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
apiMgtDAO.setDefaultVersion(apiTypeWrapper);
api.setDefaultVersion(apiTypeWrapper.getDefaultVersion());
api.setAsPublishedDefaultVersion(apiTypeWrapper.getPublishedDefaultVersion());
apiMgtDAO.setDefaultVersion(api);
}
protected void populateDefaultVersion(APIProduct apiProduct) throws APIManagementException {
apiMgtDAO.setDefaultVersion(apiProduct);
}

private boolean isTenantDomainNotMatching(String tenantDomain) {
Expand Down Expand Up @@ -506,6 +506,12 @@ public boolean isContextExist(String context, String organization) throws APIMan
return apiMgtDAO.isContextExist(context, organization);
}

public boolean isContextExistForAPIProducts(String context, String contextWithVersion, String organization)
throws APIManagementException {

return apiMgtDAO.isContextExistForAPIProducts(context, contextWithVersion, organization);
}

protected String getTenantDomainFromUrl(String url) {

return MultitenantUtils.getTenantDomainFromUrl(url);
Expand Down
Loading

0 comments on commit b74d446

Please sign in to comment.