formatting work
This commit is contained in:
+2
-6
@@ -9,8 +9,7 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@ComponentScan(basePackages = {"com.baeldung.spring.data.neo4j.services"})
|
||||
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
||||
@Configuration
|
||||
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
|
||||
public class MovieDatabaseNeo4jConfiguration extends Neo4jConfiguration {
|
||||
@@ -20,10 +19,7 @@ public class MovieDatabaseNeo4jConfiguration extends Neo4jConfiguration {
|
||||
@Bean
|
||||
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
||||
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
||||
config
|
||||
.driverConfiguration()
|
||||
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
|
||||
.setURI(URL);
|
||||
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -10,20 +10,17 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
||||
import org.springframework.data.neo4j.server.Neo4jServer;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@EnableTransactionManagement
|
||||
@ComponentScan(basePackages = {"com.baeldung.spring.data.neo4j.services"})
|
||||
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
||||
@Configuration
|
||||
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
|
||||
@Profile({"embedded", "test"})
|
||||
@Profile({ "embedded", "test" })
|
||||
public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration {
|
||||
|
||||
@Bean
|
||||
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
||||
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
||||
config
|
||||
.driverConfiguration()
|
||||
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
|
||||
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.neo4j.ogm.annotation.Relationship;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIdentityInfo(generator=JSOGGenerator.class)
|
||||
@JsonIdentityInfo(generator = JSOGGenerator.class)
|
||||
|
||||
@NodeEntity
|
||||
public class Movie {
|
||||
@@ -21,9 +21,11 @@ public class Movie {
|
||||
private int released;
|
||||
private String tagline;
|
||||
|
||||
@Relationship(type="ACTED_IN", direction = Relationship.INCOMING) private List<Role> roles;
|
||||
@Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
|
||||
private List<Role> roles;
|
||||
|
||||
public Movie() { }
|
||||
public Movie() {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
@@ -56,6 +58,5 @@ public class Movie {
|
||||
public void setRoles(List<Role> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.spring.data.neo4j.domain;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
||||
import org.neo4j.ogm.annotation.GraphId;
|
||||
@@ -9,7 +8,7 @@ import org.neo4j.ogm.annotation.Relationship;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIdentityInfo(generator=JSOGGenerator.class)
|
||||
@JsonIdentityInfo(generator = JSOGGenerator.class)
|
||||
@NodeEntity
|
||||
public class Person {
|
||||
@GraphId
|
||||
@@ -21,7 +20,8 @@ public class Person {
|
||||
@Relationship(type = "ACTED_IN")
|
||||
private List<Movie> movies;
|
||||
|
||||
public Person() { }
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -46,5 +46,5 @@ public class Person {
|
||||
public void setMovies(List<Movie> movies) {
|
||||
this.movies = movies;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.spring.data.neo4j.domain;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
||||
import org.neo4j.ogm.annotation.EndNode;
|
||||
@@ -10,7 +9,7 @@ import org.neo4j.ogm.annotation.StartNode;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@JsonIdentityInfo(generator=JSOGGenerator.class)
|
||||
@JsonIdentityInfo(generator = JSOGGenerator.class)
|
||||
@RelationshipEntity(type = "ACTED_IN")
|
||||
public class Role {
|
||||
@GraphId
|
||||
|
||||
+1
-3
@@ -18,7 +18,5 @@ public interface MovieRepository extends GraphRepository<Movie> {
|
||||
Collection<Movie> findByTitleContaining(@Param("title") String title);
|
||||
|
||||
@Query("MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) RETURN m.title as movie, collect(a.name) as cast LIMIT {limit}")
|
||||
List<Map<String,Object>> graph(@Param("limit") int limit);
|
||||
List<Map<String, Object>> graph(@Param("limit") int limit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -4,8 +4,7 @@ import com.baeldung.spring.data.neo4j.domain.Person;
|
||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface PersonRepository extends GraphRepository<Person> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -15,31 +15,31 @@ public class MovieService {
|
||||
MovieRepository movieRepository;
|
||||
|
||||
private Map<String, Object> toD3Format(Iterator<Map<String, Object>> result) {
|
||||
List<Map<String,Object>> nodes = new ArrayList<Map<String,Object>>();
|
||||
List<Map<String,Object>> rels= new ArrayList<Map<String,Object>>();
|
||||
int i=0;
|
||||
List<Map<String, Object>> nodes = new ArrayList<Map<String, Object>>();
|
||||
List<Map<String, Object>> rels = new ArrayList<Map<String, Object>>();
|
||||
int i = 0;
|
||||
while (result.hasNext()) {
|
||||
Map<String, Object> row = result.next();
|
||||
nodes.add(map("title",row.get("movie"),"label","movie"));
|
||||
int target=i;
|
||||
nodes.add(map("title", row.get("movie"), "label", "movie"));
|
||||
int target = i;
|
||||
i++;
|
||||
for (Object name : (Collection) row.get("cast")) {
|
||||
Map<String, Object> actor = map("title", name,"label","actor");
|
||||
Map<String, Object> actor = map("title", name, "label", "actor");
|
||||
int source = nodes.indexOf(actor);
|
||||
if (source == -1) {
|
||||
nodes.add(actor);
|
||||
source = i++;
|
||||
}
|
||||
rels.add(map("source",source,"target",target));
|
||||
rels.add(map("source", source, "target", target));
|
||||
}
|
||||
}
|
||||
return map("nodes", nodes, "links", rels);
|
||||
}
|
||||
|
||||
private Map<String, Object> map(String key1, Object value1, String key2, Object value2) {
|
||||
Map<String, Object> result = new HashMap<String,Object>(2);
|
||||
result.put(key1,value1);
|
||||
result.put(key2,value2);
|
||||
Map<String, Object> result = new HashMap<String, Object>(2);
|
||||
result.put(key1, value1);
|
||||
result.put(key2, value2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -82,8 +82,7 @@ public class MovieRepositoryTest {
|
||||
@DirtiesContext
|
||||
public void testFindAll() {
|
||||
System.out.println("findAll");
|
||||
Collection<Movie> result =
|
||||
(Collection<Movie>) movieRepository.findAll();
|
||||
Collection<Movie> result = (Collection<Movie>) movieRepository.findAll();
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
@@ -93,8 +92,7 @@ public class MovieRepositoryTest {
|
||||
public void testFindByTitleContaining() {
|
||||
System.out.println("findByTitleContaining");
|
||||
String title = "Italian";
|
||||
Collection<Movie> result =
|
||||
movieRepository.findByTitleContaining(title);
|
||||
Collection<Movie> result = movieRepository.findByTitleContaining(title);
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
@@ -126,8 +124,7 @@ public class MovieRepositoryTest {
|
||||
public void testDeleteAll() {
|
||||
System.out.println("deleteAll");
|
||||
movieRepository.deleteAll();
|
||||
Collection<Movie> result =
|
||||
(Collection<Movie>) movieRepository.findAll();
|
||||
Collection<Movie> result = (Collection<Movie>) movieRepository.findAll();
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user