Database Reference
In-Depth Information
graphStory.setUsers(graphStoryDAO.getUserDAO()
.searchNotFollowing(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey),
graphStory.getUsername()
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// the searchNotFollowing method returns users NOT being followed already
public List<User> searchNotFollowing(String currentusername, String username) {
try
{
username = username.toLowerCase() + ".*";
ResultSet resultSet = cypher.resultSetQuery(
" MATCH (users:User), (user { username:{1}}) " +
// where n.username WILDCARD on param 'u'
// but is not the current user
" WHERE (users.username =~ {2} AND users <> user) " +
// and don't return users already being followed
" AND (NOT (user)-[:FOLLOWS]->(users)) " +
" RETURN users" +
" ORDER BY users.username",
map("1", currentusername, "2", username));
ResultSetMapper<User> resultSetMapper = new ResultSetMapper<User>();
return resultSetMapper.mapRersultSetToObject(resultSet, User.class);
}
catch (Exception e) {
log.error(e);
return null;
}
}
The searchByUsername in {PROJECTROOT}/WebContent/resources/js/graphstory.js uses an AJAX request and
formats the response in renderSearchByUsername . If the list contains users, it will be displayed in the center of the
page under the search form, as shown in Figure 12-9 . Otherwise, the response will display “No Users Found”.
Once the search returns results, the next action would be to click on the “Add as Friend” link, which calls the
addfriend method in graphstory.js . This will perform an AJAX request to the follow method in the UserAction
and calls the follow method in UserDAO . The follow method in UserDAO , shown in Listing 12-28, will create the
relationship between the two users by first finding each entity via the MATCH clause and then by using the CREATE
UNIQUE clause to create the directed FOLLOWS relationship. Once the operation is complete, the controller then
requests the following method in UserService to return the full list of followers ordered by the username.
 
Search WWH ::




Custom Search