-
-
Save IdanFridman/22637f95ba696f498b6c to your computer and use it in GitHub Desktop.
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
package com.mycompany.wm.common.repo; | |
import com.mycompany.common.messaging.dto.ArrDistItem; | |
import com.mycompany.wm.common.dto.NodeDTO; | |
import com.mycompany.wm.common.dto.follow.followItem; | |
import com.mycompany.wm.common.repo.neo4j.Neo4jCypherRestClient; | |
import com.mycompany.wm.common.repo.neo4j.Neo4jResultSet; | |
import com.mycompany.wm.common.utils.LocationUtils; | |
import com.mycompany.wm.common.utils.follow_RELATIONSHIP_DIRECTION; | |
import org.apache.log4j.Logger; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import javax.annotation.PostConstruct; | |
import javax.annotation.PreDestroy; | |
import javax.inject.Inject; | |
import java.sql.Connection; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Set; | |
/** | |
* Created by idan on 9/17/15. | |
*/ | |
public class Neo4jRepo { | |
private static final String LABEL_NAME = "follow"; | |
private final Logger logger = Logger.getLogger(Neo4jRepo.class); | |
private Connection conn = null; | |
@Inject | |
Neo4jDataSource neo4jDataSource; | |
@Autowired | |
private Neo4jCypherRestClient neo4jCypherRestClient; | |
/* test lasttime active with real tests. should set lasttime active when ever doing reportfollow (delete,create)*/ | |
@PostConstruct | |
public void init() throws SQLException { | |
logger.debug("Neo4jRepo, Init"); | |
conn = neo4jDataSource.openConnection(); | |
} | |
@PreDestroy | |
public void close() { | |
neo4jDataSource.closeConnection(conn); | |
} | |
public List<followItem> executeQuery(String userIdInput) { | |
String getUsersStatement = | |
"MATCH p=shortestPath((user:" + LABEL_NAME + " {userId:{1}})-[r:follow*1..3]-(f:" + LABEL_NAME + ")) " + | |
"WHERE f <> user " + | |
"RETURN (f.userId) as userId," + | |
"(f.lastTimeActive) as lastTimeActive, " + | |
"reduce(s = '', rel IN r | s + rel.dist + ',') as dist," + | |
// "reduce(y = '', rel IN r | y + rel.reportDate + ',') as reportDate, " + | |
"length(r) as hop"; | |
Neo4jResultSet rs = neo4jCypherRestClient.query(getUsersStatement, userIdInput); | |
... | |
return followItems; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment