-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elisabeth Engel
committed
Jul 3, 2013
1 parent
433a483
commit 378c173
Showing
13 changed files
with
656 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# Maven | ||
log/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
spring-data-neo4j-showcase | ||
========================== | ||
Our Spring Data Neo4j showcase application for comSysto Blog Article Spring Data Neo4j (>>Link here<<). | ||
|
||
Showcase for our blog entry about Spring Data Neo4j. | ||
It uses Spring, Spring Data Neo4j and Maven to demonstrate how to recommend products based on other users' views. | ||
|
||
Please mail comments to [email protected] or [email protected]! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>spring-data-neo4j-showcase</groupId> | ||
<artifactId>spring-data-neo4j-showcase</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<spring.data.neo4j.version>2.2.0.RELEASE</spring.data.neo4j.version> | ||
<neo4j.kernel.version>1.9</neo4j.kernel.version> | ||
<spring.core.version>3.2.1.RELEASE</spring.core.version> | ||
<neo4j.cypher.dsl.version>1.9.M04</neo4j.cypher.dsl.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.core.version}</version> | ||
</dependency> | ||
<!-- Spring Data Neo4j --> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-neo4j</artifactId> | ||
<version>${spring.data.neo4j.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j</artifactId> | ||
<version>${neo4j.kernel.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-cypher</artifactId> | ||
<version>${neo4j.kernel.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-cypher-dsl</artifactId> | ||
<version>${neo4j.cypher.dsl.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j-kernel</artifactId> | ||
<version>${neo4j.kernel.version}</version> | ||
<type>test-jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.core.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>cglib</groupId> | ||
<artifactId>cglib</artifactId> | ||
<version>2.2.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<version>1.1.0.Final</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>org.springframework.maven.release</id> | ||
<name>Spring Maven Release Repository</name> | ||
<url>http://maven.springsource.org/release</url> | ||
<releases> | ||
<enabled>true</enabled></releases> | ||
<snapshots> | ||
<enabled>false</enabled></snapshots> | ||
</repository> | ||
<repository> | ||
<id>neo4j-public-release-repository</id> | ||
<url>http://m2.neo4j.org/releases</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/comsysto/springDataNeo4j/showcase/ClickedRelationship.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.comsysto.springDataNeo4j.showcase; | ||
|
||
import org.springframework.data.neo4j.annotation.*; | ||
|
||
|
||
@RelationshipEntity(type = RelationshipTypes.CLICKED) | ||
public class ClickedRelationship | ||
{ | ||
@GraphId | ||
private Long graphId; | ||
|
||
@StartNode | ||
private User user; | ||
|
||
@EndNode | ||
@Fetch | ||
private Product product; | ||
|
||
private Integer count; | ||
|
||
public ClickedRelationship() {/* NOOP */} | ||
|
||
public ClickedRelationship(User user, Product product) | ||
{ | ||
this.user = user; | ||
this.product = product; | ||
} | ||
|
||
|
||
public Integer getCount() { | ||
return this.count; | ||
} | ||
|
||
public void setCount(Integer count) { | ||
this.count = count; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
ClickedRelationship that = (ClickedRelationship) o; | ||
|
||
if (product != null ? !product.equals(that.product) : that.product != null) return false; | ||
if (count != null ? !count.equals(that.count) : that.count != null) return false; | ||
if (user != null ? !user.equals(that.user) : that.user != null) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = user != null ? user.hashCode() : 0; | ||
result = 31 * result + (product != null ? product.hashCode() : 0); | ||
result = 31 * result + (count != null ? count.hashCode() : 0); | ||
return result; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/comsysto/springDataNeo4j/showcase/IdentifiableEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.comsysto.springDataNeo4j.showcase; | ||
|
||
import org.springframework.data.neo4j.annotation.GraphId; | ||
|
||
/** | ||
* @author: rkowalewski | ||
*/ | ||
public abstract class IdentifiableEntity { | ||
@GraphId | ||
private Long graphId; | ||
|
||
public Long getGraphId() { | ||
return graphId; | ||
} | ||
|
||
@Override | ||
public boolean equals( Object obj ) { | ||
return obj instanceof IdentifiableEntity && graphId.equals( ((IdentifiableEntity) obj).getGraphId() ); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 0; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/com/comsysto/springDataNeo4j/showcase/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.comsysto.springDataNeo4j.showcase; | ||
|
||
import org.springframework.data.neo4j.annotation.Indexed; | ||
import org.springframework.data.neo4j.annotation.NodeEntity; | ||
import org.springframework.data.neo4j.annotation.RelatedToVia; | ||
import org.springframework.data.neo4j.support.index.IndexType; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@NodeEntity | ||
public class Product extends IdentifiableEntity { | ||
|
||
@Indexed(indexName = "productId") | ||
private String productId; | ||
|
||
@Indexed(indexType = IndexType.FULLTEXT, indexName = "productName") | ||
private String productName; | ||
|
||
@RelatedToVia(type = RelationshipTypes.VIEWED) | ||
private Set<Product> productsViewed = new HashSet<Product>(); | ||
|
||
|
||
public Product() {/* NOOP */} | ||
|
||
public Product(String productId, String productName) { | ||
super(); | ||
|
||
this.productId = productId; | ||
this.productName = productName; | ||
|
||
} | ||
|
||
public String getProductId() { | ||
return productId; | ||
} | ||
|
||
public void setProductId(String productId) { | ||
this.productId = productId; | ||
} | ||
|
||
public String getProductName() { | ||
return productName; | ||
} | ||
|
||
public void setProductName(String productName) { | ||
this.productName = productName; | ||
} | ||
|
||
public Set<Product> getProductsViewed() { | ||
return productsViewed; | ||
} | ||
|
||
public void setProductsViewed(Set<Product> productsViewed) { | ||
this.productsViewed = productsViewed; | ||
} | ||
|
||
public void addProductViewed(Product productViewed) | ||
{ | ||
productsViewed.add(productViewed); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "Product{" + | ||
"graphId=" + this.getGraphId() + | ||
", productId=" + productId + | ||
", productName=" + productName + | ||
//", #productsViewed=" + productsViewed.size() + | ||
//", #userClicked=" + usersClicked.size() + | ||
'}'; | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (!super.equals(o)) return false; | ||
|
||
Product product = (Product) o; | ||
|
||
if (productId != null ? !productId.equals(product.productId) : product.productId != null) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + (productId != null ? productId.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/comsysto/springDataNeo4j/showcase/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.comsysto.springDataNeo4j.showcase; | ||
|
||
import org.springframework.data.neo4j.annotation.Query; | ||
import org.springframework.data.neo4j.repository.GraphRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
|
||
public interface ProductRepository extends GraphRepository<Product> { | ||
|
||
Product findByProductId(String productId); | ||
|
||
List<Product> findByProductNameLike(String productName); | ||
|
||
@Query("START product=node:Product(productId='{productId}') " + | ||
"MATCH product-[viewed:VIEWED]->otherProduct " + | ||
"RETURN distinct otherProduct " + | ||
"ORDER BY viewed.count desc " + | ||
"LIMIT 5") | ||
List<Product> findOtherUsersAlsoViewedProducts(@Param("productId") String productId); | ||
|
||
@Query("START product=node:Product(productId='*') " + | ||
"RETURN distinct product " + | ||
"ORDER BY product.productName") | ||
List<Product> findAllProductsSortedByName(); | ||
|
||
@Query("START product=node:Product(productId='{productId}'), user=node:User(userId='{userId}') " + | ||
"MATCH user-[clicked:CLICKED]->product-[viewed:VIEWED]->otherProduct " + | ||
"WHERE not(user-[:CLICKED]->otherProduct) " + | ||
"RETURN distinct otherProduct " + | ||
"ORDER BY viewed.count DESC " + | ||
"LIMIT 5") | ||
List<Product> findOtherUsersAlsoViewedProductsWithoutAlreadyViewed(@Param("productId") String productId, @Param("userId") String userId); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/comsysto/springDataNeo4j/showcase/RelationshipTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.comsysto.springDataNeo4j.showcase; | ||
|
||
/** | ||
* @author: rkowalewski | ||
*/ | ||
public final class RelationshipTypes { | ||
public static final String MEMBER_OF = "MEMBEROF"; | ||
|
||
public static final String CLICKED = "CLICKED"; | ||
public static final String VIEWED = "VIEWED"; | ||
|
||
} |
Oops, something went wrong.