1

Has anyone got GraphAware TimeTree working with Spring Data Neo4J using their Java API and can provide a simple example please?

John
  • 10,837
  • 17
  • 78
  • 141

2 Answers2

1

GraphAware extensions are server-side code and Spring Data Neo4j is client-side. Bearing that in mind, you could annotate your Java classes that use SDN (assuming v4) along the same lines as here and here in order to make your mapping match the TimeTree structure.

That said, SDN (v4) does not yet have any explicit support for unmanaged extensions and transaction event handlers (GraphAware Framework is both of these), so you will need to handle this yourself. For instance, if you use the TimeTree auto-attachment feature and persist an Event from SDN, you will need to reload it in order to fetch the TimeTree nodes.

Community
  • 1
  • 1
Michal Bachman
  • 2,661
  • 17
  • 22
1

Here's my first repository class. Seems to work, but Michael or Luanne (or someone) may be able to improve on this significantly. I haven't included queries for events in a range yet, but they're coming.

A couple of notes on what is here:

timeType parameter is the name of the relationship between your domain node and the timetree.

package myproject.core.repository.timeline;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import myproject.BaseNode;

@Repository
public interface TimelineRepository extends Neo4jRepository<BaseNode> {

// Attaches a node to the time tree
    @Query("match (e:Event {domainId: {domainId}}) with e call ga.timetree.events.attach({node: e, time: {timestamp}, resolution: 'MILLISECOND', relationshipType: {timeType}}) yield node return node;")
    public void setTime(@Param("domainId") String domainId, @Param("timeType") String typeType, @Param("timestamp") Long timestamp);

// Detaches a node from the timetree
    @Query("match (e:Event {domainId: {domainId}})-[s]-() where type(s) = {timeType} delete s;")
    public void unsetTime(@Param("domainId") String domainId, @Param("timeType") String timeType);
}

Below is the config I have in my neo4j.conf. I'm using neo4j 3.0.6. Almost all of what I have written here is straight from the docs at https://github.com/graphaware/neo4j-timetree.

#For the framework to work at all, you need this
dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware

# Runtime must be enabled like this
com.graphaware.runtime.enabled=true

# A Runtime module that takes care of attaching the events like this (TT is the ID of the module)
com.graphaware.module.TT.1=com.graphaware.module.timetree.module.TimeTreeModuleBootstrapper

# autoAttach must be set to true
com.graphaware.module.TT.autoAttach=true

#Uncommenting this prevents properties of our Event class from persisting
# Optionally, nodes which represent events and should be attached automatically have to be defined (defaults to nodes with label Event)
#com.graphaware.module.TT.event=hasLabel('Message')

# Optionally, a property on the event nodes that represents the the time (long) at which the event took place must be specified (defaults to "timestamp")
#com.graphaware.module.TT.timestamp=time

# Optionally, a property on the event nodes that represents the node ID (long) of the root node for the tree, to which the event should be attached (defaults to "timeTreeRootId")
#com.graphaware.module.TT.customTimeTreeRootProperty=rootId

# Optionally, a resolution can be specified (defaults to DAY)
#com.graphaware.module.TT.resolution=MILLISECOND

# Optionally, a time zone can be specified (defaults to UTC)
#com.graphaware.module.TT.timezone=GMT+1

# Optionally, a relationship type with which the events will be attached to the tree can be specified (defaults to AT_TIME)
#com.graphaware.module.TT.relationship=SENT_ON

# Optionally, a relationship direction (from the tree's point of view), with which the events will be attached to the tree can be specified (defaults to INCOMING)
#com.graphaware.module.TT.direction=INCOMING

You should be able to create something that looks a little like this (in its most simple form)..

Event example

John Deverall
  • 5,954
  • 3
  • 27
  • 37