Commit 4978a9be by TJBChris

Fixed JSON output for search and relationshipwalk. Subobjects were not

broken out properly
parent ebcb1392
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.discovery; package org.apache.hadoop.metadata.discovery;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.codehaus.jettison.json.JSONObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -45,12 +46,12 @@ public interface DiscoveryService { ...@@ -45,12 +46,12 @@ public interface DiscoveryService {
* @param searchText is plain text * @param searchText is plain text
* @param prop is the Vertex property to search. * @param prop is the Vertex property to search.
*/ */
Map<String, HashMap<String,Map<String,String>>> textSearch(String searchText, int depth, String prop); Map<String, HashMap<String,JSONObject>> textSearch(String searchText, int depth, String prop);
/** /**
* Simple graph walker for search interface, which allows following of specific edges only. * Simple graph walker for search interface, which allows following of specific edges only.
* @param edgesToFollow is a comma-separated-list of edges to follow. * @param edgesToFollow is a comma-separated-list of edges to follow.
*/ */
Map<String, HashMap<String,Map<String,String>>> relationshipWalk(String guid, int depth, String edgesToFollow); Map<String, HashMap<String,JSONObject>> relationshipWalk(String guid, int depth, String edgesToFollow);
} }
...@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions; ...@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.repository.MetadataRepository; import org.apache.hadoop.metadata.repository.MetadataRepository;
import org.codehaus.jettison.json.JSONObject;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -60,7 +61,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -60,7 +61,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
* @param prop is the Vertex property to search. * @param prop is the Vertex property to search.
*/ */
@Override @Override
public Map<String, HashMap<String,Map<String,String>>> textSearch(String searchText, int depth, String prop) { public Map<String, HashMap<String,JSONObject>> textSearch(String searchText, int depth, String prop) {
Preconditions.checkNotNull(searchText, "Invalid argument: \"text\" cannot be null."); Preconditions.checkNotNull(searchText, "Invalid argument: \"text\" cannot be null.");
Preconditions.checkNotNull(prop, "Invalid argument: \"prop\" cannot be null."); Preconditions.checkNotNull(prop, "Invalid argument: \"prop\" cannot be null.");
...@@ -72,7 +73,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -72,7 +73,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
* @param edgesToFollow is a comma-separated-list of edges to follow. * @param edgesToFollow is a comma-separated-list of edges to follow.
*/ */
@Override @Override
public Map<String, HashMap<String,Map<String,String>>> relationshipWalk(String guid, int depth, String edgesToFollow) { public Map<String, HashMap<String,JSONObject>> relationshipWalk(String guid, int depth, String edgesToFollow) {
Preconditions.checkNotNull(guid, "Invalid argument: \"guid\" cannot be null."); Preconditions.checkNotNull(guid, "Invalid argument: \"guid\" cannot be null.");
Preconditions.checkNotNull(edgesToFollow, "Invalid argument: \"edgesToFollow\" cannot be null."); Preconditions.checkNotNull(edgesToFollow, "Invalid argument: \"edgesToFollow\" cannot be null.");
......
...@@ -23,6 +23,7 @@ import org.apache.hadoop.metadata.ITypedReferenceableInstance; ...@@ -23,6 +23,7 @@ import org.apache.hadoop.metadata.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.service.Service; import org.apache.hadoop.metadata.service.Service;
import org.apache.hadoop.metadata.storage.RepositoryException; import org.apache.hadoop.metadata.storage.RepositoryException;
import org.codehaus.jettison.json.JSONObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -56,11 +57,11 @@ public interface MetadataRepository extends Service { ...@@ -56,11 +57,11 @@ public interface MetadataRepository extends Service {
* @param searchText is plain text * @param searchText is plain text
* @param prop is the Vertex property to search. * @param prop is the Vertex property to search.
*/ */
Map<String,HashMap<String,Map<String,String>>> textSearch(String searchText, int depth, String prop); Map<String, HashMap<String,JSONObject>> textSearch(String searchText, int depth, String prop);
/** /**
* Simple graph walker for search interface, which allows following of specific edges only. * Simple graph walker for search interface, which allows following of specific edges only.
* @param edgesToFollow is a comma-separated-list of edges to follow. * @param edgesToFollow is a comma-separated-list of edges to follow.
*/ */
Map<String,HashMap<String,Map<String,String>>> relationshipWalk(String guid, int depth, String edgesToFollow); Map<String, HashMap<String,JSONObject>> relationshipWalk(String guid, int depth, String edgesToFollow);
} }
...@@ -47,6 +47,7 @@ import org.apache.hadoop.metadata.types.ObjectGraphWalker; ...@@ -47,6 +47,7 @@ import org.apache.hadoop.metadata.types.ObjectGraphWalker;
import org.apache.hadoop.metadata.types.StructType; import org.apache.hadoop.metadata.types.StructType;
import org.apache.hadoop.metadata.types.TraitType; import org.apache.hadoop.metadata.types.TraitType;
import org.apache.hadoop.metadata.types.TypeSystem; import org.apache.hadoop.metadata.types.TypeSystem;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -184,7 +185,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -184,7 +185,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
return entityList; return entityList;
} }
private static void searchWalker (Vertex vtx, final int max, int counter, HashMap<String,Map<String,String>> e, HashMap<String,Map<String,String>> v, String edgesToFollow) { private static void searchWalker (Vertex vtx, final int max, int counter, HashMap<String,JSONObject> e, HashMap<String,JSONObject> v, String edgesToFollow) {
counter++; counter++;
if (counter <= max) { if (counter <= max) {
...@@ -215,7 +216,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -215,7 +216,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
// Add to the Vertex map. // Add to the Vertex map.
v.put(vtx.getId().toString(), jsonVertexMap); v.put(vtx.getId().toString(), new JSONObject(jsonVertexMap));
// Follow this Vertex's edges // Follow this Vertex's edges
while (edgeIterator != null && edgeIterator.hasNext()) { while (edgeIterator != null && edgeIterator.hasNext()) {
...@@ -246,7 +247,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -246,7 +247,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
*/ */
e.put(edge.getId().toString(), jsonEdgeMap); e.put(edge.getId().toString(), new JSONObject(jsonEdgeMap));
searchWalker (edge.getVertex(d), max, counter, e, v, edgesToFollow); searchWalker (edge.getVertex(d), max, counter, e, v, edgesToFollow);
} }
...@@ -263,14 +264,14 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -263,14 +264,14 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
* @param prop is the Vertex property to search. * @param prop is the Vertex property to search.
*/ */
@Override @Override
public Map<String,HashMap<String,Map<String,String>>> textSearch(String searchText, int depth, String prop) { public Map<String,HashMap<String,JSONObject>> textSearch(String searchText, int depth, String prop) {
HashMap<String,HashMap<String,Map<String,String>>> result = new HashMap<String,HashMap<String,Map<String,String>>>(); HashMap<String,HashMap<String,JSONObject>> result = new HashMap<String,HashMap<String,JSONObject>>();
// HashMaps, which contain sub JOSN Objects to be relayed back to the parent. // 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,JSONObject> vertices = new HashMap<String,JSONObject>();
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>(); HashMap<String,JSONObject> edges = new HashMap<String,JSONObject>();
/* Later - when we allow search limitation by "type". /* Later - when we allow search limitation by "type".
ArrayList<String> typesList = new ArrayList<String>(); ArrayList<String> typesList = new ArrayList<String>();
...@@ -306,13 +307,13 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -306,13 +307,13 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
* @param edgesToFollow is a comma-separated-list of edges to follow. * @param edgesToFollow is a comma-separated-list of edges to follow.
*/ */
@Override @Override
public Map<String,HashMap<String,Map<String,String>>> relationshipWalk(String guid, int depth, String edgesToFollow) { public Map<String,HashMap<String,JSONObject>> relationshipWalk(String guid, int depth, String edgesToFollow) {
HashMap<String,HashMap<String,Map<String,String>>> result = new HashMap<String,HashMap<String,Map<String,String>>>(); HashMap<String,HashMap<String,JSONObject>> result = new HashMap<String,HashMap<String,JSONObject>>();
// HashMaps, which contain sub JOSN Objects to be relayed back to the parent. // 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,JSONObject> vertices = new HashMap<String,JSONObject>();
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>(); HashMap<String,JSONObject> edges = new HashMap<String,JSONObject>();
// Get the Vertex with the specified GUID. // Get the Vertex with the specified GUID.
Vertex v = GraphHelper.findVertexByGUID(graphService.getBlueprintsGraph(), guid); Vertex v = GraphHelper.findVertexByGUID(graphService.getBlueprintsGraph(), guid);
......
...@@ -135,10 +135,10 @@ public class MetadataDiscoveryResource { ...@@ -135,10 +135,10 @@ public class MetadataDiscoveryResource {
try { try {
response.put("requestId", Thread.currentThread().getName()); response.put("requestId", Thread.currentThread().getName());
if (resultMap.containsKey("vertices")) { if (resultMap.containsKey("vertices")) {
response.put("vertices",resultMap.get("vertices")); response.put("vertices",new JSONObject(resultMap.get("vertices")));
} }
if (resultMap.containsKey("edges")) { if (resultMap.containsKey("edges")) {
response.put("edges",resultMap.get("edges")); response.put("edges",new JSONObject(resultMap.get("vertices")));
} }
} catch (JSONException e) { } catch (JSONException e) {
throw new WebApplicationException( throw new WebApplicationException(
......
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