Skip to content

Commit

Permalink
Added review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
HasiniSama committed Jul 22, 2024
1 parent 005af26 commit 362908c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -26,4 +26,10 @@ public class OrganizationManagementEndpointConstants {
public static final String DESC_SORT_ORDER = "DESC";
public static final String ASC_SORT_ORDER = "ASC";
public static final String DISCOVERY_PATH = "discovery";
public static final String META_ATTRIBUTES_PATH = "meta-attributes";
public static final String NEXT = "next";
public static final String PREVIOUS = "previous";
public static final String FILTER_PARAM = "filter";
public static final String LIMIT_PARAM = "limit";
public static final String RECURSIVE_PARAM = "recursive";
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,20 @@
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.ASC_SORT_ORDER;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.DESC_SORT_ORDER;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.DISCOVERY_PATH;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.FILTER_PARAM;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.LIMIT_PARAM;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.META_ATTRIBUTES_PATH;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.NEXT;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.PREVIOUS;
import static org.wso2.carbon.identity.api.server.organization.management.v1.constants.OrganizationManagementEndpointConstants.RECURSIVE_PARAM;
import static org.wso2.carbon.identity.api.server.organization.management.v1.util.OrganizationManagementEndpointUtil.buildOrganizationURL;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_BUILDING_PAGINATED_RESPONSE_URL;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_INVALID_PAGINATION_PARAMETER_NEGATIVE_LIMIT;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_INVALID_SHARE_APPLICATION_EMPTY_REQUEST_BODY;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_INVALID_SHARE_APPLICATION_REQUEST_BODY;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ORGANIZATION_PATH;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.PAGINATION_AFTER;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.PAGINATION_BEFORE;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.PATH_SEPARATOR;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.generateUniqueID;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getOrganizationId;
Expand Down Expand Up @@ -732,10 +740,10 @@ private OrganizationsResponse getOrganizationsResponse(Integer limit, String aft
(StringUtils.isNotBlank(before) && !hasMoreItems);
boolean isLastPage = !hasMoreItems && (StringUtils.isNotBlank(after) || StringUtils.isBlank(before));

String url = "?limit=" + limit + "&recursive=" + recursive;
String url = "?" + LIMIT_PARAM + "=" + limit + "&" + RECURSIVE_PARAM + "=" + recursive;
if (StringUtils.isNotBlank(filter)) {
try {
url += "&filter=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name());
url += "&" + FILTER_PARAM + "=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new OrganizationManagementServerException(
ERROR_CODE_ERROR_BUILDING_PAGINATED_RESPONSE_URL.getMessage(),
Expand All @@ -755,17 +763,19 @@ private OrganizationsResponse getOrganizationsResponse(Integer limit, String aft
.getBytes(StandardCharsets.UTF_8));
Link link = new Link();
link.setHref(URI.create(
OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&before=" + encodedString));
link.setRel("previous");
OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&" + PAGINATION_BEFORE + "="
+ encodedString));
link.setRel(PREVIOUS);
organizationsResponse.addLinksItem(link);
}
if (!isLastPage) {
String encodedString = Base64.getEncoder().encodeToString(organizations.get(organizations.size() - 1)
.getCreated().toString().getBytes(StandardCharsets.UTF_8));
Link link = new Link();
link.setHref(URI.create(
OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&after=" + encodedString));
link.setRel("next");
OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&" + PAGINATION_AFTER + "="
+ encodedString));
link.setRel(NEXT);
organizationsResponse.addLinksItem(link);
}

Expand Down Expand Up @@ -952,10 +962,11 @@ private MetaAttributesResponse getMetaAttributesResponse(Integer limit, String a
(StringUtils.isNotBlank(before) && !hasMoreItems);
boolean isLastPage = !hasMoreItems && (StringUtils.isNotBlank(after) || StringUtils.isBlank(before));

String url = "/meta-attributes" + "?limit=" + limit + "&recursive=" + recursive;
String url = PATH_SEPARATOR + META_ATTRIBUTES_PATH + "?" + LIMIT_PARAM + "=" + limit + "&" + RECURSIVE_PARAM
+ "=" + recursive;
if (StringUtils.isNotBlank(filter)) {
try {
url += "&filter=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name());
url += "&" + FILTER_PARAM + "=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new OrganizationManagementServerException(
ERROR_CODE_ERROR_BUILDING_PAGINATED_RESPONSE_URL.getMessage(),
Expand All @@ -973,18 +984,18 @@ private MetaAttributesResponse getMetaAttributesResponse(Integer limit, String a
String encodedString = Base64.getEncoder().encodeToString(metaAttributes.get(0)
.getBytes(StandardCharsets.UTF_8));
Link link = new Link();
link.setHref(URI.create(OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&before="
+ encodedString));
link.setRel("previous");
link.setHref(URI.create(OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&"
+ PAGINATION_BEFORE + "=" + encodedString));
link.setRel(PREVIOUS);
metaAttributesResponse.addLinksItem(link);
}
if (!isLastPage) {
String encodedString = Base64.getEncoder().encodeToString(metaAttributes.get(metaAttributes.size() - 1)
.getBytes(StandardCharsets.UTF_8));
Link link = new Link();
link.setHref(URI.create(OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&after="
+ encodedString));
link.setRel("next");
link.setHref(URI.create(OrganizationManagementEndpointUtil.buildURIForPagination(url) + "&"
+ PAGINATION_AFTER + "=" + encodedString));
link.setRel(NEXT);
metaAttributesResponse.addLinksItem(link);
}
metaAttributesResponse.attributes(metaAttributes);
Expand Down

0 comments on commit 362908c

Please sign in to comment.