Search in sources :

Example 1 with IndexQueryResponse

use of gov.ca.cwds.rest.api.domain.es.IndexQueryResponse 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 IndexQueryResponse

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

the class IndexQueryService method handleRequest.

@Override
protected IndexQueryResponse handleRequest(IndexQueryRequest req) {
    checkArgument(req != null, "query cannot be Null or empty");
    @SuppressWarnings("unchecked") String query = new JSONObject((Map<String, String>) req.getQuery()).toString();
    if (StringUtils.isBlank(query)) {
        LOGGER.error("query cannot be null.");
        throw new ServiceException("query cannot be null.");
    }
    return new IndexQueryResponse(callDao(req.getIndex(), query));
}
Also used : IndexQueryResponse(gov.ca.cwds.rest.api.domain.es.IndexQueryResponse) JSONObject(org.json.JSONObject) ServiceException(gov.ca.cwds.rest.services.ServiceException) Map(java.util.Map)

Example 3 with IndexQueryResponse

use of gov.ca.cwds.rest.api.domain.es.IndexQueryResponse 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

IndexQueryResponse (gov.ca.cwds.rest.api.domain.es.IndexQueryResponse)3 IndexQueryRequest (gov.ca.cwds.rest.api.domain.es.IndexQueryRequest)2 JSONObject (org.json.JSONObject)2 ApiException (gov.ca.cwds.rest.api.ApiException)1 ServiceException (gov.ca.cwds.rest.services.ServiceException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 Test (org.junit.Test)1