mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix consumer REST calls
This commit is contained in:
parent
342e201c4c
commit
c455bfe187
@ -80,6 +80,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
|
|
||||||
private static final Log log = LogFactory.getLog(APIManagementProviderServiceImpl.class);
|
private static final Log log = LogFactory.getLog(APIManagementProviderServiceImpl.class);
|
||||||
public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance();
|
public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance();
|
||||||
|
private static final String UNLIMITED_TIER = "Unlimited";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTierLoaded() {
|
public boolean isTierLoaded() {
|
||||||
@ -238,6 +239,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices();
|
APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices();
|
||||||
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application = new io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application();
|
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application = new io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application();
|
||||||
application.setName(applicationName);
|
application.setName(applicationName);
|
||||||
|
application.setThrottlingPolicy(UNLIMITED_TIER);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
application = consumerRESTAPIServices.createApplication(tokenInfo, application);
|
application = consumerRESTAPIServices.createApplication(tokenInfo, application);
|
||||||
@ -254,7 +256,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
throw new APIManagerException(msg);
|
throw new APIManagerException(msg);
|
||||||
}
|
}
|
||||||
ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
|
ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(tokenInfo, application.getApplicationId(),
|
||||||
keyManager.getName(), keyType, validityTime);
|
keyManager.getName(), validityTime, keyType);
|
||||||
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
||||||
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
||||||
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
||||||
@ -317,6 +319,8 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setApiId(apiInfo.getId());
|
subscription.setApiId(apiInfo.getId());
|
||||||
subscription.setApplicationId(application.getApplicationId());
|
subscription.setApplicationId(application.getApplicationId());
|
||||||
|
subscription.setThrottlingPolicy(UNLIMITED_TIER);
|
||||||
|
subscription.setRequestedThrottlingPolicy(UNLIMITED_TIER);
|
||||||
subscriptionList.add(subscription);
|
subscriptionList.add(subscription);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -649,7 +653,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
APIApplicationKey apiApplicationKey;
|
APIApplicationKey apiApplicationKey;
|
||||||
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo accessTokenInfo;
|
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo accessTokenInfo;
|
||||||
try {
|
try {
|
||||||
if (username == null && password == null) {
|
if (username == null || password == null) {
|
||||||
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
|
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
|
||||||
} else {
|
} else {
|
||||||
apiApplicationKey = apiApplicationServices.generateAndRetrieveApplicationKeys(username, password);
|
apiApplicationKey = apiApplicationServices.generateAndRetrieveApplicationKeys(username, password);
|
||||||
|
|||||||
@ -176,7 +176,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|||||||
" \"description\": \"" + application.getDescription() + "\",\n" +
|
" \"description\": \"" + application.getDescription() + "\",\n" +
|
||||||
" \"tokenType\": \"" + application.getTokenType() + "\",\n" +
|
" \"tokenType\": \"" + application.getTokenType() + "\",\n" +
|
||||||
" \"groups\": " + gson.toJson(application.getGroups()) + ",\n" +
|
" \"groups\": " + gson.toJson(application.getGroups()) + ",\n" +
|
||||||
" \"attributes\": " + application.getAttributes().toString() + ",\n" +
|
" \"attributes\": " + gson.toJson(application.getAttributes()) + ",\n" +
|
||||||
" \"subscriptionScopes\": " + gson.toJson(application.getSubscriptionScopes()) + "\n" +
|
" \"subscriptionScopes\": " + gson.toJson(application.getSubscriptionScopes()) + "\n" +
|
||||||
"}";
|
"}";
|
||||||
RequestBody requestBody = RequestBody.create(JSON, applicationInfo);
|
RequestBody requestBody = RequestBody.create(JSON, applicationInfo);
|
||||||
@ -291,7 +291,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|||||||
|
|
||||||
ApiApplicationInfo apiApplicationInfo = tokenInfo.getApiApplicationInfo();
|
ApiApplicationInfo apiApplicationInfo = tokenInfo.getApiApplicationInfo();
|
||||||
boolean token = isTokenNull(apiApplicationInfo, tokenInfo.getAccessToken());
|
boolean token = isTokenNull(apiApplicationInfo, tokenInfo.getAccessToken());
|
||||||
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "?applicationId=" + applicationId;
|
String getAllScopesUrl = endPointPrefix + Constants.SUBSCRIPTION_API + "?applicationId=" + applicationId + "&limit=1000";
|
||||||
|
|
||||||
Request.Builder builder = new Request.Builder();
|
Request.Builder builder = new Request.Builder();
|
||||||
builder.url(getAllScopesUrl);
|
builder.url(getAllScopesUrl);
|
||||||
@ -497,8 +497,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
|
|||||||
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()) {
|
||||||
JSONArray subscriptionsArray = (JSONArray) new JSONObject(response.body().string()).get("list");
|
return gson.fromJson(response.body().string(), Subscription[].class);
|
||||||
return gson.fromJson(subscriptionsArray.toString(), Subscription[].class);
|
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
|
|||||||
@ -36,31 +36,16 @@ public class APIInfo {
|
|||||||
private String context;
|
private String context;
|
||||||
private String version;
|
private String version;
|
||||||
private String provider;
|
private String provider;
|
||||||
private JSONObject apiDefinition;
|
|
||||||
private String wsdlUri;
|
|
||||||
private String lifeCycleStatus;
|
private String lifeCycleStatus;
|
||||||
private boolean isDefaultVersion;
|
private String thumbnailUri;
|
||||||
private String type;
|
|
||||||
private Set<String> transport;
|
|
||||||
private List<JSONObject> operations;
|
|
||||||
private String authorizationHeader;
|
|
||||||
private String securityScheme;
|
|
||||||
private Set<String> tags;
|
|
||||||
private List<JSONObject> tiers;
|
|
||||||
private boolean hasThumbnail;
|
|
||||||
private String additionalProperties;
|
|
||||||
private JSONObject monetization;
|
|
||||||
private List<JSONObject> endpointURLs;
|
|
||||||
private JSONObject businessInformation;
|
|
||||||
private List<JSONObject> environmentList;
|
|
||||||
private List<ScopeUtils> scopes;
|
|
||||||
private String avgRating;
|
private String avgRating;
|
||||||
|
private List<String> throttlingPolicies;
|
||||||
private JSONObject advertiseInfo;
|
private JSONObject advertiseInfo;
|
||||||
|
private JSONObject businessInformation;
|
||||||
private boolean isSubscriptionAvailable;
|
private boolean isSubscriptionAvailable;
|
||||||
private List<JSONObject> categories;
|
private String monetizationLabel;
|
||||||
private List<String> keyManagers = new ArrayList();
|
private String gatewayVendor;
|
||||||
private String createdTime;
|
private List<String> additionalProperties;
|
||||||
private String lastUpdatedTime;
|
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -110,22 +95,6 @@ public class APIInfo {
|
|||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getApiDefinition() {
|
|
||||||
return apiDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApiDefinition(JSONObject apiDefinition) {
|
|
||||||
this.apiDefinition = apiDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWsdlUri() {
|
|
||||||
return wsdlUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWsdlUri(String wsdlUri) {
|
|
||||||
this.wsdlUri = wsdlUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLifeCycleStatus() {
|
public String getLifeCycleStatus() {
|
||||||
return lifeCycleStatus;
|
return lifeCycleStatus;
|
||||||
}
|
}
|
||||||
@ -134,124 +103,12 @@ public class APIInfo {
|
|||||||
this.lifeCycleStatus = lifeCycleStatus;
|
this.lifeCycleStatus = lifeCycleStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDefaultVersion() {
|
public String getThumbnailUri() {
|
||||||
return isDefaultVersion;
|
return thumbnailUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultVersion(boolean defaultVersion) {
|
public void setThumbnailUri(String thumbnailUri) {
|
||||||
isDefaultVersion = defaultVersion;
|
this.thumbnailUri = thumbnailUri;
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getTransport() {
|
|
||||||
return transport;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransport(Set<String> transport) {
|
|
||||||
this.transport = transport;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JSONObject> getOperations() {
|
|
||||||
return operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperations(List<JSONObject> operations) {
|
|
||||||
this.operations = operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthorizationHeader() {
|
|
||||||
return authorizationHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorizationHeader(String authorizationHeader) {
|
|
||||||
this.authorizationHeader = authorizationHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSecurityScheme() {
|
|
||||||
return securityScheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecurityScheme(String securityScheme) {
|
|
||||||
this.securityScheme = securityScheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(Set<String> tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JSONObject> getTiers() {
|
|
||||||
return tiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTiers(List<JSONObject> tiers) {
|
|
||||||
this.tiers = tiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasThumbnail() {
|
|
||||||
return hasThumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasThumbnail(boolean hasThumbnail) {
|
|
||||||
this.hasThumbnail = hasThumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAdditionalProperties() {
|
|
||||||
return additionalProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAdditionalProperties(String additionalProperties) {
|
|
||||||
this.additionalProperties = additionalProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject getMonetization() {
|
|
||||||
return monetization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMonetization(JSONObject monetization) {
|
|
||||||
this.monetization = monetization;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JSONObject> getEndpointURLs() {
|
|
||||||
return endpointURLs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndpointURLs(List<JSONObject> endpointURLs) {
|
|
||||||
this.endpointURLs = endpointURLs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject getBusinessInformation() {
|
|
||||||
return businessInformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBusinessInformation(JSONObject businessInformation) {
|
|
||||||
this.businessInformation = businessInformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JSONObject> getEnvironmentList() {
|
|
||||||
return environmentList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnvironmentList(List<JSONObject> environmentList) {
|
|
||||||
this.environmentList = environmentList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ScopeUtils> getScopes() {
|
|
||||||
return scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScopes(List<ScopeUtils> scopes) {
|
|
||||||
this.scopes = scopes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAvgRating() {
|
public String getAvgRating() {
|
||||||
@ -262,6 +119,14 @@ public class APIInfo {
|
|||||||
this.avgRating = avgRating;
|
this.avgRating = avgRating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getThrottlingPolicies() {
|
||||||
|
return throttlingPolicies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrottlingPolicies(List<String> throttlingPolicies) {
|
||||||
|
this.throttlingPolicies = throttlingPolicies;
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject getAdvertiseInfo() {
|
public JSONObject getAdvertiseInfo() {
|
||||||
return advertiseInfo;
|
return advertiseInfo;
|
||||||
}
|
}
|
||||||
@ -270,6 +135,14 @@ public class APIInfo {
|
|||||||
this.advertiseInfo = advertiseInfo;
|
this.advertiseInfo = advertiseInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject getBusinessInformation() {
|
||||||
|
return businessInformation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBusinessInformation(JSONObject businessInformation) {
|
||||||
|
this.businessInformation = businessInformation;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSubscriptionAvailable() {
|
public boolean isSubscriptionAvailable() {
|
||||||
return isSubscriptionAvailable;
|
return isSubscriptionAvailable;
|
||||||
}
|
}
|
||||||
@ -278,35 +151,27 @@ public class APIInfo {
|
|||||||
isSubscriptionAvailable = subscriptionAvailable;
|
isSubscriptionAvailable = subscriptionAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JSONObject> getCategories() {
|
public String getMonetizationLabel() {
|
||||||
return categories;
|
return monetizationLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCategories(List<JSONObject> categories) {
|
public void setMonetizationLabel(String monetizationLabel) {
|
||||||
this.categories = categories;
|
this.monetizationLabel = monetizationLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getKeyManagers() {
|
public String getGatewayVendor() {
|
||||||
return keyManagers;
|
return gatewayVendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyManagers(List<String> keyManagers) {
|
public void setGatewayVendor(String gatewayVendor) {
|
||||||
this.keyManagers = keyManagers;
|
this.gatewayVendor = gatewayVendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedTime() {
|
public List<String> getAdditionalProperties() {
|
||||||
return createdTime;
|
return additionalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreatedTime(String createdTime) {
|
public void setAdditionalProperties(List<String> additionalProperties) {
|
||||||
this.createdTime = createdTime;
|
this.additionalProperties = additionalProperties;
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastUpdatedTime() {
|
|
||||||
return lastUpdatedTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastUpdatedTime(String lastUpdatedTime) {
|
|
||||||
this.lastUpdatedTime = lastUpdatedTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,13 +18,15 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class Subscription {
|
public class Subscription {
|
||||||
|
|
||||||
private String subscriptionId;
|
private String subscriptionId;
|
||||||
private String applicationId;
|
private String applicationId;
|
||||||
private String apiId;
|
private String apiId;
|
||||||
private APIInfo apiInfo;
|
private APIInfo apiInfo;
|
||||||
private Application applicationInfo;
|
private JSONObject applicationInfo;
|
||||||
private String throttlingPolicy;
|
private String throttlingPolicy;
|
||||||
private String requestedThrottlingPolicy;
|
private String requestedThrottlingPolicy;
|
||||||
private String status;
|
private String status;
|
||||||
@ -62,11 +64,11 @@ public class Subscription {
|
|||||||
this.apiInfo = apiInfo;
|
this.apiInfo = apiInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Application getApplicationInfo() {
|
public JSONObject getApplicationInfo() {
|
||||||
return applicationInfo;
|
return applicationInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicationInfo(Application applicationInfo) {
|
public void setApplicationInfo(JSONObject applicationInfo) {
|
||||||
this.applicationInfo = applicationInfo;
|
this.applicationInfo = applicationInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user