Commit 2f3ab4fc authored by neelesh thakur's avatar neelesh thakur
Browse files

Merge branch 'master' into sort

parents b6f9efdf 664239f3
Pipeline #45246 failed with stages
in 65 minutes and 18 seconds
......@@ -16,6 +16,7 @@ package org.opengroup.osdu.search.api;
import io.swagger.annotations.*;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.model.http.AppError;
......@@ -93,8 +94,8 @@ public class SearchApi {
try{
QueryResponse searchResponse = queryService.queryIndex(queryRequest);
return new ResponseEntity<QueryResponse>(searchResponse, HttpStatus.OK);
} catch (NotFoundException e) {
return new ResponseEntity<QueryResponse>(QueryResponse.getEmptyResponse(), HttpStatus.OK);
} catch (AppException e) {
return handleIndexNotFoundException(e, QueryResponse.getEmptyResponse());
}
}
......@@ -126,8 +127,8 @@ public class SearchApi {
try{
CursorQueryResponse searchResponse = scrollQueryService.queryIndex(queryRequest);
return new ResponseEntity<CursorQueryResponse>(searchResponse, HttpStatus.OK);
} catch (NotFoundException e) {
return new ResponseEntity<CursorQueryResponse>(CursorQueryResponse.getEmptyResponse(), HttpStatus.OK);
} catch (AppException e) {
return handleIndexNotFoundException(e, CursorQueryResponse.getEmptyResponse());
}
}
......@@ -159,8 +160,15 @@ public class SearchApi {
try{
CcsQueryResponse searchResponse = ccsQueryService.makeRequest(queryRequest);
return new ResponseEntity<CcsQueryResponse>(searchResponse, HttpStatus.OK);
} catch (NotFoundException e) {
return new ResponseEntity<CcsQueryResponse>(new CcsQueryResponse(), HttpStatus.OK);
} catch (AppException e) {
return handleIndexNotFoundException(e, new CcsQueryResponse());
}
}
private <T> ResponseEntity<T> handleIndexNotFoundException(AppException e, T response) {
if (e.getError().getCode() == HttpStatus.NOT_FOUND.value()
&& e.getError().getMessage().equals("Resource you are trying to find does not exists"))
return new ResponseEntity<>(response, HttpStatus.OK);
throw e;
}
}
......@@ -155,6 +155,33 @@ public class SearchApiTest {
}
}
@Test
public void should_handle_notFoundException_whenQueried() throws Exception {
AppException exception = new AppException(HttpServletResponse.SC_NOT_FOUND, "Not Found", "Resource you are trying to find does not exists");
when(this.queryService.queryIndex(any())).thenThrow(exception);
ResponseEntity<QueryResponse> response = this.sut.queryRecords(new QueryRequest());
assertEquals(HttpServletResponse.SC_OK, response.getStatusCodeValue());
QueryResponse apiResponse = response.getBody();
assertEquals(0, apiResponse.getTotalCount());
assertEquals(0, apiResponse.getAggregations().size());
assertEquals(0, apiResponse.getResults().size());
}
@Test
public void should_handle_notFoundException_whenCursorQueried() throws Exception {
AppException exception = new AppException(HttpServletResponse.SC_NOT_FOUND, "Not Found", "Resource you are trying to find does not exists");
when(this.scrollQueryService.queryIndex(any())).thenThrow(exception);
ResponseEntity<CursorQueryResponse> response = this.sut.queryWithCursor(new CursorQueryRequest());
assertEquals(HttpServletResponse.SC_OK, response.getStatusCodeValue());
CursorQueryResponse apiResponse = response.getBody();
assertEquals(0, apiResponse.getTotalCount());
assertEquals(0, apiResponse.getResults().size());
}
@Test
public void should_returnRecords_whenCursorQueried() throws Exception {
......
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