Implment API layer for API publisher

mssqlgeofencefix1
Pasindu Rupasinghe 2 years ago
parent fa3c112a68
commit c6b43cc794

@ -72,7 +72,8 @@ public interface PublisherRESTAPIServices {
String uuid, String action)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
String deploymentStatus)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
@ -85,4 +86,27 @@ public interface PublisherRESTAPIServices {
boolean deployAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevisionDeployment apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevision apiRevision, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIIdentifier apiIdentifier, String documentID)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
Documentation addDocumentation(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIIdentifier apiIdentifier, Documentation documentation)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
API api, String docId, String docContent)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
}

@ -139,7 +139,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
public boolean addNewSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addNewScope = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
String addNewSharedScopeEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.SCOPE_API_ENDPOINT + scope.getId();
ScopeUtils scopeUtil = new ScopeUtils();
@ -151,7 +151,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
RequestBody requestBody = RequestBody.create(JSON, scopeString);
Request request = new Request.Builder()
.url(addNewScope)
.url(addNewSharedScopeEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.post(requestBody)
@ -167,7 +167,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope);
return addNewSharedScope(apiApplicationKey, refreshedAccessToken, scope);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
@ -552,7 +552,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return addApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation);
return updateApiSpecificMediationPolicyContent(apiApplicationKey, refreshedAccessToken, uuid, mediation);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
@ -614,14 +614,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
}
@Override
public JSONObject getAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
String deploymentStatus)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getLatestRevisionUUIDEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + uuid + "/revisions?query=deployed:true";
String getAPIRevisionsEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + uuid + "/revisions" + deploymentStatus;
Request request = new Request.Builder()
.url(getLatestRevisionUUIDEndPoint)
.url(getAPIRevisionsEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.get()
@ -638,7 +639,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return getAPIRevision(apiApplicationKey, refreshedAccessToken, uuid);
return getAPIRevisions(apiApplicationKey, refreshedAccessToken, uuid, deploymentStatus);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
@ -784,4 +785,266 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new APIServicesException(e);
}
}
@Override
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevisionDeployment apiRevisionDeployment, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String apiRevisionEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + uuid + "/revisions/"
+ apiRevisionDeployment.getRevisionUUID();
RequestBody requestBody = RequestBody.create(JSON, String.valueOf(apiRevisionDeployment));
Request request = new Request.Builder()
.url(apiRevisionEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_CREATED == response.code()) {
return true;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return undeployAPIRevisionDeployment(apiApplicationKey, refreshedAccessToken, apiRevisionDeployment, uuid);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
@Override
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIRevision apiRevision, String uuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String apiRevisionEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + uuid + "/revisions/"
+ apiRevision.getRevisionUUID();
Request request = new Request.Builder()
.url(apiRevisionEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.delete()
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
return true;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return deleteAPIRevision(apiApplicationKey, refreshedAccessToken, apiRevision, uuid);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
@Override
public JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getDocumentationsEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + apiIdentifier.getUUID() + "/documents?limit=1000";
Request request = new Request.Builder()
.url(getDocumentationsEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.get()
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
JSONObject jsonObject = new JSONObject(response.body().string());
return jsonObject;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return getDocumentations(apiApplicationKey, refreshedAccessToken, apiIdentifier);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
@Override
public boolean deleteDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIIdentifier apiIdentifier, String documentID)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String getDocumentationsEndPoint = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + apiIdentifier.getUUID() + "/documents/" + documentID;
Request request = new Request.Builder()
.url(getDocumentationsEndPoint)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.delete()
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
return true;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return deleteDocumentations(apiApplicationKey, refreshedAccessToken, apiIdentifier, documentID);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
@Override
public Documentation addDocumentation(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
APIIdentifier apiIdentifier, Documentation documentation)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addNewScope = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + apiIdentifier.getUUID() + "/documents";
String document = "{\n" +
" \"name\": \" " + documentation.getName() + " \",\n" +
" \"type\": \" " + documentation.getType() + " \",\n" +
" \"summary\": \" " + documentation.getSummary() + " \",\n" +
" \"sourceType\": \" " + documentation.getSourceType() + " \",\n" +
" \"inlineContent\": \" " + documentation.getSourceType() + " \",\n" +
" \"visibility\": \" " + documentation.getVisibility() + " \",\n" +
" \"createdBy\": \" admin \"\n" +
"}";
RequestBody requestBody = RequestBody.create(JSON, document);
Request request = new Request.Builder()
.url(addNewScope)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_CREATED == response.code()) {
return gson.fromJson(response.body().string(), Documentation.class);
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return addDocumentation(apiApplicationKey, refreshedAccessToken, apiIdentifier, documentation);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
@Override
public boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
API api, String docId, String docContent)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String addNewScope = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host
+ Constants.COLON + port + Constants.API_ENDPOINT + api.getUuid() + "/documents/" + docId;
RequestBody requestBody = RequestBody.create(JSON, docContent);
Request request = new Request.Builder()
.url(addNewScope)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
return true;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return addDocumentationContent(apiApplicationKey, refreshedAccessToken, api,docId ,docContent);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(e);
}
}
}

@ -242,10 +242,9 @@ public class APIPublisherServiceImpl implements APIPublisherService {
// 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
// if the scope is not available as shared scope, and it is assigned to an API as a local scope
// need remove the local scope and add as a shared scope
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, apiScope.getKey())) {
// if (apiProvider.isScopeKeyAssignedLocally(apiIdentifier, apiScope.getKey(), tenantId)) {
if (apiProvider.isScopeKeyAssignedLocally(apiIdentifier, apiScope.getKey(), tenantId)) {
// collect scope to move as shared scopes
scopesToMoveAsSharedScopes.add(apiScope);
@ -315,8 +314,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
for (Mediation m : mediationList) {
if (apiConfig.getInSequenceName().equals(m.getName())) {
m.setConfig(apiConfig.getInSequenceConfig());
// apiProvider
// .updateApiSpecificMediationPolicyContent(existingAPI.getUuid(), m,
// apiProvider.updateApiSpecificMediationPolicyContent(existingAPI.getUuid(), m,
// tenantDomain);
publisherRESTAPIServices.
updateApiSpecificMediationPolicyContent(apiApplicationKey,
@ -334,36 +332,59 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
// Assumption: Assume the latest revision is the published one
String latestRevisionUUID = apiProvider.getLatestRevisionUUID(existingAPI.getUuid());
// List<APIRevisionDeployment> latestRevisionDeploymentList =
// String latestRevisionUUID = apiProvider.getLatestRevisionUUID(existingAPI.getUuid());
// List<APIRevisionDeployment> revisionDeploymentList =
// apiProvider.getAPIRevisionDeploymentList(latestRevisionUUID);
List<APIRevisionDeployment> latestRevisionDeploymentList = (List<APIRevisionDeployment>)
// 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
List<APIRevision> undeployedRevisionList = (List<APIRevision>)
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");
if (apiRevisionList.size() >= 5) {
String earliestRevisionUUID = apiProvider.getEarliestRevisionUUID(existingAPI.getUuid());
// List<APIRevisionDeployment> earliestRevisionDeploymentList =
// 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> earliestRevisionDeploymentList = (List<APIRevisionDeployment>)
publisherRESTAPIServices.getAPIRevisionDeployment(apiApplicationKey, accessTokenInfo, existingAPI.getUuid());
apiProvider.undeployAPIRevisionDeployment(existingAPI.getUuid(), earliestRevisionUUID, earliestRevisionDeploymentList);
apiProvider.deleteAPIRevision(existingAPI.getUuid(), earliestRevisionUUID, tenantDomain);
// 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());
}
// create new revision
APIRevision apiRevision = new APIRevision();
apiRevision.setApiUUID(existingAPI.getUuid());
apiRevision.setDescription("Updated Revision");
String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain);
// String apiRevisionId = apiProvider.addAPIRevision(apiRevision, tenantDomain);
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
accessTokenInfo, apiRevision).getRevisionUUID();
apiProvider.deployAPIRevision(existingAPI.getUuid(), apiRevisionId, latestRevisionDeploymentList);
// 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);
// apiProvider.changeLifeCycleStatus(tenantDomain, existingAPI.getUuid(), PUBLISH_ACTION, null);
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey,accessTokenInfo,
existingAPI.getUuid(), PUBLISH_ACTION);
}
}
}
@ -395,17 +416,33 @@ public class APIPublisherServiceImpl implements APIPublisherService {
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
apiDocumentation.setOtherTypeName(null);
try {
//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());
apiProvider.removeDocumentation(api.getId(), existingDoc.getId(), null);
} catch (APIManagementException e) {
// Documentation existingDoc = apiProvider.getDocumentation(api.getId(), DocumentationType.HOWTO, apiConfig.getApiDocumentationName());
JSONArray documentList = (JSONArray) publisherRESTAPIServices.getDocumentations(apiApplicationKey,
accessTokenInfo, api.getId()).get("list");
if (!(documentList.length() == 0)) {
for (int i = 0; i < documentList.length(); i++) {
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"));
}
}
} else {
log.info("There is no any existing api documentation.");
}
apiProvider.addDocumentation(api.getId(), apiDocumentation);
apiProvider.addDocumentationContent(api, apiConfig.getApiDocumentationName(), docContent);
// 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);
}
} catch (FaultGatewaysException | APIManagementException | IOException | APIServicesException |
} catch (APIManagementException | IOException | APIServicesException |
BadRequestException | UnexpectedResponseException e) {
String msg = "Error occurred while publishing api";
log.error(msg, e);

Loading…
Cancel
Save