You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2015/04/01 16:54:29 UTC

[3/4] incubator-streams git commit: PR feedback for https://github.com/apache/incubator-streams/pull/203

PR feedback for https://github.com/apache/incubator-streams/pull/203


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/44c5a6a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/44c5a6a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/44c5a6a9

Branch: refs/heads/master
Commit: 44c5a6a99293ca59ab94fd5e431a96cc2bfe0b98
Parents: b411186
Author: Steve Blackmon (@steveblackmon) <sb...@apache.org>
Authored: Wed Apr 1 09:52:51 2015 -0500
Committer: Steve Blackmon (@steveblackmon) <sb...@apache.org>
Committed: Wed Apr 1 09:52:51 2015 -0500

----------------------------------------------------------------------
 .../http/provider/SimpleHttpProvider.java       | 20 +++++++++++++++++--
 .../org/apache/streams/graph/GraphHelper.java   |  4 +++-
 .../streams/graph/neo4j/CypherGraphHelper.java  | 21 ++++++++++++++++----
 3 files changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/44c5a6a9/streams-components/streams-http/src/main/java/org/apache/streams/components/http/provider/SimpleHttpProvider.java
----------------------------------------------------------------------
diff --git a/streams-components/streams-http/src/main/java/org/apache/streams/components/http/provider/SimpleHttpProvider.java b/streams-components/streams-http/src/main/java/org/apache/streams/components/http/provider/SimpleHttpProvider.java
index fc00db9..1a4a557 100644
--- a/streams-components/streams-http/src/main/java/org/apache/streams/components/http/provider/SimpleHttpProvider.java
+++ b/streams-components/streams-http/src/main/java/org/apache/streams/components/http/provider/SimpleHttpProvider.java
@@ -204,7 +204,7 @@ public class SimpleHttpProvider implements StreamsProvider {
         StreamsResultSet current;
 
         uriBuilder = uriBuilder.setPath(
-            Joiner.on("/").skipNulls().join(uriBuilder.getPath(), configuration.getResource(), configuration.getResourcePostfix())
+                Joiner.on("/").skipNulls().join(uriBuilder.getPath(), configuration.getResource(), configuration.getResourcePostfix())
         );
 
         URI uri;
@@ -286,7 +286,23 @@ public class SimpleHttpProvider implements StreamsProvider {
      Override this to change how metadata is derived from object
      */
     protected StreamsDatum newDatum(ObjectNode item) {
-        return new StreamsDatum(item, item.get("id").asText(), new DateTime(item.get("timestamp").asText()));
+        try {
+            String id = null;
+            if( item.get("id") != null )
+                id = item.get("id").asText();
+            DateTime timestamp = null;
+            if( item.get("timestamp") != null )
+                timestamp = new DateTime(item.get("timestamp").asText());
+            if( id != null && timestamp != null )
+                return new StreamsDatum(item, id, timestamp);
+            else if( id != null )
+                return new StreamsDatum(item, id);
+            else if( timestamp != null )
+                return new StreamsDatum(item, null, timestamp);
+            else return new StreamsDatum(item);
+        } catch( Exception e ) {
+            return new StreamsDatum(item);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/44c5a6a9/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHelper.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHelper.java b/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHelper.java
index 8964bae..fee2f6f 100644
--- a/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHelper.java
+++ b/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/GraphHelper.java
@@ -28,7 +28,9 @@ import org.apache.streams.pojo.json.ActivityObject;
  */
 public interface GraphHelper {
 
-    public ObjectNode getVertexRequest(String id);
+    public ObjectNode getVertexRequest(String streamsId);
+
+    public ObjectNode getVertexRequest(Long vertexId);
 
     public ObjectNode createVertexRequest(ActivityObject activityObject);
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/44c5a6a9/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/neo4j/CypherGraphHelper.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/neo4j/CypherGraphHelper.java b/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/neo4j/CypherGraphHelper.java
index 1af6f56..d01f6d5 100644
--- a/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/neo4j/CypherGraphHelper.java
+++ b/streams-contrib/streams-persist-graph/src/main/java/org/apache/streams/graph/neo4j/CypherGraphHelper.java
@@ -43,7 +43,8 @@ public class CypherGraphHelper implements org.apache.streams.graph.GraphHelper {
     public final static String paramsKey = "parameters";
     public final static String propsKey = "props";
 
-    public final static String getVertexStatementTemplate = "MATCH (v {id: '<id>'} ) RETURN v";
+    public final static String getVertexLongIdStatementTemplate = "MATCH (v) WHERE ID(v) = <id> RETURN v";
+    public final static String getVertexStringIdStatementTemplate = "MATCH (v {id: '<id>'} ) RETURN v";
 
     public final static String createVertexStatementTemplate = "MATCH (x {id: '<id>'}) "+
                                                                 "CREATE UNIQUE (n:<type> { props }) "+
@@ -58,12 +59,24 @@ public class CypherGraphHelper implements org.apache.streams.graph.GraphHelper {
                                                             "CREATE UNIQUE (s)-[r:<r_type> <r_props>]->(d) "+
                                                             "RETURN r";
 
-    public ObjectNode getVertexRequest(String id) {
+    public ObjectNode getVertexRequest(String streamsId) {
 
         ObjectNode request = mapper.createObjectNode();
 
-        ST getVertex = new ST(getVertexStatementTemplate);
-        getVertex.add("id", id);
+        ST getVertex = new ST(getVertexStringIdStatementTemplate);
+        getVertex.add("id", streamsId);
+        request.put(statementKey, getVertex.render());
+
+        return request;
+    }
+
+    @Override
+    public ObjectNode getVertexRequest(Long vertexId) {
+
+        ObjectNode request = mapper.createObjectNode();
+
+        ST getVertex = new ST(getVertexLongIdStatementTemplate);
+        getVertex.add("id", vertexId);
         request.put(statementKey, getVertex.render());
 
         return request;