Neo4j TimeTree in Spring Data Neo4j 4.0

后端 未结 2 1106
梦谈多话
梦谈多话 2020-12-20 06:30

I\'m trying to utilize the timetree library in my spring data neo4j 4.0.0 project.

As elaborated in this page, https://github.com/graphaware/neo4j-timetree, I\'ve e

2条回答
  •  情歌与酒
    2020-12-20 07:17

    The dependency is only useful if you're using the timetree programatically. If your application is running against a Neo4j server, then you need to download and save to your Neo4j server plugins directory:

    a) The GraphAware framework (choose either Community or Enterprise)

    b) The TimeTree module

    Both can be downloaded from http://graphaware.com/products/

    Without this, even with a configuration in neo4j.properties, the GraphAware Runtime isn't started and the timetree will not work.

    If you want to run your code via a test, then you need to include the dependencies for the TimeTree and GraphAware Runtime and start the GraphAware Runtime yourself, with code such as:

     GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
            runtime.registerModule(new TimeTreeModule("timetree",
                    TimeTreeConfiguration
                            .defaultConfiguration()
                            .with(new NodeInclusionPolicy() {
                                @Override
                                public boolean include(Node node) {
                                    return node.hasLabel(DynamicLabel.label("User"));
                                }
                            })
    
                            })
                            .withRelationshipType(DynamicRelationshipType.withName("CREATED_ON"))
                            .withTimeZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+1")))
                            .withTimestampProperty("createdOn")
                            .withResolution(Resolution.DAY)
                    ,
                    getDatabase()));
            runtime.start();
    

    Then you can write tests such as

     @Test
        public void shouldSaveUser()
        {
            User user = new User( "Michal" );
            user.setCreatedOn(1431937636995l);
            userRepository.save( user );
    
            assertSameGraph( getDatabase(), "CREATE (u:User:Person {name:'Michal', createdOn:1431937636995})," +
                    "(root:TimeTreeRoot)," +
                            "(root)-[:FIRST]->(year:Year {value:2015})," +
                            "(root)-[:CHILD]->(year)," +
                            "(root)-[:LAST]->(year)," +
                            "(year)-[:FIRST]->(month:Month {value:5})," +
                            "(year)-[:CHILD]->(month)," +
                            "(year)-[:LAST]->(month)," +
                            "(month)-[:FIRST]->(day:Day {value:18})," +
                            "(month)-[:CHILD]->(day)," +
                            "(month)-[:LAST]->(day)," +
                            "(day)<-[:CREATED_ON]-(u)"
            );
    
        }
    

提交回复
热议问题