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