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