Map JsonObject to dto classes in publisher API revesion

revert
Pasindu Rupasinghe 1 year ago
parent bdf1e97d84
commit fa37fa33cc

@ -19,16 +19,11 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api; package io.entgra.device.mgt.core.apimgt.extension.rest.api;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
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.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.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 org.json.JSONObject; import org.json.JSONObject;
import java.util.List; import java.util.List;
@ -63,8 +58,8 @@ public interface PublisherRESTAPIServices {
String asyncApiDefinition) String asyncApiDefinition)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String apiUuid) String apiUuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
@ -72,18 +67,18 @@ public interface PublisherRESTAPIServices {
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, Mediation mediation) String uuid, Mediation mediation)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String uuid, String action) String uuid, String action)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
Boolean deploymentStatus) Boolean deploymentStatus)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevision apiRevision) APIRevision apiRevision)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
@ -92,11 +87,11 @@ public interface PublisherRESTAPIServices {
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevisionDeployment, String uuid) APIRevision apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevision, String uuid) APIRevision apiRevision, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException; throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,

@ -643,7 +643,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
} }
@Override @Override
public JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
String apiUuid) String apiUuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
@ -658,8 +658,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
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()) {
JSONObject jsonObject = new JSONObject(response.body().string()); JSONArray mediationPolicyList = (JSONArray) new JSONObject(response.body().string()).get("list");
return jsonObject; return gson.fromJson(mediationPolicyList.toString(), MediationPolicy[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices. AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -814,7 +814,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
} }
@Override @Override
public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
Boolean deploymentStatus) Boolean deploymentStatus)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
@ -831,8 +831,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
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()) {
JSONObject jsonObject = new JSONObject(response.body().string()); JSONArray revisionList = (JSONArray) new JSONObject(response.body().string()).get("list");
return jsonObject; return gson.fromJson(revisionList.toString(), APIRevision[].class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices. AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -856,16 +856,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
} }
@Override @Override
public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision) public APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions"; String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
String apiRevisionDescription = "{\n" + JSONObject payload = new JSONObject();
" \"description\":\"" + apiRevision.getDescription() + "\"\n" + payload.put("description", (apiRevision.getDescription() != null ? apiRevision.getDescription() : null));
"}";
RequestBody requestBody = RequestBody.create(JSON, apiRevisionDescription); RequestBody requestBody = RequestBody.create(JSON, payload.toString());
Request request = new Request.Builder() Request request = new Request.Builder()
.url(addNewScope) .url(addNewScope)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
@ -876,8 +875,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
if (HttpStatus.SC_CREATED == response.code()) { if (HttpStatus.SC_CREATED == response.code()) {
JSONObject jsonObject = new JSONObject(response.body().string()); return gson.fromJson(response.body().string(), APIRevision.class);
return jsonObject;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices. AccessTokenInfo refreshedAccessToken = apiApplicationServices.
@ -908,15 +906,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId; String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId;
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0); APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0);
String revision = "[\n" + JSONArray payload = new JSONArray();
" {\n" + JSONObject revision = new JSONObject();
" \"name\": \"" + apiRevisionDeployment.getDeployment() + "\",\n" + revision.put("name", (apiRevisionDeployment.getName() != null ? apiRevisionDeployment.getName() : ""));
" \"vhost\": \"" + apiRevisionDeployment.getVhost() + "\",\n" + revision.put("vhost", (apiRevisionDeployment.getVhost() != null ? apiRevisionDeployment.getVhost() : ""));
" \"displayOnDevportal\": " + apiRevisionDeployment.isDisplayOnDevportal() + "\n" + revision.put("displayOnDevportal", apiRevisionDeployment.isDisplayOnDevportal());
" }\n" + payload.put(revision);
"]";
RequestBody requestBody = RequestBody.create(JSON, revision); RequestBody requestBody = RequestBody.create(JSON, payload.toString());
Request request = new Request.Builder() Request request = new Request.Builder()
.url(deployAPIRevisionEndPoint) .url(deployAPIRevisionEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
@ -953,23 +950,22 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
@Override @Override
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevisionDeployment, String uuid) APIRevision apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId=" String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId="
+ apiRevisionDeployment.getString("id"); + apiRevisionDeployment.getId();
JSONArray array = apiRevisionDeployment.getJSONArray("deploymentInfo"); List<APIRevisionDeployment> apiRevisionDeployments = apiRevisionDeployment.getDeploymentInfo();
JSONObject obj = array.getJSONObject(0); APIRevisionDeployment earliestDeployment = apiRevisionDeployments.get(0);
String revision = "[\n" + JSONArray payload = new JSONArray();
" {\n" + JSONObject revision = new JSONObject();
" \"name\": \"" + obj.getString("name") + "\",\n" + revision.put("name", (earliestDeployment.getName() != null ? earliestDeployment.getName() : ""));
" \"vhost\": \"" + obj.getString("vhost") + "\",\n" + revision.put("vhost", (earliestDeployment.getVhost() != null ? earliestDeployment.getVhost() : ""));
" \"displayOnDevportal\": " + obj.get("displayOnDevportal") + "\n" + revision.put("displayOnDevportal", earliestDeployment.isDisplayOnDevportal());
" }\n" + payload.put(revision);
"]";
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
RequestBody requestBody = RequestBody.create(JSON, revision);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(undeployAPIRevisionEndPoint) .url(undeployAPIRevisionEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
@ -1005,11 +1001,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
@Override @Override
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
JSONObject apiRevision, String uuid) APIRevision apiRevision, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException { throws APIServicesException, BadRequestException, UnexpectedResponseException {
String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" + String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" +
apiRevision.getString("id"); apiRevision.getId();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(apiRevisionEndPoint) .url(apiRevisionEndPoint)

@ -17,26 +17,26 @@
*/ */
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo; package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
import org.wso2.carbon.apimgt.api.model.APIRevisionDeployment;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
public class APIRevision implements Serializable { public class APIRevision implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int id; private String id;
private String apiUUID; private String apiUUID;
private String revisionUUID; private String revisionUUID;
private String description; private String description;
private String displayName;
private String createdBy; private String createdBy;
private String createdTime; private String createdTime;
private List<APIRevisionDeployment> apiRevisionDeploymentList; private APIInfo apiInfo;
private List<APIRevisionDeployment> deploymentInfo;
public int getId() { public String getId() {
return id; return id;
} }
public void setId(int id) { public void setId(String id) {
this.id = id; this.id = id;
} }
@ -80,11 +80,28 @@ public class APIRevision implements Serializable {
this.createdTime = createdTime; this.createdTime = createdTime;
} }
public List<APIRevisionDeployment> getApiRevisionDeploymentList() { public List<APIRevisionDeployment> getDeploymentInfo() {
return apiRevisionDeploymentList; return deploymentInfo;
}
public void setDeploymentInfo(List<APIRevisionDeployment> deploymentInfo) {
this.deploymentInfo = deploymentInfo;
}
public String getDisplayName() {
return displayName;
} }
public void setApiRevisionDeploymentList(List<APIRevisionDeployment> apiRevisionDeploymentList) { public void setDisplayName(String displayName) {
this.apiRevisionDeploymentList = apiRevisionDeploymentList; this.displayName = displayName;
} }
public APIInfo getApiInfo() {
return apiInfo;
}
public void setApiInfo(APIInfo apiInfo) {
this.apiInfo = apiInfo;
}
} }

@ -23,10 +23,10 @@ import java.io.Serializable;
public class APIRevisionDeployment implements Serializable { public class APIRevisionDeployment implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int id; private int id;
private String revisionUUID; private String revisionUuid;
private String deployment; private String name;
private String vhost; private String vhost;
private boolean isDisplayOnDevportal; private boolean displayOnDevportal;
private String deployedTime; private String deployedTime;
public int getId() { public int getId() {
@ -37,20 +37,20 @@ public class APIRevisionDeployment implements Serializable {
this.id = id; this.id = id;
} }
public String getRevisionUUID() { public String getRevisionUuid() {
return revisionUUID; return revisionUuid;
} }
public void setRevisionUUID(String revisionUUID) { public void setRevisionUuid(String revisionUuid) {
this.revisionUUID = revisionUUID; this.revisionUuid = revisionUuid;
} }
public String getDeployment() { public String getName() {
return deployment; return name;
} }
public void setDeployment(String deployment) { public void setName(String name) {
this.deployment = deployment; this.name = name;
} }
public String getVhost() { public String getVhost() {
@ -62,11 +62,11 @@ public class APIRevisionDeployment implements Serializable {
} }
public boolean isDisplayOnDevportal() { public boolean isDisplayOnDevportal() {
return isDisplayOnDevportal; return displayOnDevportal;
} }
public void setDisplayOnDevportal(boolean displayOnDevportal) { public void setDisplayOnDevportal(boolean displayOnDevportal) {
isDisplayOnDevportal = displayOnDevportal; this.displayOnDevportal = displayOnDevportal;
} }
public String getDeployedTime() { public String getDeployedTime() {

@ -215,10 +215,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiRevision.setApiUUID(apiUuid); apiRevision.setApiUUID(apiUuid);
apiRevision.setDescription("Initial Revision"); apiRevision.setDescription("Initial Revision");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey, String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getString("id"); accessTokenInfo, apiRevision).getId();
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment(); APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT); apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host")); apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
apiRevisionDeployment.setDisplayOnDevportal(true); apiRevisionDeployment.setDisplayOnDevportal(true);
@ -308,15 +308,14 @@ public class APIPublisherServiceImpl implements APIPublisherService {
mediation.setType("in"); mediation.setType("in");
mediation.setGlobal(false); mediation.setGlobal(false);
JSONArray mediationList = (JSONArray) publisherRESTAPIServices MediationPolicy[] mediationList = publisherRESTAPIServices
.getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, .getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, apiUuid);
apiUuid).get("list");
boolean isMediationPolicyFound = false; boolean isMediationPolicyFound = false;
for (int i = 0; i < mediationList.length(); i++) { for (int i = 0; i < mediationList.length; i++) {
JSONObject mediationObj = mediationList.getJSONObject(i); MediationPolicy mediationPolicy = mediationList[i];
if (apiConfig.getInSequenceName().equals(mediationObj.getString("name"))) { if (apiConfig.getInSequenceName().equals(mediationPolicy.getName())) {
mediation.setUuid(mediationObj.getString("id")); mediation.setUuid(mediationPolicy.getId());
publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiApplicationKey, publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiApplicationKey,
accessTokenInfo, apiUuid, mediation); accessTokenInfo, apiUuid, mediation);
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey, publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
@ -331,24 +330,22 @@ public class APIPublisherServiceImpl implements APIPublisherService {
} }
} }
int apiRevisionCount = (int) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey, int apiRevisionCount = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
accessTokenInfo, apiUuid, null).get("count"); accessTokenInfo, apiUuid, null).length;
if (apiRevisionCount >= 5) { if (apiRevisionCount >= 5) {
// This will retrieve the deployed revision // This will retrieve the deployed revision
JSONArray revisionDeploymentList = (JSONArray) publisherRESTAPIServices.getAPIRevisions( APIRevision[] revisionDeploymentList = publisherRESTAPIServices.getAPIRevisions(
apiApplicationKey, accessTokenInfo, apiUuid, apiApplicationKey, accessTokenInfo, apiUuid, true);
true).get("list"); if (revisionDeploymentList.length > 0) {
if (revisionDeploymentList.length() > 0) { APIRevision latestRevisionDeployment = revisionDeploymentList[0];
JSONObject latestRevisionDeployment = revisionDeploymentList.getJSONObject(0);
publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey, publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey,
accessTokenInfo, latestRevisionDeployment, apiUuid); accessTokenInfo, latestRevisionDeployment, apiUuid);
} }
// This will retrieve the un deployed revision list // This will retrieve the undeployed revision list
JSONArray undeployedRevisionList = (JSONArray) publisherRESTAPIServices.getAPIRevisions( APIRevision[] undeployedRevisionList = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
apiApplicationKey, accessTokenInfo, apiUuid, accessTokenInfo, apiUuid, false);
false).get("list"); if (undeployedRevisionList.length > 0) {
if (undeployedRevisionList.length() > 0) { APIRevision earliestUndeployRevision = undeployedRevisionList[0];
JSONObject earliestUndeployRevision = undeployedRevisionList.getJSONObject(0);
publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo, publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo,
earliestUndeployRevision, apiUuid); earliestUndeployRevision, apiUuid);
} }
@ -359,10 +356,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiRevision.setApiUUID(apiUuid); apiRevision.setApiUUID(apiUuid);
apiRevision.setDescription("Updated Revision"); apiRevision.setDescription("Updated Revision");
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey, String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getString("id"); accessTokenInfo, apiRevision).getId();
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment(); APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT); apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host")); apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
apiRevisionDeployment.setDisplayOnDevportal(true); apiRevisionDeployment.setDisplayOnDevportal(true);

Loading…
Cancel
Save