Improvements in consumer rest apis

apim420
Pasindu Rupasinghe 1 year ago
parent c46a459e6d
commit a513c13037

@ -18,32 +18,33 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIKey;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.KeyManager;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
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;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import org.json.JSONObject;
import java.util.List;
import java.util.Map;
public interface ConsumerRESTAPIServices {
JSONObject getAllApplications(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String appName)
Application[] getAllApplications(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String appName)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
Application createApplication(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Application application)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAllSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Subscription[] getAllSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String applicationId)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Map<String, String> queryParam)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
@ -51,7 +52,7 @@ public interface ConsumerRESTAPIServices {
Subscription subscriptions)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
Subscription createSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Subscription[] createSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
List<Subscription> subscriptions)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
@ -59,6 +60,6 @@ public interface ConsumerRESTAPIServices {
String applicationId)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAllKeyManagers(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
KeyManager[] getAllKeyManagers(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
}

@ -19,9 +19,11 @@
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.bean.APIMConsumer.APIInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIKey;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.KeyManager;
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.AccessTokenInfo;
@ -33,6 +35,7 @@ import okhttp3.*;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
@ -51,7 +54,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
+ Constants.COLON + port;
@Override
public JSONObject getAllApplications(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String appName)
public Application[] getAllApplications(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String appName)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getAllApplicationsUrl = endPointPrefix + Constants.APPLICATIONS_API + "?query=" + appName;
@ -65,8 +68,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
JSONObject jsonObject = new JSONObject(response.body().string());
return jsonObject;
JSONArray applicationList = (JSONArray) new JSONObject(response.body().string()).get("list");
return gson.fromJson(applicationList.toString(), Application[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -141,7 +144,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
}
@Override
public JSONObject getAllSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
public Subscription[] getAllSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String applicationId)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
@ -156,8 +159,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
JSONObject jsonObject = new JSONObject(response.body().string());
return jsonObject;
JSONArray subscriptionList = (JSONArray) new JSONObject(response.body().string()).get("list");
return gson.fromJson(subscriptionList.toString(), Subscription[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -181,7 +184,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
}
@Override
public JSONObject getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
public APIInfo[] getAllApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
Map<String, String> queryParams)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
@ -201,8 +204,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
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.
@ -274,7 +277,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
}
@Override
public Subscription createSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
public Subscription[] createSubscriptions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
List<Subscription> subscriptions)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
@ -293,7 +296,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
return gson.fromJson(response.body().string(), Subscription.class);
JSONArray subscriptionsArray = (JSONArray) new JSONObject(response.body().string()).get("list");
return gson.fromJson(subscriptionsArray.toString(), Subscription[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -364,7 +368,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
}
@Override
public JSONObject getAllKeyManagers(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
public KeyManager[] getAllKeyManagers(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getAllKeyManagersUrl = endPointPrefix + Constants.KEY_MANAGERS_API;
@ -378,8 +382,8 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices {
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
JSONObject jsonObject = new JSONObject(response.body().string());
return jsonObject;
JSONArray keyManagerList = (JSONArray) new JSONObject(response.body().string()).get("list");
return gson.fromJson(keyManagerList.toString(), KeyManager[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.

@ -0,0 +1,312 @@
/*
* 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.bean.APIMConsumer;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* This class represents the Consumer API Information.
*/
public class APIInfo {
private String id;
private String name;
private String description;
private String context;
private String version;
private String provider;
private JSONObject apiDefinition;
private String wsdlUri;
private String lifeCycleStatus;
private boolean isDefaultVersion;
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 JSONObject advertiseInfo;
private boolean isSubscriptionAvailable;
private List<JSONObject> categories;
private List<String> keyManagers = new ArrayList();
private String createdTime;
private String lastUpdatedTime;
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;
}
public String getContext() {
return context;
}
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;
}
public void setProvider(String 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() {
return lifeCycleStatus;
}
public void setLifeCycleStatus(String lifeCycleStatus) {
this.lifeCycleStatus = lifeCycleStatus;
}
public boolean isDefaultVersion() {
return isDefaultVersion;
}
public void setDefaultVersion(boolean defaultVersion) {
isDefaultVersion = defaultVersion;
}
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() {
return avgRating;
}
public void setAvgRating(String avgRating) {
this.avgRating = avgRating;
}
public JSONObject getAdvertiseInfo() {
return advertiseInfo;
}
public void setAdvertiseInfo(JSONObject advertiseInfo) {
this.advertiseInfo = advertiseInfo;
}
public boolean isSubscriptionAvailable() {
return isSubscriptionAvailable;
}
public void setSubscriptionAvailable(boolean subscriptionAvailable) {
isSubscriptionAvailable = subscriptionAvailable;
}
public List<JSONObject> getCategories() {
return categories;
}
public void setCategories(List<JSONObject> categories) {
this.categories = categories;
}
public List<String> getKeyManagers() {
return keyManagers;
}
public void setKeyManagers(List<String> keyManagers) {
this.keyManagers = keyManagers;
}
public String getCreatedTime() {
return createdTime;
}
public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}
public String getLastUpdatedTime() {
return lastUpdatedTime;
}
public void setLastUpdatedTime(String lastUpdatedTime) {
this.lastUpdatedTime = lastUpdatedTime;
}
}

@ -18,6 +18,10 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
/**
* This class represents the Consumer API Key Information.
*/
public class APIKey {
private String apikey;

@ -22,6 +22,10 @@ import org.json.JSONObject;
import java.util.List;
/**
* This class represents the Consumer Application Information.
*/
public class Application {
private String applicationId;
private String name;

@ -0,0 +1,110 @@
/*
* 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.bean.APIMConsumer;
import io.apicurio.datamodels.asyncapi.v2.visitors.Aai20Traverser;
import java.util.List;
/**
* This class represents the Consumer Application configuration Information.
*/
public class ApplicationConfigurations {
private String name;
private String label;
private String type;
private boolean required;
private boolean mask;
private boolean multiple;
private String tooltip;
private List<String> values;
private String defaults;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public boolean isMask() {
return mask;
}
public void setMask(boolean mask) {
this.mask = mask;
}
public boolean isMultiple() {
return multiple;
}
public void setMultiple(boolean multiple) {
this.multiple = multiple;
}
public String getTooltip() {
return tooltip;
}
public void setTooltip(String tooltip) {
this.tooltip = tooltip;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
public String getDefaults() {
return defaults;
}
public void setDefaults(String defaults) {
this.defaults = defaults;
}
}

@ -0,0 +1,184 @@
/*
* 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.bean.APIMConsumer;
import org.json.JSONObject;
import java.util.List;
/**
* This class represents the Consumer Key manager Information.
*/
public class KeyManager {
private String id;
private String name;
private String type;
private String displayName;
private String description;
private boolean enabled;
private List<String> availableGrantTypes;
private String tokenEndpoint;
private String revokeEndpoint;
private String userInfoEndpoint;
private String enableTokenGeneration;
private String enableTokenEncryption;
private String enableTokenHashing;
private String enableOAuthAppCreation;
private String enableMapOAuthConsumerApps;
private List<ApplicationConfigurations> applicationConfiguration;
private JSONObject additionalProperties;
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 String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public List<String> getAvailableGrantTypes() {
return availableGrantTypes;
}
public void setAvailableGrantTypes(List<String> availableGrantTypes) {
this.availableGrantTypes = availableGrantTypes;
}
public String getTokenEndpoint() {
return tokenEndpoint;
}
public void setTokenEndpoint(String tokenEndpoint) {
this.tokenEndpoint = tokenEndpoint;
}
public String getRevokeEndpoint() {
return revokeEndpoint;
}
public void setRevokeEndpoint(String revokeEndpoint) {
this.revokeEndpoint = revokeEndpoint;
}
public String getUserInfoEndpoint() {
return userInfoEndpoint;
}
public void setUserInfoEndpoint(String userInfoEndpoint) {
this.userInfoEndpoint = userInfoEndpoint;
}
public String getEnableTokenGeneration() {
return enableTokenGeneration;
}
public void setEnableTokenGeneration(String enableTokenGeneration) {
this.enableTokenGeneration = enableTokenGeneration;
}
public String getEnableTokenEncryption() {
return enableTokenEncryption;
}
public void setEnableTokenEncryption(String enableTokenEncryption) {
this.enableTokenEncryption = enableTokenEncryption;
}
public String getEnableTokenHashing() {
return enableTokenHashing;
}
public void setEnableTokenHashing(String enableTokenHashing) {
this.enableTokenHashing = enableTokenHashing;
}
public String getEnableOAuthAppCreation() {
return enableOAuthAppCreation;
}
public void setEnableOAuthAppCreation(String enableOAuthAppCreation) {
this.enableOAuthAppCreation = enableOAuthAppCreation;
}
public String getEnableMapOAuthConsumerApps() {
return enableMapOAuthConsumerApps;
}
public void setEnableMapOAuthConsumerApps(String enableMapOAuthConsumerApps) {
this.enableMapOAuthConsumerApps = enableMapOAuthConsumerApps;
}
public List<ApplicationConfigurations> getApplicationConfiguration() {
return applicationConfiguration;
}
public void setApplicationConfiguration(List<ApplicationConfigurations> applicationConfiguration) {
this.applicationConfiguration = applicationConfiguration;
}
public JSONObject getAdditionalProperties() {
return additionalProperties;
}
public void setAdditionalProperties(JSONObject additionalProperties) {
this.additionalProperties = additionalProperties;
}
}

@ -25,8 +25,8 @@ public class Subscription {
private String subscriptionId;
private String applicationId;
private String apiId;
private JSONObject apiInfo;
private JSONObject applicationInfo;
private APIInfo apiInfo;
private Application applicationInfo;
private String throttlingPolicy;
private String requestedThrottlingPolicy;
private String status;
@ -56,19 +56,19 @@ public class Subscription {
this.apiId = apiId;
}
public JSONObject getApiInfo() {
public APIInfo getApiInfo() {
return apiInfo;
}
public void setApiInfo(JSONObject apiInfo) {
public void setApiInfo(APIInfo apiInfo) {
this.apiInfo = apiInfo;
}
public JSONObject getApplicationInfo() {
public Application getApplicationInfo() {
return applicationInfo;
}
public void setApplicationInfo(JSONObject applicationInfo) {
public void setApplicationInfo(Application applicationInfo) {
this.applicationInfo = applicationInfo;
}

Loading…
Cancel
Save