Search in sources :

Example 21 with UserContext

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;
}
Also used : DocumentSearchResult(org.wso2.carbon.apimgt.persistence.dto.DocumentSearchResult) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) DocumentationPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)

Example 22 with UserContext

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;
}
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 23 with UserContext

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

Example 24 with UserContext

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;
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) JSONObject(org.json.simple.JSONObject) Tag(org.wso2.carbon.apimgt.api.model.Tag)

Aggregations

UserContext (org.wso2.carbon.apimgt.persistence.dto.UserContext)17 ArrayList (java.util.ArrayList)14 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)14 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)11 Registry (org.wso2.carbon.registry.core.Registry)10 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 JSONObject (org.json.simple.JSONObject)7 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)6 TreeSet (java.util.TreeSet)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 API (org.wso2.carbon.apimgt.api.model.API)5 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)5 DocumentationPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.DocumentationPersistenceException)5 DocumentSearchContent (org.wso2.carbon.apimgt.persistence.dto.DocumentSearchContent)4 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)4 Matchers.anyString (org.mockito.Matchers.anyString)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3