Search in sources :

Example 6 with PublisherAPIInfo

use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo in project carbon-apimgt by wso2.

the class APIProviderImpl method searchPaginatedAPIs.

@Override
public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organization, int start, int end, String sortBy, String sortOrder) throws APIManagementException {
    Map<String, Object> result = new HashMap<String, Object>();
    if (log.isDebugEnabled()) {
        log.debug("Original search query received : " + searchQuery);
    }
    Organization org = new Organization(organization);
    String[] roles = APIUtil.getFilteredUserRoles(userNameWithoutChange);
    Map<String, Object> properties = APIUtil.getUserProperties(userNameWithoutChange);
    UserContext userCtx = new UserContext(userNameWithoutChange, org, properties, roles);
    try {
        PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, searchQuery, start, end, userCtx, sortBy, sortOrder);
        if (log.isDebugEnabled()) {
            log.debug("searched APIs for query : " + searchQuery + " :-->: " + searchAPIs.toString());
        }
        Set<Object> apiSet = new LinkedHashSet<>();
        if (searchAPIs != null) {
            List<PublisherAPIInfo> list = searchAPIs.getPublisherAPIInfoList();
            List<Object> apiList = new ArrayList<>();
            for (PublisherAPIInfo publisherAPIInfo : list) {
                API mappedAPI = APIMapper.INSTANCE.toApi(publisherAPIInfo);
                populateAPIStatus(mappedAPI);
                populateDefaultVersion(mappedAPI);
                apiList.add(mappedAPI);
            }
            apiSet.addAll(apiList);
            result.put("apis", apiSet);
            result.put("length", searchAPIs.getTotalAPIsCount());
            result.put("isMore", true);
        } else {
            result.put("apis", apiSet);
            result.put("length", 0);
            result.put("isMore", false);
        }
    } catch (APIPersistenceException e) {
        throw new APIManagementException("Error while searching the api ", e);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) ArrayList(java.util.ArrayList) PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PublisherAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult) JSONObject(org.json.simple.JSONObject) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)

Example 7 with PublisherAPIInfo

use of org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo in project carbon-apimgt by wso2.

the class AbstractAPIManager method getAllAPIs.

public List<API> getAllAPIs() throws APIManagementException {
    List<API> apiSortedList = new ArrayList<API>();
    Organization org = new Organization(tenantDomain);
    String[] roles = APIUtil.getFilteredUserRoles(username);
    Map<String, Object> properties = APIUtil.getUserProperties(username);
    UserContext userCtx = new UserContext(username, org, properties, roles);
    try {
        PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, "", 0, Integer.MAX_VALUE, userCtx, null, null);
        if (searchAPIs != null) {
            List<PublisherAPIInfo> list = searchAPIs.getPublisherAPIInfoList();
            for (PublisherAPIInfo publisherAPIInfo : list) {
                API mappedAPI = APIMapper.INSTANCE.toApi(publisherAPIInfo);
                apiSortedList.add(mappedAPI);
            }
        }
    } catch (APIPersistenceException e) {
        throw new APIManagementException("Error while searching the api ", e);
    }
    Collections.sort(apiSortedList, new APINameComparator());
    return apiSortedList;
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) ArrayList(java.util.ArrayList) APINameComparator(org.wso2.carbon.apimgt.impl.utils.APINameComparator) PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PublisherAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) JSONObject(org.json.simple.JSONObject)

Aggregations

ArrayList (java.util.ArrayList)6 PublisherAPIInfo (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo)6 PublisherAPISearchResult (org.wso2.carbon.apimgt.persistence.dto.PublisherAPISearchResult)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 API (org.wso2.carbon.apimgt.api.model.API)4 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)4 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)4 UserContext (org.wso2.carbon.apimgt.persistence.dto.UserContext)4 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)4 HashMap (java.util.HashMap)3 JSONObject (org.json.simple.JSONObject)3 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 PublisherAPISearchResultComparator (org.wso2.carbon.apimgt.persistence.utils.PublisherAPISearchResultComparator)2 Resource (org.wso2.carbon.registry.core.Resource)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 LinkedHashSet (java.util.LinkedHashSet)1 TreeSet (java.util.TreeSet)1