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

Modified link attribute's href in get all applications response. #501

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -279,7 +279,7 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
.count(resultsInCurrentPage)
.applications(getApplicationListItems(serviceProviderList, requestedAttributeList))
.links(Util.buildPaginationLinks(limit, offset, totalResults,
APPLICATION_MANAGEMENT_PATH_COMPONENT)
APPLICATION_MANAGEMENT_PATH_COMPONENT, requiredAttributes, filter)
.entrySet()
.stream()
.map(link -> new Link().rel(link.getKey()).href(link.getValue()))
Expand All @@ -291,7 +291,7 @@ public ApplicationListResponse getAllApplications(Integer limit, Integer offset,
.count(resultsInCurrentPage)
.applications(getApplicationListItems(filteredAppList))
.links(Util.buildPaginationLinks(limit, offset, totalResults,
APPLICATION_MANAGEMENT_PATH_COMPONENT)
APPLICATION_MANAGEMENT_PATH_COMPONENT, requiredAttributes, filter)
.entrySet()
.stream()
.map(link -> new Link().rel(link.getKey()).href(link.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.wso2.carbon.identity.api.server.common;

import org.apache.commons.lang.StringUtils;
import org.slf4j.MDC;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.recovery.ChallengeQuestionManager;
Expand Down Expand Up @@ -100,22 +101,32 @@ public static String base64URLDecode(String value) {

/**
* Build 'next' and 'previous' pagination links.
* @param limit Value of the 'limit' parameter.
* @param currentOffset Value of the 'currentOffset' parameter.
*
* @param limit Value of the 'limit' parameter.
* @param currentOffset Value of the 'currentOffset' parameter.
* @param totalResultsFromSearch Value of the 'totalResultsFromSearch' parameter.
* @param servicePathComponent API service path. E.g: applications/
* @param servicePathComponent API service path. E.g: applications/
* @param requiredAttributes Value of the 'attributes' parameter.
* @param filter Value of the 'filter' parameter.
* @return A map containing pagination link key-value pairs.
*/
public static Map<String, String> buildPaginationLinks(int limit, int currentOffset, int totalResultsFromSearch,
ashanthamara marked this conversation as resolved.
Show resolved Hide resolved
String servicePathComponent) {
String servicePathComponent, String requiredAttributes, String filter) {

Map<String, String> links = new HashMap<>();

StringBuilder otherParams = new StringBuilder();
if (!StringUtils.isEmpty(requiredAttributes)) {
otherParams.append("&attributes=").append(requiredAttributes);
}
if (!StringUtils.isEmpty(filter)) {
otherParams.append("&filter=").append(filter.replace(" ", "+"));
}

// Next link.
if ((currentOffset + limit) < totalResultsFromSearch) {
links.put(PAGE_LINK_REL_NEXT, ContextLoader.buildURIForBody
(String.format(PAGINATION_LINK_FORMAT, servicePathComponent, (currentOffset + limit), limit))
.toString());
links.put(PAGE_LINK_REL_NEXT, ContextLoader.buildURIForBody(String.format(PAGINATION_LINK_FORMAT,
servicePathComponent, (currentOffset + limit), limit) + otherParams).toString());
}

/*
Expand All @@ -126,11 +137,12 @@ public static Map<String, String> buildPaginationLinks(int limit, int currentOff
if ((currentOffset - limit) >= 0) { // A previous page of size 'limit' exists.
links.put(PAGE_LINK_REL_PREVIOUS, ContextLoader.buildURIForBody
(String.format(PAGINATION_LINK_FORMAT, servicePathComponent,
calculateOffsetForPreviousLink(currentOffset, limit, totalResultsFromSearch), limit))
.toString());
calculateOffsetForPreviousLink(currentOffset, limit, totalResultsFromSearch), limit) +
otherParams).toString());
} else { // A previous page exists but it's size is less than the specified limit.
links.put(PAGE_LINK_REL_PREVIOUS, ContextLoader.buildURIForBody
(String.format(PAGINATION_LINK_FORMAT, servicePathComponent, 0, currentOffset)).toString());
(String.format(PAGINATION_LINK_FORMAT, servicePathComponent, 0, currentOffset) +
otherParams).toString());
}
}

Expand Down
Loading