title: Neo4j TimeTree REST API Previous and Next Navigation
body: <p>I am currently using Neo4j TimeTree REST API and is there any way to navigate to the time before and after a given timestamp? My resolution is Second and I just realize that if the minute has changed, then there is no 'NEXT' relationship bridging the previous Second in previous Minute to the current Second. This makes the cypher query quite complicated and I just don't want to reinvent the wheel again if it's already available.
  Thanks in advance and your response would be really appreciated!</p>
  
  <p>EDIT</p>
  
  <p>I've got to reproduce the missing NEXT relationship issue again, as you can see in the picture below. This starts to happen from the third time I add a new Second time instant.</p>
  
  <p><img src="https://i.stack.imgur.com/XYojF.png" alt="enter image description here"></p>
  
  <p>I actually create a NodeEntity to operate with the Second nodes. The class is like below.</p>
  
  <pre><code>@NodeEntity(label = "Second")
  public class TimeTreeSecond {
      @GraphId
      private Long id;
  
      private Integer value;
  
      @Relationship(type = "CREATED_ON", direction = Relationship.INCOMING)
      private FilterVersionChange relatedFilterVersionChange;
  
      @Relationship(type = "NEXT", direction = Relationship.OUTGOING)
      private TimeTreeSecond nextTimeTreeSecond;
  
      @Relationship(type = "NEXT", direction = Relationship.INCOMING)
      private TimeTreeSecond prevTimeTreeSecond;
  
      public TimeTreeSecond() {
      }
  
      public Long getId() {
          return id;
      }
  
      public void next(TimeTreeSecond nextTimeTreeSecond) {
          this.nextTimeTreeSecond = nextTimeTreeSecond;
      }
  
      public FilterVersionChange getRelatedFilterVersionChange() {
          return relatedFilterVersionChange;
      }
  }
  </code></pre>
  
  <p>The problem here is the Incoming NEXT relationship. When I omit that, everything works fine.
  Sometimes I even get this kind of exception in my console when I create the time instant repetitively with short delay.</p>
  
  <pre><code>Exception in thread "main" org.neo4j.ogm.session.result.ResultProcessingException: Could not initialise response
      at org.neo4j.ogm.session.response.GraphModelResponse.&lt;init&gt;(GraphModelResponse.java:38)
      at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRequestHandler.java:55)
      at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:108)
      at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:100)
      at org.springframework.data.neo4j.repository.GraphRepositoryImpl.findOne(GraphRepositoryImpl.java:50)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:452)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:437)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:409)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy32.findOne(Unknown Source)
      at de.rwthaachen.service.core.FilterDefinitionServiceImpl.createNewFilterVersionChange(FilterDefinitionServiceImpl.java:100)
      at sampleapp.FilterLauncher.main(FilterLauncher.java:50)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  Caused by: org.neo4j.ogm.session.result.ResultProcessingException: "errors":[{"code":"Neo.ClientError.Statement.InvalidType","message":"Expected a numeric value for empty iterator, but got null"}]}
      at org.neo4j.ogm.session.response.JsonResponse.parseErrors(JsonResponse.java:128)
      at org.neo4j.ogm.session.response.JsonResponse.parseColumns(JsonResponse.java:102)
      at org.neo4j.ogm.session.response.JsonResponse.initialiseScan(JsonResponse.java:46)
      at org.neo4j.ogm.session.response.GraphModelResponse.initialiseScan(GraphModelResponse.java:66)
      at org.neo4j.ogm.session.response.GraphModelResponse.&lt;init&gt;(GraphModelResponse.java:36)
      ... 27 more
  2015-05-23 01:30:46,204  INFO ork.data.neo4j.config.Neo4jConfiguration:  62 - Intercepted exception
  </code></pre>
  
  <p>Below is one REST call example which I use to create the time instant nodes:
  <a href="http://localhost:7474/graphaware/timetree/1202/single/1432337658713?resolution=Second&amp;timezone=Europe/Amsterdam" rel="nofollow noreferrer">http://localhost:7474/graphaware/timetree/1202/single/1432337658713?resolution=Second&amp;timezone=Europe/Amsterdam</a></p>
  
  <p>method that I use to create the data :</p>
  
  <pre><code>public FilterVersionChange createNewFilterVersionChange(String projectName,
                                                              String filterVersionName,
                                                              String filterVersionChangeDescription,
                                                              Set&lt;FilterState&gt; filterStates)
      {
          Long filterVersionNodeId = filterVersionRepository.findFilterVersionByName(projectName, filterVersionName);
          FilterVersion newFilterVersion = filterVersionRepository.findOne(filterVersionNodeId, 2);
  
          // Populate all the existing filters in the current project
          Map&lt;String, Filter&gt; existingFilters = new HashMap&lt;String, Filter&gt;();
          try
          {
              for(Filter filter : newFilterVersion.getProject().getFilters())
              {
                  existingFilters.put(filter.getMatchingString(), filter);
              }
          }
          catch(Exception e) {}
  
          // Map the filter states to the populated filters, if any. Otherwise, create new filter for it.
          for(FilterState filterState : filterStates)
          {
              Filter filter = existingFilters.get(filterState.getMatchingString());
              if(filter == null)
              {
                  filter = new Filter(filterState.getMatchingString(), filterState.getMatchingType(), newFilterVersion.getProject());
              }
              filterState.stateOf(filter);
          }
  
          Long now = System.currentTimeMillis();
          TimeTreeSecond timeInstantNode = timeTreeSecondRepository.findOne(timeTreeService.getFilterTimeInstantNodeId(projectName, now));
          FilterVersionChange filterVersionChange = new FilterVersionChange(filterVersionChangeDescription, now, filterStates, filterStates, newFilterVersion, timeInstantNode);
          FilterVersionChange addedFilterVersionChange = filterVersionChangeRepository.save(filterVersionChange);
  
          return addedFilterVersionChange;
      }
  </code></pre>