Map Json object return types to dto classes in Publisher

master
Pasindu Rupasinghe 1 year ago
parent 565a7614ad
commit bdf1e97d84

@ -47,13 +47,13 @@ public interface PublisherRESTAPIServices {
boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
@ -91,7 +91,7 @@ public interface PublisherRESTAPIServices {
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;

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

@ -20,7 +20,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import org.json.JSONObject;
import java.util.*;
import java.util.List;
/**
* This class represents the API response.
@ -35,7 +35,7 @@ public class APIInfo {
private String version;
private String provider;
private String lifeCycleStatus;
private String wsdlInfo;
private type wsdlInfo;
private String wsdlUrl;
private boolean responseCachingEnabled;
private int cacheTimeout;
@ -45,59 +45,65 @@ public class APIInfo {
private String revisionedApiId;
private int revisionId;
private boolean enableSchemaValidation;
private boolean enableStore;
private String type;
private Set<String> transport;
private Set<String> tags;
private Set<String> policies;
private List<String> transport;
private List<String> tags;
private List<String> policies;
private String apiThrottlingPolicy;
private String authorizationHeader;
private String securityScheme;
private String maxTps;
private List<String> securityScheme;
private APIMaxTps maxTps;
private String visibility;
private String visibleRoles;
private String visibleTenants;
private String mediationPolicies;
private List<String> visibleRoles;
private List<String> visibleTenants;
private List<MediationPolicy> mediationPolicies;
private String subscriptionAvailability;
private String subscriptionAvailableTenants;
private String additionalProperties;
private String monetization;
private List<String> subscriptionAvailableTenants;
private List<AdditionalProperties> additionalProperties;
private Monetization monetization;
private String accessControl;
private String accessControlRoles;
private List<String> accessControlRoles;
private BusinessInformation businessInformation;
private CORSConfiguration corsConfiguration;
private WebsubSubscriptionConfiguration websubSubscriptionConfiguration;
private String workflowStatus;
private String createdTime;
private String lastUpdatedTime;
private JSONObject endpointConfig = new JSONObject();
private JSONObject endpointConfig;
private String endpointImplementationType;
private List<JSONObject> scopes = new ArrayList();
private List<JSONObject> operations;
private String threatProtectionPolicies;
private List<String> keyManagers = new ArrayList();
private JSONObject serviceInfo = new JSONObject();
private List<JSONObject> scopes;
private List<Operations> operations;
private JSONObject threatProtectionPolicies;
private List<String> categories;
private List<String> keyManagers;
private ServiceInfo serviceInfo;
private AdvertiseInfo advertiseInfo;
private String asyncApiDefinition;
private Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
private String inSequence;
public enum type {
WSDL, ZIP
}
private Map<String, String> wsUriMapping;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ -109,12 +115,15 @@ public class APIInfo {
public void setContext(String context) {
this.context = context;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getProvider() {
return provider;
}
@ -131,11 +140,11 @@ public class APIInfo {
this.lifeCycleStatus = lifeCycleStatus;
}
public String getWsdlInfo() {
public APIInfo.type getWsdlInfo() {
return wsdlInfo;
}
public void setWsdlInfo(String wsdlInfo) {
public void setWsdlInfo(APIInfo.type wsdlInfo) {
this.wsdlInfo = wsdlInfo;
}
@ -211,6 +220,14 @@ public class APIInfo {
this.enableSchemaValidation = enableSchemaValidation;
}
public boolean isEnableStore() {
return enableStore;
}
public void setEnableStore(boolean enableStore) {
this.enableStore = enableStore;
}
public String getType() {
return type;
}
@ -219,27 +236,27 @@ public class APIInfo {
this.type = type;
}
public Set<String> getTransport() {
public List<String> getTransport() {
return transport;
}
public void setTransport(Set<String> transport) {
public void setTransport(List<String> transport) {
this.transport = transport;
}
public Set<String> getTags() {
public List<String> getTags() {
return tags;
}
public void setTags(Set<String> tags) {
public void setTags(List<String> tags) {
this.tags = tags;
}
public Set<String> getPolicies() {
public List<String> getPolicies() {
return policies;
}
public void setPolicies(Set<String> policies) {
public void setPolicies(List<String> policies) {
this.policies = policies;
}
@ -259,19 +276,19 @@ public class APIInfo {
this.authorizationHeader = authorizationHeader;
}
public String getSecurityScheme() {
public List<String> getSecurityScheme() {
return securityScheme;
}
public void setSecurityScheme(String securityScheme) {
public void setSecurityScheme(List<String> securityScheme) {
this.securityScheme = securityScheme;
}
public String getMaxTps() {
public APIMaxTps getMaxTps() {
return maxTps;
}
public void setMaxTps(String maxTps) {
public void setMaxTps(APIMaxTps maxTps) {
this.maxTps = maxTps;
}
@ -283,27 +300,27 @@ public class APIInfo {
this.visibility = visibility;
}
public String getVisibleRoles() {
public List<String> getVisibleRoles() {
return visibleRoles;
}
public void setVisibleRoles(String visibleRoles) {
public void setVisibleRoles(List<String> visibleRoles) {
this.visibleRoles = visibleRoles;
}
public String getVisibleTenants() {
public List<String> getVisibleTenants() {
return visibleTenants;
}
public void setVisibleTenants(String visibleTenants) {
public void setVisibleTenants(List<String> visibleTenants) {
this.visibleTenants = visibleTenants;
}
public String getMediationPolicies() {
public List<MediationPolicy> getMediationPolicies() {
return mediationPolicies;
}
public void setMediationPolicies(String mediationPolicies) {
public void setMediationPolicies(List<MediationPolicy> mediationPolicies) {
this.mediationPolicies = mediationPolicies;
}
@ -315,27 +332,27 @@ public class APIInfo {
this.subscriptionAvailability = subscriptionAvailability;
}
public String getSubscriptionAvailableTenants() {
public List<String> getSubscriptionAvailableTenants() {
return subscriptionAvailableTenants;
}
public void setSubscriptionAvailableTenants(String subscriptionAvailableTenants) {
public void setSubscriptionAvailableTenants(List<String> subscriptionAvailableTenants) {
this.subscriptionAvailableTenants = subscriptionAvailableTenants;
}
public String getAdditionalProperties() {
public List<AdditionalProperties> getAdditionalProperties() {
return additionalProperties;
}
public void setAdditionalProperties(String additionalProperties) {
public void setAdditionalProperties(List<AdditionalProperties> additionalProperties) {
this.additionalProperties = additionalProperties;
}
public String getMonetization() {
public Monetization getMonetization() {
return monetization;
}
public void setMonetization(String monetization) {
public void setMonetization(Monetization monetization) {
this.monetization = monetization;
}
@ -347,11 +364,11 @@ public class APIInfo {
this.accessControl = accessControl;
}
public String getAccessControlRoles() {
public List<String> getAccessControlRoles() {
return accessControlRoles;
}
public void setAccessControlRoles(String accessControlRoles) {
public void setAccessControlRoles(List<String> accessControlRoles) {
this.accessControlRoles = accessControlRoles;
}
@ -371,6 +388,14 @@ public class APIInfo {
this.corsConfiguration = corsConfiguration;
}
public WebsubSubscriptionConfiguration getWebsubSubscriptionConfiguration() {
return websubSubscriptionConfiguration;
}
public void setWebsubSubscriptionConfiguration(WebsubSubscriptionConfiguration websubSubscriptionConfiguration) {
this.websubSubscriptionConfiguration = websubSubscriptionConfiguration;
}
public String getWorkflowStatus() {
return workflowStatus;
}
@ -419,22 +444,30 @@ public class APIInfo {
this.scopes = scopes;
}
public List<JSONObject> getOperations() {
public List<Operations> getOperations() {
return operations;
}
public void setOperations(List<JSONObject> operations) {
public void setOperations(List<Operations> operations) {
this.operations = operations;
}
public String getThreatProtectionPolicies() {
public JSONObject getThreatProtectionPolicies() {
return threatProtectionPolicies;
}
public void setThreatProtectionPolicies(String threatProtectionPolicies) {
public void setThreatProtectionPolicies(JSONObject threatProtectionPolicies) {
this.threatProtectionPolicies = threatProtectionPolicies;
}
public List<String> getCategories() {
return categories;
}
public void setCategories(List<String> categories) {
this.categories = categories;
}
public List<String> getKeyManagers() {
return keyManagers;
}
@ -443,11 +476,11 @@ public class APIInfo {
this.keyManagers = keyManagers;
}
public JSONObject getServiceInfo() {
public ServiceInfo getServiceInfo() {
return serviceInfo;
}
public void setServiceInfo(JSONObject serviceInfo) {
public void setServiceInfo(ServiceInfo serviceInfo) {
this.serviceInfo = serviceInfo;
}
@ -458,36 +491,4 @@ public class APIInfo {
public void setAdvertiseInfo(AdvertiseInfo advertiseInfo) {
this.advertiseInfo = advertiseInfo;
}
public String getInSequence() {
return inSequence;
}
public void setInSequence(String inSequence) {
this.inSequence = inSequence;
}
public String getAsyncApiDefinition() {
return asyncApiDefinition;
}
public void setAsyncApiDefinition(String asyncApiDefinition) {
this.asyncApiDefinition = asyncApiDefinition;
}
public Set<URITemplate> getUriTemplates() {
return uriTemplates;
}
public void setUriTemplates(Set<URITemplate> uriTemplates) {
this.uriTemplates = uriTemplates;
}
public Map<String, String> getWsUriMapping() {
return wsUriMapping;
}
public void setWsUriMapping(Map<String, String> wsUriMapping) {
this.wsUriMapping = wsUriMapping;
}
}

@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import java.io.Serializable;
public class APIMaxTps implements Serializable {
private static final long serialVersionUID = 1L;
int production;
int sandbox;
public int getProduction() {
return production;
}
public void setProduction(int production) {
this.production = production;
}
public int getSandbox() {
return sandbox;
}
public void setSandbox(int sandbox) {
this.sandbox = sandbox;
}
}

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
public class AdditionalProperties {
private String name;
private String value;
private boolean display;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public boolean isDisplay() {
return display;
}
public void setDisplay(boolean display) {
this.display = display;
}
}

@ -0,0 +1,59 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
public class MediationPolicy {
private String id;
private String name;
private String type;
private boolean shared;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isShared() {
return shared;
}
public void setShared(boolean shared) {
this.shared = shared;
}
}

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import org.json.JSONObject;
public class Monetization {
private boolean enabled;
private JSONObject properties;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public JSONObject getProperties() {
return properties;
}
public void setProperties(JSONObject properties) {
this.properties = properties;
}
}

@ -18,7 +18,8 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import java.util.Set;
import org.json.JSONObject;
import java.util.List;
/**
* This hold the api operations information.
@ -29,8 +30,8 @@ public class Operations {
private String verb;
private String authType;
private String throttlingPolicy;
private Set<String> scopes;
private String usedProductIds;
private List<String> scopes;
private List<String> usedProductIds;
private String amznResourceName;
private String amznResourceTimeout;
private String payloadSchema;
@ -78,19 +79,19 @@ public class Operations {
this.throttlingPolicy = throttlingPolicy;
}
public Set<String> getScopes() {
public List<String> getScopes() {
return scopes;
}
public void setScopes(Set<String> scopes) {
public void setScopes(List<String> scopes) {
this.scopes = scopes;
}
public String getUsedProductIds() {
public List<String> getUsedProductIds() {
return usedProductIds;
}
public void setUsedProductIds(String usedProductIds) {
public void setUsedProductIds(List<String> usedProductIds) {
this.usedProductIds = usedProductIds;
}

@ -0,0 +1,59 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
public class ServiceInfo {
private String key;
private String name;
private String version;
private boolean outdated;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public boolean isOutdated() {
return outdated;
}
public void setOutdated(boolean outdated) {
this.outdated = outdated;
}
}

@ -0,0 +1,41 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
public class ThreatProtectionPolicies {
private String policyID;
private int priority;
public String getPolicyID() {
return policyID;
}
public void setPolicyID(String policyID) {
this.policyID = policyID;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}

@ -0,0 +1,61 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
/**
* This hold the Websub Subscription Configuration of an API.
*/
public class WebsubSubscriptionConfiguration {
private boolean enable;
private String secret;
private String signingAlgorithm;
private String signatureHeader;
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getSigningAlgorithm() {
return signingAlgorithm;
}
public void setSigningAlgorithm(String signingAlgorithm) {
this.signingAlgorithm = signingAlgorithm;
}
public String getSignatureHeader() {
return signatureHeader;
}
public void setSignatureHeader(String signatureHeader) {
this.signatureHeader = signatureHeader;
}
}

@ -17,19 +17,15 @@
*/
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
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.APIInfo.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.APIInfo.CORSConfiguration;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
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.BadRequestException;
@ -91,6 +87,7 @@ import java.util.Date;
*/
public class APIPublisherServiceImpl implements APIPublisherService {
public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance();
private static final Gson gson = new Gson();
private static final String UNLIMITED_TIER = "Unlimited";
private static final String WS_UNLIMITED_TIER = "AsyncUnlimited";
private static final String API_PUBLISH_ENVIRONMENT = "Default";
@ -166,14 +163,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiConfig.getName(), apiConfig.getVersion());
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
JSONArray apiList = (JSONArray) publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo).get("list");
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
boolean apiFound = false;
for (int i = 0; i < apiList.length(); i++) {
JSONObject apiObj = apiList.getJSONObject(i);
if (apiObj.getString("name").equals(apiIdentifier.getApiName().replace(Constants.SPACE,
for (int i = 0; i < apiList.length; i++) {
APIInfo apiObj = apiList[i];
if (apiObj.getName().equals(apiIdentifier.getApiName().replace(Constants.SPACE,
Constants.EMPTY_STRING))) {
apiFound = true;
apiIdentifier.setUuid(apiObj.getString("id"));
apiIdentifier.setUuid(apiObj.getId());
break;
}
}
@ -194,13 +191,13 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
APIInfo api = getAPI(apiConfig, true);
JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
apiUuid = createdAPI.getString("id");
APIInfo createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
apiUuid = createdAPI.getId();
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
apiUuid, apiConfig.getAsyncApiDefinition());
}
if (CREATED_STATUS.equals(createdAPI.getString("lifeCycleStatus"))) {
if (CREATED_STATUS.equals(createdAPI.getLifeCycleStatus())) {
// if endpoint type "dynamic" and then add in sequence
if ("dynamic".equals(apiConfig.getEndpointType())) {
Mediation mediation = new Mediation();
@ -272,12 +269,12 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
// Get existing API
JSONObject existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
APIInfo existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
apiUuid);
if (scopesToMoveAsSharedScopes.size() > 0) {
// update API to remove local scopes
APIInfo api = getAPI(apiConfig, false);
api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus"));
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
@ -294,7 +291,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiUuid);
APIInfo api = getAPI(apiConfig, true);
api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus"));
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
api.setId(apiUuid);
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
@ -375,7 +372,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
apiUuid, apiRevisionId, apiRevisionDeploymentList);
if (CREATED_STATUS.equals(existingAPI.getString("lifeCycleStatus"))) {
if (CREATED_STATUS.equals(existingAPI.getLifeCycleStatus())) {
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
apiUuid, PUBLISH_ACTION);
}
@ -779,55 +776,49 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiInfo.setRevisionedApiId(null);
apiInfo.setEnableSchemaValidation(false);
Set<String> tags = new HashSet<>();
List<String> tags = new ArrayList<>();
tags.addAll(Arrays.asList(config.getTags()));
apiInfo.setTags(tags);
Set<String> availableTiers = new HashSet<>();
List<String> availableTiers = new ArrayList<>();
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
availableTiers.add(WS_UNLIMITED_TIER);
} else {
availableTiers.add(UNLIMITED_TIER);
}
apiInfo.setPolicies(availableTiers);
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
apiInfo.setAsyncApiDefinition(config.getAsyncApiDefinition());
}
apiInfo.setApiThrottlingPolicy(UNLIMITED_TIER);
//set operations and scopes
List<JSONObject> operations = new ArrayList();
List<Operations> operations = new ArrayList();
List<JSONObject> scopeSet = new ArrayList();
Iterator<ApiUriTemplate> iterator;
for (iterator = config.getUriTemplates().iterator(); iterator.hasNext(); ) {
ApiUriTemplate apiUriTemplate = iterator.next();
JSONObject operation = new JSONObject();
operation.put("target", apiUriTemplate.getUriTemplate());
operation.put("verb", apiUriTemplate.getHttpVerb());
operation.put("authType", apiUriTemplate.getAuthType());
operation.put("throttlingPolicy", UNLIMITED_TIER);
operation.put("uriMapping", apiUriTemplate.getUriMapping());
Operations operation = new Operations();
operation.setTarget(apiUriTemplate.getUriTemplate());
operation.setVerb(apiUriTemplate.getHttpVerb());
operation.setAuthType(apiUriTemplate.getAuthType());
operation.setThrottlingPolicy(UNLIMITED_TIER);
operation.setUriMapping(apiUriTemplate.getUriMapping());
if (includeScopes) {
if (apiUriTemplate.getScope() != null) {
String scopeString = "{\n" +
" \"scope\": {\n" +
" \"id\": null,\n" +
" \"name\": \"" + apiUriTemplate.getScope().getKey() + "\",\n" +
" \"displayName\": \"" + apiUriTemplate.getScope().getName() + "\",\n" +
" \"description\": \"" + apiUriTemplate.getScope().getDescription() + "\",\n" +
" \"bindings\": [\n" +
" \"" + apiUriTemplate.getScope().getRoles() + "\"\n" +
" ],\n" +
" \"usageCount\": null\n" +
" },\n" +
" \"shared\": true\n" +
" }";
JSONObject scope = new JSONObject(scopeString);
scopeSet.add(scope);
Scope scope = new Scope();
scope.setName(apiUriTemplate.getScope().getKey());
scope.setDisplayName(apiUriTemplate.getScope().getName());
scope.setDescription(apiUriTemplate.getScope().getDescription());
scope.setBindings(apiUriTemplate.getScope().getRoles());
JSONObject scopeObject = new JSONObject();
scopeObject.put("scope", new JSONObject(gson.toJson(scope)));
scopeObject.put("shared", true);
scopeSet.add(scopeObject);
Set<String> scopes = new HashSet<>();
scopes.add(apiUriTemplate.getScope().getKey());
operation.put("scopes", scopes);
List<String> scopes = new ArrayList<>();
scopes.addAll(Arrays.asList(apiUriTemplate.getScope().getKey()));
operation.setScopes(scopes);
}
}
operations.add(operation);
@ -855,8 +846,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
" }";
JSONObject endPointConfig = new JSONObject(endpointConfig);
Set<String> transports = new HashSet<>();
transports.addAll(Arrays.asList(config.getTransports()));
List<String> transports = new ArrayList<>();
transports.addAll(Arrays.asList(config.getTransports().split(",")));
apiInfo.setTransport(transports);
apiInfo.setType("HTTP");
@ -872,7 +863,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
" }\n" +
" }";
endPointConfig = new JSONObject(endpointConfig);
apiInfo.setInSequence(config.getInSequenceName());
apiInfo.setEndpointImplementationType("ENDPOINT");
}
// if ws endpoint
@ -888,7 +879,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
" }";
endPointConfig = new JSONObject(endpointConfig);
transports.addAll(Arrays.asList("wss,ws"));
transports.add("wss");
transports.add("ws");
apiInfo.setTransport(transports);
apiInfo.setType("WS");
}
@ -922,6 +914,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiInfo.setEnableSchemaValidation(false);
apiInfo.setMonetization(null);
apiInfo.setServiceInfo(null);
apiInfo.setWebsubSubscriptionConfiguration(null);
apiInfo.setAdvertiseInfo(null);
return apiInfo;
}

Loading…
Cancel
Save