Remove comented code lines

app-mgt-restructure
Pasindu Rupasinghe 2 years ago
parent a8cc35ef3d
commit 65da984f66

@ -1,139 +0,0 @@
/*
* Copyright (c) 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.util;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
/**
* This class represents the api data.
*/
public class APIUtils {
private APIIdentifier id;
private String name;
private String description;
private String context;
private String version;
private String provider;
private String type;
private String lifeCycleStatus;
private String workflowStatus;
private String hasThumbnail;
private String transport;
public APIIdentifier getId() {
return id;
}
public void setId(APIIdentifier 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 String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLifeCycleStatus() {
return lifeCycleStatus;
}
public void setLifeCycleStatus(String lifeCycleStatus) {
this.lifeCycleStatus = lifeCycleStatus;
}
public String getWorkflowStatus() {
return workflowStatus;
}
public void setWorkflowStatus(String workflowStatus) {
this.workflowStatus = workflowStatus;
}
public String getHasThumbnail() {
return hasThumbnail;
}
public void setHasThumbnail(String hasThumbnail) {
this.hasThumbnail = hasThumbnail;
}
public String getTransport() {
return transport;
}
public void setTransport(String transport) {
this.transport = transport;
}
public String toJSON() {
String jsonString = "{\n" +
" \"name\":\" " + name + "\",\n" +
" \"description\":\" " + description + "\",\n" +
" \"context\":\" " + context + " \",\n" +
" \"transport\":[\n" +
" \" " + transport + " \"\n" +
" ]\n" +
"}";
return jsonString;
}
}

@ -36,7 +36,6 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.FaultGatewaysException;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.APIRevision;
@ -168,23 +167,19 @@ public class APIPublisherServiceImpl implements APIPublisherService {
if (!apiFound) {
// add new scopes as shared scopes
for (ApiScope apiScope : apiConfig.getScopes()) {
// if (!allSharedScopeKeys.contains(apiScope.getKey())) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, apiScope.getKey())) {
Scope scope = new Scope();
scope.setName(apiScope.getName());
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
// apiProvider.addSharedScope(scope, tenantDomain); //add scope
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
API api = getAPI(apiConfig, true);
api.setId(apiIdentifier);
// API createdAPI = apiProvider.addAPI(api); // add api
API createdAPI = publisherRESTAPIServices.createAPI(apiApplicationKey, accessTokenInfo , api); // add api
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
// apiProvider.saveAsyncApiDefinition(api, apiConfig.getAsyncApiDefinition()); //Update Topics of an Async API
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
api.getUuid(), apiConfig.getAsyncApiDefinition());
}
@ -196,18 +191,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
mediation.setConfig(apiConfig.getInSequenceConfig());
mediation.setType("in");
mediation.setGlobal(false);
// apiProvider.addApiSpecificMediationPolicy(createdAPI.getUuid(), mediation,
// tenantDomain); //Update an API Specific Mediation Policy
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
accessTokenInfo, createdAPI.getUuid(), mediation);
}
// apiProvider.changeLifeCycleStatus(tenantDomain, createdAPI.getUuid(), PUBLISH_ACTION, null); //Change API Status
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo, createdAPI.getUuid(), PUBLISH_ACTION);
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(createdAPI.getUuid());
apiRevision.setDescription("Initial Revision");
// String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain); //Create API Revision
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getRevisionUUID();
@ -218,7 +209,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
apiRevisionDeploymentList.add(apiRevisionDeployment);
// apiProvider.deployAPIRevision(createdAPI.getUuid(), apiRevisionId, apiRevisionDeploymentList); //Deploy Revision
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
createdAPI.getUuid(), apiRevisionId, apiRevisionDeploymentList);
}
@ -239,7 +229,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
// 1. add new scopes as shared scopes
// 2. update the API adding scopes for the URI Templates
// Set<String> allSharedScopeKeys = apiProvider.getAllSharedScopeKeys(tenantDomain); //get all scopes
Set<ApiScope> scopesToMoveAsSharedScopes = new HashSet<>();
for (ApiScope apiScope : apiConfig.getScopes()) {
// if the scope is not available as shared scope, and it is assigned to an API as a local scope
@ -255,7 +244,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
// apiProvider.addSharedScope(scope, tenantDomain); //add scope
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
@ -264,13 +252,11 @@ public class APIPublisherServiceImpl implements APIPublisherService {
// Get existing API
API existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo , apiIdentifier);
// API existingAPI = apiProvider.getAPI(apiIdentifier);
if (scopesToMoveAsSharedScopes.size() > 0) {
// update API to remove local scopes
API api = getAPI(apiConfig, false);
api.setStatus(existingAPI.getStatus());
// apiProvider.updateAPI(api);
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
@ -279,20 +265,16 @@ public class APIPublisherServiceImpl implements APIPublisherService {
scope.setDescription(apiScope.getDescription());
scope.setKey(apiScope.getKey());
scope.setRoles(apiScope.getRoles());
// apiProvider.addSharedScope(scope, tenantDomain);
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
// existingAPI = apiProvider.getAPI(apiIdentifier);
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo , apiIdentifier);;
API api = getAPI(apiConfig, true);
api.setStatus(existingAPI.getStatus());
// apiProvider.updateAPI(api);
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
// apiProvider.saveAsyncApiDefinition(api, apiConfig.getAsyncApiDefinition());
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
api.getUuid(), apiConfig.getAsyncApiDefinition());
}
@ -305,8 +287,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
mediation.setType("in");
mediation.setGlobal(false);
// List<Mediation> mediationList = apiProvider
// .getAllApiSpecificMediationPolicies(apiIdentifier);
List<Mediation> mediationList = (List) publisherRESTAPIServices
.getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, apiIdentifier).get("list");
@ -314,8 +294,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
for (Mediation m : mediationList) {
if (apiConfig.getInSequenceName().equals(m.getName())) {
m.setConfig(apiConfig.getInSequenceConfig());
// apiProvider.updateApiSpecificMediationPolicyContent(existingAPI.getUuid(), m,
// tenantDomain);
publisherRESTAPIServices.
updateApiSpecificMediationPolicyContent(apiApplicationKey,
accessTokenInfo, existingAPI.getUuid(), m);
@ -324,19 +302,11 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
if (!isMediationPolicyFound) {
// apiProvider.addApiSpecificMediationPolicy(existingAPI.getUuid(), mediation,
// tenantDomain);
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
accessTokenInfo, existingAPI.getUuid(), mediation);
}
}
// Assumption: Assume the latest revision is the published one
// String latestRevisionUUID = apiProvider.getLatestRevisionUUID(existingAPI.getUuid());
// List<APIRevisionDeployment> revisionDeploymentList =
// apiProvider.getAPIRevisionDeploymentList(latestRevisionUUID);
// This will retrieve the deployed revision list
List<APIRevisionDeployment> revisionDeploymentList = (List<APIRevisionDeployment>)
publisherRESTAPIServices.getAPIRevisionDeployment(apiApplicationKey, accessTokenInfo, existingAPI.getUuid());
// This will retrieve the un deployed revision list
@ -344,27 +314,16 @@ public class APIPublisherServiceImpl implements APIPublisherService {
publisherRESTAPIServices.getAPIRevisions(apiApplicationKey, accessTokenInfo,
existingAPI.getUuid(), "?query=deployed:false").get("list");
// List<APIRevision> apiRevisionList = apiProvider.getAPIRevisions(existingAPI.getUuid());
// List<APIRevision> apiRevisionList = (List<APIRevision>) publisherRESTAPIServices.getAPIRevision(apiApplicationKey,
// accessTokenInfo, existingAPI.getUuid()).get("list");
int apiRevisionCount = (int) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
accessTokenInfo, existingAPI.getUuid(), "").get("count");
if (apiRevisionCount >= 5) {
// String earliestRevisionUUID = apiProvider.getEarliestRevisionUUID(existingAPI.getUuid());
// List<APIRevisionDeployment> undeployedRevisionList =
// apiProvider.getAPIRevisionDeploymentList(earliestRevisionUUID);
// List<APIRevisionDeployment> undeployedRevisionList = (List<APIRevisionDeployment>)
// publisherRESTAPIServices.getAPIRevisionDeployment(apiApplicationKey, accessTokenInfo, existingAPI.getUuid());
APIRevisionDeployment latestRevisionDeployment = revisionDeploymentList.get(0);
APIRevision earliestUndeployRevision = undeployedRevisionList.get(0);
// apiProvider.undeployAPIRevisionDeployment(existingAPI.getUuid(), earliestRevisionUUID, undeployedRevisionList);
publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey,
accessTokenInfo, latestRevisionDeployment, existingAPI.getUuid());
// apiProvider.deleteAPIRevision(existingAPI.getUuid(), earliestRevisionUUID, tenantDomain);
publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo,
earliestUndeployRevision, existingAPI.getUuid());
}
@ -373,16 +332,13 @@ public class APIPublisherServiceImpl implements APIPublisherService {
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(existingAPI.getUuid());
apiRevision.setDescription("Updated Revision");
// String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain);
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getRevisionUUID();
// apiProvider.deployAPIRevision(existingAPI.getUuid(), apiRevisionId, revisionDeploymentList);
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
existingAPI.getUuid(), apiRevisionId, revisionDeploymentList);
if (CREATED_STATUS.equals(existingAPI.getStatus())) {
// apiProvider.changeLifeCycleStatus(tenantDomain, existingAPI.getUuid(), PUBLISH_ACTION, null);
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey,accessTokenInfo,
existingAPI.getUuid(), PUBLISH_ACTION);
}
@ -416,8 +372,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
apiDocumentation.setOtherTypeName(null);
//Including below code lines inside the try block because 'getDocumentation' method returns an APIManagementException exception when it doesn't have any existing doc
// Documentation existingDoc = apiProvider.getDocumentation(api.getId(), DocumentationType.HOWTO, apiConfig.getApiDocumentationName());
JSONArray documentList = (JSONArray) publisherRESTAPIServices.getDocumentations(apiApplicationKey,
accessTokenInfo, api.getId()).get("list");
@ -426,7 +380,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
JSONObject existingDoc = documentList.getJSONObject(i);
if (existingDoc.getString("name").equals(apiConfig.getApiDocumentationName())
&& existingDoc.getString("type").equals(DocumentationType.HOWTO)) {
//apiProvider.removeDocumentation(api.getId(), existingDoc.getId(), null);
publisherRESTAPIServices.deleteDocumentations(apiApplicationKey, accessTokenInfo,
api.getId(), existingDoc.getString("documentId"));
}
@ -434,11 +387,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} else {
log.info("There is no any existing api documentation.");
}
// apiProvider.addDocumentation(api.getId(), apiDocumentation);
Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo,
api.getId(), apiDocumentation);
// apiProvider.addDocumentationContent(api, apiConfig.getApiDocumentationName(), docContent);
publisherRESTAPIServices.addDocumentationContent(apiApplicationKey, accessTokenInfo, api,
createdDoc.getId(), docContent);
}

@ -25,20 +25,6 @@
<version>5.0.26-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<artifactId>apimgt-extensions</artifactId>

Loading…
Cancel
Save