Skip to content

Commit

Permalink
Merge pull request #12736 from Jithmi004/master
Browse files Browse the repository at this point in the history
Fix Functional and API Definition Issues in the Product Rest APIs
  • Loading branch information
RakhithaRR authored Jan 8, 2025
2 parents bffbaf8 + 96c7817 commit 03356aa
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ List<APIProductResource> getResourcesOfAPIProduct(APIProductIdentifier productId
* @return
* @throws APIManagementException
*/
Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end,
String sortBy, String sortOrder) throws APIManagementException;
Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end)
throws APIManagementException;

/**
* Search in content of apis, api products and documents and provide the results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ private int isCategoryAttached(APICategory category, String username) throws API
//APIs and API categories
String searchQuery = APIConstants.CATEGORY_SEARCH_TYPE_PREFIX + ":*" + category.getName() + "*";
String tenantDomain = MultitenantUtils.getTenantDomain(username);
Map<String, Object> result = apiProvider.searchPaginatedAPIs(searchQuery, tenantDomain, 0, Integer.MAX_VALUE, null, null);
Map<String, Object> result = apiProvider.searchPaginatedAPIs(searchQuery, tenantDomain, 0, Integer.MAX_VALUE);
return (int) (Integer) result.get("length");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3840,8 +3840,8 @@ public void changeUserPassword(String currentPassword, String newPassword) throw
}

@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end,
String sortBy, String sortOrder) throws APIManagementException {
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end)
throws APIManagementException {

Map<String, Object> result = new HashMap<String, Object>();
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5407,7 +5407,7 @@ public APISearchResult searchPaginatedAPIsByFQDN(String endpoint, String tenantD

try {
PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, query,
offset, limit, userCtx, "createdTime", "desc");
offset, limit, userCtx);
if (log.isDebugEnabled()) {
log.debug("Running Solr query : " + query);
}
Expand Down Expand Up @@ -5514,8 +5514,8 @@ public APIProduct getAPIProductbyUUID(String uuid, String organization) throws A
}

@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end,
String sortBy, String sortOrder) throws APIManagementException {
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end)
throws APIManagementException {
Map<String, Object> result = new HashMap<String, Object>();
if (log.isDebugEnabled()) {
log.debug("Original search query received : " + searchQuery);
Expand All @@ -5527,7 +5527,7 @@ public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organi
UserContext userCtx = new UserContext(userNameWithoutChange, org, properties, roles);
try {
PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, searchQuery,
start, end, userCtx, sortBy, sortOrder);
start, end, userCtx);
if (log.isDebugEnabled()) {
log.debug("searched APIs for query : " + searchQuery + " :-->: " + searchAPIs.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public List<API> getAllAPIs() throws APIManagementException {
UserContext userCtx = new UserContext(username, org, properties, roles);
try {
PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, "", 0,
Integer.MAX_VALUE, userCtx, null, null);
Integer.MAX_VALUE, userCtx);

if (searchAPIs != null) {
List<PublisherAPIInfo> list = searchAPIs.getPublisherAPIInfoList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,9 +1657,7 @@ public void testSearchPaginatedAPIsByFQDNWithCorrectInputs() throws APIManagemen
Mockito.anyString(),
Mockito.anyInt(),
Mockito.anyInt(),
Mockito.any(UserContext.class),
Mockito.anyString(),
Mockito.anyString())).thenReturn(returnSearchAPIs);
Mockito.any(UserContext.class))).thenReturn(returnSearchAPIs);

APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO);

Expand Down Expand Up @@ -1692,9 +1690,7 @@ public void testSearchPaginatedAPIsByFQDNWhenSearchResultIsNull() throws APIMana
Mockito.anyString(),
Mockito.anyInt(),
Mockito.anyInt(),
Mockito.any(UserContext.class),
Mockito.anyString(),
Mockito.anyString())).thenReturn(null);
Mockito.any(UserContext.class))).thenReturn(null);

APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testGetAllApis() throws GovernanceException, APIManagementException,
value.setPublisherAPIInfoList(publisherAPIInfoList);

Mockito.when(apiPersistenceInstance.searchAPIsForPublisher(any(Organization.class), anyString(),
anyInt(), anyInt(), any(UserContext.class), isNull(), isNull())).thenReturn(value);
anyInt(), anyInt(), any(UserContext.class))).thenReturn(value);
List<API> apis = abstractAPIManager.getAllAPIs();
Assert.assertNotNull(apis);
Assert.assertEquals(apis.size(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public API getLightweightAPIByUUID(String uuid, String organization) throws APIM
}

@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end,
String sortBy, String sortOrder) throws APIManagementException {
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end)
throws APIManagementException {
// TODO Auto-generated method stub
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,11 @@ void deleteAPIRevision(Organization org, String apiUUID, String revisionUUID, in
* @param searchQuery search query
* @param start starting index
* @param offset offset to search
* @param sortBy sort criteria
* @param sortOrder sort order
* @return Publisher API Search Result
* @throws APIPersistenceException
*/
PublisherAPISearchResult searchAPIsForPublisher(Organization org, String searchQuery, int start,
int offset, UserContext ctx, String sortBy, String sortOrder) throws APIPersistenceException;
int offset, UserContext ctx) throws APIPersistenceException;

/**
* Search APIs to be displayed on Dev Portal API listing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public void deleteAllAPIs(Organization org) throws APIPersistenceException {

@Override
public PublisherAPISearchResult searchAPIsForPublisher(Organization org, String searchQuery, int start, int offset,
UserContext ctx, String sortBy, String sortOrder) throws APIPersistenceException {
UserContext ctx) throws APIPersistenceException {
String requestedTenantDomain = org.getName();

boolean isTenantFlowStarted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public Response getAllAPIs(Integer limit, Integer offset, String query, String i
query = query == null ? APIConstants.CHAR_ASTERIX : query;
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
String organization = RestApiUtil.getOrganization(messageContext);
Map<String, Object> result = apiProvider.searchPaginatedAPIs(query, organization, offset, limit,
RestApiConstants.DEFAULT_SORT_BY, RestApiConstants.DEFAULT_SORT_ORDER);
Map<String, Object> result = apiProvider.searchPaginatedAPIs(query, organization, offset, limit);
List<Object> apis = SearchApiServiceImplUtil.getAPIListFromAPISearchResult(result);
List<ApiResultDTO> allMatchedResults = getAllMatchedResults(apis);
resultListDTO.setApis(allMatchedResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,24 @@ public static String getSubscriptionPaginatedURLForAPIId(Integer offset, Integer
return paginatedURL;
}

/**
* Returns the paginated url for subscriptions
*
* @param offset starting index
* @param limit max number of objects returned
* @param groupId groupId of the Application
* @return constructed paginated url
*/
public static String getSubscriptionPaginatedURL(Integer offset, Integer limit, String groupId) {

groupId = groupId == null ? "" : groupId;
String paginatedURL = RestApiConstants.SUBSCRIPTIONS_GET_PAGINATION_URL_APIID;
paginatedURL = paginatedURL.replace(RestApiConstants.LIMIT_PARAM, String.valueOf(limit));
paginatedURL = paginatedURL.replace(RestApiConstants.OFFSET_PARAM, String.valueOf(offset));
paginatedURL = paginatedURL.replace(RestApiConstants.GROUPID_PARAM, groupId);
return paginatedURL;
}

/**
* Returns the paginated url for subscriptions for a particular application
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ paths:
parameters:
- $ref: '#/components/parameters/limit'
- $ref: '#/components/parameters/offset'
- $ref: '#/components/parameters/sortBy'
- $ref: '#/components/parameters/sortOrder'
- $ref: '#/components/parameters/requestedTenant'
- name: query
in: query
Expand Down Expand Up @@ -14195,30 +14193,6 @@ components:
schema:
type: integer
default: 0
sortBy:
name: sortBy
in: query
description: |
Criteria for sorting.
schema:
type: string
default: createdTime
enum:
- apiName
- version
- createdTime
- status
sortOrder:
name: sortOrder
in: query
description: |
Order of sorting(ascending/descending).
schema:
type: string
default: desc
enum:
- asc
- desc
If-None-Match:
name: If-None-Match
in: header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,31 @@ public static void setPaginationParams(SubscriptionListDTO subscriptionListDTO,
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);

if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil
.getSubscriptionPaginatedURLForAPIId(
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
if (apiId != null) {
paginatedPrevious = RestApiCommonUtil
.getSubscriptionPaginatedURLForAPIId(
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
} else {
paginatedPrevious = RestApiCommonUtil
.getSubscriptionPaginatedURL(
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), groupId);
}
}

if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil
.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
if (apiId != null) {
paginatedPrevious = RestApiCommonUtil
.getSubscriptionPaginatedURLForAPIId(
paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
} else {
paginatedPrevious = RestApiCommonUtil
.getSubscriptionPaginatedURL(
paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET),
paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), groupId);
}
}

PaginationDTO pagination = new PaginationDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,8 @@ public Response getAllAPISpecificOperationPolicies(@ApiParam(value = "**API ID**
@ApiResponse(code = 200, message = "OK. List of qualifying APIs is returned. ", response = APIListDTO.class),
@ApiResponse(code = 304, message = "Not Modified. Empty body because the client has already the latest version of the requested resource (Will be supported in future). ", response = Void.class),
@ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) })
public Response getAllAPIs( @ApiParam(value = "Maximum size of resource array to return. ", defaultValue="25") @DefaultValue("25") @QueryParam("limit") Integer limit, @ApiParam(value = "Starting point within the complete list of items qualified. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @ApiParam(value = "Criteria for sorting. ", allowableValues="apiName, version, createdTime, status", defaultValue="createdTime") @DefaultValue("createdTime") @QueryParam("sortBy") String sortBy, @ApiParam(value = "Order of sorting(ascending/descending). ", allowableValues="asc, desc", defaultValue="desc") @DefaultValue("desc") @QueryParam("sortOrder") String sortOrder, @ApiParam(value = "For cross-tenant invocations, this is used to specify the tenant domain, where the resource need to be retirieved from. " )@HeaderParam("X-WSO2-Tenant") String xWSO2Tenant, @ApiParam(value = "**Search condition**. You can search in attributes by using an **\"<attribute>:\"** modifier. Eg. \"provider:wso2\" will match an API if the provider of the API contains \"wso2\". \"provider:\"wso2\"\" will match an API if the provider of the API is exactly \"wso2\". \"status:PUBLISHED\" will match an API if the API is in PUBLISHED state. Also you can use combined modifiers Eg. name:pizzashack version:v1 will match an API if the name of the API is pizzashack and version is v1. Supported attribute modifiers are [**version, context, name, status, description, provider, api-category, tags, doc, contexttemplate, lcstate, content, type, label, enablestore, thirdparty**] If no advanced attribute modifier has been specified, the API names containing the search term will be returned as a result. Please note that you need to use encoded URL (URL encoding) if you are using a client which does not support URL encoding (such as curl) ") @QueryParam("query") String query, @ApiParam(value = "Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource. " )@HeaderParam("If-None-Match") String ifNoneMatch, @ApiParam(value = "Media types acceptable for the response. Default is application/json. " , defaultValue="application/json")@HeaderParam("Accept") String accept) throws APIManagementException{
return delegate.getAllAPIs(limit, offset, sortBy, sortOrder, xWSO2Tenant, query, ifNoneMatch, accept, securityContext);
public Response getAllAPIs( @ApiParam(value = "Maximum size of resource array to return. ", defaultValue="25") @DefaultValue("25") @QueryParam("limit") Integer limit, @ApiParam(value = "Starting point within the complete list of items qualified. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset, @ApiParam(value = "For cross-tenant invocations, this is used to specify the tenant domain, where the resource need to be retirieved from. " )@HeaderParam("X-WSO2-Tenant") String xWSO2Tenant, @ApiParam(value = "**Search condition**. You can search in attributes by using an **\"<attribute>:\"** modifier. Eg. \"provider:wso2\" will match an API if the provider of the API contains \"wso2\". \"provider:\"wso2\"\" will match an API if the provider of the API is exactly \"wso2\". \"status:PUBLISHED\" will match an API if the API is in PUBLISHED state. Also you can use combined modifiers Eg. name:pizzashack version:v1 will match an API if the name of the API is pizzashack and version is v1. Supported attribute modifiers are [**version, context, name, status, description, provider, api-category, tags, doc, contexttemplate, lcstate, content, type, label, enablestore, thirdparty**] If no advanced attribute modifier has been specified, the API names containing the search term will be returned as a result. Please note that you need to use encoded URL (URL encoding) if you are using a client which does not support URL encoding (such as curl) ") @QueryParam("query") String query, @ApiParam(value = "Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resource. " )@HeaderParam("If-None-Match") String ifNoneMatch, @ApiParam(value = "Media types acceptable for the response. Default is application/json. " , defaultValue="application/json")@HeaderParam("Accept") String accept) throws APIManagementException{
return delegate.getAllAPIs(limit, offset, xWSO2Tenant, query, ifNoneMatch, accept, securityContext);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface ApisApiService {
public Response getAPISwagger(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException;
public Response getAPIThumbnail(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException;
public Response getAllAPISpecificOperationPolicies(String apiId, Integer limit, Integer offset, String query, MessageContext messageContext) throws APIManagementException;
public Response getAllAPIs(Integer limit, Integer offset, String sortBy, String sortOrder, String xWSO2Tenant, String query, String ifNoneMatch, String accept, MessageContext messageContext) throws APIManagementException;
public Response getAllAPIs(Integer limit, Integer offset, String xWSO2Tenant, String query, String ifNoneMatch, String accept, MessageContext messageContext) throws APIManagementException;
public Response getAllCommentsOfAPI(String apiId, String xWSO2Tenant, Integer limit, Integer offset, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException;
public Response getAllPublishedExternalStoresByAPI(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException;
public Response getAmazonResourceNamesOfAPI(String apiId, MessageContext messageContext) throws APIManagementException;
Expand Down
Loading

0 comments on commit 03356aa

Please sign in to comment.