Database Reference
In-Depth Information
Deleting a Status Update
As with the “edit” option, when status updates are displayed, the current user's status updates will contain a link to
“Delete” the status. Once clicked, it asks if you want it deleted (no regrets!) and, if accepted, generates an AJAX GET
request to call the delete route and corresponding method in the ContentDAO class, as shown in Listing 12-33.
The Cypher in the delete method begins by finding the user and content that will be used in the rest of the query.
In the first MATCH , you can determine if this status update is the CURRENTPOST by checking to see if it is related to a
NEXTPOST . If this relationship pattern matches, make the NEXTPOST into the CURRENTPOST with CREATE UNIQUE .
Next, the query asks if the status update is somewhere the middle of the list, which is performed by determining
if the status update has incoming and outgoing NEXTPOST relationships. If the pattern is matched, connect the before
and after status updates via NEXTPOST .
Regardless of the status update's location in the linked list, you will retrieve it and its relationships and then
delete the node along with all of its relationships.
To recap, if one of the relationship patterns matches, replace that pattern with the nodes on either side of the
status update in question. Once that is performed, the node and its relationships can be removed from the graph.
Listing 12-33. deleteContent Methods in SocialAction and ContentDAO
@Action(value = "/posts/delete/{contentId}",
results = {
@Result(name = "success", type = "json")
})
public String deleteContent() {
try {
graphStoryDAO.getContentDAO()
.deleteContent(
contentId,
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
);
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("Msg", "OK");
graphStory.setMessage(msg);
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
// deleteContent method in ContentDAO
public void deleteContent(String contentId, String username) {
cypher.iteratorQuery(
" MATCH (u:User { username: {1} }), (c:Content { contentId: {2} }) " +
" WITH u,c " +
" MATCH (u)-[:CURRENTPOST]->(c)-[:NEXTPOST]->(nextPost) " +
" WHERE nextPost is not null " +
" CREATE UNIQUE (u)-[:CURRENTPOST]->(nextPost) " +
" WITH count(nextPost) as cnt " +
" MATCH (before)-[:NEXTPOST]->(c:Content { contentId: {2}})-[:NEXTPOST]->(after) " +
 
Search WWH ::




Custom Search