use of org.wso2.carbon.apimgt.persistence.dto.UserContext in project carbon-apimgt by wso2.
the class APIProviderImpl method isDocumentationExist.
@Override
public boolean isDocumentationExist(String uuid, String docName, String organization) throws APIManagementException {
boolean exist = false;
UserContext ctx = null;
try {
DocumentSearchResult result = apiPersistenceInstance.searchDocumentation(new Organization(organization), uuid, 0, 0, "name:" + docName, ctx);
if (result != null && result.getDocumentationList() != null && !result.getDocumentationList().isEmpty()) {
String returnDocName = result.getDocumentationList().get(0).getName();
if (returnDocName != null && returnDocName.equals(docName)) {
exist = true;
}
}
} catch (DocumentationPersistenceException e) {
handleException("Failed to search documentation for name " + docName, e);
}
return exist;
}
use of org.wso2.carbon.apimgt.persistence.dto.UserContext 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.UserContext 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;
}
use of org.wso2.carbon.apimgt.persistence.dto.UserContext in project carbon-apimgt by wso2.
the class APIConsumerImpl method getAllTags.
@Override
public Set<Tag> getAllTags(String organization) throws APIManagementException {
/* We keep track of the lastUpdatedTime of the TagCache to determine its freshness.
*/
long lastUpdatedTimeAtStart = lastUpdatedTime;
long currentTimeAtStart = System.currentTimeMillis();
if (isTagCacheEnabled && ((currentTimeAtStart - lastUpdatedTimeAtStart) < tagCacheValidityTime)) {
if (tagSet != null) {
return tagSet;
}
}
Organization org = new Organization(organization);
String userName = (userNameWithoutChange != null) ? userNameWithoutChange : username;
String[] roles = APIUtil.getListOfRoles(userName);
Map<String, Object> properties = APIUtil.getUserProperties(userName);
UserContext userCtx = new UserContext(userNameWithoutChange, org, properties, roles);
try {
Set<Tag> tempTagSet = apiPersistenceInstance.getAllTags(org, userCtx);
synchronized (tagCacheMutex) {
lastUpdatedTime = System.currentTimeMillis();
this.tagSet = tempTagSet;
}
} catch (APIPersistenceException e) {
String msg = "Failed to get API tags";
throw new APIManagementException(msg, e);
}
return tagSet;
}
Aggregations