Search in sources :

Example 1 with ServiceListDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO in project carbon-apimgt by wso2.

the class ServiceEntryMappingUtil method setPaginationParams.

public static void setPaginationParams(ServiceListDTO serviceListDTO, int offset, int limit, int size, ServiceFilterParams filterParams) {
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    String paginatedPrevious = "";
    String paginatedNext = "";
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = getServicesPaginatedUrl(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), filterParams);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = getServicesPaginatedUrl(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), filterParams);
    }
    PaginationDTO paginationDTO = getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    serviceListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO)

Example 2 with ServiceListDTO

use of org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO in project carbon-apimgt by wso2.

the class ServicesApiServiceImpl method searchServices.

@Override
public Response searchServices(String name, String version, String definitionType, String key, Boolean shrink, String sortBy, String sortOrder, Integer limit, Integer offset, MessageContext messageContext) throws APIManagementException {
    String userName = RestApiCommonUtil.getLoggedInUsername();
    int tenantId = APIUtil.getTenantId(userName);
    try {
        List<ServiceDTO> serviceDTOList = new ArrayList<>();
        ServiceFilterParams filterParams = ServiceEntryMappingUtil.getServiceFilterParams(name, version, definitionType, key, sortBy, sortOrder, limit, offset);
        List<ServiceEntry> services = serviceCatalog.getServices(filterParams, tenantId, shrink);
        int totalServices = serviceCatalog.getServicesCount(tenantId, filterParams);
        for (ServiceEntry service : services) {
            serviceDTOList.add(ServiceEntryMappingUtil.fromServiceToDTO(service, shrink));
        }
        ServiceListDTO serviceListDTO = new ServiceListDTO();
        serviceListDTO.setList(serviceDTOList);
        ServiceEntryMappingUtil.setPaginationParams(serviceListDTO, filterParams.getOffset(), filterParams.getLimit(), totalServices, filterParams);
        return Response.ok().entity(serviceListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Services";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : ServiceListDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) ServiceDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO) ServiceEntry(org.wso2.carbon.apimgt.api.model.ServiceEntry) ServiceFilterParams(org.wso2.carbon.apimgt.api.model.ServiceFilterParams)

Aggregations

ArrayList (java.util.ArrayList)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 ServiceEntry (org.wso2.carbon.apimgt.api.model.ServiceEntry)1 ServiceFilterParams (org.wso2.carbon.apimgt.api.model.ServiceFilterParams)1 PaginationDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.PaginationDTO)1 ServiceDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceDTO)1 ServiceListDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.ServiceListDTO)1