Database Reference
In-Depth Information
The edit feature, like the add feature, uses a method in the SocialController and a function in graphstory.js ,
which are edit and updateContent , respectively. The edit method will first determine whether the tag set should
be updated, and then call the edit method in ContentImpl , which is shown in Listing 11-34. In the case of the edit
feature, you will not need to update relationships. Instead, you will simply retrieve the existing node by its generated
String Id (not graph id), update its properties where necessary, and save it back to the graph.
Listing 11-37. The edit Method for ContentImpl
public Content edit (Content content, User user) {
Content c = contentRepository.findByContentId (content.getContentId());
// just update the essentials. it will NOT be re-ordered.
c.setTitle(content.getTitle());
c.setUrl(content.getUrl());
if (content.getTags() != null) {
c.setTags(content.getTags());
c.setTagstr(removeTrailingComma(content.getTagstr()));
}
content = contentRepository.save (c);
return content;
}
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 immediately (you wanted it gone, so no regrets!) generates an AJAX GET request
to call the delete method in the SocialController. This method then calls the delete method in ContentImpl, shown in
Listing 11-38.
The delete method in ContentImpl first determines where in the status update chain the provided status exists.
If the status was the CURRENTPOST, which the currentpost method in the ContentRepository interface returns, then
you need to “promote” the NEXTPOST in the chain to the CURRENTPOST relationship.
If the status is connected to CURRENTPOST, you need to remove the relationship, find the subsequent
NEXTPOST, and make it connected to the CURRENTPOST. If neither of these conditions exists, then the status is
further down the chain. So, you will remove its relationship to the NEXTPOST and then connect the status updates
that were previously on either side of the soon-to-be-deleted status update. Once the relationships have been
rearranged, the entity can be removed through the neo4jTemplate's delete method.
Listing 11-38. Deleting a status update
public void delete (String contentId, User user) {
// find the content
Content content = getContentItem(contentId);
// get the CURRENTPOST
Content currentPost = contentRepository.currentpost (user.getNodeId());
 
Search WWH ::




Custom Search