Rename API dto file and refactor

vpp
Pasindu Rupasinghe 2 years ago
parent b133f56965
commit 014f95bd10

@ -23,7 +23,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils.APIResponseUtil; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.model.APIIdentifier; import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.Scope; import org.wso2.carbon.apimgt.api.model.Scope;
@ -54,10 +54,10 @@ public interface PublisherRESTAPIServices {
JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIResponseUtil api) JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIResponseUtil api) boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean saveAsyncApiDefinition(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, boolean saveAsyncApiDefinition(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
@ -113,6 +113,6 @@ public interface PublisherRESTAPIServices {
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIResponseUtil api, String docId, String docContent) APIInfo api, String docId, String docContent)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
} }

@ -25,7 +25,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils.APIResponseUtil; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils; import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils;
import okhttp3.MediaType; import okhttp3.MediaType;
@ -315,7 +315,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
} }
@Override @Override
public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIResponseUtil api) public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT; String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
@ -402,7 +402,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
} }
@Override @Override
public boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIResponseUtil api) public boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId(); String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
@ -1063,7 +1063,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
@Override @Override
public boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, public boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIResponseUtil api, String docId, String docContent) APIInfo api, String docId, String docContent)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addDocumentationContentEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId() + "/documents/" + docId; String addDocumentationContentEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId() + "/documents/" + docId;

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils; package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.model.APICategory; import org.wso2.carbon.apimgt.api.model.APICategory;
@ -31,7 +31,7 @@ import java.util.Set;
* This class represents the API response. * This class represents the API response.
*/ */
public class APIResponseUtil { public class APIInfo {
private String id; private String id;
private String name; private String name;

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils; package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
/** /**
* This hold the advertisement information of an API. * This hold the advertisement information of an API.

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils; package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
/** /**
* This hold the business information of an API. * This hold the business information of an API.

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils; package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import java.util.Set; import java.util.Set;

@ -174,11 +174,7 @@
org.scannotation;version="1.0", org.scannotation;version="1.0",
org.scannotation.archiveiterator;version="1.0", org.scannotation.archiveiterator;version="1.0",
org.w3c.dom, org.w3c.dom,
io.entgra.device.mgt.core.apimgt.extension.rest.api, io.entgra.device.mgt.core.apimgt.extension.rest.api.*,
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto,
io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions,
io.entgra.device.mgt.core.apimgt.extension.rest.api.constants,
io.entgra.device.mgt.core.apimgt.extension.rest.api.util.*,
io.entgra.device.mgt.core.apimgt.annotations, io.entgra.device.mgt.core.apimgt.annotations,
org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api,
org.wso2.carbon.apimgt.api.model, org.wso2.carbon.apimgt.api.model,

@ -28,7 +28,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIUtils.APIResponseUtil; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -180,7 +180,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
} }
} }
APIResponseUtil api = getAPI(apiConfig, true); APIInfo api = getAPI(apiConfig, true);
JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api); JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) { if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo, publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
@ -260,7 +260,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiIdentifier); apiIdentifier);
if (scopesToMoveAsSharedScopes.size() > 0) { if (scopesToMoveAsSharedScopes.size() > 0) {
// update API to remove local scopes // update API to remove local scopes
APIResponseUtil api = getAPI(apiConfig, false); APIInfo api = getAPI(apiConfig, false);
api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus")); api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus"));
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api); publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
@ -275,7 +275,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} }
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiIdentifier); existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiIdentifier);
APIResponseUtil api = getAPI(apiConfig, true); APIInfo api = getAPI(apiConfig, true);
api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus")); api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus"));
api.setId(existingAPI.getString("id")); api.setId(existingAPI.getString("id"));
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api); publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
@ -357,7 +357,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} }
} }
if (apiConfig.getApiDocumentationSourceFile() != null) { if (apiConfig.getApiDocumentationSourceFile() != null) {
APIResponseUtil api = getAPI(apiConfig, true); APIInfo api = getAPI(apiConfig, true);
String fileName = String fileName =
CarbonUtils.getCarbonHome() + File.separator + "repository" + CarbonUtils.getCarbonHome() + File.separator + "repository" +
@ -541,28 +541,28 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} }
} }
private APIResponseUtil getAPI(APIConfig config, boolean includeScopes) { private APIInfo getAPI(APIConfig config, boolean includeScopes) {
APIResponseUtil apiResponseUtil = new APIResponseUtil(); APIInfo apiInfo = new APIInfo();
apiResponseUtil.setName(config.getName().replace(Constants.SPACE, Constants.EMPTY_STRING)); apiInfo.setName(config.getName().replace(Constants.SPACE, Constants.EMPTY_STRING));
apiResponseUtil.setDescription(""); apiInfo.setDescription("");
apiResponseUtil.setContext(config.getContext()); apiInfo.setContext(config.getContext());
apiResponseUtil.setVersion(config.getVersion()); apiInfo.setVersion(config.getVersion());
apiResponseUtil.setProvider(config.getOwner()); apiInfo.setProvider(config.getOwner());
apiResponseUtil.setLifeCycleStatus(CREATED_STATUS); apiInfo.setLifeCycleStatus(CREATED_STATUS);
apiResponseUtil.setWsdlInfo(null); apiInfo.setWsdlInfo(null);
apiResponseUtil.setWsdlUrl(null); apiInfo.setWsdlUrl(null);
apiResponseUtil.setResponseCachingEnabled(false); apiInfo.setResponseCachingEnabled(false);
apiResponseUtil.setCacheTimeout(0); apiInfo.setCacheTimeout(0);
apiResponseUtil.setHasThumbnail(false); apiInfo.setHasThumbnail(false);
apiResponseUtil.setDefaultVersion(config.isDefault()); apiInfo.setDefaultVersion(config.isDefault());
apiResponseUtil.setRevision(false); apiInfo.setRevision(false);
apiResponseUtil.setRevisionedApiId(null); apiInfo.setRevisionedApiId(null);
apiResponseUtil.setEnableSchemaValidation(false); apiInfo.setEnableSchemaValidation(false);
Set<String> tags = new HashSet<>(); Set<String> tags = new HashSet<>();
tags.addAll(Arrays.asList(config.getTags())); tags.addAll(Arrays.asList(config.getTags()));
apiResponseUtil.setTags(tags); apiInfo.setTags(tags);
Set<String> availableTiers = new HashSet<>(); Set<String> availableTiers = new HashSet<>();
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) { if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
@ -570,7 +570,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} else { } else {
availableTiers.add(UNLIMITED_TIER); availableTiers.add(UNLIMITED_TIER);
} }
apiResponseUtil.setPolicies(availableTiers); apiInfo.setPolicies(availableTiers);
if (config.getEndpointType() == null) { if (config.getEndpointType() == null) {
List<JSONObject> operations = new ArrayList(); List<JSONObject> operations = new ArrayList();
@ -608,16 +608,16 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} }
operations.add(operation); operations.add(operation);
} }
apiResponseUtil.setScopes(scopeSet); apiInfo.setScopes(scopeSet);
apiResponseUtil.setOperations(operations); apiInfo.setOperations(operations);
} }
if (config.isSharedWithAllTenants()) { if (config.isSharedWithAllTenants()) {
apiResponseUtil.setSubscriptionAvailability(SUBSCRIPTION_TO_ALL_TENANTS); apiInfo.setSubscriptionAvailability(SUBSCRIPTION_TO_ALL_TENANTS);
apiResponseUtil.setVisibility(API_GLOBAL_VISIBILITY); apiInfo.setVisibility(API_GLOBAL_VISIBILITY);
} else { } else {
apiResponseUtil.setSubscriptionAvailability(SUBSCRIPTION_TO_CURRENT_TENANT); apiInfo.setSubscriptionAvailability(SUBSCRIPTION_TO_CURRENT_TENANT);
apiResponseUtil.setVisibility(API_PRIVATE_VISIBILITY); apiInfo.setVisibility(API_PRIVATE_VISIBILITY);
} }
String endpointConfig; String endpointConfig;
@ -634,9 +634,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
Set<String> transports = new HashSet<>(); Set<String> transports = new HashSet<>();
transports.addAll(Arrays.asList(config.getTransports())); transports.addAll(Arrays.asList(config.getTransports()));
apiResponseUtil.setTransport(transports); apiInfo.setTransport(transports);
apiResponseUtil.setType("HTTP"); apiInfo.setType("HTTP");
if (config.getEndpointType() != null && "dynamic".equals(config.getEndpointType())) { if (config.getEndpointType() != null && "dynamic".equals(config.getEndpointType())) {
endpointConfig = "{\n" + endpointConfig = "{\n" +
@ -650,7 +650,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
" }"; " }";
endPointConfig = new JSONObject(endpointConfig); endPointConfig = new JSONObject(endpointConfig);
//TODO: Will be used in dynamic endpoints //TODO: Will be used in dynamic endpoints
// apiResponseUtil.setInSequence(config.getInSequenceName()); // apiInfo.setInSequence(config.getInSequenceName());
} }
// if ws endpoint // if ws endpoint
@ -667,10 +667,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
endPointConfig = new JSONObject(endpointConfig); endPointConfig = new JSONObject(endpointConfig);
transports.addAll(Arrays.asList("wss,ws")); transports.addAll(Arrays.asList("wss,ws"));
apiResponseUtil.setTransport(transports); apiInfo.setTransport(transports);
apiResponseUtil.setType("WS"); apiInfo.setType("WS");
} }
apiResponseUtil.setEndpointConfig(endPointConfig); apiInfo.setEndpointConfig(endPointConfig);
List<String> accessControlAllowOrigins = new ArrayList<>(); List<String> accessControlAllowOrigins = new ArrayList<>();
accessControlAllowOrigins.add("*"); accessControlAllowOrigins.add("*");
@ -691,17 +691,17 @@ public class APIPublisherServiceImpl implements APIPublisherService {
accessControlAllowMethods.add("OPTIONS"); accessControlAllowMethods.add("OPTIONS");
CORSConfiguration corsConfiguration = new CORSConfiguration(false, accessControlAllowOrigins, false, CORSConfiguration corsConfiguration = new CORSConfiguration(false, accessControlAllowOrigins, false,
accessControlAllowHeaders, accessControlAllowMethods); accessControlAllowHeaders, accessControlAllowMethods);
apiResponseUtil.setCorsConfiguration(corsConfiguration); apiInfo.setCorsConfiguration(corsConfiguration);
apiResponseUtil.setAuthorizationHeader("Authorization"); apiInfo.setAuthorizationHeader("Authorization");
List<String> keyManagers = new ArrayList<>(); List<String> keyManagers = new ArrayList<>();
keyManagers.add("all"); keyManagers.add("all");
apiResponseUtil.setKeyManagers(keyManagers); apiInfo.setKeyManagers(keyManagers);
apiResponseUtil.setEnableSchemaValidation(false); apiInfo.setEnableSchemaValidation(false);
apiResponseUtil.setMonetization(null); apiInfo.setMonetization(null);
apiResponseUtil.setServiceInfo(null); apiInfo.setServiceInfo(null);
return apiResponseUtil; return apiInfo;
//TODO: Will be used in WS or dynamic endpoints //TODO: Will be used in WS or dynamic endpoints
// if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) { // if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {

Loading…
Cancel
Save