diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json index a7fa59630d63..8040e385bd35 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json @@ -1354,8 +1354,8 @@ "type" : "string", "example" : "EXCHANGED", "description" : "The type of the tokens to be used (exchanged or without exchanged). Accepted values are EXCHANGED, DIRECT or BOTH.", - "enum" : [ "EXCHANGED", "DIRECT", "BOTH" ], - "default" : "DIRECT" + "default" : "DIRECT", + "enum" : [ "EXCHANGED", "DIRECT", "BOTH" ] } } }, diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml index b99d43642ed8..9aa71906468b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/devportal-api.yaml @@ -2537,6 +2537,12 @@ paths: Update if application exists schema: type: boolean + - name: ignoreTier + in: query + description: | + Ignore tier and proceed with subscribed APIs + schema: + type: boolean requestBody: content: multipart/form-data: diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java index 66e3b162daeb..c1d536b58a9a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApi.java @@ -507,8 +507,8 @@ public Response applicationsExportGet( @NotNull @ApiParam(value = "Application N @ApiResponse(code = 207, message = "Multi Status. Partially successful response with skipped APIs information object as entity in the body. ", response = APIInfoListDTO.class), @ApiResponse(code = 400, message = "Bad Request. Invalid request or validation error.", response = ErrorDTO.class), @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) }) - public Response applicationsImportPost( @Multipart(value = "file") InputStream fileInputStream, @Multipart(value = "file" ) Attachment fileDetail, @ApiParam(value = "Preserve Original Creator of the Application ") @QueryParam("preserveOwner") Boolean preserveOwner, @ApiParam(value = "Skip importing Subscriptions of the Application ") @QueryParam("skipSubscriptions") Boolean skipSubscriptions, @ApiParam(value = "Expected Owner of the Application in the Import Environment ") @QueryParam("appOwner") String appOwner, @ApiParam(value = "Skip importing Keys of the Application ") @QueryParam("skipApplicationKeys") Boolean skipApplicationKeys, @ApiParam(value = "Update if application exists ") @QueryParam("update") Boolean update) throws APIManagementException{ - return delegate.applicationsImportPost(fileInputStream, fileDetail, preserveOwner, skipSubscriptions, appOwner, skipApplicationKeys, update, securityContext); + public Response applicationsImportPost( @Multipart(value = "file") InputStream fileInputStream, @Multipart(value = "file" ) Attachment fileDetail, @ApiParam(value = "Preserve Original Creator of the Application ") @QueryParam("preserveOwner") Boolean preserveOwner, @ApiParam(value = "Skip importing Subscriptions of the Application ") @QueryParam("skipSubscriptions") Boolean skipSubscriptions, @ApiParam(value = "Expected Owner of the Application in the Import Environment ") @QueryParam("appOwner") String appOwner, @ApiParam(value = "Skip importing Keys of the Application ") @QueryParam("skipApplicationKeys") Boolean skipApplicationKeys, @ApiParam(value = "Update if application exists ") @QueryParam("update") Boolean update, @ApiParam(value = "Ignore tier and proceed with subscribed APIs ") @QueryParam("ignoreTier") Boolean ignoreTier) throws APIManagementException{ + return delegate.applicationsImportPost(fileInputStream, fileDetail, preserveOwner, skipSubscriptions, appOwner, skipApplicationKeys, update, ignoreTier, securityContext); } @POST diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java index 5afc3a221695..eeb050ca82f6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/store/v1/ApplicationsApiService.java @@ -60,6 +60,6 @@ public interface ApplicationsApiService { public Response applicationsApplicationIdResetThrottlePolicyPost(String applicationId, ApplicationThrottleResetDTO applicationThrottleResetDTO, MessageContext messageContext) throws APIManagementException; public Response applicationsExportGet(String appName, String appOwner, Boolean withKeys, String format, MessageContext messageContext) throws APIManagementException; public Response applicationsGet(String groupId, String query, String sortBy, String sortOrder, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) throws APIManagementException; - public Response applicationsImportPost(InputStream fileInputStream, Attachment fileDetail, Boolean preserveOwner, Boolean skipSubscriptions, String appOwner, Boolean skipApplicationKeys, Boolean update, MessageContext messageContext) throws APIManagementException; + public Response applicationsImportPost(InputStream fileInputStream, Attachment fileDetail, Boolean preserveOwner, Boolean skipSubscriptions, String appOwner, Boolean skipApplicationKeys, Boolean update, Boolean ignoreTier, MessageContext messageContext) throws APIManagementException; public Response applicationsPost(ApplicationDTO applicationDTO, MessageContext messageContext) throws APIManagementException; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java index 616753f2b2d0..1bfb1e365880 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/impl/ApplicationsApiServiceImpl.java @@ -133,7 +133,7 @@ public Response applicationsGet(String groupId, String query, String sortBy, Str // todo: Do a second level filtering for the incoming group ID. // todo: eg: use case is when there are lots of applications which is accessible to his group "g1", he wants to see - // todo: what are the applications shared to group "g2" among them. + // todo: what are the applications shared to group "g2" among them. groupId = RestApiUtil.getLoggedInUserGroupId(); try { String organization = RestApiUtil.getValidatedOrganization(messageContext); @@ -201,12 +201,13 @@ public Response applicationsGet(String groupId, String query, String sortBy, Str * @param appOwner Target owner of the application * @param skipApplicationKeys Skip application keys while importing * @param update Update if existing application found or import + * @param ignoreTier Ignore tier and proceed with subscribed APIs * @param messageContext Message Context * @return imported Application */ @Override public Response applicationsImportPost(InputStream fileInputStream, Attachment fileDetail, Boolean preserveOwner, Boolean skipSubscriptions, String appOwner, Boolean skipApplicationKeys, - Boolean update, MessageContext messageContext) throws APIManagementException { + Boolean update, Boolean ignoreTier, MessageContext messageContext) throws APIManagementException { String ownerId; Application application; @@ -259,7 +260,7 @@ public Response applicationsGet(String groupId, String query, String sortBy, Str if (skipSubscriptions == null || !skipSubscriptions) { skippedAPIs = ImportUtils .importSubscriptions(exportedApplication.getSubscribedAPIs(), ownerId, application, - update, apiConsumer, organization); + update, ignoreTier, apiConsumer, organization); } Application importedApplication = apiConsumer.getApplicationById(application.getId()); importedApplication.setOwner(ownerId); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java index 01653ad6912c..f9fc894667f6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java @@ -25,11 +25,13 @@ public class ExportedSubscribedAPI { private APIIdentifier apiId; private Subscriber subscriber; private String throttlingPolicy; + private String subscriptionStatus; - public ExportedSubscribedAPI(APIIdentifier apiId, Subscriber subscriber, String throttlingPolicy) { + public ExportedSubscribedAPI(APIIdentifier apiId, Subscriber subscriber, String throttlingPolicy, String subscriptionStatus) { this.apiId = apiId; this.subscriber = subscriber; this.throttlingPolicy = throttlingPolicy; + this.subscriptionStatus = subscriptionStatus; } public APIIdentifier getApiId() { @@ -55,4 +57,12 @@ public String getThrottlingPolicy() { public void setThrottlingPolicy(String throttlingPolicy) { this.throttlingPolicy = throttlingPolicy; } + + public String getSubscriptionStatus() { + return subscriptionStatus; + } + + public void setSubscriptionStatus(String subscriptionStatus) { + this.subscriptionStatus = subscriptionStatus; + } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java index a1c3eae28b4f..8a3e4cf242e0 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java @@ -151,7 +151,7 @@ private static ExportedApplication createApplicationDTOToExport(Application appl Set exportedSubscribedAPIs = new HashSet<>(); for (SubscribedAPI subscribedAPI : subscribedAPIs) { ExportedSubscribedAPI exportedSubscribedAPI = new ExportedSubscribedAPI(subscribedAPI.getAPIIdentifier(), - subscribedAPI.getSubscriber(), subscribedAPI.getTier().getName()); + subscribedAPI.getSubscriber(), subscribedAPI.getTier().getName(), subscribedAPI.getSubStatus()); exportedSubscribedAPIs.add(exportedSubscribedAPI); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java index 7e36e5f62c94..964a0109e8c3 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java @@ -154,7 +154,7 @@ public static APIKey getAPIKeyFromApplicationKeyDTO(ApplicationKeyDTO applicatio * @throws UserStoreException if an error occurs while checking whether the tenant domain exists */ public static List importSubscriptions(Set subscribedAPIs, String userId, - Application application, Boolean update, + Application application, Boolean update,Boolean ignoreTier, APIConsumer apiConsumer, String organization) throws APIManagementException, UserStoreException { @@ -253,6 +253,18 @@ public static List importSubscriptions(Set // on update skip subscriptions that already exists apiConsumer.addSubscription(apiTypeWrapper, userId, application); } + } else if (ignoreTier != null && ignoreTier && apiTypeWrapper.getStatus() != null + && APIConstants.PUBLISHED.equals(apiTypeWrapper.getStatus())) { + apiTypeWrapper.setTier(targetTier); + // Add subscription if update flag is not specified + // It will throw an error if subscriber already exists + if (update == null || !update) { + apiConsumer.addSubscription(apiTypeWrapper, userId, application); + } else if (!apiConsumer.isSubscribedToApp(subscribedAPI.getApiId(), userId + , application.getId())) { + // on update skip subscriptions that already exists + apiConsumer.addSubscription(apiTypeWrapper, userId, application); + } } else { log.error("Failed to import Subscription as API/API Product " + apiIdentifier.getName() + "-" + apiIdentifier.getVersion() + " as one or more " + @@ -308,10 +320,10 @@ private static boolean isTierAvailable(String targetTierName, ApiTypeWrapper api } } if (!apiTypeWrapper.isAPIProduct()) { - log.error("Tier:" + targetTierName + " is not available for API " + api.getId().getApiName() + "-" + api + log.warn("Tier:" + targetTierName + " is not available for API " + api.getId().getApiName() + "-" + api .getId().getVersion()); } else { - log.error( + log.warn( "Tier:" + targetTierName + " is not available for API Product " + apiProduct.getId().getName() + "-" + apiProduct.getId().getVersion()); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml index b99d43642ed8..9aa71906468b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/resources/devportal-api.yaml @@ -2537,6 +2537,12 @@ paths: Update if application exists schema: type: boolean + - name: ignoreTier + in: query + description: | + Ignore tier and proceed with subscribed APIs + schema: + type: boolean requestBody: content: multipart/form-data: