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

Update the GET applications API to exclude system apps when the excludeSystemApps=true query parameter is included. #667

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -481,9 +481,9 @@ public Response getAllApplicationTemplates( @Valid@ApiParam(value = "Maximum
@ApiResponse(code = 500, message = "Server Error", response = Error.class),
@ApiResponse(code = 501, message = "Not Implemented", response = Error.class)
})
public Response getAllApplications( @Valid @Min(1)@ApiParam(value = "Maximum number of records to return. ", defaultValue="30") @DefaultValue("30") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Number of records to skip for pagination. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew', and 'eq' operations with 'and', 'or' logical operators. Please note that 'and' and 'or' operators in filters follow the general precedence of logical operators ex: A and B or C and D = (A and B) or (C and D)). Currently supports only filtering based on the 'name', the 'clientId', and the 'issuer' attributes. /applications?filter=name+eq+user_portal <br> /applications?filter=name+co+prod+or+clientId+co+123 ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _This parameter is not supported yet._ ", allowableValues="ASC, DESC") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _This parameter is not supported yet._ ") @QueryParam("sortBy") String sortBy, @Valid@ApiParam(value = "Specifies the required parameters in the response. Currently supports for only 'advancedConfigurations', 'templateId', 'templateVersion', 'clientId', 'issuer', 'applicationEnabled' and 'associatedRoles.allowedAudience' attributes. /applications?attributes=advancedConfigurations,templateId,templateVersion,clientId,applicationEnabled,associatedRoles.allowedAudience ") @QueryParam("attributes") String attributes) {
public Response getAllApplications( @Valid @Min(1)@ApiParam(value = "Maximum number of records to return. ", defaultValue="30") @DefaultValue("30") @QueryParam("limit") Integer limit, @Valid@ApiParam(value = "Number of records to skip for pagination. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @Valid@ApiParam(value = "Condition to filter the retrieval of records. Supports 'sw', 'co', 'ew', and 'eq' operations with 'and', 'or' logical operators. Please note that 'and' and 'or' operators in filters follow the general precedence of logical operators ex: A and B or C and D = (A and B) or (C and D)). Currently supports only filtering based on the 'name', the 'clientId', and the 'issuer' attributes. /applications?filter=name+eq+user_portal <br> /applications?filter=name+co+prod+or+clientId+co+123 ") @QueryParam("filter") String filter, @Valid@ApiParam(value = "Define the order in which the retrieved records should be sorted. _This parameter is not supported yet._ ", allowableValues="ASC, DESC") @QueryParam("sortOrder") String sortOrder, @Valid@ApiParam(value = "Attribute by which the retrieved records should be sorted. _This parameter is not supported yet._ ") @QueryParam("sortBy") String sortBy, @Valid@ApiParam(value = "Specifies the required parameters in the response. Currently supports for only 'advancedConfigurations', 'templateId', 'templateVersion', 'clientId', 'issuer', 'applicationEnabled' and 'associatedRoles.allowedAudience' attributes. /applications?attributes=advancedConfigurations,templateId,templateVersion,clientId,applicationEnabled,associatedRoles.allowedAudience ") @QueryParam("attributes") String attributes, @Valid@ApiParam(value = "Specifies whether to exclude system applications when exporting applications. ", defaultValue="false") @DefaultValue("false") @QueryParam("excludeSystemApps") Boolean excludeSystemApps) {

return delegate.getAllApplications(limit, offset, filter, sortOrder, sortBy, attributes );
return delegate.getAllApplications(limit, offset, filter, sortOrder, sortBy, attributes, excludeSystemApps );
}

@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public interface ApplicationsApiService {

public Response getAllApplicationTemplates(Integer limit, Integer offset, SearchContext searchContext);

public Response getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String attributes);
public Response getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String attributes, Boolean excludeSystemApps);

public Response getApplication(String applicationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public class ServerApplicationManagementService {
private ServerApplicationMetadataService applicationMetadataService;

public ApplicationListResponse getAllApplications(Integer limit, Integer offset, String filter, String sortOrder,
String sortBy, String requiredAttributes) {
String sortBy, String requiredAttributes,
Boolean excludeSystemApps) {

handleNotImplementedCapabilities(sortOrder, sortBy);
String tenantDomain = ContextLoader.getTenantDomainFromContext();
Expand All @@ -279,9 +280,39 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
int totalResults = getApplicationManagementService()
.getCountOfApplications(tenantDomain, username, filter);

ApplicationBasicInfo[] filteredAppList = getApplicationManagementService()
.getApplicationBasicInfo(tenantDomain, username, filter, offset, limit);
int resultsInCurrentPage = filteredAppList.length;
List<ApplicationBasicInfo> filteredAppList = new ArrayList<>();
int currentOffset = offset;
int remainingLimit = limit;

while (filteredAppList.size() < limit && currentOffset < totalResults) {
ApplicationBasicInfo[] batch = getApplicationManagementService()
.getApplicationBasicInfo(tenantDomain, username, filter, currentOffset, remainingLimit);

if (batch.length == 0) {
break;
}

for (ApplicationBasicInfo app : batch) {
if (Boolean.TRUE.equals(excludeSystemApps) &&
(CONSOLE_APP.equals(app.getApplicationName()) ||
MY_ACCOUNT_APP.equals(app.getApplicationName()))) {
continue;
}
filteredAppList.add(app);
if (filteredAppList.size() == limit) {
break;
}
}

currentOffset += batch.length;
remainingLimit = limit - filteredAppList.size();
}

int resultsInCurrentPage = filteredAppList.size();

if (Boolean.TRUE.equals(excludeSystemApps)) {
totalResults = totalResults - 2; // Subtract 2 for CONSOLE_APP and MY_ACCOUNT_APP
}

List<String> requestedAttributeList = new ArrayList<>();
if (StringUtils.isNotEmpty(requiredAttributes)) {
Expand All @@ -299,7 +330,8 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
}

if (CollectionUtils.isNotEmpty(requestedAttributeList)) {
List<ServiceProvider> serviceProviderList = getSpWithRequiredAttributes(filteredAppList,
List<ServiceProvider> serviceProviderList = getSpWithRequiredAttributes(
filteredAppList.toArray(new ApplicationBasicInfo[0]),
requestedAttributeList);

return new ApplicationListResponse()
Expand All @@ -318,7 +350,7 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
.totalResults(totalResults)
.startIndex(offset + 1)
.count(resultsInCurrentPage)
.applications(getApplicationListItems(filteredAppList))
.applications(getApplicationListItems(filteredAppList.toArray(new ApplicationBasicInfo[0])))
.links(Util.buildPaginationLinks(limit, offset, totalResults,
APPLICATION_MANAGEMENT_PATH_COMPONENT, requiredAttributes, filter)
.entrySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public class ApplicationsApiServiceImpl implements ApplicationsApiService {

@Override
public Response getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy,
String requiredAttributes) {
String requiredAttributes, Boolean excludeSystemApps) {

ApplicationListResponse listResponse = applicationManagementService
.getAllApplications(limit, offset, filter, sortOrder, sortBy, requiredAttributes);
.getAllApplications(limit, offset, filter, sortOrder, sortBy, requiredAttributes, excludeSystemApps);
return Response.ok().entity(listResponse).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ paths:
- $ref: '#/components/parameters/sortOrderQueryParam'
- $ref: '#/components/parameters/sortByQueryParam'
- $ref: '#/components/parameters/attributesQueryParam'
- $ref: '#/components/parameters/excludeSystemAppsQueryParam'
responses:
'200':
description: OK
Expand Down Expand Up @@ -2701,6 +2702,15 @@ components:
/applications?attributes=advancedConfigurations,templateId,templateVersion,clientId,applicationEnabled,associatedRoles.allowedAudience
schema:
type: string
excludeSystemAppsQueryParam:
in: query
name: excludeSystemApps
required: false
description: |
Specifies whether to exclude system applications when exporting applications.
schema:
type: boolean
default: false
exportSecretsQueryParam:
in: query
name: exportSecrets
Expand Down
Loading