Search in sources :

Example 1 with APIProductListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a APIProductListDTO object given pagination parameters and url parameters.
 *
 * @param apiProductListDTO a APIProductListDTO object
 * @param query             search condition
 * @param limit             max number of objects returned
 * @param offset            starting index
 * @param size              max offset
 */
public static void setPaginationParams(APIProductListDTO apiProductListDTO, 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.getAPIProductPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), query);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getAPIProductPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), query);
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    apiProductListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)

Example 2 with APIProductListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO in project carbon-apimgt by wso2.

the class ApiProductsApiServiceImpl method getAllAPIProducts.

@Override
public Response getAllAPIProducts(Integer limit, Integer offset, String query, String accept, String ifNoneMatch, MessageContext messageContext) {
    List<APIProduct> allMatchedProducts = new ArrayList<>();
    APIProductListDTO apiProductListDTO;
    // setting default limit and offset values if they are not set
    limit = limit != null ? limit : RestApiConstants.PAGINATION_LIMIT_DEFAULT;
    offset = offset != null ? offset : RestApiConstants.PAGINATION_OFFSET_DEFAULT;
    query = query == null ? "" : query;
    try {
        String username = RestApiCommonUtil.getLoggedInUsername();
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(username));
        if (log.isDebugEnabled()) {
            log.debug("API Product list request by " + username);
        }
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        Map<String, Object> result = apiProvider.searchPaginatedAPIProducts(query, tenantDomain, offset, limit);
        Set<APIProduct> apiProducts = (Set<APIProduct>) result.get("products");
        allMatchedProducts.addAll(apiProducts);
        apiProductListDTO = APIMappingUtil.fromAPIProductListtoDTO(allMatchedProducts);
        // Add pagination section in the response
        Object totalLength = result.get("length");
        Integer length = 0;
        if (totalLength != null) {
            length = (Integer) totalLength;
        }
        APIMappingUtil.setPaginationParams(apiProductListDTO, query, offset, limit, length);
        return Response.ok().entity(apiProductListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API Products ";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO) Set(java.util.Set) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 3 with APIProductListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIProductListtoDTO.

public static APIProductListDTO fromAPIProductListtoDTO(List<APIProduct> productList) {
    APIProductListDTO listDto = new APIProductListDTO();
    List<APIProductInfoDTO> list = new ArrayList<APIProductInfoDTO>();
    for (APIProduct apiProduct : productList) {
        APIProductInfoDTO productDto = new APIProductInfoDTO();
        productDto.setName(apiProduct.getId().getName());
        productDto.setProvider(APIUtil.replaceEmailDomainBack(apiProduct.getId().getProviderName()));
        productDto.setContext(apiProduct.getContext());
        productDto.setDescription(apiProduct.getDescription());
        productDto.setState(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductInfoDTO.StateEnum.valueOf(apiProduct.getState()));
        productDto.setId(apiProduct.getUuid());
        if (apiProduct.getApiSecurity() != null) {
            productDto.setSecurityScheme(Arrays.asList(apiProduct.getApiSecurity().split(",")));
        }
        list.add(productDto);
    }
    listDto.setList(list);
    listDto.setCount(list.size());
    return listDto;
}
Also used : APIProductListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductInfoDTO) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)2 APIProductListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductListDTO)2 Set (java.util.Set)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 APIProductInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductInfoDTO)1 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)1