Biblioteca Java - Blame information for rev 18
Subversion Repositories:
(root)/Frameworks and Technologies/Neo4J Samples/Neo4JTutorial/src/main/java/com/linkscreens/graphsin/repository/CommentNode.java
Rev | Author | Line No. | Line |
---|---|---|---|
18 | mihai | 1 | package com.linkscreens.graphsin.repository; |
2 | |||
3 | import java.util.Date; | ||
4 | |||
5 | import org.neo4j.graphdb.Direction; | ||
6 | import org.neo4j.graphdb.Node; | ||
7 | import org.neo4j.graphdb.traversal.Evaluators; | ||
8 | import org.neo4j.graphdb.traversal.TraversalDescription; | ||
9 | import org.neo4j.graphdb.traversal.Traverser; | ||
10 | import org.neo4j.helpers.collection.IteratorUtil; | ||
11 | |||
12 | /** | ||
13 | * A comment added to a social object. | ||
14 | * @author evo2 | ||
15 | * | ||
16 | */ | ||
17 | public class CommentNode { | ||
18 | static final String TEXT = "TEXT"; | ||
19 | static final String DATE = "DATE"; | ||
20 | |||
21 | private final Node underlyingNode; | ||
22 | |||
23 | |||
24 | public CommentNode( Node underlyingNode ) | ||
25 | { | ||
26 | |||
27 | this.underlyingNode = underlyingNode; | ||
28 | } | ||
29 | |||
30 | public Node getUnderlyingNode() | ||
31 | { | ||
32 | return underlyingNode; | ||
33 | } | ||
34 | |||
35 | public MediaItemNode getSocialObject() | ||
36 | { | ||
37 | return new MediaItemNode( getSocialObjectNode() ); | ||
38 | } | ||
39 | |||
40 | private Node getSocialObjectNode() | ||
41 | { | ||
42 | TraversalDescription traversalDescription = underlyingNode.getGraphDatabase() | ||
43 | .traversalDescription() | ||
44 | .depthFirst() | ||
45 | .relationships( RelTypes.NEXT_COMMENT, Direction.INCOMING ) | ||
46 | .relationships( RelTypes.COMMENT, Direction.INCOMING ) | ||
47 | .evaluator( Evaluators.includeWhereLastRelationshipTypeIs( RelTypes.COMMENT ) ); | ||
48 | |||
49 | Traverser traverser = traversalDescription.traverse( getUnderlyingNode() ); | ||
50 | |||
51 | return IteratorUtil.singleOrNull( traverser.iterator() ).endNode(); | ||
52 | } | ||
53 | |||
54 | public String getCommentText() | ||
55 | { | ||
56 | return (String) underlyingNode.getProperty( TEXT ); | ||
57 | } | ||
58 | |||
59 | public Date getDate() | ||
60 | { | ||
61 | Long l = (Long) underlyingNode.getProperty( DATE ); | ||
62 | |||
63 | return new Date( l ); | ||
64 | } | ||
65 | } |