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 Nov 2, 2023
1 parent a0e8dbd commit acec19d
Show file tree
Hide file tree
Showing 24 changed files with 1,085 additions and 242 deletions.
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 = null;
private boolean isPublishedDefaultVersion = false;
public APIProduct(){}

public APIProduct(APIProductIdentifier id) {
Expand Down Expand Up @@ -194,6 +196,19 @@ 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;
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 @@ -1732,7 +1732,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
Loading

0 comments on commit acec19d

Please sign in to comment.