Coding standards and consistency sweep across new services code in remote-api project.

Covers spacing, trailing {, @since tags, tabs and copyright headers.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30216 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2011-09-03 21:52:43 +00:00
parent 6a98ee59eb
commit 7efdd5aa2f
80 changed files with 1389 additions and 1389 deletions

View File

@@ -118,7 +118,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
protected String getOrNull(JSONObject json, String key)
{
if(json.containsKey(key))
if (json.containsKey(key))
{
return (String)json.get(key);
}
@@ -135,26 +135,26 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
int startIndex = 0;
String pageSizeS = req.getParameter("pageSize");
if(pageSizeS != null)
if (pageSizeS != null)
{
try
{
pageSize = Integer.parseInt(pageSizeS);
}
catch(NumberFormatException e)
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
}
}
String startIndexS = req.getParameter("startIndex");
if(startIndexS != null)
if (startIndexS != null)
{
try
{
startIndex = Integer.parseInt(startIndexS);
}
catch(NumberFormatException e)
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
}
@@ -168,14 +168,14 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
protected List<String> getTags(JSONObject json)
{
List<String> tags = null;
if(json.containsKey("tags"))
if (json.containsKey("tags"))
{
// Is it "tags":"" or "tags":[...] ?
if(json.get("tags") instanceof String)
if (json.get("tags") instanceof String)
{
// This is normally an empty string, skip
String tagsS = (String)json.get("tags");
if("".equals(tagsS))
if ("".equals(tagsS))
{
// No tags were given
return null;
@@ -191,7 +191,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
{
tags = new ArrayList<String>();
JSONArray jsTags = (JSONArray)json.get("tags");
for(int i=0; i<jsTags.size(); i++)
for (int i=0; i<jsTags.size(); i++)
{
tags.add( (String)jsTags.get(i) );
}
@@ -210,7 +210,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
PostInfo post, SiteInfo site, WebScriptRequest req, JSONObject json)
{
// We can only add activities against a site
if(site == null)
if (site == null)
{
logger.info("Unable to add activity entry for " + thing + " " + event + " as no site given");
return;
@@ -218,14 +218,14 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// What page is this for?
String page = req.getParameter("page");
if(page == null && json != null)
if (page == null && json != null)
{
if(json.containsKey("page"))
if (json.containsKey("page"))
{
page = (String)json.get("page");
}
}
if(page == null)
if (page == null)
{
// Default
page = "discussions-topicview";
@@ -233,10 +233,10 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// Get the title
String title = topic.getTitle();
if(post != null)
if (post != null)
{
String postTitle = post.getTitle();
if(postTitle != null && postTitle.length() > 0)
if (postTitle != null && postTitle.length() > 0)
{
title = postTitle;
}
@@ -256,8 +256,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
"org.alfresco.discussions." + thing + "-" + event,
site.getShortName(),
DISCUSSIONS_SERVICE_ACTIVITY_APP_NAME,
activity.toString()
);
activity.toString());
}
catch(Exception e)
{
@@ -277,19 +276,19 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
{
// Are they OK on the node?
AccessStatus canEdit = permissionService.hasPermission(post.getNodeRef(), PermissionService.WRITE);
if(canEdit == AccessStatus.ALLOWED)
if (canEdit == AccessStatus.ALLOWED)
{
// Only the creator and site managers may edit
String user = AuthenticationUtil.getFullyAuthenticatedUser();
if(post.getCreator().equals(user))
if (post.getCreator().equals(user))
{
// It's their post
return true;
}
if(site != null)
if (site != null)
{
String role = siteService.getMembersRole(site.getShortName(), user);
if(SiteServiceImpl.SITE_MANAGER.equals(role))
if (SiteServiceImpl.SITE_MANAGER.equals(role))
{
// Managers may edit
return true;
@@ -303,7 +302,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
protected Object buildPerson(String username)
{
if(username == null || username.length() == 0)
if (username == null || username.length() == 0)
{
// Empty string needed
return "";
@@ -338,7 +337,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
{
// Fetch the primary post
PostInfo primaryPost = discussionService.getPrimaryPost(topic);
if(primaryPost == null)
if (primaryPost == null)
{
throw new WebScriptException(Status.STATUS_PRECONDITION_FAILED,
"First (primary) post was missing from the topic, can't fetch");
@@ -349,7 +348,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// Find out how many replies there are
int numReplies;
if(mostRecentPost.getNodeRef().equals( primaryPost.getNodeRef() ))
if (mostRecentPost.getNodeRef().equals( primaryPost.getNodeRef() ))
{
// Only the one post in the topic
mostRecentPost = null;
@@ -379,7 +378,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
item.put("totalReplyCount", numReplies);
// We want details on the most recent post
if(mostRecentPost != null)
if (mostRecentPost != null)
{
item.put("lastReply", mostRecentPost.getNodeRef());
item.put("lastReplyBy", buildPerson(mostRecentPost.getCreator()));
@@ -418,7 +417,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// Data
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
for(TopicInfo topic : topics)
for (TopicInfo topic : topics)
{
items.add(renderTopic(topic, site));
}
@@ -437,7 +436,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
model.put(KEY_POST, post);
// Capture the site details only if site based
if(site != null)
if (site != null)
{
model.put("siteId", site.getShortName());
model.put("site", site);
@@ -446,13 +445,13 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// The limit on the length of the content to be returned
int contentLength = -1;
String contentLengthS = req.getParameter("contentLength");
if(contentLengthS != null)
if (contentLengthS != null)
{
try
{
contentLength = Integer.parseInt(contentLengthS);
}
catch(NumberFormatException e)
catch (NumberFormatException e)
{
logger.info("Skipping invalid length " + contentLengthS);
}
@@ -468,7 +467,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
if(templateVars == null)
if (templateVars == null)
{
String error = "No parameters supplied";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -478,22 +477,22 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// Parse the JSON, if supplied
JSONObject json = null;
String contentType = req.getContentType();
if(contentType != null && contentType.indexOf(';') != -1)
if (contentType != null && contentType.indexOf(';') != -1)
{
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if(MimetypeMap.MIMETYPE_JSON.equals(contentType))
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
{
JSONParser parser = new JSONParser();
try
{
json = (JSONObject)parser.parse(req.getContent().getContent());
}
catch(IOException io)
catch (IOException io)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
}
catch(ParseException pe)
catch (ParseException pe)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
}
@@ -506,24 +505,24 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
TopicInfo topic = null;
PostInfo post = null;
if(templateVars.containsKey("site"))
if (templateVars.containsKey("site"))
{
// Site, and optionally topic
String siteName = templateVars.get("site");
site = siteService.getSite(siteName);
if(site == null)
if (site == null)
{
String error = "Could not find site: " + siteName;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
// Did they give a topic name too?
if(templateVars.containsKey("path"))
if (templateVars.containsKey("path"))
{
String name = templateVars.get("path");
topic = discussionService.getTopic(site.getShortName(), name);
if(topic == null)
if (topic == null)
{
String error = "Could not find topic '" + name + "' for site '" +
site.getShortName() + "'";
@@ -534,23 +533,23 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
else
{
// The NodeRef is the container (if it exists)
if(siteService.hasContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT))
if (siteService.hasContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT))
{
nodeRef = siteService.getContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT);
}
}
}
else if(templateVars.containsKey("store_type") &&
templateVars.containsKey("store_id") &&
templateVars.containsKey("id"))
else if (templateVars.containsKey("store_type") &&
templateVars.containsKey("store_id") &&
templateVars.containsKey("id"))
{
// NodeRef, normally Topic or Discussion
StoreRef store = new StoreRef(
templateVars.get("store_type"),
templateVars.get("store_id")
);
templateVars.get("store_id"));
nodeRef = new NodeRef(store, templateVars.get("id"));
if(! nodeService.exists(nodeRef))
if (! nodeService.exists(nodeRef))
{
String error = "Could not find node: " + nodeRef;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
@@ -558,20 +557,20 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
// Try to build the appropriate object for it
Pair<TopicInfo,PostInfo> objects = discussionService.getForNodeRef(nodeRef);
if(objects != null)
if (objects != null)
{
topic = objects.getFirst();
post = objects.getSecond();
}
// See if it's actually attached to a site
if(topic != null)
if (topic != null)
{
NodeRef container = topic.getContainerNodeRef();
if(container != null)
if (container != null)
{
NodeRef maybeSite = nodeService.getPrimaryParent(container).getParentRef();
if(maybeSite != null)
if (maybeSite != null)
{
// Try to make it a site, will return Null if it isn't one
site = siteService.getSite(maybeSite);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -67,7 +67,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
private static Log logger = LogFactory.getLog(DiscussionRestApiTest.class);
private static final String DELETED_REPLY_POST_MARKER = "[[deleted]]";
private MutableAuthenticationService authenticationService;
private AuthenticationComponent authenticationComponent;
private TransactionService transactionService;
@@ -160,13 +160,13 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
// delete the discussions users
personService.deletePerson(USER_ONE);
if(this.authenticationService.authenticationExists(USER_ONE))
if (this.authenticationService.authenticationExists(USER_ONE))
{
this.authenticationService.deleteAuthentication(USER_ONE);
}
personService.deletePerson(USER_TWO);
if(this.authenticationService.authenticationExists(USER_TWO))
if (this.authenticationService.authenticationExists(USER_TWO))
{
this.authenticationService.deleteAuthentication(USER_TWO);
}
@@ -230,6 +230,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doCreatePost(URL_FORUM_SITE_POSTS, title, content, expectedStatus);
}
/**
* Creates a new topic+post under the given node
*/
@@ -238,6 +239,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doCreatePost(getPostsUrl(nodeRef), title, content, expectedStatus);
}
private JSONObject doCreatePost(String url, String title, String content,
int expectedStatus) throws Exception
{
@@ -262,11 +264,13 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doUpdatePost(getPostUrl(nodeRef), title, content, expectedStatus);
}
private JSONObject updatePost(String name, String title, String content,
int expectedStatus) throws Exception
{
return doUpdatePost(URL_FORUM_SITE_POST + name, title, content, expectedStatus);
}
private JSONObject doUpdatePost(String url, String title, String content,
int expectedStatus) throws Exception
{
@@ -288,10 +292,12 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doGetPost(URL_FORUM_SITE_POST + name, expectedStatus);
}
private JSONObject getPost(NodeRef nodeRef, int expectedStatus) throws Exception
{
return doGetPost(getPostUrl(nodeRef), expectedStatus);
}
private JSONObject doGetPost(String url, int expectedStatus) throws Exception
{
Response response = sendRequest(new GetRequest(url), expectedStatus);
@@ -310,10 +316,12 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doGetReplies(getRepliesUrl(name), expectedStatus);
}
private JSONObject getReplies(NodeRef nodeRef, int expectedStatus) throws Exception
{
return doGetReplies(getRepliesUrl(nodeRef), expectedStatus);
}
private JSONObject doGetReplies(String url, int expectedStatus) throws Exception
{
Response response = sendRequest(new GetRequest(url), expectedStatus);
@@ -332,30 +340,32 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doGetPosts(URL_FORUM_SITE_POSTS, type, expectedStatus);
}
private JSONObject getPosts(NodeRef nodeRef, String type, int expectedStatus) throws Exception
{
return doGetPosts(getPostsUrl(nodeRef), type, expectedStatus);
}
private JSONObject doGetPosts(String baseUrl, String type, int expectedStatus) throws Exception
{
String url = null;
if(type == null)
if (type == null)
{
url = baseUrl;
}
else if(type == "limit")
else if (type == "limit")
{
url = baseUrl + "?pageSize=1";
}
else if(type == "hot")
else if (type == "hot")
{
url = baseUrl + "/hot";
}
else if(type == "mine")
else if (type == "mine")
{
url = baseUrl + "/myposts";
}
else if(type.startsWith("new"))
else if (type.startsWith("new"))
{
url = baseUrl + "/" + type;
}
@@ -380,10 +390,12 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return doDeletePost(URL_FORUM_SITE_POST + name, expectedStatus);
}
private JSONObject deletePost(NodeRef nodeRef, int expectedStatus) throws Exception
{
return doDeletePost(getPostUrl(nodeRef), expectedStatus);
}
private JSONObject doDeletePost(String url, int expectedStatus) throws Exception
{
Response response = sendRequest(new DeleteRequest(url), Status.STATUS_OK);
@@ -401,6 +413,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return getPostUrl(nodeRef) + "/replies";
}
private String getRepliesUrl(String postName)
{
return URL_FORUM_SITE_POST + postName + "/replies";
@@ -410,6 +423,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
{
return URL_FORUM_NODE_POST_BASE + nodeRef.toString().replace("://", "/");
}
private String getPostsUrl(NodeRef nodeRef)
{
return URL_FORUM_NODE_POSTS_BASE + nodeRef.toString().replace("://", "/") + "/posts";
@@ -491,30 +505,30 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
public void testCreateForumPost() throws Exception
{
String title = "test";
String content = "test";
JSONObject item = createSitePost(title, content, Status.STATUS_OK);
// Check that the values in the response are correct
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(0, item.get("replyCount"));
assertEquals("Invalid JSON " + item, true, item.has("createdOn"));
assertEquals("Invalid JSON " + item, true, item.has("modifiedOn"));
assertEquals("Invalid JSON " + item, true, item.has("author"));
assertEquals("Invalid JSON " + item, true, item.has("permissions"));
assertEquals("Invalid JSON " + item, true, item.has("url"));
assertEquals("Invalid JSON " + item, true, item.has("repliesUrl"));
assertEquals("Invalid JSON " + item, true, item.has("nodeRef"));
// Save some details
String name = item.getString("name");
NodeRef nodeRef = new NodeRef(item.getString("nodeRef"));
String title = "test";
String content = "test";
JSONObject item = createSitePost(title, content, Status.STATUS_OK);
// Check that the values in the response are correct
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(0, item.get("replyCount"));
assertEquals("Invalid JSON " + item, true, item.has("createdOn"));
assertEquals("Invalid JSON " + item, true, item.has("modifiedOn"));
assertEquals("Invalid JSON " + item, true, item.has("author"));
assertEquals("Invalid JSON " + item, true, item.has("permissions"));
assertEquals("Invalid JSON " + item, true, item.has("url"));
assertEquals("Invalid JSON " + item, true, item.has("repliesUrl"));
assertEquals("Invalid JSON " + item, true, item.has("nodeRef"));
// Save some details
String name = item.getString("name");
NodeRef nodeRef = new NodeRef(item.getString("nodeRef"));
// Fetch the post by name and check
item = getPost(name, Status.STATUS_OK);
item = getPost(name, Status.STATUS_OK);
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(0, item.get("replyCount"));
@@ -525,9 +539,9 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
assertEquals("Invalid JSON " + item, true, item.has("url"));
assertEquals("Invalid JSON " + item, true, item.has("repliesUrl"));
assertEquals("Invalid JSON " + item, true, item.has("nodeRef"));
// Fetch the post by noderef and check
// Fetch the post by noderef and check
item = getPost(nodeRef, Status.STATUS_OK);
assertEquals(title, item.get("title"));
@@ -540,9 +554,9 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
assertEquals("Invalid JSON " + item, true, item.has("url"));
assertEquals("Invalid JSON " + item, true, item.has("repliesUrl"));
assertEquals("Invalid JSON " + item, true, item.has("nodeRef"));
// Create another post, this time by noderef
// Create another post, this time by noderef
title = "By Node Title";
content = "By Node Content";
item = createNodePost(FORUM_NODE, title, content, Status.STATUS_OK);
@@ -562,73 +576,73 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
public void testUpdateForumPost() throws Exception
{
String title = "test";
String content = "test";
JSONObject item = createSitePost(title, content, 200);
// check that the values
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
assertEquals(true, item.has("name"));
String name = item.getString("name");
assertEquals(true, item.has("nodeRef"));
NodeRef nodeRef = new NodeRef(item.getString("nodeRef"));
// fetch the post by name
item = getPost(item.getString("name"), 200);
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
String title = "test";
String content = "test";
JSONObject item = createSitePost(title, content, 200);
// Fetch the post by noderef
item = getPost(nodeRef, 200);
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
// check that the values
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
assertEquals(true, item.has("name"));
String name = item.getString("name");
assertEquals(true, item.has("nodeRef"));
NodeRef nodeRef = new NodeRef(item.getString("nodeRef"));
// fetch the post by name
item = getPost(item.getString("name"), 200);
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
// Fetch the post by noderef
item = getPost(nodeRef, 200);
assertEquals(title, item.get("title"));
assertEquals(content, item.get("content"));
assertEquals(false, item.getBoolean("isUpdated"));
// Update it by name
String title2 = "updated test";
String content2 = "test updated";
item = updatePost(name, title2, content2, 200);
// Update it by name
String title2 = "updated test";
String content2 = "test updated";
item = updatePost(name, title2, content2, 200);
// Check the response
assertEquals(title2, item.get("title"));
assertEquals(content2, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Check the response
assertEquals(title2, item.get("title"));
assertEquals(content2, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Fetch and check
item = getPost(nodeRef, 200);
assertEquals(title2, item.get("title"));
assertEquals(content2, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Fetch and check
item = getPost(nodeRef, 200);
assertEquals(title2, item.get("title"));
assertEquals(content2, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Update it again, this time by noderef
String title3 = "updated 3 test";
String content3 = "test 3 updated";
item = updatePost(nodeRef, title3, content3, 200);
// Check that the values returned are correct
assertEquals(title3, item.get("title"));
assertEquals(content3, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Fetch and re-check
item = getPost(nodeRef, 200);
assertEquals(title3, item.get("title"));
assertEquals(content3, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Update it again, this time by noderef
String title3 = "updated 3 test";
String content3 = "test 3 updated";
item = updatePost(nodeRef, title3, content3, 200);
// Check that the values returned are correct
assertEquals(title3, item.get("title"));
assertEquals(content3, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
// Fetch and re-check
item = getPost(nodeRef, 200);
assertEquals(title3, item.get("title"));
assertEquals(content3, item.get("content"));
assertEquals(name, item.get("name"));
assertEquals(nodeRef.toString(), item.get("nodeRef"));
assertEquals(true, item.getBoolean("isUpdated"));
}
/**
@@ -687,57 +701,57 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
public void testAddReply() throws Exception
{
// Create a root post
JSONObject item = createSitePost("test", "test", Status.STATUS_OK);
String topicName = item.getString("name");
NodeRef topicNodeRef = new NodeRef(item.getString("nodeRef"));
// Add a reply
JSONObject reply = createReply(topicNodeRef, "test", "test", Status.STATUS_OK);
NodeRef replyNodeRef = new NodeRef(reply.getString("nodeRef"));
assertEquals("test", reply.getString("title"));
assertEquals("test", reply.getString("content"));
// Add a reply to the reply
JSONObject reply2 = createReply(replyNodeRef, "test2", "test2", 200);
NodeRef reply2NodeRef = new NodeRef(reply2.getString("nodeRef"));
assertEquals("test2", reply2.getString("title"));
assertEquals("test2", reply2.getString("content"));
// Check things were correctly setup. These should all be siblings
// of each other, with relations between the replies
assertEquals(ForumModel.TYPE_TOPIC, nodeService.getType(topicNodeRef));
assertEquals(ForumModel.TYPE_POST, nodeService.getType(replyNodeRef));
assertEquals(ForumModel.TYPE_POST, nodeService.getType(reply2NodeRef));
assertEquals(topicNodeRef, nodeService.getPrimaryParent(replyNodeRef).getParentRef());
assertEquals(topicNodeRef, nodeService.getPrimaryParent(reply2NodeRef).getParentRef());
// Create a root post
JSONObject item = createSitePost("test", "test", Status.STATUS_OK);
String topicName = item.getString("name");
NodeRef topicNodeRef = new NodeRef(item.getString("nodeRef"));
// Reply 2 should have an assoc to Reply 1
assertEquals(0, nodeService.getSourceAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(1, nodeService.getTargetAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(replyNodeRef, nodeService.getTargetAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).get(0).getTargetRef());
assertEquals(1, nodeService.getSourceAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(1, nodeService.getTargetAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(reply2NodeRef, nodeService.getSourceAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).get(0).getSourceRef());
// Add a reply
JSONObject reply = createReply(topicNodeRef, "test", "test", Status.STATUS_OK);
NodeRef replyNodeRef = new NodeRef(reply.getString("nodeRef"));
assertEquals("test", reply.getString("title"));
assertEquals("test", reply.getString("content"));
// Add a reply to the reply
JSONObject reply2 = createReply(replyNodeRef, "test2", "test2", 200);
NodeRef reply2NodeRef = new NodeRef(reply2.getString("nodeRef"));
assertEquals("test2", reply2.getString("title"));
assertEquals("test2", reply2.getString("content"));
// Check things were correctly setup. These should all be siblings
// of each other, with relations between the replies
assertEquals(ForumModel.TYPE_TOPIC, nodeService.getType(topicNodeRef));
assertEquals(ForumModel.TYPE_POST, nodeService.getType(replyNodeRef));
assertEquals(ForumModel.TYPE_POST, nodeService.getType(reply2NodeRef));
assertEquals(topicNodeRef, nodeService.getPrimaryParent(replyNodeRef).getParentRef());
assertEquals(topicNodeRef, nodeService.getPrimaryParent(reply2NodeRef).getParentRef());
// Reply 2 should have an assoc to Reply 1
assertEquals(0, nodeService.getSourceAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(1, nodeService.getTargetAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(replyNodeRef, nodeService.getTargetAssocs(reply2NodeRef, RegexQNamePattern.MATCH_ALL).get(0).getTargetRef());
// Fetch all replies for the post
JSONObject result = getReplies(topicNodeRef, Status.STATUS_OK);
// check the number of replies
assertEquals(1, result.getJSONArray("items").length());
// Check the replies by name too
result = getReplies(topicName, Status.STATUS_OK);
assertEquals(1, result.getJSONArray("items").length());
// Fetch the top level post again, and check the counts there
// That post should have one direct reply, and one reply to it's reply
item = getPost(topicName, Status.STATUS_OK);
assertEquals(2, item.getInt("totalReplyCount"));
assertEquals(1, item.getInt("replyCount"));
assertEquals(1, nodeService.getSourceAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(1, nodeService.getTargetAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).size());
assertEquals(reply2NodeRef, nodeService.getSourceAssocs(replyNodeRef, RegexQNamePattern.MATCH_ALL).get(0).getSourceRef());
// Fetch all replies for the post
JSONObject result = getReplies(topicNodeRef, Status.STATUS_OK);
// check the number of replies
assertEquals(1, result.getJSONArray("items").length());
// Check the replies by name too
result = getReplies(topicName, Status.STATUS_OK);
assertEquals(1, result.getJSONArray("items").length());
// Fetch the top level post again, and check the counts there
// That post should have one direct reply, and one reply to it's reply
item = getPost(topicName, Status.STATUS_OK);
assertEquals(2, item.getInt("totalReplyCount"));
assertEquals(1, item.getInt("replyCount"));
}
public void testUpdateReply() throws Exception

View File

@@ -51,11 +51,11 @@ public class ForumPostDelete extends AbstractDiscussionWebScript
// Are we deleting a topic, or a post in it?
String message = null;
if(post != null)
if (post != null)
{
message = doDeletePost(topic, post);
}
else if(topic != null)
else if (topic != null)
{
message = doDeleteTopic(topic, site, req, json);
}
@@ -78,7 +78,7 @@ public class ForumPostDelete extends AbstractDiscussionWebScript
discussionService.deleteTopic(topic);
// Add an activity entry for this if it's site based
if(site != null)
if (site != null)
{
addActivityEntry("post", "deleted", topic, null, site, req, json);
}

View File

@@ -47,11 +47,11 @@ public class ForumPostGet extends AbstractDiscussionWebScript
Map<String, Object> model = buildCommonModel(site, topic, post, req);
// Did they want just one post, or the whole of the topic?
if(post != null)
if (post != null)
{
model.put(KEY_POSTDATA, renderPost(post, site));
}
else if(topic != null)
else if (topic != null)
{
model.put(KEY_POSTDATA, renderTopic(topic, site));
}

View File

@@ -48,7 +48,7 @@ public class ForumPostPut extends AbstractDiscussionWebScript
Map<String, Object> model = buildCommonModel(site, topic, post, req);
// Did they want to change a reply or the whole topic?
if(post != null)
if (post != null)
{
// Update the specified post
doUpdatePost(post, post.getTopic(), req, json);
@@ -59,11 +59,11 @@ public class ForumPostPut extends AbstractDiscussionWebScript
// Build the JSON for just this post
model.put(KEY_POSTDATA, renderPost(post, site));
}
else if(topic != null)
else if (topic != null)
{
// Update the primary post of the topic
post = discussionService.getPrimaryPost(topic);
if(post == null)
if (post == null)
{
throw new WebScriptException(Status.STATUS_PRECONDITION_FAILED,
"First (primary) post was missing from the topic, can't fetch");
@@ -92,29 +92,29 @@ public class ForumPostPut extends AbstractDiscussionWebScript
// Fetch the details from the JSON
// Update the titles on the post and it's topic
if(json.containsKey("title"))
if (json.containsKey("title"))
{
String title = (String)json.get("title");
post.setTitle(title);
if(title.length() > 0)
if (title.length() > 0)
{
topic.setTitle(title);
}
}
// Contents is on the post
if(json.containsKey("content"))
if (json.containsKey("content"))
{
post.setContents((String)json.get("content"));
}
// Tags are on the topic
if(json.containsKey("tags"))
if (json.containsKey("tags"))
{
topic.getTags().clear();
List<String> tags = getTags(json);
if(tags != null)
if (tags != null)
{
topic.getTags().addAll(tags);
}

View File

@@ -49,13 +49,13 @@ public class ForumPostRepliesGet extends AbstractDiscussionWebScript
// How many levels did they want?
int levels = 1;
String levelsS = req.getParameter("levels");
if(levelsS != null)
if (levelsS != null)
{
try
{
levels = Integer.parseInt(levelsS);
}
catch(NumberFormatException e)
catch (NumberFormatException e)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Level depth parameter invalid");
}
@@ -63,11 +63,11 @@ public class ForumPostRepliesGet extends AbstractDiscussionWebScript
// Fetch the replies
PostWithReplies replies;
if(post != null)
if (post != null)
{
replies = discussionService.listPostReplies(post, levels);
}
else if(topic != null)
else if (topic != null)
{
replies = discussionService.listPostReplies(topic, levels);
}
@@ -93,7 +93,7 @@ public class ForumPostRepliesGet extends AbstractDiscussionWebScript
reply.put("childCount", replies.getReplies().size());
List<Map<String,Object>> r = new ArrayList<Map<String,Object>>();
for(PostWithReplies child : replies.getReplies())
for (PostWithReplies child : replies.getReplies())
{
r.add(renderReplies(child, site));
}

View File

@@ -46,16 +46,16 @@ public class ForumPostRepliesPost extends AbstractDiscussionWebScript
{
// If they're trying to create a reply to a topic, they actually
// mean to create the reply on the primary post
if(post == null)
if (post == null)
{
post = discussionService.getPrimaryPost(topic);
if(post == null)
if (post == null)
{
throw new WebScriptException(Status.STATUS_PRECONDITION_FAILED,
"First (primary) post was missing from the topic, can't fetch");
}
}
else if(topic == null)
else if (topic == null)
{
String error = "Node was of the wrong type, only Topic and Post are supported";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -82,13 +82,13 @@ public class ForumPostRepliesPost extends AbstractDiscussionWebScript
{
// Fetch the details from the JSON
String title = null;
if(json.containsKey("title"))
if (json.containsKey("title"))
{
title = (String)json.get("title");
}
String contents = null;
if(json.containsKey("content"))
if (json.containsKey("content"))
{
contents = (String)json.get("content");
}
@@ -98,7 +98,7 @@ public class ForumPostRepliesPost extends AbstractDiscussionWebScript
PostInfo reply = discussionService.createReply(post, contents);
// Set the title if needed (it normally isn't)
if(title != null && title.length() > 0)
if (title != null && title.length() > 0)
{
nodeService.setProperty(reply.getNodeRef(), ContentModel.PROP_TITLE, title);
reply = discussionService.getPost(topic, reply.getSystemName());

View File

@@ -45,7 +45,7 @@ public class ForumTopicPost extends AbstractDiscussionWebScript
Status status, Cache cache)
{
// They shouldn't be adding to an existing Post or Topic
if(topic != null || post != null)
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);
@@ -55,11 +55,11 @@ public class ForumTopicPost extends AbstractDiscussionWebScript
// Grab the details of the new Topic and Post
String title = "";
String contents = "";
if(json.containsKey("title"))
if (json.containsKey("title"))
{
title = (String)json.get("title");
}
if(json.containsKey("content"))
if (json.containsKey("content"))
{
contents = (String)json.get("content");
}
@@ -67,7 +67,7 @@ public class ForumTopicPost extends AbstractDiscussionWebScript
// Have the topic created
if(site != null)
if (site != null)
{
topic = discussionService.createTopic(site.getShortName(), title);
}
@@ -75,7 +75,7 @@ public class ForumTopicPost extends AbstractDiscussionWebScript
{
topic = discussionService.createTopic(nodeRef, title);
}
if(tags != null && tags.size() > 0)
if (tags != null && tags.size() > 0)
{
topic.getTags().clear();
topic.getTags().addAll(tags);

View File

@@ -46,7 +46,7 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if(topic != null || post != null)
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -55,7 +55,7 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
// Do we need to list or search?
boolean tagSearch = false;
String tag = req.getParameter("tag");
if(tag != null && tag.length() > 0)
if (tag != null && tag.length() > 0)
{
tagSearch = true;
}
@@ -64,10 +64,10 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
boolean oldestTopicsFirst = true;
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(tagSearch)
if (tagSearch)
{
// Tag based is a search rather than a listing
if(site != null)
if (site != null)
{
topics = discussionService.findTopics(site.getShortName(), null, tag, oldestTopicsFirst, paging);
}
@@ -78,7 +78,7 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
}
else
{
if(site != null)
if (site != null)
{
topics = discussionService.listTopics(site.getShortName(), oldestTopicsFirst, paging);
}
@@ -91,7 +91,7 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if(site != null && nodeRef == null)
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}

View File

@@ -53,7 +53,7 @@ public class ForumTopicsHotGet extends AbstractDiscussionWebScript
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if(topic != null || post != null)
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -62,7 +62,7 @@ public class ForumTopicsHotGet extends AbstractDiscussionWebScript
// Grab the date range to search over
String numDaysS = req.getParameter("numdays");
int numDays = RECENT_POSTS_PERIOD_DAYS;
if(numDaysS != null)
if (numDaysS != null)
{
numDays = Integer.parseInt(numDaysS);
}
@@ -73,7 +73,7 @@ public class ForumTopicsHotGet extends AbstractDiscussionWebScript
// Get the topics with recent replies
PagingResults<Pair<TopicInfo,Integer>> topicsAndCounts = null;
PagingRequest paging = buildPagingRequest(req);
if(site != null)
if (site != null)
{
topicsAndCounts = discussionService.listHotTopics(site.getShortName(), since, paging);
}
@@ -84,7 +84,7 @@ public class ForumTopicsHotGet extends AbstractDiscussionWebScript
// For this, we actually only need the topics, not their counts too
List<TopicInfo> topics = new ArrayList<TopicInfo>();
for(Pair<TopicInfo,Integer> tc : topicsAndCounts.getPage())
for (Pair<TopicInfo,Integer> tc : topicsAndCounts.getPage())
{
topics.add(tc.getFirst());
}
@@ -92,7 +92,7 @@ public class ForumTopicsHotGet extends AbstractDiscussionWebScript
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if(site != null && nodeRef == null)
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}

View File

@@ -47,7 +47,7 @@ public class ForumTopicsMineGet extends AbstractDiscussionWebScript
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if(topic != null || post != null)
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -59,7 +59,7 @@ public class ForumTopicsMineGet extends AbstractDiscussionWebScript
// Get the topics for the user, oldest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(site != null)
if (site != null)
{
topics = discussionService.listTopics(site.getShortName(), username, true, paging);
}
@@ -71,7 +71,7 @@ public class ForumTopicsMineGet extends AbstractDiscussionWebScript
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if(site != null && nodeRef == null)
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}

View File

@@ -50,7 +50,7 @@ public class ForumTopicsRecentGet extends AbstractDiscussionWebScript
Status status, Cache cache)
{
// They shouldn't be trying to list of an existing Post or Topic
if(topic != null || post != null)
if (topic != null || post != null)
{
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
@@ -59,7 +59,7 @@ public class ForumTopicsRecentGet extends AbstractDiscussionWebScript
// Grab the date range to search over
String numDaysS = req.getParameter("numdays");
int numDays = RECENT_SEARCH_PERIOD_DAYS;
if(numDaysS != null)
if (numDaysS != null)
{
numDays = Integer.parseInt(numDaysS);
}
@@ -71,7 +71,7 @@ public class ForumTopicsRecentGet extends AbstractDiscussionWebScript
// Get the recent topics, newest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(site != null)
if (site != null)
{
topics = discussionService.listTopics(site.getShortName(), from, to, false, paging);
}
@@ -83,7 +83,7 @@ public class ForumTopicsRecentGet extends AbstractDiscussionWebScript
// If they did a site based search, and the component hasn't
// been created yet, use the site for the permissions checking
if(site != null && nodeRef == null)
if (site != null && nodeRef == null)
{
nodeRef = site.getNodeRef();
}