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);
}
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;
}
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;
}
Aggregations