Skip to content

Commit

Permalink
Adding versioning support for APIProducts
Browse files Browse the repository at this point in the history
  • Loading branch information
HiranyaKavishani committed Dec 20, 2023
1 parent 7244641 commit d2710f6
Show file tree
Hide file tree
Showing 32 changed files with 1,730 additions and 302 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 @@ -328,6 +328,19 @@ List<SubscribedAPI> getSubscriptionsOfAPI(String apiName, String apiVersion, Str
API createNewAPIVersion(String apiId, String newVersion, Boolean defaultVersion, String organization)
throws APIManagementException;

/**
* Create a new version of the <code>apiProduct</code>, with version <code>newVersion</code>
*
* @param apiProductId The id of the API Product to be copied
* @param newVersion The version of the new API Product
* @param defaultVersion whether this version is default or not
* @param organization Identifier of an organization
* @return apiProduct created apiProduct
* @throws APIManagementException If an error occurs while trying to create
* * the new version of the API Product
*/
APIProduct createNewAPIProductVersion(String apiProductId, String newVersion, Boolean defaultVersion,
String organization) throws APIManagementException;
/**
* Retrieve the Key of the Service used in the API
* @param apiId Unique Identifier of the API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ExceptionCodes implements ErrorHandler {
API_VERSION_ALREADY_EXISTS(900252, "The API version already exists.", 409, "An API with version '%s' already exists for API '%s'"),

API_PRODUCT_CONTEXT_ALREADY_EXISTS(900275, "The API Product context already exists.", 409, "An API Product with context '%s' already exists"),
API_PRODUCT_VERSION_ALREADY_EXISTS(900276, "The API Product version already exists.", 409, "An API Product with version '%s' already exists for API Product '%s'"),

API_CONTEXT_MALFORMED_EXCEPTION(900253, "The API context is malformed.", 400, "'%s'"),
API_ALREADY_EXISTS(900300, "The API already exists.", 409, "The API already exists"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.wso2.carbon.apimgt.api.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand All @@ -29,7 +30,7 @@
import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONObject;

public class APIProduct {
public class APIProduct implements Serializable {
// TODO add rest of the properties
private APIProductIdentifier id;
private String uuid;
Expand Down Expand Up @@ -131,7 +132,8 @@ public class APIProduct {
* Used to set the workflow status in lifecycle state change workflow
*/
private String workflowStatus = null;

private Boolean isDefaultVersion = true;
private boolean isPublishedDefaultVersion = false;
public APIProduct(){}

public APIProduct(APIProductIdentifier id) {
Expand Down Expand Up @@ -194,6 +196,20 @@ public String getTechnicalOwnerEmail() {
public void setTechnicalOwnerEmail(String technicalOwnerEmail) {
this.technicalOwnerEmail = technicalOwnerEmail;
}
public void setDefaultVersion(Boolean isDefaultVersion) {
this.isDefaultVersion = isDefaultVersion;
}
public void setAsPublishedDefaultVersion(boolean value) {
isPublishedDefaultVersion = value;
}

public Boolean isDefaultVersion() {
return isDefaultVersion;
}

public Boolean isPublishedDefaultVersion() {
return isPublishedDefaultVersion;
}

public String getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public APIProductIdentifier(String providerName, String apiProductName, String v

this.apiProductName = apiProductName;
this.providerName = providerName;
this.version = "1.0.0";
this.version = version == null ? "1.0.0" : version;
}

public APIProductIdentifier(String providerName, String apiProductName, String version, String uuid) {

this.apiProductName = apiProductName;
this.providerName = providerName;
this.version = "1.0.0";
this.version = version == null ? "1.0.0" : version;
this.uuid = uuid;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public int hashCode() {
@Override
public String toString() {

return this.getProviderName() + '-' + this.getName();
return this.getProviderName() + '-' + this.getName() + '-' + this.getVersion();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ public void setContext(String context) {
}
}

public void setAsDefaultVersion(boolean value) {
if (isAPIProduct) {
apiProduct.setDefaultVersion(value);
} else {
api.setDefaultVersion(value);
}
}

public void setAsPublishedDefaultVersion(boolean value) {
if (isAPIProduct) {
apiProduct.setAsPublishedDefaultVersion(value);
} else {
api.setAsPublishedDefaultVersion(value);
}
}

public String getContext() {
return isAPIProduct ? apiProduct.getContext() : api.getContext();
}
Expand Down Expand Up @@ -160,10 +176,24 @@ public String getAccessControlRoles() {
return api.getAccessControlRoles();
}

public String geType() {
public String getType() {
if (isAPIProduct){
return apiProduct.getType();
}
return api.getType();
}

public boolean getPublishedDefaultVersion() {
if (isAPIProduct){
return apiProduct.isPublishedDefaultVersion();
}
return api.isPublishedDefaultVersion();
}

public boolean getDefaultVersion() {
if (isAPIProduct){
return apiProduct.isDefaultVersion();
}
return api.isDefaultVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,9 @@ public enum RegistryResourceTypesForUI {

public static final String API_LC_ACTION_DEPRECATE = "Deprecate";
public static final String DEPRECATE_CHECK_LIST_ITEM = "Deprecate old versions after publishing the API";
public static final String DEPRECATE_CHECK_LIST_ITEM_API_PRODUCT = "Deprecate old versions after publishing the API Product";
public static final String RESUBSCRIBE_CHECK_LIST_ITEM = "Requires re-subscription when publishing the API";
public static final String RESUBSCRIBE_CHECK_LIST_ITEM_API_PRODUCT = "Requires re-subscription when publishing the API Product";
public static final String PUBLISH_IN_PRIVATE_JET_MODE = "Publish In Private-Jet Mode";

public static final String METRICS_PREFIX = "org.wso2.am";
Expand Down Expand Up @@ -1913,7 +1915,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 @@ -3816,7 +3817,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
Loading

0 comments on commit d2710f6

Please sign in to comment.