Commit 9d50a245 by Suma Shivaprasad

BUG-32830 Fixed - Result count for all search API calls

parent 54c3c7f0
......@@ -51,13 +51,16 @@ public class MetadataServiceClient {
private static final Logger LOG = LoggerFactory.getLogger(MetadataServiceClient.class);
public static final String REQUEST_ID = "requestId";
public static final String RESULTS = "results";
public static final String TOTAL_SIZE = "totalSize";
public static final String COUNT = "count";
public static final String ROWS = "rows";
private static final String BASE_URI = "api/metadata/";
private static final String URI_TYPES = "types";
private static final String URI_ENTITIES = "entities";
private static final String URI_TRAITS = "traits";
private static final String URI_SEARCH = "discovery/search";
private WebResource service;
public MetadataServiceClient(String baseUrl) {
......
......@@ -143,14 +143,10 @@ public class EntityResource {
* Gets the list of entities for a given entity type.
*
* @param entityType name of a type which is unique
* @param offset starting offset for pagination
* @param resultsPerPage number of results for pagination
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getEntityListByType(@QueryParam("type") String entityType,
@DefaultValue("0") @QueryParam("offset") Integer offset,
@QueryParam("numResults") Integer resultsPerPage) {
public Response getEntityListByType(@QueryParam("type") String entityType) {
Preconditions.checkNotNull(entityType, "Entity type cannot be null");
try {
LOG.debug("Fetching entity list for type={} ", entityType);
......@@ -160,7 +156,7 @@ public class EntityResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("type", entityType);
response.put(MetadataServiceClient.RESULTS, new JSONArray(entityList));
response.put(MetadataServiceClient.TOTAL_SIZE, entityList.size());
response.put(MetadataServiceClient.COUNT, entityList.size());
return Response.ok(response).build();
} catch (MetadataException | IllegalArgumentException e) {
......@@ -225,7 +221,7 @@ public class EntityResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(GUID, guid);
response.put(MetadataServiceClient.RESULTS, new JSONArray(traitNames));
response.put(MetadataServiceClient.TOTAL_SIZE, traitNames.size());
response.put(MetadataServiceClient.COUNT, traitNames.size());
return Response.ok(response).build();
} catch (MetadataException | IllegalArgumentException e) {
......
......@@ -165,7 +165,7 @@ public class RexsterGraphResource {
JSONObject response = new JSONObject();
response.put(MetadataServiceClient.RESULTS, new JSONObject(vertexProperties));
response.put(MetadataServiceClient.TOTAL_SIZE, vertexProperties.size());
response.put(MetadataServiceClient.COUNT, vertexProperties.size());
return Response.ok(response).build();
} catch (JSONException e) {
throw new WebApplicationException(
......@@ -276,7 +276,7 @@ public class RexsterGraphResource {
if (!countOnly) {
response.put(MetadataServiceClient.RESULTS, elementArray);
}
response.put(MetadataServiceClient.TOTAL_SIZE, counter);
response.put(MetadataServiceClient.COUNT, counter);
return Response.ok(response).build();
}
......@@ -323,7 +323,7 @@ public class RexsterGraphResource {
JSONObject response = new JSONObject();
response.put(MetadataServiceClient.RESULTS, vertexArray);
response.put(MetadataServiceClient.TOTAL_SIZE, counter);
response.put(MetadataServiceClient.COUNT, counter);
return response;
}
......
......@@ -136,7 +136,7 @@ public class TypesResource {
JSONObject response = new JSONObject();
response.put(MetadataServiceClient.RESULTS, new JSONArray(result));
response.put(MetadataServiceClient.TOTAL_SIZE, result.size());
response.put(MetadataServiceClient.COUNT, result.size());
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build();
......
......@@ -83,8 +83,12 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
JSONObject results = response.getJSONObject(MetadataServiceClient.RESULTS);
Assert.assertNotNull(results);
JSONArray rows = results.getJSONArray("rows");
JSONArray rows = results.getJSONArray(MetadataServiceClient.ROWS);
Assert.assertEquals(rows.length(), 1);
int numRows = response.getInt(MetadataServiceClient.COUNT);
Assert.assertEquals(numRows, 1);
}
@Test
......@@ -164,6 +168,9 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(row.get("guid"));
Assert.assertEquals(row.getString("typeName"), "dsl_test_type");
Assert.assertNotNull(row.get("score"));
int numRows = response.getInt(MetadataServiceClient.COUNT);
Assert.assertEquals(numRows, 1);
}
private void createTypes() throws Exception {
......
Markdown is supported
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