1   /**
2    * Licensed to Neo Technology under one or more contributor
3    * license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright
5    * ownership. Neo Technology licenses this file to you under
6    * the Apache License, Version 2.0 (the "License"); you may
7    * not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.neo4j.examples.socnet;
21  
22  import org.neo4j.graphdb.Direction;
23  import org.neo4j.graphdb.Node;
24  import org.neo4j.graphdb.traversal.TraversalDescription;
25  import org.neo4j.graphdb.traversal.Traverser;
26  import org.neo4j.helpers.collection.IteratorUtil;
27  import org.neo4j.kernel.Traversal;
28  
29  import java.util.Date;
30  
31  import static org.neo4j.examples.socnet.RelTypes.NEXT;
32  import static org.neo4j.examples.socnet.RelTypes.STATUS;
33  
34  public class StatusUpdate
35  {
36      private final Node underlyingNode;
37      static final String TEXT = "TEXT";
38      static final String DATE = "DATE";
39  
40      public StatusUpdate( Node underlyingNode )
41      {
42  
43          this.underlyingNode = underlyingNode;
44      }
45  
46      public Node getUnderlyingNode()
47      {
48          return underlyingNode;
49      }
50  
51      public Person getPerson()
52      {
53          return new Person( getPersonNode() );
54      }
55  
56      private Node getPersonNode()
57      {
58          TraversalDescription traversalDescription = Traversal.description().
59                  depthFirst().
60                  relationships( NEXT, Direction.INCOMING ).
61                  relationships( STATUS, Direction.INCOMING ).
62                  filter( Traversal.returnWhereLastRelationshipTypeIs( STATUS ));
63  
64          Traverser traverser = traversalDescription.traverse( getUnderlyingNode() );
65  
66          return IteratorUtil.singleOrNull( traverser.iterator() ).endNode();
67      }
68  
69      public String getStatusText()
70      {
71          return (String)underlyingNode.getProperty( TEXT );
72      }
73  
74      public Date getDate()
75      {
76          Long l = (Long)underlyingNode.getProperty( DATE );
77  
78          return new Date( l );
79      }
80  
81  }