use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIListDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setPaginationParams.
/**
* Sets pagination urls for a APIListDTO object given pagination parameters and url parameters
*
* @param apiListDTO APIListDTO object to which pagination urls need to be set
* @param query query parameter
* @param offset starting index
* @param limit max number of returned objects
* @param size max offset
*/
public static void setPaginationParams(APIListDTO apiListDTO, String query, int offset, int limit, int size) {
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 = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
apiListDTO.setPagination(paginationDTO);
}
use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIListDTO in project carbon-apimgt by wso2.
the class ServicesApiServiceImpl method getServiceUsage.
@Override
public Response getServiceUsage(String serviceId, MessageContext messageContext) {
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
try {
List<API> apiList = serviceCatalog.getServiceUsage(serviceId, tenantId);
if (apiList != null) {
APIListDTO apiListDTO = new APIListDTO();
List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
for (API api : apiList) {
apiInfoDTOList.add(ServiceEntryMappingUtil.fromAPIToAPIInfoDTO(api));
}
apiListDTO.setList(apiInfoDTOList);
apiListDTO.setCount(apiList.size());
return Response.ok().entity(apiListDTO).build();
} else {
RestApiUtil.handleResourceNotFoundError("Service", serviceId, log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API usage of service";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations