From fba2f470c3634aa6680b349b3e1cbb63c75d58ce Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Sat, 1 Nov 2014 23:32:00 -0400
Subject: [PATCH] Added frames example

---
 pom.xml                                       |  5 ++++
 .../titangraph/example/TitanGods.java         |  3 ++-
 .../titangraph/example/frames/God.java        | 24 +++++++++++++++++++
 .../titangraph/example/frames/Location.java   | 15 ++++++++++++
 .../titangraph/example/FramesTest.java        | 20 ++++++++++++++++
 5 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/com/syncleus/titangraph/example/frames/God.java
 create mode 100644 src/main/java/com/syncleus/titangraph/example/frames/Location.java
 create mode 100644 src/test/java/com/syncleus/titangraph/example/FramesTest.java

diff --git a/pom.xml b/pom.xml
index 3b3ad6f..a3b01de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,5 +122,10 @@
             <artifactId>gremlin-java</artifactId>
             <version>2.6.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.tinkerpop</groupId>
+            <artifactId>frames</artifactId>
+            <version>2.6.0</version>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/com/syncleus/titangraph/example/TitanGods.java b/src/main/java/com/syncleus/titangraph/example/TitanGods.java
index 76f1589..8c131ab 100644
--- a/src/main/java/com/syncleus/titangraph/example/TitanGods.java
+++ b/src/main/java/com/syncleus/titangraph/example/TitanGods.java
@@ -118,7 +118,7 @@ public class TitanGods {
         neptune.addEdge("brother", pluto);
 
         hercules.addEdge("father", jupiter);
-        hercules.addEdge("mother", alcmene);
+        hercules.addEdge("lives", sky).setProperty("reason", "loves heights");
         ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1, "place", Geoshape.point(38.1f, 23.7f));
         ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2, "place", Geoshape.point(37.7f, 23.9f));
         ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12, "place", Geoshape.point(39f, 22f));
@@ -130,6 +130,7 @@ public class TitanGods {
         pluto.addEdge("pet", cerberus);
 
         cerberus.addEdge("lives", tartarus);
+        ElementHelper.setProperties(cerberus.addEdge("battled", alcmene), "time", 5, "place", Geoshape.point(68.1f, 13.3f));
 
         // commit the transaction to disk
         graph.commit();
diff --git a/src/main/java/com/syncleus/titangraph/example/frames/God.java b/src/main/java/com/syncleus/titangraph/example/frames/God.java
new file mode 100644
index 0000000..67cef59
--- /dev/null
+++ b/src/main/java/com/syncleus/titangraph/example/frames/God.java
@@ -0,0 +1,24 @@
+package com.syncleus.titangraph.example.frames;
+
+import com.tinkerpop.frames.*;
+import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy;
+
+public interface God {
+    @Property("name")
+    public String getName();
+
+    @Property("age")
+    public String getAge();
+
+    @Property("type")
+    public String getType();
+
+    @Adjacency(label="father")
+    public God getFather();
+
+    @GremlinGroovy("it.in('father')")
+    public God getSon();
+
+    @Adjacency(label="lives")
+    public Location getHome();
+}
diff --git a/src/main/java/com/syncleus/titangraph/example/frames/Location.java b/src/main/java/com/syncleus/titangraph/example/frames/Location.java
new file mode 100644
index 0000000..5d18258
--- /dev/null
+++ b/src/main/java/com/syncleus/titangraph/example/frames/Location.java
@@ -0,0 +1,15 @@
+package com.syncleus.titangraph.example.frames;
+
+import com.tinkerpop.frames.*;
+import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy;
+
+public interface Location {
+    @Property("name")
+    public String getName();
+
+    @Property("type")
+    public String getType();
+
+    @GremlinGroovy("it.in('lives')")
+    public Iterable<God> getResidents();
+}
diff --git a/src/test/java/com/syncleus/titangraph/example/FramesTest.java b/src/test/java/com/syncleus/titangraph/example/FramesTest.java
new file mode 100644
index 0000000..423c174
--- /dev/null
+++ b/src/test/java/com/syncleus/titangraph/example/FramesTest.java
@@ -0,0 +1,20 @@
+package com.syncleus.titangraph.example;
+
+import com.syncleus.titangraph.example.frames.God;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.tinkerpop.frames.*;
+import com.tinkerpop.frames.modules.gremlingroovy.GremlinGroovyModule;
+import org.junit.*;
+
+public class FramesTest {
+    @Test
+    public void testFrames() {
+        final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB");
+        FramedGraphFactory factory = new FramedGraphFactory(new GremlinGroovyModule());
+
+        FramedGraph framedGraph = factory.create(godGraph);
+
+        Iterable<God> gods = (Iterable<God>) framedGraph.getVertices("name", "saturn", God.class);
+        Assert.assertEquals(gods.iterator().next().getName(), "saturn");
+    }
+}
-- 
GitLab