Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add changes to add subscription status to application.yaml when exporting and to support ignoreTier query param when importing #12442

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
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) {

Check warning on line 30 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java#L30

Added line #L30 was not covered by tests
this.apiId = apiId;
this.subscriber = subscriber;
this.throttlingPolicy = throttlingPolicy;
this.subscriptionStatus = subscriptionStatus;

Check warning on line 34 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java#L34

Added line #L34 was not covered by tests
}

public APIIdentifier getApiId() {
Expand All @@ -55,4 +57,12 @@
public void setThrottlingPolicy(String throttlingPolicy) {
this.throttlingPolicy = throttlingPolicy;
}

public String getSubscriptionStatus() {
return subscriptionStatus;

Check warning on line 62 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java#L62

Added line #L62 was not covered by tests
}

public void setSubscriptionStatus(String subscriptionStatus) {
this.subscriptionStatus = subscriptionStatus;
}

Check warning on line 67 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/models/ExportedSubscribedAPI.java#L66-L67

Added lines #L66 - L67 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
Set<ExportedSubscribedAPI> 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());

Check warning on line 154 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ExportUtils.java#L154

Added line #L154 was not covered by tests
exportedSubscribedAPIs.add(exportedSubscribedAPI);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
* @throws UserStoreException if an error occurs while checking whether the tenant domain exists
*/
public static List<APIIdentifier> importSubscriptions(Set<ExportedSubscribedAPI> subscribedAPIs, String userId,
Application application, Boolean update,
Application application, Boolean update,Boolean ignoreTier,
APIConsumer apiConsumer, String organization)
throws APIManagementException,
UserStoreException {
Expand Down Expand Up @@ -253,6 +253,18 @@
// 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);

Check warning on line 258 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L258

Added line #L258 was not covered by tests
// 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);

Check warning on line 262 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L262

Added line #L262 was not covered by tests
} else if (!apiConsumer.isSubscribedToApp(subscribedAPI.getApiId(), userId
, application.getId())) {

Check warning on line 264 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L264

Added line #L264 was not covered by tests
// on update skip subscriptions that already exists
apiConsumer.addSubscription(apiTypeWrapper, userId, application);

Check warning on line 266 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L266

Added line #L266 was not covered by tests
}
} else {
log.error("Failed to import Subscription as API/API Product "
+ apiIdentifier.getName() + "-" + apiIdentifier.getVersion() + " as one or more " +
Expand Down Expand Up @@ -308,10 +320,10 @@
}
}
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

Check warning on line 323 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L323

Added line #L323 was not covered by tests
.getId().getVersion());
} else {
log.error(
log.warn(

Check warning on line 326 in components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/utils/ImportUtils.java#L326

Added line #L326 was not covered by tests
"Tier:" + targetTierName + " is not available for API Product " + apiProduct.getId().getName() + "-"
+ apiProduct.getId().getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading