use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class CommonMappingUtil method getPaginationDTO.
/**
* Retreives a pagination DTO object given
*
* @param limit limit value
* @param offset offset value (starting position)
* @param total total number of resources available
* @param next link to the next page
* @param previous link to the previous page
* @return a pagination DTO object given above properties
*/
public static PaginationDTO getPaginationDTO(int limit, int offset, int total, String next, String previous) {
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(limit);
paginationDTO.setOffset(offset);
paginationDTO.setTotal(total);
paginationDTO.setNext(next);
paginationDTO.setPrevious(previous);
return paginationDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class SearchResultMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a SearchResultListDTO object given pagination parameters and url parameters
*
* @param resultListDTO a SearchResultListDTO object
* @param query search condition
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(SearchResultListDTO resultListDTO, String query, int offset, int limit, int size) {
// acquiring pagination parameters and setting pagination urls
Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
String paginatedPrevious = "";
String paginatedNext = "";
if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
paginatedPrevious = RestApiCommonUtil.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
}
if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getAPIPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
}
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setOffset(offset);
paginationDTO.setLimit(limit);
paginationDTO.setTotal(size);
paginationDTO.setNext(paginatedNext);
paginationDTO.setPrevious(paginatedPrevious);
resultListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a SubscriptionListDTO object given pagination parameters and url parameters
*
* @param subscriptionListDTO a SubscriptionListDTO object
* @param apiId uuid/id of API
* @param groupId group id of the applications to be returned
* @param limit max number of objects returned
* @param offset starting index
* @param size max offset
*/
public static void setPaginationParams(SubscriptionListDTO subscriptionListDTO, String apiId, String groupId, int limit, int offset, int size) {
String paginatedPrevious = "";
String paginatedNext = "";
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 (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
paginatedNext = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
}
PaginationDTO pagination = new PaginationDTO();
pagination.setOffset(offset);
pagination.setLimit(limit);
pagination.setNext(paginatedNext);
pagination.setPrevious(paginatedPrevious);
pagination.setTotal(size);
subscriptionListDTO.setPagination(pagination);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
/**
* Retrieves all the applications that the user has access to
*
* @param groupId group Id
* @param query search condition
* @param limit max number of objects returns
* @param offset starting index
* @param ifNoneMatch If-None-Match header value
* @return Response object containing resulted applications
*/
@Override
public Response applicationsGet(String groupId, String query, String sortBy, String sortOrder, Integer limit, Integer offset, String ifNoneMatch, MessageContext messageContext) {
limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
sortOrder = sortOrder != null ? sortOrder : RestApiConstants.DEFAULT_SORT_ORDER;
sortBy = sortBy != null ? ApplicationMappingUtil.getApplicationSortByField(sortBy) : APIConstants.APPLICATION_NAME;
query = query == null ? "" : query;
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
String username = RestApiCommonUtil.getLoggedInUsername();
// 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.
groupId = RestApiUtil.getLoggedInUserGroupId();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIConsumer apiConsumer = RestApiCommonUtil.getConsumer(username);
Subscriber subscriber = new Subscriber(username);
Application[] applications;
applications = apiConsumer.getApplicationsWithPagination(new Subscriber(username), groupId, offset, limit, query, sortBy, sortOrder, organization);
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
int applicationCount = apiMgtDAO.getAllApplicationCount(subscriber, groupId, query);
applicationListDTO = ApplicationMappingUtil.fromApplicationsToDTO(applications);
ApplicationMappingUtil.setPaginationParamsWithSortParams(applicationListDTO, groupId, limit, offset, applicationCount, sortOrder, sortBy.toLowerCase());
return Response.ok().entity(applicationListDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.rootCauseMessageMatches(e, "start index seems to be greater than the limit count")) {
// this is not an error of the user as he does not know the total number of applications available.
// Thus sends an empty response
applicationListDTO.setCount(0);
applicationListDTO.setPagination(new PaginationDTO());
return Response.ok().entity(applicationListDTO).build();
} else {
String errorMessage = "Error while retrieving Applications";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO in project carbon-apimgt by wso2.
the class ServiceEntryMappingUtil method getPaginationDTO.
private static PaginationDTO getPaginationDTO(int limit, int offset, int total, String next, String previous) {
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(limit);
paginationDTO.setOffset(offset);
paginationDTO.setTotal(total);
paginationDTO.setNext(next);
paginationDTO.setPrevious(previous);
return paginationDTO;
}
Aggregations