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