Skip to content

Commit

Permalink
Add changes to add subscription status to application.yaml when expor…
Browse files Browse the repository at this point in the history
…ting and to support ignoreTier query param when importing
  • Loading branch information
shnrndk committed May 10, 2024
1 parent 9c6829f commit ea285be
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 13 deletions.
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 @@ -2534,6 +2534,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 @@ -485,8 +485,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 @@ -58,6 +58,6 @@ public interface ApplicationsApiService {
public Response applicationsApplicationIdPut(String applicationId, ApplicationDTO applicationDTO, String ifMatch, 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 @@ -131,7 +131,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 @@ -199,12 +199,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 @@ -257,7 +258,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 @@ 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() {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static ExportedApplication createApplicationDTOToExport(Application appl
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());
exportedSubscribedAPIs.add(exportedSubscribedAPI);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public static APIKey getAPIKeyFromApplicationKeyDTO(ApplicationKeyDTO applicatio
* @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, APIConsumer apiConsumer, String organization)
Application application, Boolean update,Boolean ignoreTier,
APIConsumer apiConsumer, String organization)
throws APIManagementException,
UserStoreException {
List<APIIdentifier> skippedAPIList = new ArrayList<>();
Expand Down Expand Up @@ -189,6 +190,18 @@ public static List<APIIdentifier> importSubscriptions(Set<ExportedSubscribedAPI>
// 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 tiers may "
Expand Down Expand Up @@ -243,10 +256,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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,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

0 comments on commit ea285be

Please sign in to comment.