Database Reference
In-Depth Information
Listing 12-38. Methods to Add a userview for Product
@Action(value = "consumptionview/add/{productNodeId}", results = {
@Result(name = "success", type = "json")
})
public String addUserViewAndReturnProductTrail() {
try {
graphStory.setProductTrail(graphStoryDAO.getProductDAO()
.addUserViewAndReturnProductTrail(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey), productNodeId
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// the method to add a user view in the ProductDAO class
public List<MappedProductUserViews> addUserViewAndReturnProductTrail(
String username, Long productNodeId) {
try {
Date timestamp = new Date(dateAsLong);
SimpleDateFormat dformatter = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat tformatter = new SimpleDateFormat("h:mm a");
String dateAsStr = dformatter.format(timestamp)
+ " at " + tformatter.format(timestamp);
ResultSet rs = cypher.resultSetQuery(
" MATCH (p:Product), (u:User { username:{1} })" +
" WHERE id(p) = {2}" +
" WITH u,p" +
" MERGE (u)-[r:VIEWED]->(p)" +
" SET r.dateAsStr={3}, r.timestamp={4}" +
" WITH u " +
" MATCH (u)-[r:VIEWED]->(p)" +
" RETURN p.title as title, r.dateAsStr as dateAsStr" +
" ORDER BY r.timestamp desc",
map("1", username, "2", productNodeId, "3", dateAsStr,
"4", timestamp.getTime()));
ResultSetMapper<MappedProductUserViews> resultSetMapper
= new ResultSetMapper<MappedProductUserViews>();
return resultSetMapper
.mapResultSetToListMappedClass(rs, MappedProductUserViews.class);
}
catch (Exception e) {
log.error(e);
return null;
}
}
 
Search WWH ::




Custom Search