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 4e7d79403aa..b86437b6f31 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,23 +19,18 @@ 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; 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) @@ -47,13 +42,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) @@ -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; @@ -91,15 +86,15 @@ public interface PublisherRESTAPIServices { String apiRevisionId, List apiRevisionDeploymentList) throws APIServicesException, BadRequestException, UnexpectedResponseException; - abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - JSONObject apiRevisionDeployment, String uuid) + boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + 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, + Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid) throws APIServicesException, BadRequestException, UnexpectedResponseException; @@ -107,7 +102,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 40a8e92c613..8ba8bb12f72 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,18 +21,12 @@ 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; 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; @@ -56,7 +50,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; @@ -70,8 +64,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. @@ -124,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,14 +138,21 @@ 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(); + if (scope.getBindings() != null) { + for (String str : scope.getBindings()) { + bindings.put(str); + } + } + + JSONObject payload = new JSONObject(); + 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, 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 +192,21 @@ 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(); + if (scope.getBindings() != null) { + for (String str : scope.getBindings()) { + bindings.put(str); + } + } + + JSONObject payload = new JSONObject(); + 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, 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 @@ -233,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; @@ -247,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. @@ -272,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; @@ -286,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. @@ -311,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" + - "}"; - - RequestBody requestBody = RequestBody.create(JSON, apiString); + 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, payload.toString()); Request request = new Request.Builder() .url(addAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -374,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. @@ -404,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" + - "}"; - - RequestBody requestBody = RequestBody.create(JSON, apiString); + 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, payload.toString()); Request request = new Request.Builder() .url(updateAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -463,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. @@ -534,8 +643,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - String apiUuid) + public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + String apiUuid) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAPIMediationEndPoint = endPointPrefix + Constants.API_ENDPOINT + apiUuid + "/mediation-policies"; @@ -549,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. @@ -623,7 +732,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(); @@ -705,8 +814,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } @Override - public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, - Boolean deploymentStatus) + public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid, + Boolean deploymentStatus) throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAPIRevisionsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions?query=deployed:" @@ -722,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. @@ -747,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 @@ -767,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. @@ -799,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 @@ -844,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 @@ -896,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) @@ -936,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"; @@ -951,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. @@ -1022,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/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 b7443b0f535..a48a10c9e3e 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 00000000000..5925b3c79a3 --- /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/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 581fbb17926..c3f3b5831b5 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 20c84232cce..4be3a64836c 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.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 00000000000..fbb51bc0813 --- /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/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 5d54bc7567b..5d4c733b424 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.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 00000000000..9db34dbe384 --- /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 00000000000..5b014fbe58f --- /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 2dd00c44828..51e5d0c3de6 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/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 01d3f53d360..53a40e27079 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.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; - String 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 String getRoles() { - return roles; + public List getBindings() { + return bindings; } - public void setRoles(String roles) { - this.roles = roles; + public void setBindings(List bindings) { + this.bindings = removeDuplicatesFromRoleString(bindings); } public String getDescription() { @@ -87,14 +91,22 @@ 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) { + 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/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 00000000000..cfbcf2ea662 --- /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 00000000000..b9594830f93 --- /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 00000000000..a029c69cb0d --- /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.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 58cff08553b..00000000000 --- 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 69f20fa0203..1691776be53 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"; @@ -100,7 +97,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); @@ -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; } } @@ -184,21 +181,23 @@ 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); } } 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(); @@ -216,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); @@ -257,10 +256,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); } @@ -268,27 +269,29 @@ 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) { 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); } } 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); @@ -305,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, @@ -328,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); } @@ -356,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); @@ -369,7 +369,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); } @@ -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, @@ -458,10 +458,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 +502,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,52 +547,43 @@ 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); 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); - - //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)) { - scope.setId(scopeObj.getString("id")); - -// Including already existing roles - JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); - for (int j = 0; j < existingRolesArray.length(); j++) { - roleString = roleString + "," + existingRolesArray.get(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(roleString); + 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()) { @@ -601,12 +596,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"; @@ -642,13 +632,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 { @@ -680,7 +671,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. @@ -688,7 +679,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); @@ -699,22 +690,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) { @@ -724,14 +714,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); @@ -783,55 +773,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); @@ -859,8 +843,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"); @@ -876,7 +860,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { " }\n" + " }"; endPointConfig = new JSONObject(endpointConfig); - apiInfo.setInSequence(config.getInSequenceName()); + apiInfo.setEndpointImplementationType("ENDPOINT"); } // if ws endpoint @@ -892,7 +876,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"); } @@ -926,6 +911,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiInfo.setEnableSchemaValidation(false); apiInfo.setMonetization(null); apiInfo.setServiceInfo(null); + apiInfo.setWebsubSubscriptionConfiguration(null); + apiInfo.setAdvertiseInfo(null); return apiInfo; } 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 5d178a0eb36..ea5f6d3047f 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 704de6442c3..b044c9f72a4 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 988bd9c5f70..85f0d520f9f 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);