Commit d97a7236 by Dan Markwat
parents c7218046 7828bdf5
......@@ -26,9 +26,9 @@ import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.discovery.DiscoveryService;
import org.apache.hadoop.metadata.repository.graph.GraphHelper;
import org.apache.hadoop.metadata.repository.graph.GraphService;
import org.apache.hadoop.metadata.types.TypeSystem;
import org.apache.hadoop.metadata.web.util.Servlets;
......@@ -154,25 +154,30 @@ public class MetadataDiscoveryResource {
// Parent JSON Object
JSONObject response = new JSONObject();
// HashMaps, which contain sub JOSN Objects to be relayed back to the parent.
HashMap<String,Map<String,String>> vertices = new HashMap<String,Map<String,String>>();
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>();
// Get the Vertex with the specified GUID.
for (Vertex v: getGraph().query().has("guid", guid).vertices()) {
Vertex v = GraphHelper.findVertexByGUID(getGraph(), guid);
if (v != null) {
searchWalker(v, depth, 0, edges, vertices, edgesToFollow);
LOG.debug("Vertex {} found for guid {}", v, guid);
} else {
LOG.debug("Vertex not found for guid {}", guid);
}
try {
response.put("requestId", Thread.currentThread().getName());
response.put("vertices",vertices);
response.put("edges",edges);
} catch (JSONException e) {
throw new WebApplicationException(
Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR));
}
LOG.debug("JSON result:" + response.toString());
return Response.ok(response).build();
}
......@@ -215,20 +220,26 @@ public class MetadataDiscoveryResource {
HashMap<String,Map<String,String>> vertices = new HashMap<String,Map<String,String>>();
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>();
int resultCount = 0;
for (Vertex v: getGraph().query().has(prop,searchText).vertices()) {
searchWalker(v, depth, 0, edges, vertices, null);
resultCount++;
}
LOG.debug("Search for {} returned {} results.", searchText ,resultCount);
try {
response.put("requestId", Thread.currentThread().getName());
response.put("vertices",vertices);
response.put("edges",edges);
} catch (JSONException e) {
throw new WebApplicationException(
Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR));
}
LOG.debug("JSON result:" + response.toString());
return Response.ok(response).build();
}
......@@ -305,15 +316,5 @@ public class MetadataDiscoveryResource {
}
private static void validateInputs(String errorMsg, String... inputs) {
for (String input : inputs) {
if (StringUtils.isEmpty(input)) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity(errorMsg)
.type("text/plain")
.build());
}
}
}
}
......@@ -59,18 +59,19 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
}
@Test (dependsOnMethods = "testUriExists", enabled = false)
public void testSearchForNonExistentText() throws Exception {
@Test (dependsOnMethods = "testFullTextUriExists")
public void testSearchForText() throws Exception {
WebResource resource = service
.path("api/metadata/discovery/search/fulltext")
.queryParam("depth", "0").queryParam("text","foo").queryParam("property","Name");
.queryParam("depth", "3").queryParam("text","bar").queryParam("property","hive_table.name");
ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
//TODO - Assure zero vertices and edges.
Assert.assertEquals(true,true);
//TODO - Assure zero vertices and edges.
Assert.assertNotEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
......
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