Search in sources :

Example 1 with IndexQueryRequest

use of gov.ca.cwds.rest.api.domain.es.IndexQueryRequest in project API by ca-cwds.

the class IndexQueryServiceTest method testHandleRequest.

@Test
public void testHandleRequest() throws Exception {
    Map<String, String> test = new HashMap<String, String>();
    test.put("a", "value");
    req = new IndexQueryRequest("index", test);
    String query = new JSONObject(test).toString();
    when(target.callDao("index", query)).thenReturn(("fred"));
    final IndexQueryResponse actual = target.handleRequest(req);
    IndexQueryResponse expected = new IndexQueryResponse("fred");
    assertThat(actual, is(equalTo(expected)));
}
Also used : IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) IndexQueryRequest(gov.ca.cwds.rest.api.domain.es.IndexQueryRequest) Test(org.junit.Test)

Example 2 with IndexQueryRequest

use of gov.ca.cwds.rest.api.domain.es.IndexQueryRequest in project API by ca-cwds.

the class IndexQueryResource method searchIndex.

/**
   * Endpoint for Intake Person Query Search.
   * 
   * @param index {@link IndexQueryRequest}
   * @param req JSON {@link IndexQueryRequest}
   * @return web service response
   */
@POST
@Path("/{index}/_search")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Unable to process JSON"), @ApiResponse(code = 401, message = "Not Authorized"), @ApiResponse(code = 406, message = "Accept Header not supported") })
@ApiOperation(value = "Query ElasticSearch Persons on given search terms", code = HttpStatus.SC_OK, response = JSONObject.class)
@Consumes(value = MediaType.APPLICATION_JSON)
public Response searchIndex(@PathParam("index") @ApiParam(required = true, name = "index", value = "The index of the search") String index, @Valid @ApiParam(hidden = false, required = true) Object req) {
    Response ret;
    try {
        IndexQueryRequest personQueryRequest = new IndexQueryRequest(index, req);
        IndexQueryResponse personQueryResponse = (IndexQueryResponse) resourceDelegate.handle(personQueryRequest).getEntity();
        if (personQueryResponse != null) {
            ret = Response.status(Response.Status.OK).entity(personQueryResponse.getPersons()).build();
        } else {
            ret = null;
        }
    } catch (Exception e) {
        LOGGER.error("Intake Person Query ERROR: {}", e.getMessage(), e);
        throw new ApiException("Intake Person Query ERROR. " + e.getMessage(), e);
    }
    return ret;
}
Also used : IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) IndexQueryRequest(gov.ca.cwds.rest.api.domain.es.IndexQueryRequest) ApiException(gov.ca.cwds.rest.api.ApiException) ApiException(gov.ca.cwds.rest.api.ApiException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

IndexQueryRequest (gov.ca.cwds.rest.api.domain.es.IndexQueryRequest)2 IndexQueryResponse (gov.ca.cwds.rest.api.domain.es.IndexQueryResponse)2 ApiException (gov.ca.cwds.rest.api.ApiException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1