Database Reference
In-Depth Information
The edit feature, like the add feature, uses a route in the graphstory application and a function in graphstory.js ,
which are edit and editContent , respectively. The editContent action passes in the content object, with its content
id, and then calls the editContent method in ContentDAO class, as shown in Listing 12-32.
In the case of the edit feature, you do not need to update relationships. Instead, you 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 12-32. editContent Methods in SocialAction and ContentDAO
@Action(value = "posts/edit", interceptorRefs = {
@InterceptorRef(value = "cookie", params = { "cookiesName", "graphstoryUserAuthKey" }),
@InterceptorRef(value = "json", params = { "noCache", "true", "excludeNullProperties",
"true" }) },
results = {
@Result(name = "success", type = "json", params = { "noCache", "true" })
})
public String editContent () {
try {
if (graphStory.getStatusUpdate() != null) {
graphStory.setMappedContent(graphStoryDAO.getContentDAO()
. editContent (
graphStory.getStatusUpdate(),
cookiesMap.get(GraphStoryConstants.graphstoryUserAuthKey)
));
}
}
catch (Exception e) {
log.error(e);
}
return SUCCESS;
}
//editContent in ContentDAO
public MappedContent editContent (Content content, String username) {
String tagStr = trimContentTags(content.getTagstr());
Map<String, Object> contentMap = IteratorUtil.singleOrNull(cypher.iteratorQuery(
" MATCH (c:Content {contentId:{1}})-[:NEXTPOST*0..]-()-[:CURRENTPOST]-(user { username: {2}}) " +
" SET c.title = {3}, c.url = {4}, c.tagstr = {5}" +
" FOREACH (tagName in {6} | " +
" MERGE (t:Tag {wordPhrase:tagName}) " +
" MERGE (c)-[:HAS]->(t) " +
" )" +
" RETURN c.contentId as contentId, c.title as title, c.tagstr as tagstr, " +
" c.timestamp as timestamp, c.url as url, {2} as username, true as owner ",
map("1", content.getContentId(), "2", username, "3", content.getTitle(),
"4", content.getUrl(), "5", tagStr, "6", tagList(tagStr))));
ResultSetMapper<MappedContent> resultSetMapper = new ResultSetMapper<MappedContent>();
return resultSetMapper.mapResultSetToMappedClass(contentMap, MappedContent.class);
}
 
Search WWH ::




Custom Search