Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Default API Context Generation Issue #12709

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class API implements CacheableEntity<String> {
private String name = null;
private String version = null;
private String context = null;
private String contextTemplate = null;
private String policy = null;
private String apiType = null;
private Boolean isDefaultVersion = false;
Expand Down Expand Up @@ -105,6 +106,16 @@ public void setContext(String context) {
this.context = context;
}

public String getContextTemplate() {

return contextTemplate;
}

public void setContextTemplate(String contextTemplate) {

this.contextTemplate = contextTemplate;
}

public String getProvider() {

return provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public List<API> getAllApis(String organization, boolean isExpand) {
api.setOrganization(resultSet.getString("ORGANIZATION"));
String publishedDefaultApiVersion = resultSet.getString("PUBLISHED_DEFAULT_API_VERSION");
String contextTemplate = resultSet.getString("CONTEXT_TEMPLATE");
api.setContextTemplate(contextTemplate);

setDefaultVersionContext(apiType, api, version, publishedDefaultApiVersion, context, contextTemplate);

Expand Down Expand Up @@ -1151,6 +1152,7 @@ public List<API> getAllApis(String organization, String deployment, boolean isEx
}
String publishedDefaultApiVersion = resultSet.getString("PUBLISHED_DEFAULT_API_VERSION");
String contextTemplate = resultSet.getString("CONTEXT_TEMPLATE");
api.setContextTemplate(contextTemplate);

setDefaultVersionContext(apiType, api, version, publishedDefaultApiVersion, context,
contextTemplate);
Expand Down Expand Up @@ -1192,6 +1194,7 @@ private static void setDefaultVersionContext(String apiType, API api, String ver
}
String synapseContext = context + "/" + APIConstants.API_PRODUCT_VERSION_1_0_0;
api.setContext(synapseContext);
api.setContextTemplate(context);
}
}

Expand Down Expand Up @@ -1267,6 +1270,7 @@ public API getAPIByContextAndVersion(String context, String version, String depl
api.setApiType(apiType);
api.setPolicy(resultSet.getString("API_TIER"));
api.setContext(resultSet.getString("CONTEXT"));
api.setContextTemplate(resultSet.getString("CONTEXT_TEMPLATE"));
String revision = resultSet.getString("REVISION_UUID");
api.setStatus(resultSet.getString("STATUS"));
api.setOrganization(resultSet.getString("ORGANIZATION"));
Expand Down Expand Up @@ -1486,6 +1490,7 @@ public API getApiByUUID(String apiId, String deployment, String organization, bo
api.setPolicy(resultSet.getString("API_TIER"));
api.setContext(context);
api.setStatus(resultSet.getString("STATUS"));
api.setContextTemplate(contextTemplate);
if (resultSet.getString("IS_EGRESS") != null) {
api.setEgress(parseInt(resultSet.getString("IS_EGRESS")));
}
Expand Down Expand Up @@ -1591,6 +1596,7 @@ public List<API> getAllApisByLabel(String gatewayLabel, Boolean expand) {
}
String publishedDefaultApiVersion = resultSet.getString("PUBLISHED_DEFAULT_API_VERSION");
String contextTemplate = resultSet.getString("CONTEXT_TEMPLATE");
api.setContextTemplate(contextTemplate);

setDefaultVersionContext(apiType, api, version, publishedDefaultApiVersion, context,
contextTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class APIDTO {
private String name = null;
private String version = null;
private String context = null;
private String contextTemplate = null;
private String policy = null;
private String apiType = null;
private String status = null;
Expand Down Expand Up @@ -145,6 +146,24 @@ public void setContext(String context) {
this.context = context;
}

/**
* Context template of the API.
**/
public APIDTO contextTemplate(String contextTemplate) {
this.contextTemplate = contextTemplate;
return this;
}


@ApiModelProperty(value = "Context template of the API.")
@JsonProperty("contextTemplate")
public String getContextTemplate() {
return contextTemplate;
}
public void setContextTemplate(String contextTemplate) {
this.contextTemplate = contextTemplate;
}

/**
* API level throttling policy.
**/
Expand Down Expand Up @@ -357,6 +376,7 @@ public boolean equals(java.lang.Object o) {
Objects.equals(name, API.name) &&
Objects.equals(version, API.version) &&
Objects.equals(context, API.context) &&
Objects.equals(contextTemplate, API.contextTemplate) &&
Objects.equals(policy, API.policy) &&
Objects.equals(apiType, API.apiType) &&
Objects.equals(status, API.status) &&
Expand All @@ -372,7 +392,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(uuid, apiId, provider, name, version, context, policy, apiType, status, organization, isDefaultVersion, apiPolicies, urlMappings, securityScheme, isSubscriptionValidationDisabled, isEgress, subtype);
return Objects.hash(uuid, apiId, provider, name, version, context, contextTemplate, policy, apiType, status, organization, isDefaultVersion, apiPolicies, urlMappings, securityScheme, isSubscriptionValidationDisabled, isEgress, subtype);
}

@Override
Expand All @@ -386,6 +406,7 @@ public String toString() {
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" version: ").append(toIndentedString(version)).append("\n");
sb.append(" context: ").append(toIndentedString(context)).append("\n");
sb.append(" contextTemplate: ").append(toIndentedString(contextTemplate)).append("\n");
sb.append(" policy: ").append(toIndentedString(policy)).append("\n");
sb.append(" apiType: ").append(toIndentedString(apiType)).append("\n");
sb.append(" status: ").append(toIndentedString(status)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private static APIDTO fromAPItoDTO(API model) throws APIManagementException {
apidto.setVersion(model.getVersion());
apidto.setName(model.getName());
apidto.setContext(model.getContext());
apidto.setContextTemplate(model.getContextTemplate());
apidto.setPolicy(model.getPolicy());
apidto.setProvider(model.getProvider());
apidto.setApiType(model.getApiType());
Expand Down Expand Up @@ -134,6 +135,7 @@ public static APIListDTO fromAPIToAPIListDTO(API model) throws APIManagementExce
apidto.setApiId(model.getApiId());
apidto.setVersion(model.getVersion());
apidto.setContext(model.getContext());
apidto.setContextTemplate(model.getContextTemplate());
apidto.setPolicy(model.getPolicy());
apidto.setProvider(model.getProvider());
apidto.setApiType(model.getApiType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,9 @@ definitions:
context:
type: string
description: Context of the API.
contextTemplate:
type: string
description: Context template of the API.
policy:
type: string
description: API level throttling policy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class API implements CacheableEntity<String> {
private String name = null;
private String version = null;
private String context = null;
private String contextTemplate = null;
private String policy = null;
private String apiType = null;
private String status;
Expand Down Expand Up @@ -131,6 +132,16 @@ public void setContext(String context) {
this.context = context;
}

public String getContextTemplate() {

return contextTemplate;
}

public void setContextTemplate(String contextTemplate) {

this.contextTemplate = contextTemplate;
}

public String getApiTier() {

return policy;
Expand Down Expand Up @@ -206,6 +217,7 @@ public String toString() {
", name='" + name + '\'' +
", version='" + version + '\'' +
", context='" + context + '\'' +
", contextTemplate='" + contextTemplate + '\'' +
", policy='" + policy + '\'' +
", apiType='" + apiType + '\'' +
", status='" + status + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,18 @@ public Map<String, API> getAllAPIsByContextList() {
for (API api : apiMap.values()) {
apiContextAPIMap.put(api.getContext(), api);
if (api.isDefaultVersion()) {
String context = api.getContext();
String defaultContext = context;
int index = context.lastIndexOf("/" + api.getApiVersion());
if (index != -1) {
defaultContext = context.substring(0, index);
if (api.getContextTemplate() != null) {
String context = api.getContextTemplate().replace("/" + APIConstants.VERSION_PLACEHOLDER, "")
.replace(APIConstants.VERSION_PLACEHOLDER, "");
apiContextAPIMap.put(context, api);
} else {
String context = api.getContext();
int index = context.lastIndexOf("/" + api.getApiVersion());
if (index >= 0) {
context = context.substring(0, index);
}
apiContextAPIMap.put(context, api);
}
apiContextAPIMap.put(defaultContext, api);
}
}
return apiContextAPIMap;
Expand Down
Loading