Database Reference
In-Depth Information
Listing 12-29. The unfollow Route and unfollow Method
// unfollow a user
@Action(value = "unfollow/{username}",results = {@Result(name = "success", type = "json")})
public String unfollow() {
try {
graphStory.setFollowing(graphStoryDAO.getUserDAO()
.unfollow(
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey),
graphStory.getUsername()
));
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// unfollow (e.g. delete relationship) and return new list of following
public List<User> unfollow(String currentusername, String username) {
try
{
ResultSet resultSet = cypher.resultSetQuery(
" MATCH (user1:User {username:{1}} )-[f:FOLLOWS]->(user2:User {username:{2}} )" +
" DELETE f" +
" WITH user1" +
" MATCH (user1)-[f: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;
}
}
User-Generated Content
Another important feature in social media applications is being able to have users view, add, edit, and remove
content, sometimes referred to as User Generated Content. In the case of this content, you will not be creating
connections between the content and its owner but creating a linked list of status updates. In other words, you will be
connecting a User to their most recent status update and then connecting each subsequent status to the next update
through the CURRENTPOST and NEXTPOST directed relationship types, respectively.
This approach is used for two reasons. First, the sample application displays a given number of posts at a time and
using a limited linked list is more efficient than getting all status updates connected directly to a user and then sorting
and limiting the number of items to return. Second, you will also help limit the number of relationships that are placed
on the User and Content entities. Overall, the graph operations should be more efficient using the linked list approach.
 
Search WWH ::




Custom Search