Commit 4b2a4cae by Shwetha GS

fixed test failures - GraphBackedMetadataRepositoryTest#testFullTextSearch, DSLTest.test1

parent 8e73ed24
...@@ -473,9 +473,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -473,9 +473,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
Id id = typedInstance.getId(); Id id = typedInstance.getId();
Vertex instanceVertex = entityProcessor.idToVertexMap.get(id); Vertex instanceVertex = entityProcessor.idToVertexMap.get(id);
String fullText = getFullTextForVertex(instanceVertex, true); String fullText = getFullTextForVertex(instanceVertex, true);
instanceVertex.setProperty(Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); addProperty(instanceVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText);
LOG.debug("Adding {} for {} = {}", Constants.ENTITY_TEXT_PROPERTY_KEY,
instanceVertex, fullText);
} }
} }
...@@ -658,8 +656,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -658,8 +656,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
private void mapInstanceToVertex(Id id, ITypedInstance typedInstance, Vertex instanceVertex, private void mapInstanceToVertex(Id id, ITypedInstance typedInstance, Vertex instanceVertex,
Map<String, AttributeInfo> fields, Map<String, AttributeInfo> fields,
Map<Id, Vertex> idToVertexMap) throws MetadataException { Map<Id, Vertex> idToVertexMap) throws MetadataException {
LOG.debug("Mapping instance {} to vertex {} for fields {}", LOG.debug("Mapping instance {} of {} to vertex {}",
typedInstance.getTypeName(), instanceVertex, fields); typedInstance, typedInstance.getTypeName(), instanceVertex);
for (AttributeInfo attributeInfo : fields.values()) { for (AttributeInfo attributeInfo : fields.values()) {
final IDataType dataType = attributeInfo.dataType(); final IDataType dataType = attributeInfo.dataType();
mapAttributesToVertex(id, typedInstance, instanceVertex, mapAttributesToVertex(id, typedInstance, instanceVertex,
...@@ -672,9 +670,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -672,9 +670,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
Map<Id, Vertex> idToVertexMap, Map<Id, Vertex> idToVertexMap,
AttributeInfo attributeInfo, AttributeInfo attributeInfo,
IDataType dataType) throws MetadataException { IDataType dataType) throws MetadataException {
LOG.debug("mapping attributeInfo {}", attributeInfo); Object attrValue = typedInstance.get(attributeInfo.name);
LOG.debug("mapping attribute {} = {}", attributeInfo.name, attrValue);
final String propertyName = getQualifiedName(typedInstance, attributeInfo); final String propertyName = getQualifiedName(typedInstance, attributeInfo);
if (typedInstance.get(attributeInfo.name) == null) { if (attrValue == null) {
return; return;
} }
...@@ -684,8 +683,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -684,8 +683,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
break; break;
case ENUM: case ENUM:
instanceVertex.setProperty(propertyName, addProperty(instanceVertex, propertyName, typedInstance.getInt(attributeInfo.name));
typedInstance.getInt(attributeInfo.name));
break; break;
case ARRAY: case ARRAY:
...@@ -749,7 +747,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -749,7 +747,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
buffer.setLength(buffer.length() - 1); buffer.setLength(buffer.length() - 1);
// for dereference on way out // for dereference on way out
instanceVertex.setProperty(propertyName, buffer.toString()); addProperty(instanceVertex, propertyName, buffer.toString());
} }
private void mapMapCollectionToVertex(Id id, ITypedInstance typedInstance, private void mapMapCollectionToVertex(Id id, ITypedInstance typedInstance,
...@@ -778,7 +776,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -778,7 +776,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
buffer.setLength(buffer.length() - 1); buffer.setLength(buffer.length() - 1);
// for dereference on way out // for dereference on way out
instanceVertex.setProperty(propertyName, buffer.toString()); addProperty(instanceVertex, propertyName, buffer.toString());
} }
private String mapCollectionEntryToVertex(Id id, Vertex instanceVertex, private String mapCollectionEntryToVertex(Id id, Vertex instanceVertex,
...@@ -792,7 +790,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -792,7 +790,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
switch (elementType.getTypeCategory()) { switch (elementType.getTypeCategory()) {
case PRIMITIVE: case PRIMITIVE:
case ENUM: case ENUM:
instanceVertex.setProperty(propertyNameWithSuffix, value); addProperty(instanceVertex, propertyNameWithSuffix, value);
return propertyNameWithSuffix; return propertyNameWithSuffix;
case ARRAY: case ARRAY:
...@@ -851,7 +849,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -851,7 +849,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
Vertex structInstanceVertex = GraphHelper.createVertexWithoutIdentity( Vertex structInstanceVertex = GraphHelper.createVertexWithoutIdentity(
titanGraph, structInstance.getTypeName(), id, titanGraph, structInstance.getTypeName(), id,
Collections.<String>emptySet()); // no super types for struct type Collections.<String>emptySet()); // no super types for struct type
LOG.debug("created vertex {} for struct {}", structInstanceVertex, attributeInfo.name); LOG.debug("created vertex {} for struct {} value {}", structInstanceVertex, attributeInfo.name,
structInstance);
// map all the attributes to this newly created vertex // map all the attributes to this newly created vertex
mapInstanceToVertex(id, structInstance, structInstanceVertex, mapInstanceToVertex(id, structInstance, structInstanceVertex,
...@@ -895,47 +894,43 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -895,47 +894,43 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
private void mapPrimitiveToVertex(ITypedInstance typedInstance, private void mapPrimitiveToVertex(ITypedInstance typedInstance,
Vertex instanceVertex, Vertex instanceVertex,
AttributeInfo attributeInfo) throws MetadataException { AttributeInfo attributeInfo) throws MetadataException {
LOG.debug("Adding primitive {} to v {}", attributeInfo, instanceVertex); Object attrValue = typedInstance.get(attributeInfo.name);
if (typedInstance.get(attributeInfo.name) == null) { if (attrValue == null) {
return; // add only if instance has this attribute return; // add only if instance has this attribute
} }
final String vertexPropertyName = getQualifiedName(typedInstance, attributeInfo); final String vertexPropertyName = getQualifiedName(typedInstance, attributeInfo);
Object propertyValue = null;
if (attributeInfo.dataType() == DataTypes.STRING_TYPE) { if (attributeInfo.dataType() == DataTypes.STRING_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getString(attributeInfo.name);
typedInstance.getString(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.SHORT_TYPE) { } else if (attributeInfo.dataType() == DataTypes.SHORT_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getShort(attributeInfo.name);
typedInstance.getShort(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.INT_TYPE) { } else if (attributeInfo.dataType() == DataTypes.INT_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getInt(attributeInfo.name);
typedInstance.getInt(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.BIGINTEGER_TYPE) { } else if (attributeInfo.dataType() == DataTypes.BIGINTEGER_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getBigInt(attributeInfo.name);
typedInstance.getBigInt(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.BOOLEAN_TYPE) { } else if (attributeInfo.dataType() == DataTypes.BOOLEAN_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getBoolean(attributeInfo.name);
typedInstance.getBoolean(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.BYTE_TYPE) { } else if (attributeInfo.dataType() == DataTypes.BYTE_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getByte(attributeInfo.name);
typedInstance.getByte(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.LONG_TYPE) { } else if (attributeInfo.dataType() == DataTypes.LONG_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getLong(attributeInfo.name);
typedInstance.getLong(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.FLOAT_TYPE) { } else if (attributeInfo.dataType() == DataTypes.FLOAT_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getFloat(attributeInfo.name);
typedInstance.getFloat(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.DOUBLE_TYPE) { } else if (attributeInfo.dataType() == DataTypes.DOUBLE_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getDouble(attributeInfo.name);
typedInstance.getDouble(attributeInfo.name));
} else if (attributeInfo.dataType() == DataTypes.BIGDECIMAL_TYPE) { } else if (attributeInfo.dataType() == DataTypes.BIGDECIMAL_TYPE) {
instanceVertex.setProperty(vertexPropertyName, propertyValue = typedInstance.getBigDecimal(attributeInfo.name);
typedInstance.getBigDecimal(attributeInfo.name));
} }
addProperty(instanceVertex, vertexPropertyName, propertyValue);
} }
} }
private void addProperty(Vertex vertex, String propertyName, Object value) {
LOG.debug("Setting property {} = \"{}\" to vertex {}", propertyName, value, vertex);
vertex.setProperty(propertyName, value);
}
public final class GraphToTypedInstanceMapper { public final class GraphToTypedInstanceMapper {
public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, public ITypedReferenceableInstance mapGraphToTypedInstance(String guid,
...@@ -985,7 +980,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -985,7 +980,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
public void mapVertexToAttribute(Vertex instanceVertex, ITypedInstance typedInstance, public void mapVertexToAttribute(Vertex instanceVertex, ITypedInstance typedInstance,
AttributeInfo attributeInfo) throws MetadataException { AttributeInfo attributeInfo) throws MetadataException {
LOG.debug("mapping attributeInfo = " + attributeInfo); LOG.debug("mapping attributeInfo {}", attributeInfo.name);
final IDataType dataType = attributeInfo.dataType(); final IDataType dataType = attributeInfo.dataType();
final String vertexPropertyName = getQualifiedName(typedInstance, attributeInfo); final String vertexPropertyName = getQualifiedName(typedInstance, attributeInfo);
...@@ -1226,7 +1221,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -1226,7 +1221,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
ITypedStruct structInstance = structType.createInstance(); ITypedStruct structInstance = structType.createInstance();
typedInstance.set(attributeInfo.name, structInstance); typedInstance.set(attributeInfo.name, structInstance);
String relationshipLabel = getQualifiedName(structType, attributeInfo.name); String relationshipLabel = getQualifiedName(typedInstance, attributeInfo);
LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel); LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel);
for (Edge edge : instanceVertex.getEdges(Direction.OUT, relationshipLabel)) { for (Edge edge : instanceVertex.getEdges(Direction.OUT, relationshipLabel)) {
final Vertex structInstanceVertex = edge.getVertex(Direction.IN); final Vertex structInstanceVertex = edge.getVertex(Direction.IN);
......
...@@ -85,7 +85,7 @@ public final class GraphHelper { ...@@ -85,7 +85,7 @@ public final class GraphHelper {
public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex, public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex,
String edgeLabel) { String edgeLabel) {
LOG.debug("Adding edge for {} -> struct label {} -> v{}", LOG.debug("Adding edge for {} -> label {} -> {}",
fromVertex, edgeLabel, toVertex); fromVertex, edgeLabel, toVertex);
return titanGraph.addEdge(null, fromVertex, toVertex, edgeLabel); return titanGraph.addEdge(null, fromVertex, toVertex, edgeLabel);
......
...@@ -334,11 +334,6 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -334,11 +334,6 @@ public class GraphBackedMetadataRepositoryTest {
String response = discoveryService.searchByFullText("john"); String response = discoveryService.searchByFullText("john");
Assert.assertNotNull(response); Assert.assertNotNull(response);
JSONArray results = new JSONArray(response); JSONArray results = new JSONArray(response);
System.out.println("Found the following results");
for (int i = 0 ; i < results.length(); i++) {
JSONObject myrow = results.getJSONObject(i);
System.out.println(myrow.toString());
}
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
JSONObject row = (JSONObject) results.get(0); JSONObject row = (JSONObject) results.get(0);
Assert.assertEquals(row.get("typeName"), "Person"); Assert.assertEquals(row.get("typeName"), "Person");
...@@ -346,11 +341,10 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -346,11 +341,10 @@ public class GraphBackedMetadataRepositoryTest {
//person in hr department who lives in santa clara //person in hr department who lives in santa clara
response = discoveryService.searchByFullText("Jane AND santa AND clara"); response = discoveryService.searchByFullText("Jane AND santa AND clara");
Assert.assertNotNull(response); Assert.assertNotNull(response);
// todo: enable this - temporarily commented this as its failing results = new JSONArray(response);
// results = new JSONArray(response); Assert.assertEquals(results.length(), 1);
// Assert.assertEquals(results.length(), 1); row = (JSONObject) results.get(0);
// row = (JSONObject) results.get(0); Assert.assertEquals(row.get("typeName"), "Manager");
// Assert.assertEquals(row.get("typeName"), "Manager");
//search for person in hr department whose name starts is john/jahn //search for person in hr department whose name starts is john/jahn
response = discoveryService.searchByFullText("hr AND (john OR jahn)"); response = discoveryService.searchByFullText("hr AND (john OR jahn)");
......
...@@ -36,7 +36,7 @@ import scala.collection.JavaConversions._ ...@@ -36,7 +36,7 @@ import scala.collection.JavaConversions._
package object dsl { package object dsl {
val defFormat = new DefaultFormats { val defFormat = new DefaultFormats {
override protected def dateFormatter = new SimpleDateFormat("yyyy-MM-dd") override protected def dateFormatter = TypeSystem.getInstance().getDateFormat;
override val typeHints = NoTypeHints override val typeHints = NoTypeHints
} }
......
...@@ -120,7 +120,7 @@ class DSLTest { ...@@ -120,7 +120,7 @@ class DSLTest {
Assert.assertEquals(s"${i.o.asInstanceOf[java.util.Map[_, _]].keySet}", "[b, a]") Assert.assertEquals(s"${i.o.asInstanceOf[java.util.Map[_, _]].keySet}", "[b, a]")
// 5. Serialize mytype instance to Json // 5. Serialize mytype instance to Json
Assert.assertEquals(s"${pretty(render(i))}", "{\n \"$typeName$\":\"mytype\",\n \"e\":1," + "\n \"n\":[1,1.100000000000000088817841970012523233890533447265625],\n \"h\":1.0,\n \"b\":true,\n \"k\":1,\n \"j\":1,\n \"d\":2,\n \"m\":[1,1],\n \"g\":1,\n \"a\":1,\n \"i\":1.0,\n \"c\":1,\n \"l\":\"2014-12-02\",\n \"f\":1,\n \"o\":{\n \"b\":2.0,\n \"a\":1.0\n }\n}") Assert.assertEquals(s"${pretty(render(i))}", "{\n \"$typeName$\":\"mytype\",\n \"e\":1," + "\n \"n\":[1,1.100000000000000088817841970012523233890533447265625],\n \"h\":1.0,\n \"b\":true,\n \"k\":1,\n \"j\":1,\n \"d\":2,\n \"m\":[1,1],\n \"g\":1,\n \"a\":1,\n \"i\":1.0,\n \"c\":1,\n \"l\":\"2014-12-03\",\n \"f\":1,\n \"o\":{\n \"b\":2.0,\n \"a\":1.0\n }\n}")
} }
@Test def test2 { @Test def test2 {
......
...@@ -42,10 +42,10 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -42,10 +42,10 @@ import java.util.concurrent.ConcurrentHashMap;
@InterfaceAudience.Private @InterfaceAudience.Private
public class TypeSystem { public class TypeSystem {
private static final TypeSystem INSTANCE = new TypeSystem(); private static final TypeSystem INSTANCE = new TypeSystem();
public static ThreadLocal<DateFormat> dateFormat = new ThreadLocal() { private static ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal() {
@Override @Override
public DateFormat initialValue() { public SimpleDateFormat initialValue() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat; return dateFormat;
} }
...@@ -294,7 +294,7 @@ public class TypeSystem { ...@@ -294,7 +294,7 @@ public class TypeSystem {
return eT; return eT;
} }
public DateFormat getDateFormat() { public SimpleDateFormat getDateFormat() {
return dateFormat.get(); return dateFormat.get();
} }
......
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