Search in sources :

Example 46 with Pagination

use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.

the class RegistryPersistenceImpl method searchPaginatedDevPortalAPIs.

private DevPortalAPISearchResult searchPaginatedDevPortalAPIs(Registry userRegistry, int tenantIDLocal, String searchQuery, int start, int offset) throws APIManagementException {
    int totalLength = 0;
    DevPortalAPISearchResult searchResults = new DevPortalAPISearchResult();
    try {
        final int maxPaginationLimit = getMaxPaginationLimit();
        PaginationContext.init(start, offset, "ASC", APIConstants.API_OVERVIEW_NAME, maxPaginationLimit);
        log.debug("Dev portal list apis query " + searchQuery);
        List<GovernanceArtifact> governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
        totalLength = PaginationContext.getInstance().getLength();
        boolean isFound = true;
        if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
            if (searchQuery.contains(APIConstants.API_OVERVIEW_PROVIDER)) {
                searchQuery = searchQuery.replaceAll(APIConstants.API_OVERVIEW_PROVIDER, APIConstants.API_OVERVIEW_OWNER);
                governanceArtifacts = GovernanceUtils.findGovernanceArtifacts(searchQuery, userRegistry, APIConstants.API_RXT_MEDIA_TYPE, true);
                if (governanceArtifacts == null || governanceArtifacts.size() == 0) {
                    isFound = false;
                }
            } else {
                isFound = false;
            }
        }
        if (!isFound) {
            return searchResults;
        }
        // Check to see if we can speculate that there are more APIs to be loaded
        if (maxPaginationLimit == totalLength) {
            // Remove the additional 1 added earlier when setting max pagination limit
            --totalLength;
        }
        List<DevPortalAPIInfo> devPortalAPIInfoList = new ArrayList<DevPortalAPIInfo>();
        int tempLength = 0;
        for (GovernanceArtifact artifact : governanceArtifacts) {
            DevPortalAPIInfo apiInfo = new DevPortalAPIInfo();
            // devPortalAPIInfoList apiInfo = new devPortalAPIInfoList();
            apiInfo.setType(artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE));
            apiInfo.setId(artifact.getId());
            apiInfo.setApiName(artifact.getAttribute(APIConstants.API_OVERVIEW_NAME));
            apiInfo.setDescription(artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
            apiInfo.setContext(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
            apiInfo.setProviderName(artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER));
            apiInfo.setStatus(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS));
            apiInfo.setThumbnail(artifact.getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL));
            apiInfo.setBusinessOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER));
            apiInfo.setVersion(artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
            String tiers = artifact.getAttribute(APIConstants.API_OVERVIEW_TIER);
            Set<String> availableTiers = new HashSet<String>();
            if (tiers != null) {
                String[] tiersArray = tiers.split("\\|\\|");
                for (String tierName : tiersArray) {
                    availableTiers.add(tierName);
                }
            }
            apiInfo.setAvailableTierNames(availableTiers);
            apiInfo.setSubscriptionAvailability(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABILITY));
            apiInfo.setSubscriptionAvailableOrgs(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABLE_TENANTS));
            apiInfo.setGatewayVendor(artifact.getAttribute(APIConstants.API_GATEWAY_VENDOR));
            devPortalAPIInfoList.add(apiInfo);
            // Ensure the APIs returned matches the length, there could be an additional API
            // returned due incrementing the pagination limit when getting from registry
            tempLength++;
            if (tempLength >= totalLength) {
                break;
            }
        }
        searchResults.setDevPortalAPIInfoList(devPortalAPIInfoList);
        searchResults.setReturnedAPIsCount(devPortalAPIInfoList.size());
        searchResults.setTotalAPIsCount(totalLength);
    } catch (RegistryException e) {
        String msg = "Failed to search APIs with type";
        throw new APIManagementException(msg, e);
    } finally {
        PaginationContext.destroy();
    }
    return searchResults;
}
Also used : GovernanceArtifact(org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact) DevPortalAPIInfo(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPIInfo) ArrayList(java.util.ArrayList) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) DevPortalAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPISearchResult) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashSet(java.util.HashSet)

Example 47 with Pagination

use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.

the class ApplicationMappingUtil method setPaginationParamsWithSortParams.

/**
 * Sets pagination urls for a ApplicationListDTO object given pagination parameters and url parameters with
 * sortOrder and sortBy params.
 *
 * @param applicationListDTO a SubscriptionListDTO object
 * @param groupId            group id of the applications to be returned
 * @param limit              max number of objects returned
 * @param offset             starting index
 * @param size               max offset
 * @param sortOrder          sorting order
 * @param sortBy             specified sort param
 */
public static void setPaginationParamsWithSortParams(ApplicationListDTO applicationListDTO, String groupId, int limit, int offset, int size, String sortOrder, String sortBy) {
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    String paginatedPrevious = "";
    String paginatedNext = "";
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), groupId, sortOrder, sortBy);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getApplicationPaginatedURLWithSortParams(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), groupId, sortOrder, sortBy);
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    applicationListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 48 with Pagination

use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.

the class DocumentationMappingUtil method setPaginationParams.

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

Example 49 with Pagination

use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.

the class TagMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a TagListDTO object given pagination parameters and url parameters
 *
 * @param tagListDTO a TagListDTO object
 * @param limit       max number of objects returned
 * @param offset      starting index
 * @param size        max offset
 */
public static void setPaginationParams(TagListDTO tagListDTO, int limit, int offset, int size) {
    String paginatedPrevious = "";
    String paginatedNext = "";
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = RestApiCommonUtil.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT));
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getTagsPaginatedURL(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT));
    }
    PaginationDTO paginationDTO = CommonMappingUtil.getPaginationDTO(limit, offset, size, paginatedNext, paginatedPrevious);
    tagListDTO.setPagination(paginationDTO);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Example 50 with Pagination

use of org.wso2.carbon.apimgt.api.model.Pagination in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method setPaginationParams.

/**
 * Sets pagination urls for a AdditionalSubscriptionInfoListDTO object given pagination parameters and url
 * parameters
 *
 * @param additionalSubscriptionInfoListDTO a AdditionalSubscriptionInfoListDTO object
 * @param apiId               uuid/id of API
 * @param groupId             group id of the applications to be returned
 * @param limit               max number of objects returned
 * @param offset              starting index
 * @param size                max offset
 */
public static void setPaginationParams(AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO, String apiId, String groupId, int limit, int offset, int size) {
    String paginatedPrevious = "";
    String paginatedNext = "";
    Map<String, Integer> paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, size);
    if (paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET) != null) {
        paginatedPrevious = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_PREVIOUS_LIMIT), apiId, groupId);
    }
    if (paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET) != null) {
        paginatedNext = RestApiCommonUtil.getSubscriptionPaginatedURLForAPIId(paginatedParams.get(RestApiConstants.PAGINATION_NEXT_OFFSET), paginatedParams.get(RestApiConstants.PAGINATION_NEXT_LIMIT), apiId, groupId);
    }
    PaginationDTO pagination = new PaginationDTO();
    pagination.setOffset(offset);
    pagination.setLimit(limit);
    pagination.setNext(paginatedNext);
    pagination.setPrevious(paginatedPrevious);
    pagination.setTotal(size);
    additionalSubscriptionInfoListDTO.setPagination(pagination);
}
Also used : PaginationDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)

Aggregations

ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 JSONObject (org.json.simple.JSONObject)12 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)12 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)11 API (org.wso2.carbon.apimgt.api.model.API)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 PaginationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.PaginationDTO)8 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)8 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)8 TreeSet (java.util.TreeSet)7 Registry (org.wso2.carbon.registry.core.Registry)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 APINameComparator (org.wso2.carbon.apimgt.impl.utils.APINameComparator)6 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5