|
|
@ -21,12 +21,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Scope;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Mediation;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Documentation;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevision;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevisionDeployment;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
|
|
@ -123,7 +118,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
|
|
|
|
String msg = "Shared scope key not found";
|
|
|
|
String msg = "Shared scope key not found : " + key;
|
|
|
|
log.info(msg);
|
|
|
|
log.info(msg);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -144,9 +139,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
|
|
|
|
if (scope.getBindings() != null) {
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
bindings.put(str);
|
|
|
|
bindings.put(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
@ -196,9 +193,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
|
|
|
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
|
|
|
|
if (scope.getBindings() != null) {
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
bindings.put(str);
|
|
|
|
bindings.put(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
@ -242,7 +241,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
|
|
|
|
public APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiUuid;
|
|
|
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiUuid;
|
|
|
@ -256,8 +255,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
JSONObject jsonObject = new JSONObject(response.body().string());
|
|
|
|
return gson.fromJson(response.body().string(), APIInfo.class);
|
|
|
|
return jsonObject;
|
|
|
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
@ -281,7 +279,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
public APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
|
|
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
|
|
@ -295,8 +293,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
JSONObject jsonObject = new JSONObject(response.body().string());
|
|
|
|
JSONArray apiList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
|
|
|
return jsonObject;
|
|
|
|
return gson.fromJson(apiList.toString(), APIInfo[].class);
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
@ -320,59 +318,111 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
public APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
|
|
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
|
|
|
|
|
|
|
|
|
|
|
String apiString = "{\n" +
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
" \"name\": \"" + api.getName() + "\",\n" +
|
|
|
|
payload.put("name", api.getName());
|
|
|
|
" \"description\":\"" + api.getDescription() + "\",\n" +
|
|
|
|
payload.put("description", api.getDescription());
|
|
|
|
" \"context\":\"" + api.getContext() + "\",\n" +
|
|
|
|
payload.put("context", api.getContext());
|
|
|
|
" \"version\":\"" + api.getVersion() + "\",\n" +
|
|
|
|
payload.put("version", api.getVersion());
|
|
|
|
" \"provider\":\"" + api.getProvider() + "\",\n" +
|
|
|
|
payload.put("provider", api.getProvider());
|
|
|
|
" \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" +
|
|
|
|
payload.put("lifeCycleStatus", api.getLifeCycleStatus());
|
|
|
|
" \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" +
|
|
|
|
payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null));
|
|
|
|
" \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" +
|
|
|
|
payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null));
|
|
|
|
" \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" +
|
|
|
|
payload.put("responseCachingEnabled", api.isResponseCachingEnabled());
|
|
|
|
" \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" +
|
|
|
|
payload.put("cacheTimeout", api.getCacheTimeout());
|
|
|
|
" \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" +
|
|
|
|
payload.put("hasThumbnail", api.isHasThumbnail());
|
|
|
|
" \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" +
|
|
|
|
payload.put("isDefaultVersion", api.isDefaultVersion());
|
|
|
|
" \"isRevision\": " + api.isRevision() + ",\n" +
|
|
|
|
payload.put("isRevision", api.isRevision());
|
|
|
|
" \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" +
|
|
|
|
payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null));
|
|
|
|
" \"revisionId\": " + api.getRevisionId() + ",\n" +
|
|
|
|
payload.put("revisionId", api.getRevisionId());
|
|
|
|
" \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" +
|
|
|
|
payload.put("enableSchemaValidation", api.isEnableSchemaValidation());
|
|
|
|
" \"type\": \"" + api.getType() + "\",\n" +
|
|
|
|
payload.put("type", api.getType());
|
|
|
|
" \"transport\": " + gson.toJson(api.getTransport()) + ",\n" +
|
|
|
|
payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy());
|
|
|
|
" \"tags\": " + gson.toJson(api.getTags()) + ",\n" +
|
|
|
|
payload.put("authorizationHeader", api.getAuthorizationHeader());
|
|
|
|
" \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" +
|
|
|
|
payload.put("visibility", api.getVisibility());
|
|
|
|
" \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" +
|
|
|
|
payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : ""));
|
|
|
|
" \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" +
|
|
|
|
|
|
|
|
" \"visibility\": \"" + api.getVisibility() + "\",\n" +
|
|
|
|
//Lists
|
|
|
|
" \"mediationPolicies\": " + (api.getInSequence() != null ? "[{\"name\": \"" + api.getInSequence() + "\",\"type\": \"in\"}]" : null) + ",\n" +
|
|
|
|
if (api.getTransport() != null) {
|
|
|
|
" \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" +
|
|
|
|
JSONArray transport = new JSONArray();
|
|
|
|
" \"subscriptionAvailableTenants\": [],\n" +
|
|
|
|
for (String str : api.getTransport()) {
|
|
|
|
" \"additionalProperties\": [],\n" +
|
|
|
|
transport.put(str);
|
|
|
|
" \"monetization\": " + api.getMonetization() + ",\n" +
|
|
|
|
}
|
|
|
|
" \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" +
|
|
|
|
payload.put("transport", transport);
|
|
|
|
" \"websubSubscriptionConfiguration\": {\n" +
|
|
|
|
}
|
|
|
|
" \"enable\": false,\n" +
|
|
|
|
if (api.getTags() != null) {
|
|
|
|
" \"secret\": \"\",\n" +
|
|
|
|
JSONArray tags = new JSONArray();
|
|
|
|
" \"signingAlgorithm\": \"SHA1\",\n" +
|
|
|
|
for (String str : api.getTags()) {
|
|
|
|
" \"signatureHeader\": \"x-hub-signature\"\n" +
|
|
|
|
tags.put(str);
|
|
|
|
" },\n" +
|
|
|
|
}
|
|
|
|
" \"workflowStatus\": null,\n" +
|
|
|
|
payload.put("tags", tags);
|
|
|
|
" \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" +
|
|
|
|
}
|
|
|
|
" \"endpointImplementationType\": \"ENDPOINT\",\n" +
|
|
|
|
if (api.getPolicies() != null) {
|
|
|
|
" \"scopes\": " + api.getScopes().toString() + ",\n" +
|
|
|
|
JSONArray policies = new JSONArray();
|
|
|
|
" \"operations\": " + (api.getOperations() != null ? api.getOperations().toString() : null) + ",\n" +
|
|
|
|
for (String str : api.getPolicies()) {
|
|
|
|
" \"threatProtectionPolicies\": null,\n" +
|
|
|
|
policies.put(str);
|
|
|
|
" \"categories\": [],\n" +
|
|
|
|
}
|
|
|
|
" \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" +
|
|
|
|
payload.put("policies", policies);
|
|
|
|
" \"serviceInfo\": " + api.getServiceInfo() + "\n" +
|
|
|
|
}
|
|
|
|
"}";
|
|
|
|
if (api.getMediationPolicies() != null) {
|
|
|
|
|
|
|
|
JSONArray mediationPolicies = new JSONArray();
|
|
|
|
|
|
|
|
for (MediationPolicy object : api.getMediationPolicies()) {
|
|
|
|
|
|
|
|
mediationPolicies.put(new JSONObject(gson.toJson(object)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("mediationPolicies", mediationPolicies);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getSubscriptionAvailableTenants() != null) {
|
|
|
|
|
|
|
|
JSONArray subscriptionAvailableTenants = new JSONArray();
|
|
|
|
|
|
|
|
for (String str : api.getSubscriptionAvailableTenants()) {
|
|
|
|
|
|
|
|
subscriptionAvailableTenants.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getAdditionalProperties() != null) {
|
|
|
|
|
|
|
|
JSONArray additionalProperties = new JSONArray();
|
|
|
|
|
|
|
|
for (AdditionalProperties str : api.getAdditionalProperties()) {
|
|
|
|
|
|
|
|
additionalProperties.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("additionalProperties", additionalProperties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getScopes() != null) {
|
|
|
|
|
|
|
|
JSONArray scopes = new JSONArray();
|
|
|
|
|
|
|
|
for (JSONObject object : api.getScopes()) {
|
|
|
|
|
|
|
|
scopes.put(object);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("scopes", scopes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getOperations() != null) {
|
|
|
|
|
|
|
|
JSONArray operations = new JSONArray();
|
|
|
|
|
|
|
|
for (Operations operation : api.getOperations()) {
|
|
|
|
|
|
|
|
operations.put(new JSONObject(gson.toJson(operation)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("operations", operations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getCategories() != null) {
|
|
|
|
|
|
|
|
JSONArray categories = new JSONArray();
|
|
|
|
|
|
|
|
for (String str : api.getCategories()) {
|
|
|
|
|
|
|
|
categories.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("categories", categories);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//objects
|
|
|
|
|
|
|
|
payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null));
|
|
|
|
|
|
|
|
payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null));
|
|
|
|
|
|
|
|
payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null));
|
|
|
|
|
|
|
|
payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null));
|
|
|
|
|
|
|
|
payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null));
|
|
|
|
|
|
|
|
payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null));
|
|
|
|
|
|
|
|
payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null));
|
|
|
|
|
|
|
|
payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null));
|
|
|
|
|
|
|
|
payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null));
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addAPIEndPoint)
|
|
|
|
.url(addAPIEndPoint)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -383,8 +433,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (HttpStatus.SC_CREATED == response.code()) {
|
|
|
|
if (HttpStatus.SC_CREATED == response.code()) {
|
|
|
|
JSONObject jsonObject = new JSONObject(response.body().string());
|
|
|
|
return gson.fromJson(response.body().string(), APIInfo.class);
|
|
|
|
return jsonObject;
|
|
|
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
@ -413,54 +462,106 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
|
|
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
|
|
|
|
|
|
|
|
|
|
|
String apiString = "{\n" +
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
" \"name\": \"" + api.getName() + "\",\n" +
|
|
|
|
payload.put("name", api.getName());
|
|
|
|
" \"description\":\"" + api.getDescription() + "\",\n" +
|
|
|
|
payload.put("description", api.getDescription());
|
|
|
|
" \"context\":\"" + api.getContext() + "\",\n" +
|
|
|
|
payload.put("context", api.getContext());
|
|
|
|
" \"version\":\"" + api.getVersion() + "\",\n" +
|
|
|
|
payload.put("version", api.getVersion());
|
|
|
|
" \"provider\":\"" + api.getProvider() + "\",\n" +
|
|
|
|
payload.put("provider", api.getProvider());
|
|
|
|
" \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" +
|
|
|
|
payload.put("lifeCycleStatus", api.getLifeCycleStatus());
|
|
|
|
" \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" +
|
|
|
|
payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null));
|
|
|
|
" \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" +
|
|
|
|
payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null));
|
|
|
|
" \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" +
|
|
|
|
payload.put("responseCachingEnabled", api.isResponseCachingEnabled());
|
|
|
|
" \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" +
|
|
|
|
payload.put("cacheTimeout", api.getCacheTimeout());
|
|
|
|
" \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" +
|
|
|
|
payload.put("hasThumbnail", api.isHasThumbnail());
|
|
|
|
" \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" +
|
|
|
|
payload.put("isDefaultVersion", api.isDefaultVersion());
|
|
|
|
" \"isRevision\": " + api.isRevision() + ",\n" +
|
|
|
|
payload.put("isRevision", api.isRevision());
|
|
|
|
" \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" +
|
|
|
|
payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null));
|
|
|
|
" \"revisionId\": " + api.getRevisionId() + ",\n" +
|
|
|
|
payload.put("revisionId", api.getRevisionId());
|
|
|
|
" \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" +
|
|
|
|
payload.put("enableSchemaValidation", api.isEnableSchemaValidation());
|
|
|
|
" \"type\": \"" + api.getType() + "\",\n" +
|
|
|
|
payload.put("type", api.getType());
|
|
|
|
" \"transport\": " + gson.toJson(api.getTransport()) + ",\n" +
|
|
|
|
payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy());
|
|
|
|
" \"tags\": " + gson.toJson(api.getTags()) + ",\n" +
|
|
|
|
payload.put("authorizationHeader", api.getAuthorizationHeader());
|
|
|
|
" \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" +
|
|
|
|
payload.put("visibility", api.getVisibility());
|
|
|
|
" \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" +
|
|
|
|
payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : ""));
|
|
|
|
" \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" +
|
|
|
|
|
|
|
|
" \"visibility\": \"" + api.getVisibility() + "\",\n" +
|
|
|
|
//Lists
|
|
|
|
" \"mediationPolicies\": " + (api.getInSequence() != null ? "[{\"name\": \"" + api.getInSequence() + "\",\"type\": \"in\"}]" : null) + ",\n" +
|
|
|
|
if (api.getTransport() != null) {
|
|
|
|
" \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" +
|
|
|
|
JSONArray transport = new JSONArray();
|
|
|
|
" \"subscriptionAvailableTenants\": [],\n" +
|
|
|
|
for (String str : api.getTransport()) {
|
|
|
|
" \"additionalProperties\": [],\n" +
|
|
|
|
transport.put(str);
|
|
|
|
" \"monetization\": " + api.getMonetization() + ",\n" +
|
|
|
|
}
|
|
|
|
" \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" +
|
|
|
|
payload.put("transport", transport);
|
|
|
|
" \"websubSubscriptionConfiguration\": {\n" +
|
|
|
|
}
|
|
|
|
" \"enable\": false,\n" +
|
|
|
|
if (api.getTags() != null) {
|
|
|
|
" \"secret\": \"\",\n" +
|
|
|
|
JSONArray tags = new JSONArray();
|
|
|
|
" \"signingAlgorithm\": \"SHA1\",\n" +
|
|
|
|
for (String str : api.getTags()) {
|
|
|
|
" \"signatureHeader\": \"x-hub-signature\"\n" +
|
|
|
|
tags.put(str);
|
|
|
|
" },\n" +
|
|
|
|
}
|
|
|
|
" \"workflowStatus\": null,\n" +
|
|
|
|
payload.put("tags", tags);
|
|
|
|
" \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" +
|
|
|
|
}
|
|
|
|
" \"endpointImplementationType\": \"ENDPOINT\",\n" +
|
|
|
|
if (api.getPolicies() != null) {
|
|
|
|
" \"scopes\": " + api.getScopes().toString() + ",\n" +
|
|
|
|
JSONArray policies = new JSONArray();
|
|
|
|
" \"operations\": " + (api.getOperations() != null ? api.getOperations().toString() : null) + ",\n" +
|
|
|
|
for (String str : api.getPolicies()) {
|
|
|
|
" \"threatProtectionPolicies\": null,\n" +
|
|
|
|
policies.put(str);
|
|
|
|
" \"categories\": [],\n" +
|
|
|
|
}
|
|
|
|
" \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" +
|
|
|
|
payload.put("policies", policies);
|
|
|
|
" \"serviceInfo\": " + api.getServiceInfo() + "\n" +
|
|
|
|
}
|
|
|
|
"}";
|
|
|
|
if (api.getMediationPolicies() != null) {
|
|
|
|
|
|
|
|
JSONArray mediationPolicies = new JSONArray();
|
|
|
|
|
|
|
|
for (MediationPolicy object : api.getMediationPolicies()) {
|
|
|
|
|
|
|
|
mediationPolicies.put(new JSONObject(gson.toJson(object)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("mediationPolicies", mediationPolicies);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getSubscriptionAvailableTenants() != null) {
|
|
|
|
|
|
|
|
JSONArray subscriptionAvailableTenants = new JSONArray();
|
|
|
|
|
|
|
|
for (String str : api.getSubscriptionAvailableTenants()) {
|
|
|
|
|
|
|
|
subscriptionAvailableTenants.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getAdditionalProperties() != null) {
|
|
|
|
|
|
|
|
JSONArray additionalProperties = new JSONArray();
|
|
|
|
|
|
|
|
for (AdditionalProperties str : api.getAdditionalProperties()) {
|
|
|
|
|
|
|
|
additionalProperties.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("additionalProperties", additionalProperties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getScopes() != null) {
|
|
|
|
|
|
|
|
JSONArray scopes = new JSONArray();
|
|
|
|
|
|
|
|
for (JSONObject object : api.getScopes()) {
|
|
|
|
|
|
|
|
scopes.put(object);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("scopes", scopes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getOperations() != null) {
|
|
|
|
|
|
|
|
JSONArray operations = new JSONArray();
|
|
|
|
|
|
|
|
for (Operations operation : api.getOperations()) {
|
|
|
|
|
|
|
|
operations.put(new JSONObject(gson.toJson(operation)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("operations", operations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (api.getCategories() != null) {
|
|
|
|
|
|
|
|
JSONArray categories = new JSONArray();
|
|
|
|
|
|
|
|
for (String str : api.getCategories()) {
|
|
|
|
|
|
|
|
categories.put(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
payload.put("categories", categories);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//objects
|
|
|
|
|
|
|
|
payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null));
|
|
|
|
|
|
|
|
payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null));
|
|
|
|
|
|
|
|
payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null));
|
|
|
|
|
|
|
|
payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null));
|
|
|
|
|
|
|
|
payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null));
|
|
|
|
|
|
|
|
payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null));
|
|
|
|
|
|
|
|
payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null));
|
|
|
|
|
|
|
|
payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null));
|
|
|
|
|
|
|
|
payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null));
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(updateAPIEndPoint)
|
|
|
|
.url(updateAPIEndPoint)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -472,7 +573,6 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
if (HttpStatus.SC_OK == response.code()) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|