|
|
@ -21,18 +21,12 @@ 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;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils;
|
|
|
|
|
|
|
|
import okhttp3.*;
|
|
|
|
import okhttp3.*;
|
|
|
|
import okhttp3.Request.Builder;
|
|
|
|
import okhttp3.Request.Builder;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
@ -56,7 +50,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
+ Constants.COLON + port;
|
|
|
|
+ Constants.COLON + port;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
public Scope[] getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.GET_ALL_SCOPES;
|
|
|
|
String getAllScopesUrl = endPointPrefix + Constants.GET_ALL_SCOPES;
|
|
|
@ -70,8 +64,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 scopeList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
|
|
|
return jsonObject;
|
|
|
|
return gson.fromJson(scopeList.toString(), Scope[].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.
|
|
|
@ -124,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,14 +138,21 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
|
|
|
|
|
|
|
|
ScopeUtils scopeUtil = new ScopeUtils();
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
scopeUtil.setKey(scope.getKey());
|
|
|
|
if (scope.getBindings() != null) {
|
|
|
|
scopeUtil.setName(scope.getName());
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
scopeUtil.setDescription(scope.getDescription());
|
|
|
|
bindings.put(str);
|
|
|
|
scopeUtil.setRoles(scope.getRoles());
|
|
|
|
}
|
|
|
|
String scopeString = scopeUtil.toJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
|
|
|
|
|
payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : ""));
|
|
|
|
|
|
|
|
payload.put("description", (scope.getDescription() != null ? scope.getDescription() : ""));
|
|
|
|
|
|
|
|
payload.put("bindings", (bindings != null ? bindings : ""));
|
|
|
|
|
|
|
|
payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewSharedScopeEndPoint)
|
|
|
|
.url(addNewSharedScopeEndPoint)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -191,14 +192,21 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
|
|
|
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
|
|
|
|
|
|
|
|
|
|
|
ScopeUtils scopeUtil = new ScopeUtils();
|
|
|
|
JSONArray bindings = new JSONArray();
|
|
|
|
scopeUtil.setKey(scope.getKey());
|
|
|
|
if (scope.getBindings() != null) {
|
|
|
|
scopeUtil.setName(scope.getName());
|
|
|
|
for (String str : scope.getBindings()) {
|
|
|
|
scopeUtil.setDescription(scope.getDescription());
|
|
|
|
bindings.put(str);
|
|
|
|
scopeUtil.setRoles(scope.getRoles());
|
|
|
|
}
|
|
|
|
String scopeString = scopeUtil.toJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
|
|
|
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
|
|
|
|
|
|
|
payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : ""));
|
|
|
|
|
|
|
|
payload.put("description", (scope.getDescription() != null ? scope.getDescription() : ""));
|
|
|
|
|
|
|
|
payload.put("bindings", (bindings != null ? bindings : ""));
|
|
|
|
|
|
|
|
payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0));
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(updateScopeUrl)
|
|
|
|
.url(updateScopeUrl)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -233,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;
|
|
|
@ -247,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.
|
|
|
@ -272,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;
|
|
|
@ -286,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.
|
|
|
@ -311,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();
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
|
|
|
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, 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
|
|
|
@ -374,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.
|
|
|
@ -404,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();
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
|
|
|
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, 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
|
|
|
@ -463,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.
|
|
|
@ -534,7 +643,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
String apiUuid)
|
|
|
|
String apiUuid)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
@ -549,8 +658,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 mediationPolicyList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
|
|
|
return jsonObject;
|
|
|
|
return gson.fromJson(mediationPolicyList.toString(), MediationPolicy[].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.
|
|
|
@ -705,7 +814,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
|
|
|
public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
|
|
|
Boolean deploymentStatus)
|
|
|
|
Boolean deploymentStatus)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
@ -722,8 +831,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 revisionList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
|
|
|
return jsonObject;
|
|
|
|
return gson.fromJson(revisionList.toString(), APIRevision[].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.
|
|
|
@ -747,16 +856,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
|
|
|
public APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
|
|
|
|
|
|
|
|
|
|
|
String apiRevisionDescription = "{\n" +
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
" \"description\":\"" + apiRevision.getDescription() + "\"\n" +
|
|
|
|
payload.put("description", (apiRevision.getDescription() != null ? apiRevision.getDescription() : null));
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, apiRevisionDescription);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewScope)
|
|
|
|
.url(addNewScope)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -767,8 +875,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(), APIRevision.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.
|
|
|
@ -799,15 +906,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId;
|
|
|
|
String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId;
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0);
|
|
|
|
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0);
|
|
|
|
|
|
|
|
|
|
|
|
String revision = "[\n" +
|
|
|
|
JSONArray payload = new JSONArray();
|
|
|
|
" {\n" +
|
|
|
|
JSONObject revision = new JSONObject();
|
|
|
|
" \"name\": \"" + apiRevisionDeployment.getDeployment() + "\",\n" +
|
|
|
|
revision.put("name", (apiRevisionDeployment.getName() != null ? apiRevisionDeployment.getName() : ""));
|
|
|
|
" \"vhost\": \"" + apiRevisionDeployment.getVhost() + "\",\n" +
|
|
|
|
revision.put("vhost", (apiRevisionDeployment.getVhost() != null ? apiRevisionDeployment.getVhost() : ""));
|
|
|
|
" \"displayOnDevportal\": " + apiRevisionDeployment.isDisplayOnDevportal() + "\n" +
|
|
|
|
revision.put("displayOnDevportal", apiRevisionDeployment.isDisplayOnDevportal());
|
|
|
|
" }\n" +
|
|
|
|
payload.put(revision);
|
|
|
|
"]";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, revision);
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(deployAPIRevisionEndPoint)
|
|
|
|
.url(deployAPIRevisionEndPoint)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -844,23 +950,22 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
JSONObject apiRevisionDeployment, String uuid)
|
|
|
|
APIRevision apiRevisionDeployment, String uuid)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId="
|
|
|
|
String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId="
|
|
|
|
+ apiRevisionDeployment.getString("id");
|
|
|
|
+ apiRevisionDeployment.getId();
|
|
|
|
JSONArray array = apiRevisionDeployment.getJSONArray("deploymentInfo");
|
|
|
|
List<APIRevisionDeployment> apiRevisionDeployments = apiRevisionDeployment.getDeploymentInfo();
|
|
|
|
JSONObject obj = array.getJSONObject(0);
|
|
|
|
APIRevisionDeployment earliestDeployment = apiRevisionDeployments.get(0);
|
|
|
|
|
|
|
|
|
|
|
|
String revision = "[\n" +
|
|
|
|
JSONArray payload = new JSONArray();
|
|
|
|
" {\n" +
|
|
|
|
JSONObject revision = new JSONObject();
|
|
|
|
" \"name\": \"" + obj.getString("name") + "\",\n" +
|
|
|
|
revision.put("name", (earliestDeployment.getName() != null ? earliestDeployment.getName() : ""));
|
|
|
|
" \"vhost\": \"" + obj.getString("vhost") + "\",\n" +
|
|
|
|
revision.put("vhost", (earliestDeployment.getVhost() != null ? earliestDeployment.getVhost() : ""));
|
|
|
|
" \"displayOnDevportal\": " + obj.get("displayOnDevportal") + "\n" +
|
|
|
|
revision.put("displayOnDevportal", earliestDeployment.isDisplayOnDevportal());
|
|
|
|
" }\n" +
|
|
|
|
payload.put(revision);
|
|
|
|
"]";
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, revision);
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(undeployAPIRevisionEndPoint)
|
|
|
|
.url(undeployAPIRevisionEndPoint)
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
@ -896,11 +1001,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
JSONObject apiRevision, String uuid)
|
|
|
|
APIRevision apiRevision, String uuid)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" +
|
|
|
|
String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" +
|
|
|
|
apiRevision.getString("id");
|
|
|
|
apiRevision.getId();
|
|
|
|
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(apiRevisionEndPoint)
|
|
|
|
.url(apiRevisionEndPoint)
|
|
|
@ -936,7 +1041,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
|
|
|
|
public Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
|
|
String getDocumentationsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents?limit=1000";
|
|
|
|
String getDocumentationsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents?limit=1000";
|
|
|
@ -951,8 +1056,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 documentList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
|
|
|
return jsonObject;
|
|
|
|
return gson.fromJson(documentList.toString(), Documentation[].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.
|
|
|
@ -1022,17 +1127,16 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents";
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents";
|
|
|
|
|
|
|
|
|
|
|
|
String document = "{\n" +
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
" \"name\": \"" + documentation.getName() + "\",\n" +
|
|
|
|
payload.put("name", documentation.getName());
|
|
|
|
" \"type\": \"" + documentation.getType() + "\",\n" +
|
|
|
|
payload.put("type", documentation.getType());
|
|
|
|
" \"summary\": \"" + documentation.getSummary() + "\",\n" +
|
|
|
|
payload.put("summary", documentation.getSummary());
|
|
|
|
" \"sourceType\": \"" + documentation.getSourceType() + "\",\n" +
|
|
|
|
payload.put("sourceType", documentation.getSourceType());
|
|
|
|
" \"inlineContent\": \"" + documentation.getSourceType() + "\",\n" +
|
|
|
|
payload.put("inlineContent", documentation.getSourceType());
|
|
|
|
" \"visibility\": \"" + documentation.getVisibility() + "\",\n" +
|
|
|
|
payload.put("visibility", documentation.getVisibility());
|
|
|
|
" \"createdBy\": \"admin\"\n" +
|
|
|
|
payload.put("createdBy", documentation.getCreatedBy());
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
|
|
|
RequestBody requestBody = RequestBody.create(JSON, document);
|
|
|
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
.url(addNewScope)
|
|
|
|
.url(addNewScope)
|
|
|
|
.addHeader(Constants.HEADER_CONTENT_TYPE, Constants.APPLICATION_JSON)
|
|
|
|
.addHeader(Constants.HEADER_CONTENT_TYPE, Constants.APPLICATION_JSON)
|
|
|
|