Database Reference
In-Depth Information
Getting the Status Updates
To display the first set of status updates, start with the social route of the social section of the Java sample application
graphstory . This method accesses the getContent method within Content service class, which takes an argument
of the current user's username and the page being requested. The page refers to set number of objects within a
collection. In this instance the paging is zero-based, so you will request page 0 and limit the page size to 4 in order to
return the first page.
The getContent method in Content class, shown in Listing 12-30, first determines whom the user is following
and then matches that set of users with the status updates starting with the CURRENTPOST . The CURRENTPOST is then
matched on the next three status updates via the [:NEXTPOST*0..3] section of the query. Finally, the method uses
a loop to add a readable date and time string property—based on the timestamp—on the results returned to the
controller and view.
Listing 12-30. The getContent Method in ContentDAO Class
public GraphStory getContent(String username, int skip, GraphStory graphStory) {
try {
ResultSet rs = cypher.resultSetQuery(
" MATCH (u:User {username: {1} }) " +
" WITH u " +
" MATCH (u)-[:FOLLOWS*0..1]->f " +
" WITH DISTINCT f,u " +
" MATCH f-[:CURRENTPOST]-lp-[:NEXTPOST*0..3]-p " +
" RETURN p.contentId as contentId, p.title as title, p.tagstr as tagstr, " +
" p.timestamp as timestamp, p.url as url, f.username as username, f=u as owner " +
" ORDER BY p.timestamp DESC " +
" SKIP {2} LIMIT 4 ",
map("1", username, "2", skip));
ResultSetMapper<MappedContent> resultSetMapper =
new ResultSetMapper<MappedContent>();
graphStory.setContent(
resultSetMapper.mapResultSetToListMappedClass(rs,MappedContent.class));
if (graphStory.getContent().size() >= 4) {
graphStory.setMorecontent(true);
if (skip == 0) {
graphStory.setContent(graphStory.getContent().subList(0, 3));
}
} else {
graphStory.setMorecontent(false);
}
}
catch (Exception e) {
log.error(e);
}
return graphStory;
}
 
Search WWH ::




Custom Search