Database Reference
In-Depth Information
try {
graphStory.setMappedProductUserPurchaseList(graphStoryDAO
.getPurchaseDAO().friendsPurchase(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
));
graphStory.setUser(graphStoryDAO
.getUserDAO().getByUserName(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
The query finds the users being followed by the current user and then matches those users to a purchase that
has been
MADE
which
CONTAINS
a product. The return value is a set of properties that identify the product title, the
name of the friend or friends, as well the number of friends who have purchased the product. The result, as shown in
Figure
12-18
, is ordered by the number of friends who have purchased the product and then by product title
(Listing 12-45).
Listing 12-45.
FriendsPurchase
Method
public List<MappedProductUserPurchase> friendsPurchase(String username) {
try {
ResultSet rs = cypher.resultSetQuery(
"MATCH (u:User { username : {1} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p " +
" RETURN p.productId as productId, " +
" p.title as title, " +
" collect(f.firstname + ' ' + f.lastname) as fullname, " +
" null as wordPhrase, " +
" count(f) as cfriends " +
" ORDER BY cfriends desc, p.title ",
map("1", username));
ResultSetMapper<MappedProductUserPurchase> resultSetMapper =
new ResultSetMapper<MappedProductUserPurchase>();
return resultSetMapper
.mapResultSetToListMappedClass(rs, MappedProductUserPurchase.class);
}
catch (Exception e) {
log.error(e);
return null;
}
}