Search in sources :

Example 6 with UserContext

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

the class RegistryPersistenceImpl method searchAPIsForDevPortal.

@Override
public DevPortalAPISearchResult searchAPIsForDevPortal(Organization org, String searchQuery, int start, int offset, UserContext ctx) throws APIPersistenceException {
    String requestedTenantDomain = org.getName();
    boolean isTenantFlowStarted = false;
    DevPortalAPISearchResult result = null;
    try {
        RegistryHolder holder = getRegistry(ctx.getUserame(), requestedTenantDomain);
        Registry userRegistry = holder.getRegistry();
        int tenantIDLocal = holder.getTenantId();
        isTenantFlowStarted = holder.isTenantFlowStarted();
        log.debug("Requested query for devportal search: " + searchQuery);
        String modifiedQuery = RegistrySearchUtil.getDevPortalSearchQuery(searchQuery, ctx, isAllowDisplayAPIsWithMultipleStatus(), isAllowDisplayAPIsWithMultipleVersions());
        log.debug("Modified query for devportal search: " + modifiedQuery);
        String userNameLocal;
        if (holder.isAnonymousMode()) {
            userNameLocal = APIConstants.WSO2_ANONYMOUS_USER;
        } else {
            userNameLocal = getTenantAwareUsername(ctx.getUserame());
        }
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userNameLocal);
        if (searchQuery != null && searchQuery.startsWith(APIConstants.DOCUMENTATION_SEARCH_TYPE_PREFIX)) {
            result = searchPaginatedDevPortalAPIsByDoc(userRegistry, tenantIDLocal, searchQuery.split(":")[1], userNameLocal, start, offset);
        } else {
            result = searchPaginatedDevPortalAPIs(userRegistry, tenantIDLocal, modifiedQuery, start, offset);
        }
    } catch (APIManagementException e) {
        throw new APIPersistenceException("Error while searching APIs ", e);
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    return result;
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) DevPortalAPISearchResult(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPISearchResult) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry)

Example 7 with UserContext

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

the class RegistrySearchUtilTestCase method testAdminUserQueryInDevPortal.

@Test
public void testAdminUserQueryInDevPortal() throws APIPersistenceException {
    // Normal dev portal api listing
    String inputQuery = "";
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("isAdmin", true);
    UserContext ctx = new UserContext("admin", organization, properties, new String[] { "admin" });
    String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    String expected = "name=*&enableStore=(true OR null)&group=true&group.field=name&group.ngroups=true&group.sort=versionTimestamp desc&lcState=(PUBLISHED OR PROTOTYPED)";
    Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
    // search for 'test' in description
    inputQuery = "description:test";
    expected = "description=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
    // search for provider 'pubuser'
    inputQuery = "provider:pubuser";
    expected = "provider=*pubuser*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for provider search. ", expected, searchQuery);
}
Also used : HashMap(java.util.HashMap) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) Test(org.junit.Test)

Example 8 with UserContext

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

the class RegistrySearchUtilTestCase method testDevPortalUserQueryInDevPortal.

@Test
public void testDevPortalUserQueryInDevPortal() throws APIPersistenceException {
    // Normal dev portal api listing
    String inputQuery = "";
    UserContext ctx = new UserContext("devUser", organization, null, devPortalRoles);
    String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    String expected = "store_view_roles=(null OR internal\\/subscriber OR internal\\/everyone)&name=*" + "&enableStore=(true OR null)&group=true&group.field=name&group.ngroups=true&group.sort=versionTimestamp desc" + "&lcState=(PUBLISHED OR PROTOTYPED)";
    Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
    // search for 'test' in description
    inputQuery = "description:test";
    expected = "store_view_roles=(null OR internal\\/subscriber OR internal\\/everyone)&" + "description=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
    // search for provider 'pubuser'
    inputQuery = "provider:pubuser";
    expected = "store_view_roles=(null OR internal\\/subscriber OR internal\\/everyone)&" + "provider=*pubuser*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for provider search. ", expected, searchQuery);
    // search for propertyname 'test'
    inputQuery = "property_name:test";
    expected = "store_view_roles=(null OR internal\\/subscriber OR internal\\/everyone)" + "&api_meta.property_name__display=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for property search. ", expected, searchQuery);
}
Also used : UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) Test(org.junit.Test)

Example 9 with UserContext

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

the class RegistrySearchUtilTestCase method testAnonymousUserQueryInDevPortal.

@Test
public void testAnonymousUserQueryInDevPortal() throws APIPersistenceException {
    // Normal dev portal api listing
    String inputQuery = "";
    UserContext ctx = new UserContext("wso2.anonymous.user", organization, null, anonymousRoles);
    String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    String expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&name=*&enableStore=(true OR null)" + "&group=true&group.field=name&group.ngroups=true&group.sort=versionTimestamp desc&lcState=(PUBLISHED OR PROTOTYPED)";
    Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
    // search for 'test' in description
    inputQuery = "description:test";
    expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&" + "description=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
    // search for provider 'pubuser'
    inputQuery = "provider:pubuser";
    expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&" + "provider=*pubuser*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for provider search. ", expected, searchQuery);
    // search for propertyname 'test'
    inputQuery = "property_name:test";
    expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)" + "&api_meta.property_name__display=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
    searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
    Assert.assertEquals("Generated query mismatched for property search. ", expected, searchQuery);
}
Also used : UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) Test(org.junit.Test)

Example 10 with UserContext

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

the class RegistrySearchUtilTestCase method testPublisherUserQueryInPublisher.

@Test
public void testPublisherUserQueryInPublisher() throws APIPersistenceException {
    // Normal publisher api listing
    String inputQuery = "";
    UserContext ctx = new UserContext("publisher", organization, null, publisherRoles);
    String searchQuery = RegistrySearchUtil.getPublisherSearchQuery(inputQuery, ctx);
    String expected = "publisher_roles=(null OR internal\\/creator OR internal\\/publisher OR internal\\/everyone)" + "&name=*&type=(HTTP OR WS OR SOAPTOREST OR GRAPHQL OR SOAP OR SSE OR WEBSUB OR WEBHOOK OR ASYNC)";
    Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
    // search for 'test' in description
    inputQuery = "description:test";
    expected = "publisher_roles=(null OR internal\\/creator OR internal\\/publisher OR internal\\/everyone)" + "&description=*test*&type=(HTTP OR WS OR SOAPTOREST OR GRAPHQL OR SOAP OR SSE OR WEBSUB OR WEBHOOK " + "OR ASYNC)";
    searchQuery = RegistrySearchUtil.getPublisherSearchQuery(inputQuery, ctx);
    Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
}
Also used : UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) Test(org.junit.Test)

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