mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-9153 Convert the topic+post creation webscript to be Java backed and Lucene free
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29884 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,100 +0,0 @@
|
|||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js">
|
|
||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js">
|
|
||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/discussions/topicpost.lib.js">
|
|
||||||
|
|
||||||
function ensureTagScope(node)
|
|
||||||
{
|
|
||||||
if (! node.isTagScope)
|
|
||||||
{
|
|
||||||
node.isTagScope = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// also check the parent (the site!)
|
|
||||||
if (! node.parent.isTagScope)
|
|
||||||
{
|
|
||||||
node.parent.isTagScope = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a post to the passed forum node.
|
|
||||||
*/
|
|
||||||
function createPost(forumNode)
|
|
||||||
{
|
|
||||||
// fetch the data required to create a topic
|
|
||||||
var title = "";
|
|
||||||
if (json.has("title"))
|
|
||||||
{
|
|
||||||
title = json.get("title");
|
|
||||||
}
|
|
||||||
var content = "";
|
|
||||||
if (json.has("content"))
|
|
||||||
{
|
|
||||||
content = json.get("content");
|
|
||||||
}
|
|
||||||
var tags = [];
|
|
||||||
if (json.has("tags"))
|
|
||||||
{
|
|
||||||
// get the tags JSONArray and copy it into a real javascript array object
|
|
||||||
var tmp = json.get("tags");
|
|
||||||
for (var x=0; x < tmp.length(); x++)
|
|
||||||
{
|
|
||||||
tags.push(tmp.get(x));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the topic node, and add the first child node representing the topic text
|
|
||||||
// NOTE: this is a change from the old web client, where the topic title was used as name
|
|
||||||
// for the topic node. We will use generated names to make sure we won't have naming
|
|
||||||
// clashes.
|
|
||||||
var name = getUniqueChildName(forumNode, "post");
|
|
||||||
var topicNode = forumNode.createNode(name, "fm:topic");
|
|
||||||
topicNode.properties.title = title;
|
|
||||||
topicNode.save();
|
|
||||||
|
|
||||||
// We use twice the same name for the topic and the post in it
|
|
||||||
var contentNode = topicNode.createNode(name, "fm:post");
|
|
||||||
contentNode.mimetype = "text/html";
|
|
||||||
contentNode.properties.title = title;
|
|
||||||
contentNode.content = content;
|
|
||||||
contentNode.save();
|
|
||||||
|
|
||||||
// add the cm:syndication aspect
|
|
||||||
var props = new Array();
|
|
||||||
props["cm:published"] = new Date();
|
|
||||||
contentNode.addAspect("cm:syndication", props);
|
|
||||||
|
|
||||||
// add the tags to the topic node for now
|
|
||||||
topicNode.tags = tags;
|
|
||||||
|
|
||||||
return topicNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
function main()
|
|
||||||
{
|
|
||||||
// get requested node
|
|
||||||
var node = getRequestNode();
|
|
||||||
if (status.getCode() != status.STATUS_OK)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ensureTagScope(node);
|
|
||||||
|
|
||||||
var topicPost = createPost(node);
|
|
||||||
|
|
||||||
model.postData = getTopicPostData(topicPost);
|
|
||||||
|
|
||||||
// create an activity entry
|
|
||||||
if (json.has("site") && json.has("page"))
|
|
||||||
{
|
|
||||||
var data =
|
|
||||||
{
|
|
||||||
title: model.postData.post.properties.title,
|
|
||||||
page: json.get("page") + "?topicId=" + model.postData.topic.name
|
|
||||||
}
|
|
||||||
activities.postActivity("org.alfresco.discussions.post-created", json.get("site"), "discussions", jsonUtils.toJSONString(data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
@@ -1601,6 +1601,13 @@
|
|||||||
parent="abstractDiscussionWebScript">
|
parent="abstractDiscussionWebScript">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Creates a new discussions topic and primary post -->
|
||||||
|
<bean id="webscript.org.alfresco.repository.discussions.forum.forum-posts.post"
|
||||||
|
class="org.alfresco.repo.web.scripts.discussion.ForumTopicPost"
|
||||||
|
parent="abstractDiscussionWebScript">
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<!-- Lists the Discussions for a site -->
|
<!-- Lists the Discussions for a site -->
|
||||||
<!--
|
<!--
|
||||||
<bean id="webscript.org.alfresco.repository.discussions.forum.forum-posts.get"
|
<bean id="webscript.org.alfresco.repository.discussions.forum.forum-posts.get"
|
||||||
|
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.web.scripts.discussion;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.discussion.PostInfo;
|
||||||
|
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is the controller for the discussions page editing forum-posts.postt webscript.
|
||||||
|
*
|
||||||
|
* @author Nick Burch
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class ForumTopicPost extends AbstractDiscussionWebScript
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||||
|
TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json,
|
||||||
|
Status status, Cache cache)
|
||||||
|
{
|
||||||
|
// They shouldn't be adding to an existing Post or Topic
|
||||||
|
if(topic != null || post != null)
|
||||||
|
{
|
||||||
|
String error = "Can't create a new Topic inside an existing Topic or Post";
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Grab the details of the new Topic and Post
|
||||||
|
String title = "";
|
||||||
|
String contents = "";
|
||||||
|
List<String> tags = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(json.has("title"))
|
||||||
|
{
|
||||||
|
title = json.getString("title");
|
||||||
|
}
|
||||||
|
if(json.has("content"))
|
||||||
|
{
|
||||||
|
contents = json.getString("content");
|
||||||
|
}
|
||||||
|
if(json.has("tags"))
|
||||||
|
{
|
||||||
|
tags = new ArrayList<String>();
|
||||||
|
JSONArray jsTags = json.getJSONArray("tags");
|
||||||
|
for(int i=0; i<jsTags.length(); i++)
|
||||||
|
{
|
||||||
|
tags.add( jsTags.getString(i) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(JSONException e)
|
||||||
|
{
|
||||||
|
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Have the topic created
|
||||||
|
if(site != null)
|
||||||
|
{
|
||||||
|
topic = discussionService.createTopic(site.getShortName(), title);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
topic = discussionService.createTopic(nodeRef, title);
|
||||||
|
}
|
||||||
|
if(tags != null && tags.size() > 0)
|
||||||
|
{
|
||||||
|
topic.getTags().clear();
|
||||||
|
topic.getTags().addAll(tags);
|
||||||
|
discussionService.updateTopic(topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Have the primary post created
|
||||||
|
post = discussionService.createPost(topic, contents);
|
||||||
|
|
||||||
|
|
||||||
|
// Record the activity
|
||||||
|
addActivityEntry("post", "created", topic, post, site, req, json);
|
||||||
|
|
||||||
|
|
||||||
|
// Build the common model parts
|
||||||
|
Map<String, Object> model = buildCommonModel(site, topic, post, req);
|
||||||
|
|
||||||
|
// Build the JSON for the whole topic
|
||||||
|
model.put(KEY_POSTDATA, renderTopic(topic, site));
|
||||||
|
|
||||||
|
// All done
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user