Unverified Commit 47e0a898 authored by Anil Gupta's avatar Anil Gupta Committed by GitHub
Browse files

Issue #SB-25737 merge: Merge pull request #721 from shiva-rakshith/visiblity-private-search-api

SB-25737 - Search Private Read API
parents 64636afe 4bdaec7c
s-debug AmiableAnil-patch-1 Gcloud_copy Gcloud_fix Remove_unwantedCode_Gcloud_fix bulk-upload-comptenecy-mapping bulk-upload-excelsheet bulk-upload-test_excel bulk_upload csp-migration dependabot/maven/platform-core/platform-telemetry/ch.qos.logback-logback-core-1.2.9 dependabot/maven/search-api/search-core/org.apache.httpcomponents-httpclient-4.5.13 knowlg-friday knowlg-oneclick local-setup-kube master patch-1 patch-2 patch-3 poc_bulk_upload qs-schema rahul_bulk_upload_postgres release-4.10.0 release-4.10.1 release-4.3.0 release-4.4.0 release-4.5.0 release-4.6.0 release-4.7.0 release-4.7.0-debug release-4.8.0 release-4.8.0-debug release-4.9.0 release-4.9.1 release-5.0.0 release-5.0.1 release-5.1.0 release-5.1.0-content release-5.2.0 release-5.3.0 revert-718-visiblity-private-api revert-719-assessment-private-read-api revert-720-visiblity-public-search-api revert-721-visiblity-private-search-api release-5.2.0_RC2 release-5.2.0_RC1 release-5.1.0_RC1 release-5.0.0_RC2 release-5.0.0_RC1 release-4.10.0_RC2 release-4.10.0_RC1 release-4.9.1_RC1 release-4.9.0_RC8 release-4.9.0_RC7 release-4.9.0_RC6 release-4.9.0_RC5 release-4.9.0_RC4 release-4.9.0_RC3 release-4.9.0_RC2 release-4.9.0_RC1 release-4.8.0_RC5 release-4.8.0_RC4 release-4.8.0_RC3 release-4.8.0_RC2 release-4.8.0_RC1 release-4.7.0_RC6 release-4.7.0_RC5 release-4.7.0_RC4 release-4.7.0_RC3 release-4.7.0_RC2 release-4.7.0_RC1 release-4.6.0_RC2 release-4.6.0_RC1 release-4.5.0_RC2 release-4.5.0_RC1 release-4.4.0_RC6 release-4.4.0_RC5 release-4.4.0_RC4 release-4.4.0_RC3 release-4.4.0_RC2 release-4.4.0_RC1 release-4.3.0_RC10 release-4.3.0_RC9 release-4.3.0_RC8 release-4.3.0_RC7 release-4.3.0_RC6 release-4.3.0_RC5 release-4.3.0_RC4 release-4.3.0_RC3 release-4.3.0_RC2
No related merge requests found
Showing with 58 additions and 2 deletions
+58 -2
......@@ -799,6 +799,27 @@ public class SearchActorTest extends SearchBaseActorTest {
Assert.assertEquals(ResponseCode.CLIENT_ERROR.code(), response.getResponseCode().code());
}
@Test
public void testPrivateSearch() {
Request request = getSearchRequest();
getSearchRequest().setId("api.search-service.private.search");
request.put("CHANNEL_ID","in.ekstep");
Map<String, Object> filters = new HashMap<String, Object>();
filters.put("identifier", "do_10000036");
request.put("filters", filters);
Response response = getSearchResponse(request);
Map<String, Object> result = response.getResult();
Request req = getGroupSearchResultsRequest();
req.put("searchResult", result);
Response resp = getSearchResponse(req);
ResponseCode res = resp.getResponseCode();
boolean statusCode = false;
if (res == ResponseCode.OK) {
statusCode = true;
}
Assert.assertTrue(statusCode);
}
@SuppressWarnings("unchecked")
@Test
public void testSearchByFields() {
......
......@@ -162,6 +162,16 @@ public class SearchBaseActorTest {
content.put("contentType", "Course");
content.put("courseType", "TrainingCourse");
addToIndex("10000035", content);
content = getContentTestRecord("do_10000036", 36, "test-board5");
content.put("name", "Test Course - 36");
content.put("description", "Test Course - TrainingCourse");
content.put("visibility", "Private");
content.put("channel", "in.ekstep");
content.put("mimeType", "application/vnd.ekstep.content-collection");
content.put("contentType", "Course");
content.put("courseType", "TrainingCourse");
addToIndex("10000036", content);
}
private static void addToIndex(String uniqueId, Map<String, Object> doc) throws Exception {
......
......@@ -5,9 +5,10 @@ import com.google.inject.Inject
import com.google.inject.name.Named
import handlers.LoggingAction
import managers.SearchManager
import org.sunbird.search.util.SearchConstants
import play.api.mvc.ControllerComponents
import utils.{ActorNames, ApiId}
import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext
class SearchController @Inject()(@Named(ActorNames.SEARCH_ACTOR) searchActor: ActorRef, loggingAction: LoggingAction, cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends SearchBaseController(cc) {
......@@ -20,6 +21,18 @@ class SearchController @Inject()(@Named(ActorNames.SEARCH_ACTOR) searchActor: Ac
getResult(mgr.search(internalReq, searchActor), ApiId.APPLICATION_SEARCH)
}
def privateSearch() = loggingAction.async { implicit request =>
val internalReq = getRequest(ApiId.APPLICATION_PRIVATE_SEARCH)
setHeaderContext(internalReq)
val channel = internalReq.getContext.getOrDefault("CHANNEL_ID", "").asInstanceOf[String]
if(!channel.isBlank) {
val filters = internalReq.getRequest.getOrDefault(SearchConstants.filters,"").asInstanceOf[java.util.Map[String, Object]]
filters.putAll(Map("channel" -> channel).asJava)
internalReq.getContext.put("filters", filters)
}
getResult(mgr.search(internalReq, searchActor), ApiId.APPLICATION_PRIVATE_SEARCH)
}
def count() = Action.async { implicit request =>
val internalReq = getRequest(ApiId.APPLICATION_COUNT)
setHeaderContext(internalReq)
......
......@@ -5,5 +5,6 @@ object ApiId {
final val APPLICATION_HEALTH = "api.search-service.health"
final val APPLICATION_SERVICE_HEALTH = "api.search.service.health"
final val APPLICATION_SEARCH = "api.search-service.search"
final val APPLICATION_PRIVATE_SEARCH = "api.search-service.private.search"
final val APPLICATION_COUNT = "api.search-service.count"
}
......@@ -6,6 +6,7 @@ GET /service/health controllers.HealthController.serviceHealth()
#POST /v2/search controllers.SearchController.search()
POST /v3/search controllers.SearchController.search()
POST /v3/private/search controllers.SearchController.privateSearch()
POST /v2/search/count controllers.SearchController.count()
POST /v3/count controllers.SearchController.count()
#POST /v2/metrics controllers.MetricsController.search()
......
......@@ -2,6 +2,7 @@ package controllers
import org.junit.runner._
import org.specs2.runner._
import play.api.libs.json.{JsValue, Json}
import play.api.test._
import play.api.test.Helpers._
......@@ -15,7 +16,16 @@ class SearchSpec extends BaseSpec {
isOK(response)
status(response) must equalTo(OK)
}
"search contents on private search request" in {
val controller = app.injector.instanceOf[controllers.SearchController]
val json: JsValue = Json.parse("""{"request": {"filters": {"objectType": ["Framework"]}}}""")
val fakeRequest = FakeRequest("POST", "/v3/private/search").withJsonBody(json).withHeaders(FakeHeaders())
val response = controller.privateSearch()(fakeRequest)
isOK(response)
status(response) must equalTo(OK)
}
"getcount of search filters" in {
val controller = app.injector.instanceOf[controllers.SearchController]
val response = controller.count()(FakeRequest())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment