diff --git a/samples-and-tests/logisima-play-neo4j-test/conf/data.yml b/samples-and-tests/logisima-play-neo4j-test/conf/data.yml index c8f759a..c0b8255 100644 --- a/samples-and-tests/logisima-play-neo4j-test/conf/data.yml +++ b/samples-and-tests/logisima-play-neo4j-test/conf/data.yml @@ -91,3 +91,4 @@ Relation(50): type: ADDRESS from: User_2 to: Address_1 + diff --git a/samples-and-tests/logisima-play-neo4j-test/test/play/module/neo4j/FixturesTest.java b/samples-and-tests/logisima-play-neo4j-test/test/play/module/neo4j/FixturesTest.java index c15ee89..4faaf5e 100644 --- a/samples-and-tests/logisima-play-neo4j-test/test/play/module/neo4j/FixturesTest.java +++ b/samples-and-tests/logisima-play-neo4j-test/test/play/module/neo4j/FixturesTest.java @@ -3,7 +3,9 @@ import org.junit.Test; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; +import org.neo4j.tooling.GlobalGraphOperations; +import play.Logger; import play.modules.neo4j.exception.Neo4jException; import play.modules.neo4j.util.Fixtures; import play.modules.neo4j.util.Neo4j; @@ -16,12 +18,13 @@ public void importYmlTest() throws Neo4jException { Fixtures.deleteDatabase(); Fixtures.loadYml("data.yml"); assertEquals(12, countGraphNode()); - assertEquals(14, countGraphRelationType()); + assertEquals(11, countGraphRelationType()); } private int countGraphNode() { int nb = 0; - for (Node node : Neo4j.db().getAllNodes()) { + for (Node node : GlobalGraphOperations.at(Neo4j.db()).getAllNodes()) { + Logger.info("Node " + node.getId() + " => " + node.toString()); nb++; } return nb; @@ -29,7 +32,8 @@ private int countGraphNode() { private int countGraphRelationType() { int nb = 0; - for (RelationshipType relationType : Neo4j.db().getRelationshipTypes()) { + for (RelationshipType relationType : GlobalGraphOperations.at(Neo4j.db()).getAllRelationshipTypes()) { + Logger.info("Relation " + relationType.name()); nb++; } return nb; diff --git a/samples-and-tests/logisima-play-neo4j-touiteur/.classpath b/samples-and-tests/logisima-play-neo4j-touiteur/.classpath deleted file mode 100644 index b7f4fda..0000000 --- a/samples-and-tests/logisima-play-neo4j-touiteur/.classpath +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples-and-tests/logisima-play-neo4j-touiteur/.project b/samples-and-tests/logisima-play-neo4j-touiteur/.project deleted file mode 100644 index cbe30dc..0000000 --- a/samples-and-tests/logisima-play-neo4j-touiteur/.project +++ /dev/null @@ -1,24 +0,0 @@ - - - touiteur - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - org.playframework.playclipse.playNature - - secure2/usr/local/play/play-1.2.4/modules/secure/app -conf/secure2/usr/local/play/play-1.2.4/modules/secure/conf -public/secure2/usr/local/play/play-1.2.4/modules/secure/public -logisima-play-neo4j2/home/bsimard/workspace_logisima/logisima-play-neo4j/app -conf/logisima-play-neo4j2/home/bsimard/workspace_logisima/logisima-play-neo4j/conf - - diff --git a/samples-and-tests/logisima-play-neo4j-touiteur/.settings/org.eclipse.core.resources.prefs b/samples-and-tests/logisima-play-neo4j-touiteur/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 2cfff0d..0000000 --- a/samples-and-tests/logisima-play-neo4j-touiteur/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,4 +0,0 @@ -#Tue Apr 24 13:47:20 CEST 2012 -eclipse.preferences.version=1 -encoding//app/views/main.html=UTF-8 -encoding/=UTF-8 diff --git a/samples-and-tests/logisima-play-neo4j-touiteur/app/jobs/Bootstrap.java b/samples-and-tests/logisima-play-neo4j-touiteur/app/jobs/Bootstrap.java index cfbdcae..4374821 100644 --- a/samples-and-tests/logisima-play-neo4j-touiteur/app/jobs/Bootstrap.java +++ b/samples-and-tests/logisima-play-neo4j-touiteur/app/jobs/Bootstrap.java @@ -1,14 +1,16 @@ package jobs; +import play.Logger; import play.jobs.Job; import play.jobs.OnApplicationStart; +import play.modules.neo4j.util.Fixtures; @OnApplicationStart public class Bootstrap extends Job { public void doJob() { - // Logger.info("Delete database & load yml file"); - // Fixtures.deleteDatabase(); - // Fixtures.loadYml("data.yml"); + Logger.info("Delete database & load yml file"); + Fixtures.deleteDatabase(); + Fixtures.loadYml("data.yml"); } } diff --git a/samples-and-tests/logisima-play-neo4j-touiteur/app/models/User.java b/samples-and-tests/logisima-play-neo4j-touiteur/app/models/User.java index b90ba00..c55eb80 100644 --- a/samples-and-tests/logisima-play-neo4j-touiteur/app/models/User.java +++ b/samples-and-tests/logisima-play-neo4j-touiteur/app/models/User.java @@ -13,6 +13,7 @@ import org.neo4j.graphdb.Transaction; import org.neo4j.helpers.collection.IteratorUtil; +import play.Logger; import play.db.jpa.Blob; import play.modules.neo4j.annotation.Neo4jIndex; import play.modules.neo4j.annotation.Neo4jRelatedTo; @@ -150,13 +151,15 @@ public void reTouite(Long key) throws Neo4jException { // delete the previous NEXT relationship Relationship next = this.node.getSingleRelationship(RelationType.NEXT, Direction.OUTGOING); - next.delete(); + if (next != null) + next.delete(); // create next link between user & touite this.node.createRelationshipTo(retouite.node, RelationType.NEXT); // relink lasttouite with the new one - retouite.node.createRelationshipTo(lastTouite.node, RelationType.NEXT); + if (lastTouite != null) + retouite.node.createRelationshipTo(lastTouite.node, RelationType.NEXT); // create author link retouite.node.createRelationshipTo(touite.getAuthor().node, RelationType.AUTHOR); @@ -190,7 +193,8 @@ public void touite(String text) throws Neo4jException { Touite lastTouite = this.getLastTouite(); // delete the previous NEXT relationship Relationship next = this.node.getSingleRelationship(RelationType.NEXT, Direction.OUTGOING); - next.delete(); + if (next != null) + next.delete(); // create next link between user & touite this.node.createRelationshipTo(touite.node, RelationType.NEXT); @@ -199,7 +203,8 @@ public void touite(String text) throws Neo4jException { touite.node.createRelationshipTo(this.node, RelationType.AUTHOR); // relink lasttouite with the new one - touite.node.createRelationshipTo(lastTouite.node, RelationType.NEXT); + if (lastTouite != null) + touite.node.createRelationshipTo(lastTouite.node, RelationType.NEXT); // +1 if (this.nbTouite != null) { @@ -226,6 +231,12 @@ public List getSimilarUser(User user) throws Neo4jException { "RETURN reco, COUNT(*) " + "ORDER BY COUNT(*) DESC, reco.key " + "LIMIT 3"); + Logger.debug("START user=node(" + user.node.getId() + ") " + + "MATCH reco-[:IS_FRIEND*1..3]->user, user-[r?:IS_FRIEND]->reco " + + "WHERE r IS NULL and not(reco.key = user.key) " + + "RETURN reco, COUNT(*) " + + "ORDER BY COUNT(*) DESC, reco.key " + + "LIMIT 3"); //@formatter:on List recos = new ArrayList(); Iterator column = result.columnAs("reco"); diff --git a/src/play/modules/neo4j/model/Neo4jFactory.java b/src/play/modules/neo4j/model/Neo4jFactory.java index 82d0559..5060ea0 100644 --- a/src/play/modules/neo4j/model/Neo4jFactory.java +++ b/src/play/modules/neo4j/model/Neo4jFactory.java @@ -122,8 +122,10 @@ public Neo4jFactory(Class clazz) { /** * Method to retrieve a node by a key. * - * @param key the idenfifier of the node - * @param indexName Name of the index on wich to search + * @param key + * the idenfifier of the node + * @param indexName + * Name of the index on wich to search * @return */ public Node getByKey(Long key, String indexName) { @@ -154,7 +156,8 @@ public List findAll() throws Neo4jException { /** * Method to save/update and index a node. * - * @param nodeWrapper to save + * @param nodeWrapper + * to save * @return the save or update node * @throws Neo4jException * @throws IllegalAccessException @@ -210,17 +213,17 @@ public Neo4jModel saveAndIndex(Neo4jModel nodeWrapper) throws Neo4jException { Neo4jRelatedTo neo4jRelatedTo = field.getAnnotation(Neo4jRelatedTo.class); Direction relationDirection = neo4jRelatedTo.direction(); RelationshipType relationType = DynamicRelationshipType.withName(neo4jRelatedTo.value()); - + // we begin from the node Node startNode = nodeWrapper.getNode(); - // construct an hasmap of database relation from node with begin node / relation format. + // construct an hashmap of database relation from node with begin node / relation format. Map dbMapRelations = new HashMap(); - Iterable dbNodeRlation = startNode.getRelationships( - relationDirection, relationType); + Iterable dbNodeRlation = startNode.getRelationships(relationDirection, + relationType); for (Relationship relation : dbNodeRlation) { - dbMapRelations.put(startNode.getId() + "@" - + relation.getOtherNode(startNode).getId(), relation); + dbMapRelations.put(startNode.getId() + "@" + relation.getOtherNode(startNode).getId(), + relation); } // this map is the stack where relation are store and remove to khnow wich are to add or // deleted @@ -261,10 +264,12 @@ public Neo4jModel saveAndIndex(Neo4jModel nodeWrapper) throws Neo4jException { // UniqueRelation annotation if (field.isAnnotationPresent(Neo4jUniqueRelation.class)) { + // we retrive annotation value Neo4jUniqueRelation neo4jUnique = field.getAnnotation(Neo4jUniqueRelation.class); Direction relationDirection = neo4jUnique.direction(); RelationshipType relationType = DynamicRelationshipType.withName(neo4jUnique.value()); + // get GETTER method String propertyName = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); @@ -427,7 +432,8 @@ private Map getLuceneConfigParam(Field field) { * Method to delete a node. If it still have a relationship (otherwise than ref2node one), this method throw a * runtime exception. * - * @param nodeWrapper to delete + * @param nodeWrapper + * to delete * @return the deleted object * @throws Neo4jException */ @@ -438,7 +444,8 @@ public Neo4jModel delete(Neo4jModel nodeWrapper) throws Neo4jException { /** * Method to delete a node, also when it still have relationship. Use this method carefully ! * - * @param nodeWrapper to delete + * @param nodeWrapper + * to delete * @return the object deleted * @throws Neo4jException */ @@ -450,7 +457,8 @@ public Neo4jModel forceDelete(Neo4jModel nodeWrapper) throws Neo4jException { * General(private) method to delete a node. * * @param nodeWrapper - * @param forceDelete if this param is set to TRUE, then all relationship will be deleted before we delete the node. + * @param forceDelete + * if this param is set to TRUE, then all relationship will be deleted before we delete the node. * @return The object that have been deleted. * @throws Neo4jException */