From 1eda7bd237c2af2e64b52492343bb66cf9010d03 Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 3 Oct 2023 09:17:46 +0530 Subject: [PATCH 1/5] Fixes in API publishing flow --- .../api/PublisherRESTAPIServicesImpl.java | 39 ++++---- .../extension/rest/api/dto/APIInfo/Scope.java | 18 ++-- .../extension/rest/api/util/ScopeUtils.java | 90 ------------------- .../publisher/APIPublisherServiceImpl.java | 17 ++-- .../apimgt/webapp/publisher/dto/ApiScope.java | 8 +- .../lifecycle/util/AnnotationProcessor.java | 18 ++-- .../webapp/publisher/utils/TestUtils.java | 2 +- 7 files changed, 59 insertions(+), 133 deletions(-) delete mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index 40a8e92c61..90724d3cf1 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -32,7 +32,6 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIService 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.util.HttpsTrustManagerUtils; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils; import okhttp3.*; import okhttp3.Request.Builder; import org.apache.commons.httpclient.HttpStatus; @@ -144,14 +143,19 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT; - ScopeUtils scopeUtil = new ScopeUtils(); - scopeUtil.setKey(scope.getKey()); - scopeUtil.setName(scope.getName()); - scopeUtil.setDescription(scope.getDescription()); - scopeUtil.setRoles(scope.getRoles()); - String scopeString = scopeUtil.toJSON(); + JSONArray bindings = new JSONArray(); + for (String str : scope.getRoles()) { + bindings.put(str); + } + + JSONObject payload = new JSONObject(); + payload.put("name", scope.getKey()); + payload.put("displayName", scope.getName()); + payload.put("description", scope.getDescription()); + payload.put("bindings", bindings); + payload.put("usageCount", scope.getUsageCount()); - RequestBody requestBody = RequestBody.create(JSON, scopeString); + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(addNewSharedScopeEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -191,14 +195,19 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId(); - ScopeUtils scopeUtil = new ScopeUtils(); - scopeUtil.setKey(scope.getKey()); - scopeUtil.setName(scope.getName()); - scopeUtil.setDescription(scope.getDescription()); - scopeUtil.setRoles(scope.getRoles()); - String scopeString = scopeUtil.toJSON(); + JSONArray bindings = new JSONArray(); + for (String str : scope.getRoles()) { + bindings.put(str); + } + + JSONObject payload = new JSONObject(); + payload.put("name", scope.getKey()); + payload.put("displayName", scope.getName()); + payload.put("description", scope.getDescription()); + payload.put("bindings", bindings); + payload.put("usageCount", scope.getUsageCount()); - RequestBody requestBody = RequestBody.create(JSON, scopeString); + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(updateScopeUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java index 01d3f53d36..1e414675cd 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java @@ -18,7 +18,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo; import java.io.Serializable; -import java.util.Objects; +import java.util.*; public class Scope implements Serializable{ @@ -26,7 +26,7 @@ public class Scope implements Serializable{ String key; String name; - String roles; + List roles; String description; String id; int usageCount; @@ -47,12 +47,12 @@ public class Scope implements Serializable{ this.name = name; } - public String getRoles() { + public List getRoles() { return roles; } - public void setRoles(String roles) { - this.roles = roles; + public void setRoles(List roles) { + this.roles = removeDuplicatesFromRoleString(roles); } public String getDescription() { @@ -97,4 +97,12 @@ public class Scope implements Serializable{ public int hashCode() { return Objects.hash(key, name, roles, description, id); } + + private static List removeDuplicatesFromRoleString(List roles) { + Set roleSet = new HashSet<>(); + for(String role : roles) { + roleSet.add(role.trim()); + } + return new ArrayList<>(roleSet); + } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java deleted file mode 100644 index 58cff08553..0000000000 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.util; - -import java.util.HashSet; -import java.util.Set; - -/** - * This class represents the scope data. - */ -public class ScopeUtils { - - private String key; - private String name; - private String roles; - private String description; - private int id; - - public ScopeUtils() { - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getRoles() { - return roles; - } - - public void setRoles(String roles) { - this.roles = removeDuplicatesFromRoleString(roles); - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String toJSON() { - String jsonString = "{\n" + - " \"name\":\"" + key + "\",\n" + - " \"displayName\":\"" + name + "\",\n" + - " \"description\":\"" + description + "\",\n" + - " \"bindings\":[\n" + - " \"" + roles + "\"\n" + - " ]\n" + - "}"; - return jsonString; - } - - private static String removeDuplicatesFromRoleString(String roleString) { - String[] roles = roleString.split(","); - Set roleSet = new HashSet<>(); - for(String role : roles) { - roleSet.add(role.trim()); - } - return String.join(",", roleSet); - } -} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 69f20fa020..305b542777 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -553,36 +553,33 @@ public class APIPublisherServiceImpl implements APIPublisherService { // scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY); String permission = scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY; - String roleString = ""; + List rolesList = new ArrayList<>(); for (int i = 4; i < scopeMapping.length; i++) { if (scopeMapping[i] != null && StringUtils.trim(scopeMapping[i]).equals("Yes")) { - roleString = roleString + "," + roles.get(i); + rolesList.add(roles.get(i)); if (rolePermissions.containsKey(roles.get(i)) && StringUtils.isNotEmpty(permission)) { rolePermissions.get(roles.get(i)).add(permission); } } } - if (roleString.length() > 1) { - roleString = roleString.substring(1); // remove first , (comma) - } - scope.setRoles(roleString); + scope.setRoles(rolesList); //Set scope id which related to the scope key JSONArray scopeList = (JSONArray) scopeObject.get("list"); for (int i = 0; i < scopeList.length(); i++) { JSONObject scopeObj = scopeList.getJSONObject(i); - if (scopeObj.getString("name").equals(scopeMapping[2] != null ? - StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { + if (scopeObj.getString("name").equals(StringUtils.trim(scopeMapping[2]))) { scope.setId(scopeObj.getString("id")); + scope.setUsageCount(scopeObj.getInt("usageCount")); // Including already existing roles JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); for (int j = 0; j < existingRolesArray.length(); j++) { - roleString = roleString + "," + existingRolesArray.get(j); + rolesList.add(existingRolesArray.getString(j)); } } } - scope.setRoles(roleString); + scope.setRoles(rolesList); if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/dto/ApiScope.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/dto/ApiScope.java index 5d178a0eb3..ea5f6d3047 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/dto/ApiScope.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/dto/ApiScope.java @@ -18,11 +18,13 @@ package io.entgra.device.mgt.core.apimgt.webapp.publisher.dto; +import java.util.List; + public class ApiScope { String key; String name; - String roles; + List roles; String permissions; String description; int id; @@ -46,11 +48,11 @@ public class ApiScope { this.name = name; } - public String getRoles() { + public List getRoles() { return this.roles; } - public void setRoles(String roles) { + public void setRoles(List roles) { this.roles = roles; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index 704de6442c..b044c9f72a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -228,10 +228,9 @@ public class AnnotationProcessor { String permissions[]; StringBuilder aggregatedPermissions; String roles[]; - StringBuilder aggregatedRoles; + List aggregatedRoles; for (int i = 0; i < annotatedScopes.length; i++) { aggregatedPermissions = new StringBuilder(); - aggregatedRoles = new StringBuilder(); methodHandler = Proxy.getInvocationHandler(annotatedScopes[i]); scope = new ApiScope(); scope.setName(invokeMethod(scopeClass @@ -250,11 +249,8 @@ public class AnnotationProcessor { scope.setPermissions(aggregatedPermissions.toString().trim()); roles = (String[]) methodHandler.invoke(annotatedScopes[i], scopeClass .getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_ROLES, null), null); - for (String role : roles) { - aggregatedRoles.append(role); - aggregatedRoles.append(","); - } - scope.setRoles(aggregatedRoles.substring(0, aggregatedRoles.lastIndexOf(","))); + aggregatedRoles = Arrays.asList(roles); + scope.setRoles(aggregatedRoles); scopes.put(scope.getKey(), scope); } return scopes; @@ -305,11 +301,13 @@ public class AnnotationProcessor { // } else { // log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); +// List roles = new ArrayList<>(); +// roles.add(DEFAULT_SCOPE_ROLE); // scope = new ApiScope(); // scope.setName(DEFAULT_SCOPE_NAME); // scope.setDescription(DEFAULT_SCOPE_NAME); // scope.setKey(DEFAULT_SCOPE_KEY); -// scope.setRoles(DEFAULT_SCOPE_ROLE); +// scope.setRoles(roles); // scope.setPermissions(DEFAULT_SCOPE_PERMISSION); // resource.setScope(scope); // } @@ -543,11 +541,13 @@ public class AnnotationProcessor { } else { // log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); + List roles = new ArrayList<>(); + roles.add(DEFAULT_SCOPE_ROLE); scope = new ApiScope(); scope.setName(DEFAULT_SCOPE_NAME); scope.setDescription(DEFAULT_SCOPE_NAME); scope.setKey(DEFAULT_SCOPE_KEY); - scope.setRoles(DEFAULT_SCOPE_ROLE); + scope.setRoles(roles); scope.setPermissions(DEFAULT_SCOPE_PERMISSION); apiResource.setScope(scope); } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/test/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/utils/TestUtils.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/test/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/utils/TestUtils.java index 988bd9c5f7..85f0d520f9 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/test/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/utils/TestUtils.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/test/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/utils/TestUtils.java @@ -39,7 +39,7 @@ public class TestUtils { ApiScope scope = new ApiScope(); scope.setKey("win:ops:reboot"); scope.setName("Reboot"); - scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot"); + scope.setPermissions("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot"); scope.setDescription("Lock reset on Windows devices"); template.setScope(scope); uriTemplates.add(template); From 565a7614ade76bcc56ca012b6b0e2d18f1d0d9df Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 3 Oct 2023 13:39:18 +0530 Subject: [PATCH 2/5] Change JSON object return methods:Scopes --- .../rest/api/PublisherRESTAPIServices.java | 4 +- .../api/PublisherRESTAPIServicesImpl.java | 34 ++--- .../extension/rest/api/dto/APIInfo/Scope.java | 34 ++--- .../publisher/APIPublisherServiceImpl.java | 117 +++++++++--------- 4 files changed, 96 insertions(+), 93 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 4e7d79403a..868c358f23 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -35,7 +35,7 @@ import java.util.List; public interface PublisherRESTAPIServices { - JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + Scope[] getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) @@ -107,7 +107,7 @@ public interface PublisherRESTAPIServices { String uuid, String documentID) throws APIServicesException, BadRequestException, UnexpectedResponseException; - io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Documentation addDocumentation(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + Documentation addDocumentation(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, Documentation documentation) throws APIServicesException, BadRequestException, UnexpectedResponseException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index 90724d3cf1..65d2af0258 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -55,7 +55,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { + Constants.COLON + port; @Override - public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + public Scope[] getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAllScopesUrl = endPointPrefix + Constants.GET_ALL_SCOPES; @@ -69,8 +69,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + JSONArray scopeList = (JSONArray) new JSONObject(response.body().string()).get("list"); + return gson.fromJson(scopeList.toString(), Scope[].class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -144,16 +144,16 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT; JSONArray bindings = new JSONArray(); - for (String str : scope.getRoles()) { + for (String str : scope.getBindings()) { bindings.put(str); } JSONObject payload = new JSONObject(); - payload.put("name", scope.getKey()); - payload.put("displayName", scope.getName()); - payload.put("description", scope.getDescription()); - payload.put("bindings", bindings); - payload.put("usageCount", scope.getUsageCount()); + payload.put("name", (scope.getName() != null ? scope.getName() : "")); + payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : "")); + payload.put("description", (scope.getDescription() != null ? scope.getDescription() : "")); + payload.put("bindings", (bindings != null ? bindings : "")); + payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0)); RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() @@ -196,16 +196,16 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId(); JSONArray bindings = new JSONArray(); - for (String str : scope.getRoles()) { + for (String str : scope.getBindings()) { bindings.put(str); } JSONObject payload = new JSONObject(); - payload.put("name", scope.getKey()); - payload.put("displayName", scope.getName()); - payload.put("description", scope.getDescription()); - payload.put("bindings", bindings); - payload.put("usageCount", scope.getUsageCount()); + payload.put("name", (scope.getName() != null ? scope.getName() : "")); + payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : "")); + payload.put("description", (scope.getDescription() != null ? scope.getDescription() : "")); + payload.put("bindings", (bindings != null ? bindings : "")); + payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0)); RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() @@ -453,7 +453,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { " \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" + " \"endpointImplementationType\": \"ENDPOINT\",\n" + " \"scopes\": " + api.getScopes().toString() + ",\n" + - " \"operations\": " + (api.getOperations() != null? api.getOperations().toString() : null) + ",\n" + + " \"operations\": " + (api.getOperations() != null ? api.getOperations().toString() : null) + ",\n" + " \"threatProtectionPolicies\": null,\n" + " \"categories\": [],\n" + " \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" + @@ -632,7 +632,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { @Override public boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - String uuid, Mediation mediation) + String uuid, Mediation mediation) throws APIServicesException, BadRequestException, UnexpectedResponseException { String deleteApiMediationEndPOint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid(); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java index 1e414675cd..53a40e2707 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Scope.java @@ -18,25 +18,29 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo; import java.io.Serializable; -import java.util.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Objects; +import java.util.Set; +import java.util.HashSet; public class Scope implements Serializable{ private static final long serialVersionUID = 1L; - String key; + String id; String name; - List roles; + String displayName; String description; - String id; + List bindings; int usageCount; - public String getKey() { - return key; + public String getDisplayName() { + return displayName; } - public void setKey(String key) { - this.key = key; + public void setDisplayName(String displayName) { + this.displayName = displayName; } public String getName() { @@ -47,12 +51,12 @@ public class Scope implements Serializable{ this.name = name; } - public List getRoles() { - return roles; + public List getBindings() { + return bindings; } - public void setRoles(List roles) { - this.roles = removeDuplicatesFromRoleString(roles); + public void setBindings(List bindings) { + this.bindings = removeDuplicatesFromRoleString(bindings); } public String getDescription() { @@ -87,15 +91,15 @@ public class Scope implements Serializable{ Scope scope = (Scope) o; if (id != null ? !id.equals(scope.id) : scope.id != null) return false; - if (!key.equals(scope.key)) return false; if (!name.equals(scope.name)) return false; - if (roles != null ? !roles.equals(scope.roles) : scope.roles != null) return false; + if (!displayName.equals(scope.displayName)) return false; + if (bindings != null ? !bindings.equals(scope.bindings) : scope.bindings != null) return false; return description != null ? description.equals(scope.description) : scope.description == null; } @Override public int hashCode() { - return Objects.hash(key, name, roles, description, id); + return Objects.hash(name, displayName, bindings, description, id); } private static List removeDuplicatesFromRoleString(List roles) { diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 305b542777..a16e249002 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -100,7 +100,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { public static final String SUBSCRIPTION_TO_CURRENT_TENANT = "CURRENT_TENANT"; public static final String API_GLOBAL_VISIBILITY = "PUBLIC"; public static final String API_PRIVATE_VISIBILITY = "PRIVATE"; - private static final String ADMIN_ROLE_KEY = ",admin"; + private static final String ADMIN_ROLE_KEY = "admin"; private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class); @@ -184,10 +184,12 @@ public class APIPublisherServiceImpl implements APIPublisherService { if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, apiScope.getKey())) { Scope scope = new Scope(); - scope.setName(apiScope.getName()); + scope.setDisplayName(apiScope.getName()); scope.setDescription(apiScope.getDescription()); - scope.setKey(apiScope.getKey()); - scope.setRoles(apiScope.getRoles() + ADMIN_ROLE_KEY); + scope.setName(apiScope.getKey()); + List bindings = apiScope.getRoles(); + bindings.add(ADMIN_ROLE_KEY); + scope.setBindings(bindings); publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); } } @@ -257,10 +259,12 @@ public class APIPublisherServiceImpl implements APIPublisherService { } else { // if new scope add as shared scope Scope scope = new Scope(); - scope.setName(apiScope.getName()); + scope.setName(apiScope.getKey()); scope.setDescription(apiScope.getDescription()); - scope.setKey(apiScope.getKey()); - scope.setRoles(apiScope.getRoles() + ADMIN_ROLE_KEY); + scope.setDisplayName(apiScope.getName()); + List bindings = apiScope.getRoles(); + bindings.add(ADMIN_ROLE_KEY); + scope.setBindings(bindings); publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); } @@ -278,10 +282,12 @@ public class APIPublisherServiceImpl implements APIPublisherService { for (ApiScope apiScope : scopesToMoveAsSharedScopes) { Scope scope = new Scope(); - scope.setName(apiScope.getName()); + scope.setName(apiScope.getKey()); scope.setDescription(apiScope.getDescription()); - scope.setKey(apiScope.getKey()); - scope.setRoles(apiScope.getRoles() + ADMIN_ROLE_KEY); + scope.setDisplayName(apiScope.getName()); + List bindings = apiScope.getRoles(); + bindings.add(ADMIN_ROLE_KEY); + scope.setBindings(bindings); publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); } } @@ -458,10 +464,15 @@ public class APIPublisherServiceImpl implements APIPublisherService { for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) { //todo check whether scope is available or not ScopeMapping scopeMapping = defaultPermission.getScopeMapping(); - scope.setName(scopeMapping.getName()); + + String[] roles = scopeMapping.getDefaultRoles().split(","); + List bindings = Arrays.asList(roles); + bindings.add(ADMIN_ROLE_KEY); + + scope.setName(scopeMapping.getKey()); scope.setDescription(scopeMapping.getName()); - scope.setKey(scopeMapping.getKey()); - scope.setRoles(scopeMapping.getDefaultRoles() + ADMIN_ROLE_KEY); + scope.setDisplayName(scopeMapping.getName()); + scope.setBindings(bindings); publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); } } catch (BadRequestException | UnexpectedResponseException | APIServicesException e) { @@ -497,7 +508,6 @@ public class APIPublisherServiceImpl implements APIPublisherService { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); - JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); try { String fileName = @@ -543,11 +553,11 @@ public class APIPublisherServiceImpl implements APIPublisherService { } Scope scope = new Scope(); - scope.setName( + scope.setDisplayName( scopeMapping[0] != null ? StringUtils.trim(scopeMapping[0]) : StringUtils.EMPTY); scope.setDescription( scopeMapping[1] != null ? StringUtils.trim(scopeMapping[1]) : StringUtils.EMPTY); - scope.setKey( + scope.setName( scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY); // scope.setPermissions( // scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY); @@ -562,30 +572,24 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } } - scope.setRoles(rolesList); - - //Set scope id which related to the scope key - JSONArray scopeList = (JSONArray) scopeObject.get("list"); - for (int i = 0; i < scopeList.length(); i++) { - JSONObject scopeObj = scopeList.getJSONObject(i); - if (scopeObj.getString("name").equals(StringUtils.trim(scopeMapping[2]))) { - scope.setId(scopeObj.getString("id")); - scope.setUsageCount(scopeObj.getInt("usageCount")); - -// Including already existing roles - JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); - for (int j = 0; j < existingRolesArray.length(); j++) { - rolesList.add(existingRolesArray.getString(j)); - } + //Set scope details which related to the scope key + Scope[] scopes = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); + for (int i = 0; i < scopes.length; i++) { + Scope relatedScope = scopes[i]; + if (relatedScope.getName().equals(scopeMapping[2].toString())) { + scope.setId(relatedScope.getId()); + scope.setUsageCount(relatedScope.getUsageCount()); + //Including already existing roles + rolesList.addAll(relatedScope.getBindings()); } } - scope.setRoles(rolesList); + scope.setBindings(rolesList); - if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { + if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); } else { // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list - log.warn(scope.getKey() + " not available as shared scope"); + log.warn(scope.getName() + " not available as shared scope"); } } for (String role : rolePermissions.keySet()) { @@ -598,12 +602,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } catch (IOException | DirectoryIteratorException ex) { log.error("failed to read scopes from file.", ex); - } catch (APIServicesException | BadRequestException e) { - String errorMsg = "Error while calling APIs"; - log.error(errorMsg, e); - throw new APIManagerPublisherException(e); } - } } catch (APIServicesException e) { String errorMsg = "Error while processing Publisher REST API response"; @@ -639,13 +638,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { try { PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); - JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); + Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); + Map permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping(); if (permissions.length != 0) { - updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeObject, permissions, permScopeMap, false); + updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, permissions, permScopeMap, false); } if (removedPermissions.length != 0) { - updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeObject, removedPermissions, permScopeMap, true); + updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, removedPermissions, permScopeMap, true); } try { @@ -677,7 +677,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { * @param publisherRESTAPIServices {@link PublisherRESTAPIServices} * @param apiApplicationKey {@link APIApplicationKey} * @param accessTokenInfo {@link AccessTokenInfo} - * @param scopeObject scope object returning from APIM + * @param scopeList scope list returning from APIM * @param permissions List of permissions * @param permScopeMap Permission Scope map * @param removingPermissions if list of permissions has to be removed from the role send true, otherwise sends false. @@ -685,7 +685,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { */ private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices, APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject scopeObject, String[] permissions, Map permScopeMap, boolean removingPermissions ) + Scope[] scopeList, String[] permissions, Map permScopeMap, boolean removingPermissions ) throws APIManagerPublisherException { for (String permission : permissions) { String scopeValue = permScopeMap.get(permission); @@ -696,22 +696,21 @@ public class APIPublisherServiceImpl implements APIPublisherService { throw new APIManagerPublisherException(msg); } - JSONArray scopeList = (JSONArray) scopeObject.get("list"); - for (int i = 0; i < scopeList.length(); i++) { - JSONObject scopeObj = scopeList.getJSONObject(i); - if (scopeObj.getString("name").equals(scopeValue)) { + for (int i = 0; i < scopeList.length; i++) { + Scope scopeObj = scopeList[i]; + if (scopeObj.getName().equals(scopeValue)) { Scope scope = new Scope(); - scope.setName(scopeObj.getString("name")); - scope.setKey(scopeObj.getString("name")); - scope.setDescription(scopeObj.getString("description")); - scope.setId(scopeObj.getString("id")); + scope.setName(scopeObj.getName()); + scope.setDisplayName(scopeObj.getDisplayName()); + scope.setDescription(scopeObj.getDescription()); + scope.setId(scopeObj.getId()); // Including already existing roles - JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); - List existingRoleList = new ArrayList(); + List existingRoleList = new ArrayList<>(); + existingRoleList.addAll(scopeObj.getBindings()); - for (int j = 0; j < existingRolesArray.length(); j++) { - existingRoleList.add((String) existingRolesArray.get(j)); + if (!existingRoleList.contains(roleName)) { + existingRoleList.add(roleName); } if (removingPermissions) { @@ -721,14 +720,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { existingRoleList.add(roleName); } } - scope.setRoles(String.join(",", existingRoleList)); + scope.setBindings(existingRoleList); try { - if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { + if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); } else { // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list - log.warn(scope.getKey() + " not available as shared scope"); + log.warn(scope.getName() + " not available as shared scope"); } } catch (APIServicesException | BadRequestException | UnexpectedResponseException e) { log.error("Error occurred while updating role scope mapping via APIM REST endpoint.", e); From bdf1e97d847045a1f45e9f96c37e23b05b987e73 Mon Sep 17 00:00:00 2001 From: pasindu Date: Thu, 5 Oct 2023 08:30:49 +0530 Subject: [PATCH 3/5] Map Json object return types to dto classes in Publisher --- .../rest/api/PublisherRESTAPIServices.java | 8 +- .../api/PublisherRESTAPIServicesImpl.java | 330 ++++++++++++------ .../rest/api/dto/APIInfo/APIInfo.java | 183 +++++----- .../rest/api/dto/APIInfo/APIMaxTps.java | 44 +++ .../api/dto/APIInfo/AdditionalProperties.java | 50 +++ .../rest/api/dto/APIInfo/MediationPolicy.java | 59 ++++ .../rest/api/dto/APIInfo/Monetization.java | 42 +++ .../rest/api/dto/APIInfo/Operations.java | 15 +- .../rest/api/dto/APIInfo/ServiceInfo.java | 59 ++++ .../dto/APIInfo/ThreatProtectionPolicies.java | 41 +++ .../WebsubSubscriptionConfiguration.java | 61 ++++ .../publisher/APIPublisherServiceImpl.java | 104 +++--- 12 files changed, 724 insertions(+), 272 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIMaxTps.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/AdditionalProperties.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/MediationPolicy.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Monetization.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ServiceInfo.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ThreatProtectionPolicies.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/WebsubSubscriptionConfiguration.java diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 868c358f23..a191b0ac16 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -47,13 +47,13 @@ public interface PublisherRESTAPIServices { boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid) + APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api) + APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api) throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api) @@ -91,7 +91,7 @@ public interface PublisherRESTAPIServices { String apiRevisionId, List apiRevisionDeploymentList) throws APIServicesException, BadRequestException, UnexpectedResponseException; - abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, JSONObject apiRevisionDeployment, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index 65d2af0258..05f0a3fe98 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -21,12 +21,7 @@ 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.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.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 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.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; @@ -123,7 +118,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { log.error(msg); throw new BadRequestException(msg); } else if (HttpStatus.SC_NOT_FOUND == response.code()) { - String msg = "Shared scope key not found"; + String msg = "Shared scope key not found : " + key; log.info(msg); return false; } else { @@ -144,8 +139,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT; JSONArray bindings = new JSONArray(); - for (String str : scope.getBindings()) { - bindings.put(str); + if (scope.getBindings() != null) { + for (String str : scope.getBindings()) { + bindings.put(str); + } } JSONObject payload = new JSONObject(); @@ -196,8 +193,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId(); JSONArray bindings = new JSONArray(); - for (String str : scope.getBindings()) { - bindings.put(str); + if (scope.getBindings() != null) { + for (String str : scope.getBindings()) { + bindings.put(str); + } } JSONObject payload = new JSONObject(); @@ -242,7 +241,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid) + public APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiUuid; @@ -256,8 +255,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + return gson.fromJson(response.body().string(), APIInfo.class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -281,7 +279,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + public APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAllApis = endPointPrefix + Constants.GET_ALL_APIS; @@ -295,8 +293,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { 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. @@ -320,59 +318,111 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api) + public APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api) throws APIServicesException, BadRequestException, UnexpectedResponseException { String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT; - String apiString = "{\n" + - " \"name\": \"" + api.getName() + "\",\n" + - " \"description\":\"" + api.getDescription() + "\",\n" + - " \"context\":\"" + api.getContext() + "\",\n" + - " \"version\":\"" + api.getVersion() + "\",\n" + - " \"provider\":\"" + api.getProvider() + "\",\n" + - " \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" + - " \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" + - " \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" + - " \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" + - " \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" + - " \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" + - " \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" + - " \"isRevision\": " + api.isRevision() + ",\n" + - " \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" + - " \"revisionId\": " + api.getRevisionId() + ",\n" + - " \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" + - " \"type\": \"" + api.getType() + "\",\n" + - " \"transport\": " + gson.toJson(api.getTransport()) + ",\n" + - " \"tags\": " + gson.toJson(api.getTags()) + ",\n" + - " \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" + - " \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" + - " \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" + - " \"visibility\": \"" + api.getVisibility() + "\",\n" + - " \"mediationPolicies\": " + (api.getInSequence() != null ? "[{\"name\": \"" + api.getInSequence() + "\",\"type\": \"in\"}]" : null) + ",\n" + - " \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" + - " \"subscriptionAvailableTenants\": [],\n" + - " \"additionalProperties\": [],\n" + - " \"monetization\": " + api.getMonetization() + ",\n" + - " \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" + - " \"websubSubscriptionConfiguration\": {\n" + - " \"enable\": false,\n" + - " \"secret\": \"\",\n" + - " \"signingAlgorithm\": \"SHA1\",\n" + - " \"signatureHeader\": \"x-hub-signature\"\n" + - " },\n" + - " \"workflowStatus\": null,\n" + - " \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" + - " \"endpointImplementationType\": \"ENDPOINT\",\n" + - " \"scopes\": " + api.getScopes().toString() + ",\n" + - " \"operations\": " + (api.getOperations() != null ? api.getOperations().toString() : null) + ",\n" + - " \"threatProtectionPolicies\": null,\n" + - " \"categories\": [],\n" + - " \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" + - " \"serviceInfo\": " + api.getServiceInfo() + "\n" + - "}"; + JSONObject payload = new JSONObject(); + payload.put("name", api.getName()); + payload.put("description", api.getDescription()); + payload.put("context", api.getContext()); + payload.put("version", api.getVersion()); + payload.put("provider", api.getProvider()); + payload.put("lifeCycleStatus", api.getLifeCycleStatus()); + payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null)); + payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null)); + payload.put("responseCachingEnabled", api.isResponseCachingEnabled()); + payload.put("cacheTimeout", api.getCacheTimeout()); + payload.put("hasThumbnail", api.isHasThumbnail()); + payload.put("isDefaultVersion", api.isDefaultVersion()); + payload.put("isRevision", api.isRevision()); + payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null)); + payload.put("revisionId", api.getRevisionId()); + payload.put("enableSchemaValidation", api.isEnableSchemaValidation()); + payload.put("type", api.getType()); + payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy()); + payload.put("authorizationHeader", api.getAuthorizationHeader()); + payload.put("visibility", api.getVisibility()); + payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : "")); + + //Lists + if (api.getTransport() != null) { + JSONArray transport = new JSONArray(); + for (String str : api.getTransport()) { + transport.put(str); + } + payload.put("transport", transport); + } + if (api.getTags() != null) { + JSONArray tags = new JSONArray(); + for (String str : api.getTags()) { + tags.put(str); + } + payload.put("tags", tags); + } + if (api.getPolicies() != null) { + JSONArray policies = new JSONArray(); + for (String str : api.getPolicies()) { + policies.put(str); + } + payload.put("policies", policies); + } + if (api.getMediationPolicies() != null) { + JSONArray mediationPolicies = new JSONArray(); + for (MediationPolicy object : api.getMediationPolicies()) { + mediationPolicies.put(new JSONObject(gson.toJson(object))); + } + payload.put("mediationPolicies", mediationPolicies); + } + if (api.getSubscriptionAvailableTenants() != null) { + JSONArray subscriptionAvailableTenants = new JSONArray(); + for (String str : api.getSubscriptionAvailableTenants()) { + subscriptionAvailableTenants.put(str); + } + payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants); + } + if (api.getAdditionalProperties() != null) { + JSONArray additionalProperties = new JSONArray(); + for (AdditionalProperties str : api.getAdditionalProperties()) { + additionalProperties.put(str); + } + payload.put("additionalProperties", additionalProperties); + } + if (api.getScopes() != null) { + JSONArray scopes = new JSONArray(); + for (JSONObject object : api.getScopes()) { + scopes.put(object); + } + payload.put("scopes", scopes); + } + if (api.getOperations() != null) { + JSONArray operations = new JSONArray(); + for (Operations operation : api.getOperations()) { + operations.put(new JSONObject(gson.toJson(operation))); + } + payload.put("operations", operations); + } + if (api.getCategories() != null) { + JSONArray categories = new JSONArray(); + for (String str : api.getCategories()) { + categories.put(str); + } + payload.put("categories", categories); + } + + //objects + payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null)); + payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null)); + payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null)); + payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null)); + payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null)); + payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null)); + payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null)); + payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null)); + payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null)); - RequestBody requestBody = RequestBody.create(JSON, apiString); + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(addAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -383,8 +433,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_CREATED == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + return gson.fromJson(response.body().string(), APIInfo.class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -413,54 +462,106 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId(); - String apiString = "{\n" + - " \"name\": \"" + api.getName() + "\",\n" + - " \"description\":\"" + api.getDescription() + "\",\n" + - " \"context\":\"" + api.getContext() + "\",\n" + - " \"version\":\"" + api.getVersion() + "\",\n" + - " \"provider\":\"" + api.getProvider() + "\",\n" + - " \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" + - " \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" + - " \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" + - " \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" + - " \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" + - " \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" + - " \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" + - " \"isRevision\": " + api.isRevision() + ",\n" + - " \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" + - " \"revisionId\": " + api.getRevisionId() + ",\n" + - " \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" + - " \"type\": \"" + api.getType() + "\",\n" + - " \"transport\": " + gson.toJson(api.getTransport()) + ",\n" + - " \"tags\": " + gson.toJson(api.getTags()) + ",\n" + - " \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" + - " \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" + - " \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" + - " \"visibility\": \"" + api.getVisibility() + "\",\n" + - " \"mediationPolicies\": " + (api.getInSequence() != null ? "[{\"name\": \"" + api.getInSequence() + "\",\"type\": \"in\"}]" : null) + ",\n" + - " \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" + - " \"subscriptionAvailableTenants\": [],\n" + - " \"additionalProperties\": [],\n" + - " \"monetization\": " + api.getMonetization() + ",\n" + - " \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" + - " \"websubSubscriptionConfiguration\": {\n" + - " \"enable\": false,\n" + - " \"secret\": \"\",\n" + - " \"signingAlgorithm\": \"SHA1\",\n" + - " \"signatureHeader\": \"x-hub-signature\"\n" + - " },\n" + - " \"workflowStatus\": null,\n" + - " \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" + - " \"endpointImplementationType\": \"ENDPOINT\",\n" + - " \"scopes\": " + api.getScopes().toString() + ",\n" + - " \"operations\": " + (api.getOperations() != null ? api.getOperations().toString() : null) + ",\n" + - " \"threatProtectionPolicies\": null,\n" + - " \"categories\": [],\n" + - " \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" + - " \"serviceInfo\": " + api.getServiceInfo() + "\n" + - "}"; + JSONObject payload = new JSONObject(); + payload.put("name", api.getName()); + payload.put("description", api.getDescription()); + payload.put("context", api.getContext()); + payload.put("version", api.getVersion()); + payload.put("provider", api.getProvider()); + payload.put("lifeCycleStatus", api.getLifeCycleStatus()); + payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null)); + payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null)); + payload.put("responseCachingEnabled", api.isResponseCachingEnabled()); + payload.put("cacheTimeout", api.getCacheTimeout()); + payload.put("hasThumbnail", api.isHasThumbnail()); + payload.put("isDefaultVersion", api.isDefaultVersion()); + payload.put("isRevision", api.isRevision()); + payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null)); + payload.put("revisionId", api.getRevisionId()); + payload.put("enableSchemaValidation", api.isEnableSchemaValidation()); + payload.put("type", api.getType()); + payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy()); + payload.put("authorizationHeader", api.getAuthorizationHeader()); + payload.put("visibility", api.getVisibility()); + payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : "")); + + //Lists + if (api.getTransport() != null) { + JSONArray transport = new JSONArray(); + for (String str : api.getTransport()) { + transport.put(str); + } + payload.put("transport", transport); + } + if (api.getTags() != null) { + JSONArray tags = new JSONArray(); + for (String str : api.getTags()) { + tags.put(str); + } + payload.put("tags", tags); + } + if (api.getPolicies() != null) { + JSONArray policies = new JSONArray(); + for (String str : api.getPolicies()) { + policies.put(str); + } + payload.put("policies", policies); + } + if (api.getMediationPolicies() != null) { + JSONArray mediationPolicies = new JSONArray(); + for (MediationPolicy object : api.getMediationPolicies()) { + mediationPolicies.put(new JSONObject(gson.toJson(object))); + } + payload.put("mediationPolicies", mediationPolicies); + } + if (api.getSubscriptionAvailableTenants() != null) { + JSONArray subscriptionAvailableTenants = new JSONArray(); + for (String str : api.getSubscriptionAvailableTenants()) { + subscriptionAvailableTenants.put(str); + } + payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants); + } + if (api.getAdditionalProperties() != null) { + JSONArray additionalProperties = new JSONArray(); + for (AdditionalProperties str : api.getAdditionalProperties()) { + additionalProperties.put(str); + } + payload.put("additionalProperties", additionalProperties); + } + if (api.getScopes() != null) { + JSONArray scopes = new JSONArray(); + for (JSONObject object : api.getScopes()) { + scopes.put(object); + } + payload.put("scopes", scopes); + } + if (api.getOperations() != null) { + JSONArray operations = new JSONArray(); + for (Operations operation : api.getOperations()) { + operations.put(new JSONObject(gson.toJson(operation))); + } + payload.put("operations", operations); + } + if (api.getCategories() != null) { + JSONArray categories = new JSONArray(); + for (String str : api.getCategories()) { + categories.put(str); + } + payload.put("categories", categories); + } - RequestBody requestBody = RequestBody.create(JSON, apiString); + //objects + payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null)); + payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null)); + payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null)); + payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null)); + payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null)); + payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null)); + payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null)); + payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null)); + payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null)); + + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(updateAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -472,7 +573,6 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { 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. diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIInfo.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIInfo.java index b7443b0f53..a48a10c9e3 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIInfo.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIInfo.java @@ -20,7 +20,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo; import org.json.JSONObject; -import java.util.*; +import java.util.List; /** * This class represents the API response. @@ -35,69 +35,75 @@ public class APIInfo { private String version; private String provider; private String lifeCycleStatus; - private String wsdlInfo; + private type wsdlInfo; private String wsdlUrl; private boolean responseCachingEnabled; private int cacheTimeout; private boolean hasThumbnail; private boolean isDefaultVersion; private boolean isRevision; - private String revisionedApiId; + private String revisionedApiId; private int revisionId; private boolean enableSchemaValidation; + private boolean enableStore; private String type; - private Set transport; - private Set tags; - private Set policies; + private List transport; + private List tags; + private List policies; private String apiThrottlingPolicy; private String authorizationHeader; - private String securityScheme; - private String maxTps; + private List securityScheme; + private APIMaxTps maxTps; private String visibility; - private String visibleRoles; - private String visibleTenants; - private String mediationPolicies; + private List visibleRoles; + private List visibleTenants; + private List mediationPolicies; private String subscriptionAvailability; - private String subscriptionAvailableTenants; - private String additionalProperties; - private String monetization; + private List subscriptionAvailableTenants; + private List additionalProperties; + private Monetization monetization; private String accessControl; - private String accessControlRoles; + private List accessControlRoles; private BusinessInformation businessInformation; private CORSConfiguration corsConfiguration; + private WebsubSubscriptionConfiguration websubSubscriptionConfiguration; private String workflowStatus; private String createdTime; private String lastUpdatedTime; - private JSONObject endpointConfig = new JSONObject(); + private JSONObject endpointConfig; private String endpointImplementationType; - private List scopes = new ArrayList(); - private List operations; - private String threatProtectionPolicies; - private List keyManagers = new ArrayList(); - private JSONObject serviceInfo = new JSONObject(); + private List scopes; + private List operations; + private JSONObject threatProtectionPolicies; + private List categories; + private List keyManagers; + private ServiceInfo serviceInfo; private AdvertiseInfo advertiseInfo; - private String asyncApiDefinition; - - private Set uriTemplates = new LinkedHashSet(); - private String inSequence; + public enum type { + WSDL, ZIP + } - private Map wsUriMapping; 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; } @@ -109,12 +115,15 @@ public class APIInfo { 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; } @@ -131,11 +140,11 @@ public class APIInfo { this.lifeCycleStatus = lifeCycleStatus; } - public String getWsdlInfo() { + public APIInfo.type getWsdlInfo() { return wsdlInfo; } - public void setWsdlInfo(String wsdlInfo) { + public void setWsdlInfo(APIInfo.type wsdlInfo) { this.wsdlInfo = wsdlInfo; } @@ -211,6 +220,14 @@ public class APIInfo { this.enableSchemaValidation = enableSchemaValidation; } + public boolean isEnableStore() { + return enableStore; + } + + public void setEnableStore(boolean enableStore) { + this.enableStore = enableStore; + } + public String getType() { return type; } @@ -219,27 +236,27 @@ public class APIInfo { this.type = type; } - public Set getTransport() { + public List getTransport() { return transport; } - public void setTransport(Set transport) { + public void setTransport(List transport) { this.transport = transport; } - public Set getTags() { + public List getTags() { return tags; } - public void setTags(Set tags) { + public void setTags(List tags) { this.tags = tags; } - public Set getPolicies() { + public List getPolicies() { return policies; } - public void setPolicies(Set policies) { + public void setPolicies(List policies) { this.policies = policies; } @@ -259,19 +276,19 @@ public class APIInfo { this.authorizationHeader = authorizationHeader; } - public String getSecurityScheme() { + public List getSecurityScheme() { return securityScheme; } - public void setSecurityScheme(String securityScheme) { + public void setSecurityScheme(List securityScheme) { this.securityScheme = securityScheme; } - public String getMaxTps() { + public APIMaxTps getMaxTps() { return maxTps; } - public void setMaxTps(String maxTps) { + public void setMaxTps(APIMaxTps maxTps) { this.maxTps = maxTps; } @@ -283,27 +300,27 @@ public class APIInfo { this.visibility = visibility; } - public String getVisibleRoles() { + public List getVisibleRoles() { return visibleRoles; } - public void setVisibleRoles(String visibleRoles) { + public void setVisibleRoles(List visibleRoles) { this.visibleRoles = visibleRoles; } - public String getVisibleTenants() { + public List getVisibleTenants() { return visibleTenants; } - public void setVisibleTenants(String visibleTenants) { + public void setVisibleTenants(List visibleTenants) { this.visibleTenants = visibleTenants; } - public String getMediationPolicies() { + public List getMediationPolicies() { return mediationPolicies; } - public void setMediationPolicies(String mediationPolicies) { + public void setMediationPolicies(List mediationPolicies) { this.mediationPolicies = mediationPolicies; } @@ -315,27 +332,27 @@ public class APIInfo { this.subscriptionAvailability = subscriptionAvailability; } - public String getSubscriptionAvailableTenants() { + public List getSubscriptionAvailableTenants() { return subscriptionAvailableTenants; } - public void setSubscriptionAvailableTenants(String subscriptionAvailableTenants) { + public void setSubscriptionAvailableTenants(List subscriptionAvailableTenants) { this.subscriptionAvailableTenants = subscriptionAvailableTenants; } - public String getAdditionalProperties() { + public List getAdditionalProperties() { return additionalProperties; } - public void setAdditionalProperties(String additionalProperties) { + public void setAdditionalProperties(List additionalProperties) { this.additionalProperties = additionalProperties; } - public String getMonetization() { + public Monetization getMonetization() { return monetization; } - public void setMonetization(String monetization) { + public void setMonetization(Monetization monetization) { this.monetization = monetization; } @@ -347,11 +364,11 @@ public class APIInfo { this.accessControl = accessControl; } - public String getAccessControlRoles() { + public List getAccessControlRoles() { return accessControlRoles; } - public void setAccessControlRoles(String accessControlRoles) { + public void setAccessControlRoles(List accessControlRoles) { this.accessControlRoles = accessControlRoles; } @@ -371,6 +388,14 @@ public class APIInfo { this.corsConfiguration = corsConfiguration; } + public WebsubSubscriptionConfiguration getWebsubSubscriptionConfiguration() { + return websubSubscriptionConfiguration; + } + + public void setWebsubSubscriptionConfiguration(WebsubSubscriptionConfiguration websubSubscriptionConfiguration) { + this.websubSubscriptionConfiguration = websubSubscriptionConfiguration; + } + public String getWorkflowStatus() { return workflowStatus; } @@ -411,7 +436,7 @@ public class APIInfo { this.endpointImplementationType = endpointImplementationType; } - public ListgetScopes() { + public List getScopes() { return scopes; } @@ -419,22 +444,30 @@ public class APIInfo { this.scopes = scopes; } - public List getOperations() { + public List getOperations() { return operations; } - public void setOperations(List operations) { + public void setOperations(List operations) { this.operations = operations; } - public String getThreatProtectionPolicies() { + public JSONObject getThreatProtectionPolicies() { return threatProtectionPolicies; } - public void setThreatProtectionPolicies(String threatProtectionPolicies) { + public void setThreatProtectionPolicies(JSONObject threatProtectionPolicies) { this.threatProtectionPolicies = threatProtectionPolicies; } + public List getCategories() { + return categories; + } + + public void setCategories(List categories) { + this.categories = categories; + } + public List getKeyManagers() { return keyManagers; } @@ -443,11 +476,11 @@ public class APIInfo { this.keyManagers = keyManagers; } - public JSONObject getServiceInfo() { + public ServiceInfo getServiceInfo() { return serviceInfo; } - public void setServiceInfo(JSONObject serviceInfo) { + public void setServiceInfo(ServiceInfo serviceInfo) { this.serviceInfo = serviceInfo; } @@ -458,36 +491,4 @@ public class APIInfo { public void setAdvertiseInfo(AdvertiseInfo advertiseInfo) { this.advertiseInfo = advertiseInfo; } - - public String getInSequence() { - return inSequence; - } - - public void setInSequence(String inSequence) { - this.inSequence = inSequence; - } - - public String getAsyncApiDefinition() { - return asyncApiDefinition; - } - - public void setAsyncApiDefinition(String asyncApiDefinition) { - this.asyncApiDefinition = asyncApiDefinition; - } - - public Set getUriTemplates() { - return uriTemplates; - } - - public void setUriTemplates(Set uriTemplates) { - this.uriTemplates = uriTemplates; - } - - public Map getWsUriMapping() { - return wsUriMapping; - } - - public void setWsUriMapping(Map wsUriMapping) { - this.wsUriMapping = wsUriMapping; - } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIMaxTps.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIMaxTps.java new file mode 100644 index 0000000000..5925b3c79a --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIMaxTps.java @@ -0,0 +1,44 @@ +/* + * 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.dto.APIInfo; + +import java.io.Serializable; + +public class APIMaxTps implements Serializable { + + private static final long serialVersionUID = 1L; + + int production; + int sandbox; + + public int getProduction() { + return production; + } + + public void setProduction(int production) { + this.production = production; + } + + public int getSandbox() { + return sandbox; + } + + public void setSandbox(int sandbox) { + this.sandbox = sandbox; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/AdditionalProperties.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/AdditionalProperties.java new file mode 100644 index 0000000000..fbb51bc081 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/AdditionalProperties.java @@ -0,0 +1,50 @@ +/* + * 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.dto.APIInfo; + +public class AdditionalProperties { + + private String name; + private String value; + private boolean display; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public boolean isDisplay() { + return display; + } + + public void setDisplay(boolean display) { + this.display = display; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/MediationPolicy.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/MediationPolicy.java new file mode 100644 index 0000000000..9db34dbe38 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/MediationPolicy.java @@ -0,0 +1,59 @@ +/* + * 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.dto.APIInfo; + +public class MediationPolicy { + + private String id; + private String name; + private String type; + private boolean shared; + + 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 boolean isShared() { + return shared; + } + + public void setShared(boolean shared) { + this.shared = shared; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Monetization.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Monetization.java new file mode 100644 index 0000000000..5b014fbe58 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Monetization.java @@ -0,0 +1,42 @@ +/* + * 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.dto.APIInfo; + +import org.json.JSONObject; + +public class Monetization { + private boolean enabled; + private JSONObject properties; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public JSONObject getProperties() { + return properties; + } + + public void setProperties(JSONObject properties) { + this.properties = properties; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Operations.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Operations.java index 2dd00c4482..51e5d0c3de 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Operations.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Operations.java @@ -18,7 +18,8 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo; -import java.util.Set; +import org.json.JSONObject; +import java.util.List; /** * This hold the api operations information. @@ -29,8 +30,8 @@ public class Operations { private String verb; private String authType; private String throttlingPolicy; - private Set scopes; - private String usedProductIds; + private List scopes; + private List usedProductIds; private String amznResourceName; private String amznResourceTimeout; private String payloadSchema; @@ -78,19 +79,19 @@ public class Operations { this.throttlingPolicy = throttlingPolicy; } - public Set getScopes() { + public List getScopes() { return scopes; } - public void setScopes(Set scopes) { + public void setScopes(List scopes) { this.scopes = scopes; } - public String getUsedProductIds() { + public List getUsedProductIds() { return usedProductIds; } - public void setUsedProductIds(String usedProductIds) { + public void setUsedProductIds(List usedProductIds) { this.usedProductIds = usedProductIds; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ServiceInfo.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ServiceInfo.java new file mode 100644 index 0000000000..cfbcf2ea66 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ServiceInfo.java @@ -0,0 +1,59 @@ +/* + * 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.dto.APIInfo; + +public class ServiceInfo { + + private String key; + private String name; + private String version; + private boolean outdated; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public boolean isOutdated() { + return outdated; + } + + public void setOutdated(boolean outdated) { + this.outdated = outdated; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ThreatProtectionPolicies.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ThreatProtectionPolicies.java new file mode 100644 index 0000000000..b9594830f9 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/ThreatProtectionPolicies.java @@ -0,0 +1,41 @@ +/* + * 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.dto.APIInfo; + +public class ThreatProtectionPolicies { + + private String policyID; + private int priority; + + public String getPolicyID() { + return policyID; + } + + public void setPolicyID(String policyID) { + this.policyID = policyID; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/WebsubSubscriptionConfiguration.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/WebsubSubscriptionConfiguration.java new file mode 100644 index 0000000000..a029c69cb0 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/WebsubSubscriptionConfiguration.java @@ -0,0 +1,61 @@ +/* + * 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.dto.APIInfo; + +/** + * This hold the Websub Subscription Configuration of an API. + */ +public class WebsubSubscriptionConfiguration { + private boolean enable; + private String secret; + private String signingAlgorithm; + private String signatureHeader; + + public boolean isEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + public String getSigningAlgorithm() { + return signingAlgorithm; + } + + public void setSigningAlgorithm(String signingAlgorithm) { + this.signingAlgorithm = signingAlgorithm; + } + + public String getSignatureHeader() { + return signatureHeader; + } + + public void setSignatureHeader(String signatureHeader) { + this.signatureHeader = signatureHeader; + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index a16e249002..d3a43eec02 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -17,19 +17,15 @@ */ package io.entgra.device.mgt.core.apimgt.webapp.publisher; +import com.google.gson.Gson; +import io.entgra.device.mgt.core.apimgt.annotations.Scopes; import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl; import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl; 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.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 io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.CORSConfiguration; +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.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; @@ -91,6 +87,7 @@ import java.util.Date; */ public class APIPublisherServiceImpl implements APIPublisherService { public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance(); + private static final Gson gson = new Gson(); private static final String UNLIMITED_TIER = "Unlimited"; private static final String WS_UNLIMITED_TIER = "AsyncUnlimited"; private static final String API_PUBLISH_ENVIRONMENT = "Default"; @@ -166,14 +163,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiConfig.getName(), apiConfig.getVersion()); PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); - JSONArray apiList = (JSONArray) publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo).get("list"); + APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo); boolean apiFound = false; - for (int i = 0; i < apiList.length(); i++) { - JSONObject apiObj = apiList.getJSONObject(i); - if (apiObj.getString("name").equals(apiIdentifier.getApiName().replace(Constants.SPACE, + for (int i = 0; i < apiList.length; i++) { + APIInfo apiObj = apiList[i]; + if (apiObj.getName().equals(apiIdentifier.getApiName().replace(Constants.SPACE, Constants.EMPTY_STRING))) { apiFound = true; - apiIdentifier.setUuid(apiObj.getString("id")); + apiIdentifier.setUuid(apiObj.getId()); break; } } @@ -194,13 +191,13 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } APIInfo api = getAPI(apiConfig, true); - JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api); - apiUuid = createdAPI.getString("id"); + APIInfo createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api); + apiUuid = createdAPI.getId(); if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) { publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo, apiUuid, apiConfig.getAsyncApiDefinition()); } - if (CREATED_STATUS.equals(createdAPI.getString("lifeCycleStatus"))) { + if (CREATED_STATUS.equals(createdAPI.getLifeCycleStatus())) { // if endpoint type "dynamic" and then add in sequence if ("dynamic".equals(apiConfig.getEndpointType())) { Mediation mediation = new Mediation(); @@ -272,12 +269,12 @@ public class APIPublisherServiceImpl implements APIPublisherService { } // Get existing API - JSONObject existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, + APIInfo existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiUuid); if (scopesToMoveAsSharedScopes.size() > 0) { // update API to remove local scopes APIInfo api = getAPI(apiConfig, false); - api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus")); + api.setLifeCycleStatus(existingAPI.getLifeCycleStatus()); publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api); for (ApiScope apiScope : scopesToMoveAsSharedScopes) { @@ -294,7 +291,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiUuid); APIInfo api = getAPI(apiConfig, true); - api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus")); + api.setLifeCycleStatus(existingAPI.getLifeCycleStatus()); api.setId(apiUuid); publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api); @@ -375,7 +372,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo, apiUuid, apiRevisionId, apiRevisionDeploymentList); - if (CREATED_STATUS.equals(existingAPI.getString("lifeCycleStatus"))) { + if (CREATED_STATUS.equals(existingAPI.getLifeCycleStatus())) { publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo, apiUuid, PUBLISH_ACTION); } @@ -779,55 +776,49 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiInfo.setRevisionedApiId(null); apiInfo.setEnableSchemaValidation(false); - Set tags = new HashSet<>(); + List tags = new ArrayList<>(); tags.addAll(Arrays.asList(config.getTags())); apiInfo.setTags(tags); - Set availableTiers = new HashSet<>(); + List availableTiers = new ArrayList<>(); if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) { availableTiers.add(WS_UNLIMITED_TIER); } else { availableTiers.add(UNLIMITED_TIER); } apiInfo.setPolicies(availableTiers); - - if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) { - apiInfo.setAsyncApiDefinition(config.getAsyncApiDefinition()); - } + apiInfo.setApiThrottlingPolicy(UNLIMITED_TIER); //set operations and scopes - List operations = new ArrayList(); + List operations = new ArrayList(); List scopeSet = new ArrayList(); Iterator iterator; + for (iterator = config.getUriTemplates().iterator(); iterator.hasNext(); ) { ApiUriTemplate apiUriTemplate = iterator.next(); - JSONObject operation = new JSONObject(); - operation.put("target", apiUriTemplate.getUriTemplate()); - operation.put("verb", apiUriTemplate.getHttpVerb()); - operation.put("authType", apiUriTemplate.getAuthType()); - operation.put("throttlingPolicy", UNLIMITED_TIER); - operation.put("uriMapping", apiUriTemplate.getUriMapping()); + Operations operation = new Operations(); + operation.setTarget(apiUriTemplate.getUriTemplate()); + operation.setVerb(apiUriTemplate.getHttpVerb()); + operation.setAuthType(apiUriTemplate.getAuthType()); + operation.setThrottlingPolicy(UNLIMITED_TIER); + operation.setUriMapping(apiUriTemplate.getUriMapping()); if (includeScopes) { if (apiUriTemplate.getScope() != null) { - String scopeString = "{\n" + - " \"scope\": {\n" + - " \"id\": null,\n" + - " \"name\": \"" + apiUriTemplate.getScope().getKey() + "\",\n" + - " \"displayName\": \"" + apiUriTemplate.getScope().getName() + "\",\n" + - " \"description\": \"" + apiUriTemplate.getScope().getDescription() + "\",\n" + - " \"bindings\": [\n" + - " \"" + apiUriTemplate.getScope().getRoles() + "\"\n" + - " ],\n" + - " \"usageCount\": null\n" + - " },\n" + - " \"shared\": true\n" + - " }"; - JSONObject scope = new JSONObject(scopeString); - scopeSet.add(scope); - - Set scopes = new HashSet<>(); - scopes.add(apiUriTemplate.getScope().getKey()); - operation.put("scopes", scopes); + Scope scope = new Scope(); + scope.setName(apiUriTemplate.getScope().getKey()); + scope.setDisplayName(apiUriTemplate.getScope().getName()); + scope.setDescription(apiUriTemplate.getScope().getDescription()); + scope.setBindings(apiUriTemplate.getScope().getRoles()); + + JSONObject scopeObject = new JSONObject(); + scopeObject.put("scope", new JSONObject(gson.toJson(scope))); + scopeObject.put("shared", true); + + scopeSet.add(scopeObject); + + List scopes = new ArrayList<>(); + scopes.addAll(Arrays.asList(apiUriTemplate.getScope().getKey())); + operation.setScopes(scopes); } } operations.add(operation); @@ -855,8 +846,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { " }"; JSONObject endPointConfig = new JSONObject(endpointConfig); - Set transports = new HashSet<>(); - transports.addAll(Arrays.asList(config.getTransports())); + List transports = new ArrayList<>(); + transports.addAll(Arrays.asList(config.getTransports().split(","))); apiInfo.setTransport(transports); apiInfo.setType("HTTP"); @@ -872,7 +863,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { " }\n" + " }"; endPointConfig = new JSONObject(endpointConfig); - apiInfo.setInSequence(config.getInSequenceName()); + apiInfo.setEndpointImplementationType("ENDPOINT"); } // if ws endpoint @@ -888,7 +879,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { " }"; endPointConfig = new JSONObject(endpointConfig); - transports.addAll(Arrays.asList("wss,ws")); + transports.add("wss"); + transports.add("ws"); apiInfo.setTransport(transports); apiInfo.setType("WS"); } @@ -922,6 +914,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiInfo.setEnableSchemaValidation(false); apiInfo.setMonetization(null); apiInfo.setServiceInfo(null); + apiInfo.setWebsubSubscriptionConfiguration(null); + apiInfo.setAdvertiseInfo(null); return apiInfo; } From fa37fa33cc1d7b721b2e94e6456d466b770ddd46 Mon Sep 17 00:00:00 2001 From: pasindu Date: Fri, 6 Oct 2023 13:50:55 +0530 Subject: [PATCH 4/5] Map JsonObject to dto classes in publisher API revesion --- .../rest/api/PublisherRESTAPIServices.java | 23 +++--- .../api/PublisherRESTAPIServicesImpl.java | 70 +++++++++---------- .../rest/api/dto/APIInfo/APIRevision.java | 37 +++++++--- .../dto/APIInfo/APIRevisionDeployment.java | 26 +++---- .../publisher/APIPublisherServiceImpl.java | 45 ++++++------ 5 files changed, 103 insertions(+), 98 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index a191b0ac16..6793e06b92 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -19,16 +19,11 @@ 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.APIInfo.*; 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 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 java.util.List; @@ -63,8 +58,8 @@ public interface PublisherRESTAPIServices { String asyncApiDefinition) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - String apiUuid) + MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, @@ -72,18 +67,18 @@ public interface PublisherRESTAPIServices { throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - String uuid, Mediation mediation) + String uuid, Mediation mediation) throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, String action) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, - Boolean deploymentStatus) + APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, + Boolean deploymentStatus) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision) throws APIServicesException, BadRequestException, UnexpectedResponseException; @@ -92,11 +87,11 @@ public interface PublisherRESTAPIServices { throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject apiRevisionDeployment, String uuid) + APIRevision apiRevisionDeployment, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject apiRevision, String uuid) + APIRevision apiRevision, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index 05f0a3fe98..ac0d2434dc 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -643,7 +643,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { @@ -658,8 +658,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + JSONArray mediationPolicyList = (JSONArray) new JSONObject(response.body().string()).get("list"); + return gson.fromJson(mediationPolicyList.toString(), MediationPolicy[].class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -814,7 +814,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, + public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, Boolean deploymentStatus) throws APIServicesException, BadRequestException, UnexpectedResponseException { @@ -831,8 +831,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + JSONArray revisionList = (JSONArray) new JSONObject(response.body().string()).get("list"); + return gson.fromJson(revisionList.toString(), APIRevision[].class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -856,16 +856,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision) + public APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision) throws APIServicesException, BadRequestException, UnexpectedResponseException { String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions"; - String apiRevisionDescription = "{\n" + - " \"description\":\"" + apiRevision.getDescription() + "\"\n" + - "}"; + JSONObject payload = new JSONObject(); + 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() .url(addNewScope) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -876,8 +875,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_CREATED == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + return gson.fromJson(response.body().string(), APIRevision.class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -908,15 +906,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId; APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0); - String revision = "[\n" + - " {\n" + - " \"name\": \"" + apiRevisionDeployment.getDeployment() + "\",\n" + - " \"vhost\": \"" + apiRevisionDeployment.getVhost() + "\",\n" + - " \"displayOnDevportal\": " + apiRevisionDeployment.isDisplayOnDevportal() + "\n" + - " }\n" + - "]"; + JSONArray payload = new JSONArray(); + JSONObject revision = new JSONObject(); + revision.put("name", (apiRevisionDeployment.getName() != null ? apiRevisionDeployment.getName() : "")); + revision.put("vhost", (apiRevisionDeployment.getVhost() != null ? apiRevisionDeployment.getVhost() : "")); + revision.put("displayOnDevportal", apiRevisionDeployment.isDisplayOnDevportal()); + payload.put(revision); - RequestBody requestBody = RequestBody.create(JSON, revision); + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(deployAPIRevisionEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -953,23 +950,22 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { @Override public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject apiRevisionDeployment, String uuid) + APIRevision apiRevisionDeployment, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId=" - + apiRevisionDeployment.getString("id"); - JSONArray array = apiRevisionDeployment.getJSONArray("deploymentInfo"); - JSONObject obj = array.getJSONObject(0); - - String revision = "[\n" + - " {\n" + - " \"name\": \"" + obj.getString("name") + "\",\n" + - " \"vhost\": \"" + obj.getString("vhost") + "\",\n" + - " \"displayOnDevportal\": " + obj.get("displayOnDevportal") + "\n" + - " }\n" + - "]"; - - RequestBody requestBody = RequestBody.create(JSON, revision); + + apiRevisionDeployment.getId(); + List apiRevisionDeployments = apiRevisionDeployment.getDeploymentInfo(); + APIRevisionDeployment earliestDeployment = apiRevisionDeployments.get(0); + + JSONArray payload = new JSONArray(); + JSONObject revision = new JSONObject(); + revision.put("name", (earliestDeployment.getName() != null ? earliestDeployment.getName() : "")); + revision.put("vhost", (earliestDeployment.getVhost() != null ? earliestDeployment.getVhost() : "")); + revision.put("displayOnDevportal", earliestDeployment.isDisplayOnDevportal()); + payload.put(revision); + + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(undeployAPIRevisionEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -1005,11 +1001,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { @Override public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject apiRevision, String uuid) + APIRevision apiRevision, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" + - apiRevision.getString("id"); + apiRevision.getId(); Request request = new Request.Builder() .url(apiRevisionEndPoint) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevision.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevision.java index 581fbb1792..c3f3b5831b 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevision.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevision.java @@ -17,26 +17,26 @@ */ 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.util.List; public class APIRevision implements Serializable { private static final long serialVersionUID = 1L; - private int id; + private String id; private String apiUUID; private String revisionUUID; private String description; + private String displayName; private String createdBy; private String createdTime; - private List apiRevisionDeploymentList; + private APIInfo apiInfo; + private List deploymentInfo; - public int getId() { + public String getId() { return id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } @@ -80,11 +80,28 @@ public class APIRevision implements Serializable { this.createdTime = createdTime; } - public List getApiRevisionDeploymentList() { - return apiRevisionDeploymentList; + public List getDeploymentInfo() { + return deploymentInfo; + } + + public void setDeploymentInfo(List deploymentInfo) { + this.deploymentInfo = deploymentInfo; + } + + public String getDisplayName() { + return displayName; } - public void setApiRevisionDeploymentList(List apiRevisionDeploymentList) { - this.apiRevisionDeploymentList = apiRevisionDeploymentList; + public void setDisplayName(String displayName) { + this.displayName = displayName; } + + public APIInfo getApiInfo() { + return apiInfo; + } + + public void setApiInfo(APIInfo apiInfo) { + this.apiInfo = apiInfo; + } + } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevisionDeployment.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevisionDeployment.java index 20c84232cc..4be3a64836 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevisionDeployment.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/APIRevisionDeployment.java @@ -23,10 +23,10 @@ import java.io.Serializable; public class APIRevisionDeployment implements Serializable { private static final long serialVersionUID = 1L; private int id; - private String revisionUUID; - private String deployment; + private String revisionUuid; + private String name; private String vhost; - private boolean isDisplayOnDevportal; + private boolean displayOnDevportal; private String deployedTime; public int getId() { @@ -37,20 +37,20 @@ public class APIRevisionDeployment implements Serializable { this.id = id; } - public String getRevisionUUID() { - return revisionUUID; + public String getRevisionUuid() { + return revisionUuid; } - public void setRevisionUUID(String revisionUUID) { - this.revisionUUID = revisionUUID; + public void setRevisionUuid(String revisionUuid) { + this.revisionUuid = revisionUuid; } - public String getDeployment() { - return deployment; + public String getName() { + return name; } - public void setDeployment(String deployment) { - this.deployment = deployment; + public void setName(String name) { + this.name = name; } public String getVhost() { @@ -62,11 +62,11 @@ public class APIRevisionDeployment implements Serializable { } public boolean isDisplayOnDevportal() { - return isDisplayOnDevportal; + return displayOnDevportal; } public void setDisplayOnDevportal(boolean displayOnDevportal) { - isDisplayOnDevportal = displayOnDevportal; + this.displayOnDevportal = displayOnDevportal; } public String getDeployedTime() { diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index d3a43eec02..d32a7d6d30 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -215,10 +215,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiRevision.setApiUUID(apiUuid); apiRevision.setDescription("Initial Revision"); String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey, - accessTokenInfo, apiRevision).getString("id"); + accessTokenInfo, apiRevision).getId(); APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment(); - apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT); + apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT); apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host")); apiRevisionDeployment.setDisplayOnDevportal(true); @@ -308,15 +308,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { mediation.setType("in"); mediation.setGlobal(false); - JSONArray mediationList = (JSONArray) publisherRESTAPIServices - .getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, - apiUuid).get("list"); + MediationPolicy[] mediationList = publisherRESTAPIServices + .getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, apiUuid); boolean isMediationPolicyFound = false; - for (int i = 0; i < mediationList.length(); i++) { - JSONObject mediationObj = mediationList.getJSONObject(i); - if (apiConfig.getInSequenceName().equals(mediationObj.getString("name"))) { - mediation.setUuid(mediationObj.getString("id")); + for (int i = 0; i < mediationList.length; i++) { + MediationPolicy mediationPolicy = mediationList[i]; + if (apiConfig.getInSequenceName().equals(mediationPolicy.getName())) { + mediation.setUuid(mediationPolicy.getId()); publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiApplicationKey, accessTokenInfo, apiUuid, mediation); publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey, @@ -331,24 +330,22 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } - int apiRevisionCount = (int) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey, - accessTokenInfo, apiUuid, null).get("count"); + int apiRevisionCount = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey, + accessTokenInfo, apiUuid, null).length; if (apiRevisionCount >= 5) { // This will retrieve the deployed revision - JSONArray revisionDeploymentList = (JSONArray) publisherRESTAPIServices.getAPIRevisions( - apiApplicationKey, accessTokenInfo, apiUuid, - true).get("list"); - if (revisionDeploymentList.length() > 0) { - JSONObject latestRevisionDeployment = revisionDeploymentList.getJSONObject(0); + APIRevision[] revisionDeploymentList = publisherRESTAPIServices.getAPIRevisions( + apiApplicationKey, accessTokenInfo, apiUuid, true); + if (revisionDeploymentList.length > 0) { + APIRevision latestRevisionDeployment = revisionDeploymentList[0]; publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey, accessTokenInfo, latestRevisionDeployment, apiUuid); } - // This will retrieve the un deployed revision list - JSONArray undeployedRevisionList = (JSONArray) publisherRESTAPIServices.getAPIRevisions( - apiApplicationKey, accessTokenInfo, apiUuid, - false).get("list"); - if (undeployedRevisionList.length() > 0) { - JSONObject earliestUndeployRevision = undeployedRevisionList.getJSONObject(0); + // This will retrieve the undeployed revision list + APIRevision[] undeployedRevisionList = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey, + accessTokenInfo, apiUuid, false); + if (undeployedRevisionList.length > 0) { + APIRevision earliestUndeployRevision = undeployedRevisionList[0]; publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo, earliestUndeployRevision, apiUuid); } @@ -359,10 +356,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiRevision.setApiUUID(apiUuid); apiRevision.setDescription("Updated Revision"); String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey, - accessTokenInfo, apiRevision).getString("id"); + accessTokenInfo, apiRevision).getId(); APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment(); - apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT); + apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT); apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host")); apiRevisionDeployment.setDisplayOnDevportal(true); From 1325780e3b3f4541536ed7e2b0b738db23dffbf4 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 9 Oct 2023 14:56:45 +0530 Subject: [PATCH 5/5] Map JsonObject to dto classes in publisher API documentation --- .../rest/api/PublisherRESTAPIServices.java | 2 +- .../api/PublisherRESTAPIServicesImpl.java | 31 +++++----- .../rest/api/dto/APIInfo/Documentation.java | 61 ++++++++++++++++--- .../publisher/APIPublisherServiceImpl.java | 20 +++--- 4 files changed, 79 insertions(+), 35 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 6793e06b92..b86437b6f3 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -94,7 +94,7 @@ public interface PublisherRESTAPIServices { APIRevision apiRevision, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; - JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index ac0d2434dc..8ba8bb12f7 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -644,7 +644,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { @Override public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - String apiUuid) + String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAPIMediationEndPoint = endPointPrefix + Constants.API_ENDPOINT + apiUuid + "/mediation-policies"; @@ -815,7 +815,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { @Override public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, - Boolean deploymentStatus) + Boolean deploymentStatus) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAPIRevisionsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions?query=deployed:" @@ -1041,7 +1041,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid) + public Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getDocumentationsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents?limit=1000"; @@ -1056,8 +1056,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { try { Response response = client.newCall(request).execute(); if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; + JSONArray documentList = (JSONArray) new JSONObject(response.body().string()).get("list"); + return gson.fromJson(documentList.toString(), Documentation[].class); } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. @@ -1127,17 +1127,16 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid + "/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); + JSONObject payload = new JSONObject(); + payload.put("name", documentation.getName()); + payload.put("type", documentation.getType()); + payload.put("summary", documentation.getSummary()); + payload.put("sourceType", documentation.getSourceType()); + payload.put("inlineContent", documentation.getSourceType()); + payload.put("visibility", documentation.getVisibility()); + payload.put("createdBy", documentation.getCreatedBy()); + + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); Request request = new Request.Builder() .url(addNewScope) .addHeader(Constants.HEADER_CONTENT_TYPE, Constants.APPLICATION_JSON) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Documentation.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Documentation.java index 5d54bc7567..5d4c733b42 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Documentation.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIInfo/Documentation.java @@ -24,16 +24,21 @@ public class Documentation { private static final long serialVersionUID = 1L; private String id; private String documentId; - private DocumentationType type; private String name; + private DocumentationType type; private String summary; private DocumentSourceType sourceType; private String sourceUrl; - private DocumentVisibility visibility; - private Date lastUpdated; + private String fileName; private String filePath; - private Date createdDate; + private String inlineContent; private String otherTypeName; + private DocumentVisibility visibility; + private String createdTime; + private Date createdDate; + private String createdBy; + private Date lastUpdatedTime; + private String lastUpdatedBy; public String getOtherTypeName() { return this.otherTypeName; @@ -113,12 +118,12 @@ public class Documentation { return result; } - public Date getLastUpdated() { - return this.lastUpdated; + public Date getLastUpdatedTime() { + return this.lastUpdatedTime; } - public void setLastUpdated(Date lastUpdated) { - this.lastUpdated = lastUpdated; + public void setLastUpdatedTime(Date lastUpdatedTime) { + this.lastUpdatedTime = lastUpdatedTime; } public String getId() { @@ -145,6 +150,46 @@ public class Documentation { this.createdDate = createdDate; } + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getInlineContent() { + return inlineContent; + } + + public void setInlineContent(String inlineContent) { + this.inlineContent = inlineContent; + } + + public String getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(String createdTime) { + this.createdTime = createdTime; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getLastUpdatedBy() { + return lastUpdatedBy; + } + + public void setLastUpdatedBy(String lastUpdatedBy) { + this.lastUpdatedBy = lastUpdatedBy; + } + public static enum DocumentVisibility { OWNER_ONLY("owner_only"), PRIVATE("private"), diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index d32a7d6d30..1691776be5 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -397,27 +397,27 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiDocumentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL); apiDocumentation.setSourceType(Documentation.DocumentSourceType.MARKDOWN); apiDocumentation.setCreatedDate(new Date()); - apiDocumentation.setLastUpdated(new Date()); + apiDocumentation.setLastUpdatedTime(new Date()); apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary()); apiDocumentation.setOtherTypeName(null); - JSONArray documentList = (JSONArray) publisherRESTAPIServices.getDocumentations(apiApplicationKey, - accessTokenInfo, apiUuid).get("list"); + Documentation[] documentList = publisherRESTAPIServices.getDocumentations(apiApplicationKey, + accessTokenInfo, apiUuid); - 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(Documentation.DocumentationType.HOWTO.name())) { + if (documentList.length > 0) { + for (int i = 0; i < documentList.length; i++) { + Documentation existingDoc = documentList[i]; + if (existingDoc.getName().equals(apiConfig.getApiDocumentationName()) + && existingDoc.getType().equals(Documentation.DocumentationType.HOWTO.name())) { publisherRESTAPIServices.deleteDocumentations(apiApplicationKey, accessTokenInfo, - apiUuid, existingDoc.getString("documentId")); + apiUuid, existingDoc.getDocumentId()); } } } else { log.info("There is no any existing api documentation."); } - io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo, + Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo, apiUuid, apiDocumentation); publisherRESTAPIServices.addDocumentationContent(apiApplicationKey, accessTokenInfo, apiUuid,