Search in sources :

Example 26 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.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);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 27 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.APIInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 API (org.wso2.carbon.apimgt.core.models.API)7 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 APIListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIListDTO)5 HashMap (java.util.HashMap)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 API (org.wso2.carbon.apimgt.api.model.API)4 APIListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO)4 JSONObject (org.json.simple.JSONObject)3 APIListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO)3 File (java.io.File)2 Set (java.util.Set)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 APIMgtEntityImportExportException (org.wso2.carbon.apimgt.core.exception.APIMgtEntityImportExportException)2 APIDetails (org.wso2.carbon.apimgt.core.models.APIDetails)2