diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java b/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java index 27e3ff4209..dbc126154b 100644 --- a/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/blogs/BlogServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -18,7 +18,6 @@ */ package org.alfresco.repo.web.scripts.blogs; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -54,9 +53,9 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; */ public class BlogServiceTest extends BaseWebScriptTest { - @SuppressWarnings("unused") + @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(BlogServiceTest.class); - + private MutableAuthenticationService authenticationService; private AuthenticationComponent authenticationComponent; private PersonService personService; @@ -163,20 +162,20 @@ public class BlogServiceTest extends BaseWebScriptTest JSONObject post = new JSONObject(); if (title != null) { - post.put("title", title); + post.put("title", title); } if (content != null) { - post.put("content", content); + post.put("content", content); } if (tags != null) { - JSONArray arr = new JSONArray(); - for(String s : tags) - { - arr.put(s); - } - post.put("tags", arr); + JSONArray arr = new JSONArray(); + for (String s : tags) + { + arr.put(s); + } + post.put("tags", arr); } post.put("draft", isDraft); return post; @@ -186,65 +185,65 @@ public class BlogServiceTest extends BaseWebScriptTest throws Exception { JSONObject post = getRequestObject(title, content, tags, isDraft); - Response response = sendRequest(new PostRequest(URL_BLOG_POSTS, post.toString(), "application/json"), expectedStatus); - - if (expectedStatus != 200) - { - return null; - } - - //logger.debug(response.getContentAsString()); - JSONObject result = new JSONObject(response.getContentAsString()); - JSONObject item = result.getJSONObject("item"); - if (isDraft) - { - this.drafts.add(item.getString("name")); - } - else - { - this.posts.add(item.getString("name")); - } - return item; + Response response = sendRequest(new PostRequest(URL_BLOG_POSTS, post.toString(), "application/json"), expectedStatus); + + if (expectedStatus != 200) + { + return null; + } + + //logger.debug(response.getContentAsString()); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject item = result.getJSONObject("item"); + if (isDraft) + { + this.drafts.add(item.getString("name")); + } + else + { + this.posts.add(item.getString("name")); + } + return item; } private JSONObject updatePost(String name, String title, String content, String[] tags, boolean isDraft, int expectedStatus) throws Exception { - JSONObject post = getRequestObject(title, content, tags, isDraft); - Response response = sendRequest(new PutRequest(URL_BLOG_POST + name, post.toString(), "application/json"), expectedStatus); - - if (expectedStatus != 200) - { - return null; - } + JSONObject post = getRequestObject(title, content, tags, isDraft); + Response response = sendRequest(new PutRequest(URL_BLOG_POST + name, post.toString(), "application/json"), expectedStatus); + + if (expectedStatus != 200) + { + return null; + } - JSONObject result = new JSONObject(response.getContentAsString()); - return result.getJSONObject("item"); + JSONObject result = new JSONObject(response.getContentAsString()); + return result.getJSONObject("item"); } private JSONObject getPost(String name, int expectedStatus) throws Exception { - Response response = sendRequest(new GetRequest(URL_BLOG_POST + name), expectedStatus); - if (expectedStatus == 200) - { - JSONObject result = new JSONObject(response.getContentAsString()); - return result.getJSONObject("item"); - } - else - { - return null; - } + Response response = sendRequest(new GetRequest(URL_BLOG_POST + name), expectedStatus); + if (expectedStatus == 200) + { + JSONObject result = new JSONObject(response.getContentAsString()); + return result.getJSONObject("item"); + } + else + { + return null; + } } private String getCommentsUrl(String nodeRef) { - return "/api/node/" + nodeRef.replace("://", "/") + "/comments"; + return "/api/node/" + nodeRef.replace("://", "/") + "/comments"; } private String getCommentUrl(String nodeRef) { - return "/api/comment/node/" + nodeRef.replace("://", "/"); + return "/api/comment/node/" + nodeRef.replace("://", "/"); } private JSONObject createComment(String nodeRef, String title, String content, int expectedStatus) @@ -253,34 +252,34 @@ public class BlogServiceTest extends BaseWebScriptTest JSONObject comment = new JSONObject(); comment.put("title", title); comment.put("content", content); - Response response = sendRequest(new PostRequest(getCommentsUrl(nodeRef), comment.toString(), "application/json"), expectedStatus); - - if (expectedStatus != 200) - { - return null; - } - - //logger.debug("Comment created: " + response.getContentAsString()); - JSONObject result = new JSONObject(response.getContentAsString()); - return result.getJSONObject("item"); + Response response = sendRequest(new PostRequest(getCommentsUrl(nodeRef), comment.toString(), "application/json"), expectedStatus); + + if (expectedStatus != 200) + { + return null; + } + + //logger.debug("Comment created: " + response.getContentAsString()); + JSONObject result = new JSONObject(response.getContentAsString()); + return result.getJSONObject("item"); } private JSONObject updateComment(String nodeRef, String title, String content, int expectedStatus) throws Exception { - JSONObject comment = new JSONObject(); + JSONObject comment = new JSONObject(); comment.put("title", title); comment.put("content", content); - Response response = sendRequest(new PutRequest(getCommentUrl(nodeRef), comment.toString(), "application/json"), expectedStatus); - - if (expectedStatus != 200) - { - return null; - } - - //logger.debug("Comment updated: " + response.getContentAsString()); - JSONObject result = new JSONObject(response.getContentAsString()); - return result.getJSONObject("item"); + Response response = sendRequest(new PutRequest(getCommentUrl(nodeRef), comment.toString(), "application/json"), expectedStatus); + + if (expectedStatus != 200) + { + return null; + } + + //logger.debug("Comment updated: " + response.getContentAsString()); + JSONObject result = new JSONObject(response.getContentAsString()); + return result.getJSONObject("item"); } @@ -383,22 +382,22 @@ public class BlogServiceTest extends BaseWebScriptTest public void testCreatePublishedPost() throws Exception { - String title = "published"; - String content = "content"; - - JSONObject item = createPost(title, content, null, false, 200); + String title = "published"; + String content = "content"; + + JSONObject item = createPost(title, content, null, false, 200); final String postName = item.getString("name"); - - // check the values - assertEquals(title, item.get("title")); - assertEquals(content, item.get("content")); - assertEquals(false, item.get("isDraft")); - - // check that user two has access to it as well - this.authenticationComponent.setCurrentUser(USER_TWO); - getPost(item.getString("name"), 200); - this.authenticationComponent.setCurrentUser(USER_ONE); - + + // check the values + assertEquals(title, item.get("title")); + assertEquals(content, item.get("content")); + assertEquals(false, item.get("isDraft")); + + // check that user two has access to it as well + this.authenticationComponent.setCurrentUser(USER_TWO); + getPost(item.getString("name"), 200); + this.authenticationComponent.setCurrentUser(USER_ONE); + // Now we'll GET my-published to ensure that the post is there. Response response = sendRequest(new GetRequest(URL_MY_PUBLISHED_BLOG_POSTS), 200); JSONObject result = new JSONObject(response.getContentAsString()); @@ -413,159 +412,159 @@ public class BlogServiceTest extends BaseWebScriptTest public void testCreateEmptyPost() throws Exception { - JSONObject item = createPost(null, null, null, false, 200); - - // check the values - assertEquals("", item.get("title")); - assertEquals("", item.get("content")); - assertEquals(false, item.get("isDraft")); - - // check that user two has access to it as well - this.authenticationComponent.setCurrentUser(USER_TWO); - getPost(item.getString("name"), 200); - this.authenticationComponent.setCurrentUser(USER_ONE); + JSONObject item = createPost(null, null, null, false, 200); + + // check the values + assertEquals("", item.get("title")); + assertEquals("", item.get("content")); + assertEquals(false, item.get("isDraft")); + + // check that user two has access to it as well + this.authenticationComponent.setCurrentUser(USER_TWO); + getPost(item.getString("name"), 200); + this.authenticationComponent.setCurrentUser(USER_ONE); } public void testUpdated() throws Exception { - JSONObject item = createPost("test", "test", null, false, 200); - String name = item.getString("name"); - assertEquals(false, item.getBoolean("isUpdated")); - - item = updatePost(name, "new title", "new content", null, false, 200); - assertEquals(true, item.getBoolean("isUpdated")); - assertEquals("new title", item.getString("title")); - assertEquals("new content", item.getString("content")); + JSONObject item = createPost("test", "test", null, false, 200); + String name = item.getString("name"); + assertEquals(false, item.getBoolean("isUpdated")); + + item = updatePost(name, "new title", "new content", null, false, 200); + assertEquals(true, item.getBoolean("isUpdated")); + assertEquals("new title", item.getString("title")); + assertEquals("new content", item.getString("content")); } public void testUpdateWithEmptyValues() throws Exception { - JSONObject item = createPost("test", "test", null, false, 200); - String name = item.getString("name"); - assertEquals(false, item.getBoolean("isUpdated")); - - item = updatePost(item.getString("name"), null, null, null, false, 200); - assertEquals("", item.getString("title")); - assertEquals("", item.getString("content")); + JSONObject item = createPost("test", "test", null, false, 200); + String name = item.getString("name"); + assertEquals(false, item.getBoolean("isUpdated")); + + item = updatePost(item.getString("name"), null, null, null, false, 200); + assertEquals("", item.getString("title")); + assertEquals("", item.getString("content")); } public void testPublishThroughUpdate() throws Exception { - JSONObject item = createPost("test", "test", null, true, 200); - String name = item.getString("name"); - assertEquals(true, item.getBoolean("isDraft")); - - // check that user two does not have access - this.authenticationComponent.setCurrentUser(USER_TWO); - getPost(name, 404); - this.authenticationComponent.setCurrentUser(USER_ONE); - - item = updatePost(name, "new title", "new content", null, false, 200); - assertEquals("new title", item.getString("title")); - assertEquals("new content", item.getString("content")); - assertEquals(false, item.getBoolean("isDraft")); - - // check that user two does have access - this.authenticationComponent.setCurrentUser(USER_TWO); - getPost(name, 200); - this.authenticationComponent.setCurrentUser(USER_ONE); + JSONObject item = createPost("test", "test", null, true, 200); + String name = item.getString("name"); + assertEquals(true, item.getBoolean("isDraft")); + + // check that user two does not have access + this.authenticationComponent.setCurrentUser(USER_TWO); + getPost(name, 404); + this.authenticationComponent.setCurrentUser(USER_ONE); + + item = updatePost(name, "new title", "new content", null, false, 200); + assertEquals("new title", item.getString("title")); + assertEquals("new content", item.getString("content")); + assertEquals(false, item.getBoolean("isDraft")); + + // check that user two does have access + this.authenticationComponent.setCurrentUser(USER_TWO); + getPost(name, 200); + this.authenticationComponent.setCurrentUser(USER_ONE); } public void testCannotDoUnpublish() throws Exception { - JSONObject item = createPost("test", "test", null, false, 200); - String name = item.getString("name"); - assertEquals(false, item.getBoolean("isDraft")); - - item = updatePost(name, "new title", "new content", null, true, 400); // should return bad request + JSONObject item = createPost("test", "test", null, false, 200); + String name = item.getString("name"); + assertEquals(false, item.getBoolean("isDraft")); + + item = updatePost(name, "new title", "new content", null, true, 400); // should return bad request } public void testGetAll() throws Exception { - String url = URL_BLOG_POSTS; - Response response = sendRequest(new GetRequest(url), 200); - JSONObject result = new JSONObject(response.getContentAsString()); - - // we should have posts.size + drafts.size together - assertEquals(this.posts.size() + this.drafts.size(), result.getInt("total")); + String url = URL_BLOG_POSTS; + Response response = sendRequest(new GetRequest(url), 200); + JSONObject result = new JSONObject(response.getContentAsString()); + + // we should have posts.size + drafts.size together + assertEquals(this.posts.size() + this.drafts.size(), result.getInt("total")); } public void testGetNew() throws Exception { - String url = URL_BLOG_POSTS + "/new"; - Response response = sendRequest(new GetRequest(url), 200); - JSONObject result = new JSONObject(response.getContentAsString()); - - // we should have posts.size - assertEquals(this.posts.size(), result.getInt("total")); + String url = URL_BLOG_POSTS + "/new"; + Response response = sendRequest(new GetRequest(url), 200); + JSONObject result = new JSONObject(response.getContentAsString()); + + // we should have posts.size + assertEquals(this.posts.size(), result.getInt("total")); } public void testGetDrafts() throws Exception { - String url = URL_BLOG_POSTS + "/mydrafts"; - Response response = sendRequest(new GetRequest(URL_BLOG_POSTS), 200); - JSONObject result = new JSONObject(response.getContentAsString()); - - // we should have drafts.size resultss - assertEquals(this.drafts.size(), result.getInt("total")); - - // the second user should have zero - this.authenticationComponent.setCurrentUser(USER_TWO); - response = sendRequest(new GetRequest(url), 200); - result = new JSONObject(response.getContentAsString()); - assertEquals(0, result.getInt("total")); - this.authenticationComponent.setCurrentUser(USER_ONE); - + String url = URL_BLOG_POSTS + "/mydrafts"; + Response response = sendRequest(new GetRequest(URL_BLOG_POSTS), 200); + JSONObject result = new JSONObject(response.getContentAsString()); + + // we should have drafts.size resultss + assertEquals(this.drafts.size(), result.getInt("total")); + + // the second user should have zero + this.authenticationComponent.setCurrentUser(USER_TWO); + response = sendRequest(new GetRequest(url), 200); + result = new JSONObject(response.getContentAsString()); + assertEquals(0, result.getInt("total")); + this.authenticationComponent.setCurrentUser(USER_ONE); + } public void testMyPublished() throws Exception { - String url = URL_BLOG_POSTS + "/mypublished"; - Response response = sendRequest(new GetRequest(url), 200); - JSONObject result = new JSONObject(response.getContentAsString()); - - // we should have posts.size results - assertEquals(this.drafts.size(), result.getInt("total")); - - // the second user should have zero - this.authenticationComponent.setCurrentUser(USER_TWO); - response = sendRequest(new GetRequest(url), 200); - result = new JSONObject(response.getContentAsString()); - assertEquals(0, result.getInt("total")); - this.authenticationComponent.setCurrentUser(USER_ONE); + String url = URL_BLOG_POSTS + "/mypublished"; + Response response = sendRequest(new GetRequest(url), 200); + JSONObject result = new JSONObject(response.getContentAsString()); + + // we should have posts.size results + assertEquals(this.drafts.size(), result.getInt("total")); + + // the second user should have zero + this.authenticationComponent.setCurrentUser(USER_TWO); + response = sendRequest(new GetRequest(url), 200); + result = new JSONObject(response.getContentAsString()); + assertEquals(0, result.getInt("total")); + this.authenticationComponent.setCurrentUser(USER_ONE); } public void testComments() throws Exception { - JSONObject item = createPost("test", "test", null, false, 200); - String name = item.getString("name"); - String nodeRef = item.getString("nodeRef"); - - JSONObject commentOne = createComment(nodeRef, "comment", "content", 200); - JSONObject commentTwo = createComment(nodeRef, "comment", "content", 200); - - // fetch the comments - Response response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); - JSONObject result = new JSONObject(response.getContentAsString()); - assertEquals(2, result.getInt("total")); - - // add another one - JSONObject commentThree = createComment(nodeRef, "comment", "content", 200); - - response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); - result = new JSONObject(response.getContentAsString()); - assertEquals(3, result.getInt("total")); - - // delete the last comment - response = sendRequest(new DeleteRequest(getCommentUrl(commentThree.getString("nodeRef"))), 200); - - response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); - result = new JSONObject(response.getContentAsString()); - assertEquals(2, result.getInt("total")); - - JSONObject commentTwoUpdated = updateComment(commentTwo.getString("nodeRef"), "new title", "new content", 200); - assertEquals("new title", commentTwoUpdated.getString("title")); - assertEquals("new content", commentTwoUpdated.getString("content")); + JSONObject item = createPost("test", "test", null, false, 200); + String name = item.getString("name"); + String nodeRef = item.getString("nodeRef"); + + JSONObject commentOne = createComment(nodeRef, "comment", "content", 200); + JSONObject commentTwo = createComment(nodeRef, "comment", "content", 200); + + // fetch the comments + Response response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); + JSONObject result = new JSONObject(response.getContentAsString()); + assertEquals(2, result.getInt("total")); + + // add another one + JSONObject commentThree = createComment(nodeRef, "comment", "content", 200); + + response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); + result = new JSONObject(response.getContentAsString()); + assertEquals(3, result.getInt("total")); + + // delete the last comment + response = sendRequest(new DeleteRequest(getCommentUrl(commentThree.getString("nodeRef"))), 200); + + response = sendRequest(new GetRequest(getCommentsUrl(nodeRef)), 200); + result = new JSONObject(response.getContentAsString()); + assertEquals(2, result.getInt("total")); + + JSONObject commentTwoUpdated = updateComment(commentTwo.getString("nodeRef"), "new title", "new content", 200); + assertEquals("new title", commentTwoUpdated.getString("title")); + assertEquals("new content", commentTwoUpdated.getString("content")); } /** @@ -577,91 +576,93 @@ public class BlogServiceTest extends BaseWebScriptTest * * 2. JSONException, but with root cause being * get(assocs) failed on instance of org.alfresco.repo.template.TemplateNode - * The problematic instruction: + * The problematic instruction: * ---------- - * ==> if person.assocs["cm:avatar"]?? [on line 4, column 7 in org/alfresco/repository/blogs/blogpost.lib.ftl] - * + * ==> if person.assocs["cm:avatar"]?? [on line 4, column 7 in org/alfresco/repository/blogs/blogpost.lib.ftl] + * * @throws Exception */ public void _testTagsStressTest() throws Exception { - final List exceptions = Collections.synchronizedList(new ArrayList()); - List threads = new ArrayList(); - + final List exceptions = Collections.synchronizedList(new ArrayList()); + List threads = new ArrayList(); + System.err.println("Creating and starting threads..."); - for (int x=0; x < 3; x++) - { - Thread t = new Thread(new Runnable() { - public void run() { - // set the correct user - authenticationComponent.setCurrentUser(USER_ONE); - - // now do some requests - try { - for (int y=0; y < 3; y++) - { - off_testPostTags(); - off_testClearTags(); - - } - System.err.println("------------- SUCCEEDED ---------------"); - } catch (Exception e) - { - System.err.println("------------- ERROR ---------------"); - exceptions.add(e); - e.printStackTrace(); - return; - } - }} - ); - threads.add(t); - t.start(); - } - /*for (Thread t : threads) - { - t.start(); - }*/ - - for (Thread t : threads) - { - t.join(); - } - - System.err.println("------------- STACK TRACES ---------------"); - for (Exception e : exceptions) - { - e.printStackTrace(); - } - System.err.println("------------- STACK TRACES END ---------------"); - if (exceptions.size() > 0) - { - throw exceptions.get(0); - } + for (int x=0; x < 3; x++) + { + Thread t = new Thread(new Runnable() + { + public void run() + { + // set the correct user + authenticationComponent.setCurrentUser(USER_ONE); + + // now do some requests + try + { + for (int y=0; y < 3; y++) + { + off_testPostTags(); + off_testClearTags(); + } + System.err.println("------------- SUCCEEDED ---------------"); + } catch (Exception e) + { + System.err.println("------------- ERROR ---------------"); + exceptions.add(e); + e.printStackTrace(); + return; + } + }}); + + threads.add(t); + t.start(); + } + /*for (Thread t : threads) + { + t.start(); + }*/ + + for (Thread t : threads) + { + t.join(); + } + + System.err.println("------------- STACK TRACES ---------------"); + for (Exception e : exceptions) + { + e.printStackTrace(); + } + System.err.println("------------- STACK TRACES END ---------------"); + if (exceptions.size() > 0) + { + throw exceptions.get(0); + } } public void off_testPostTags() throws Exception { - String[] tags = { "first", "test" }; - JSONObject item = createPost("tagtest", "tagtest", tags, false, 200); - assertEquals(2, item.getJSONArray("tags").length()); - assertEquals("first", item.getJSONArray("tags").get(0)); - assertEquals("test", item.getJSONArray("tags").get(1)); - - item = updatePost(item.getString("name"), null, null, new String[] { "First", "Test", "Second" }, false, 200); - assertEquals(3, item.getJSONArray("tags").length()); - assertEquals("first", item.getJSONArray("tags").get(0)); - assertEquals("test", item.getJSONArray("tags").get(1)); - assertEquals("second", item.getJSONArray("tags").get(2)); + String[] tags = { "first", "test" }; + JSONObject item = createPost("tagtest", "tagtest", tags, false, 200); + assertEquals(2, item.getJSONArray("tags").length()); + assertEquals("first", item.getJSONArray("tags").get(0)); + assertEquals("test", item.getJSONArray("tags").get(1)); + + item = updatePost(item.getString("name"), null, null, new String[] { "First", "Test", "Second" }, false, 200); + assertEquals(3, item.getJSONArray("tags").length()); + assertEquals("first", item.getJSONArray("tags").get(0)); + assertEquals("test", item.getJSONArray("tags").get(1)); + assertEquals("second", item.getJSONArray("tags").get(2)); } public void off_testClearTags() throws Exception { - String[] tags = { "abc", "def"}; - JSONObject item = createPost("tagtest", "tagtest", tags, false, 200); - assertEquals(2, item.getJSONArray("tags").length()); - - item = updatePost(item.getString("name"), null, null, new String[0], false, 200); - assertEquals(0, item.getJSONArray("tags").length()); + String[] tags = { "abc", "def"}; + JSONObject item = createPost("tagtest", "tagtest", tags, false, 200); + assertEquals(2, item.getJSONArray("tags").length()); + + item = updatePost(item.getString("name"), null, null, new String[0], false, 200); + assertEquals(0, item.getJSONArray("tags").length()); } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java b/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java index 7287f6e342..c74b7e50de 100644 --- a/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java +++ b/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java @@ -29,14 +29,10 @@ import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator; import org.alfresco.repo.nodelocator.NodeLocatorService; import org.alfresco.repo.nodelocator.SitesHomeNodeLocator; import org.alfresco.repo.nodelocator.UserHomeNodeLocator; -import org.alfresco.repo.search.QueryParameterDefImpl; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.search.QueryParameterDefinition; import org.alfresco.service.cmr.site.SiteInfo; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogPut.java b/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogPut.java index 992cf1457a..c663221f3b 100644 --- a/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogPut.java +++ b/source/java/org/alfresco/repo/web/scripts/blogs/blog/BlogPut.java @@ -59,10 +59,12 @@ public class BlogPut extends AbstractBlogWebScript try { json = new JSONObject(new JSONTokener(req.getContent().getContent())); - } catch (JSONException jsonX) + } + catch (JSONException jsonX) { throw new AlfrescoRuntimeException("Could not parse JSON", jsonX); - } catch (IOException iox) + } + catch (IOException iox) { throw new AlfrescoRuntimeException("Could not parse JSON", iox); } diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java index af8d93a252..f4c07769c1 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java @@ -45,7 +45,6 @@ import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import org.json.JSONTokener; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; @@ -101,7 +100,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript protected Date parseDate(String date) { // Is there one at all? - if(date == null || date.length() == 0) + if (date == null || date.length() == 0) { return null; } @@ -111,7 +110,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { return ISO8601DateFormat.parse(date); } - catch(Exception e) {} + catch (Exception e) {} // Try YYYY/MM/DD SimpleDateFormat slashtime = new SimpleDateFormat("yyyy/MM/dd HH:mm"); @@ -120,12 +119,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { return slashtime.parse(date); } - catch(ParseException e) {} + catch (ParseException e) {} try { return slash.parse(date); } - catch(ParseException e) {} + catch (ParseException e) {} // Try YYYY-MM-DD SimpleDateFormat dashtime = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @@ -134,12 +133,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { return dashtime.parse(date); } - catch(ParseException e) {} + catch (ParseException e) {} try { return dash.parse(date); } - catch(ParseException e) {} + catch (ParseException e) {} // We don't know what it is, object throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid date '" + date + "'"); @@ -153,18 +152,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { boolean isAllDay = false; - if(json.containsKey("startAt") && json.containsKey("endAt")) + if (json.containsKey("startAt") && json.containsKey("endAt")) { // New style ISO8601 dates entry.setStart(parseDate((String)json.get("startAt"))); entry.setEnd(parseDate((String)json.get("endAt"))); - if(json.containsKey("allday")) + if (json.containsKey("allday")) { // TODO Handle All Day events properly, including timezones isAllDay = true; } } - else if(json.containsKey("allday")) + else if (json.containsKey("allday")) { // Old style all-day event entry.setStart(parseDate(getOrNull(json, "from"))); @@ -183,7 +182,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript protected String getOrNull(JSONObject json, String key) throws JSONException { - if(json.containsKey(key)) + if (json.containsKey(key)) { return (String)json.get(key); } @@ -238,14 +237,14 @@ public abstract class AbstractCalendarWebScript 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 = "calendar"; @@ -264,10 +263,9 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript "org.alfresco.calendar.event-" + event, site.getShortName(), CALENDAR_SERVICE_ACTIVITY_APP_NAME, - activityJson.toString() - ); + activityJson.toString()); } - catch(Exception e) + catch (Exception e) { // Warn, but carry on logger.warn("Error adding event " + event + " to activities feed", e); @@ -303,10 +301,10 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript Status status, Cache cache) { Map templateVars = req.getServiceMatch().getTemplateVars(); - if(templateVars == null) + if (templateVars == null) { String error = "No parameters supplied"; - if(useJSONErrors()) + if (useJSONErrors()) { return buildError(error); } @@ -320,22 +318,22 @@ public abstract class AbstractCalendarWebScript 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) { return buildError("Invalid JSON: " + io.getMessage()); } - catch(org.json.simple.parser.ParseException je) + catch (org.json.simple.parser.ParseException je) { return buildError("Invalid JSON: " + je.getMessage()); } @@ -344,29 +342,29 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript // Get the site short name. Try quite hard to do so... String siteName = templateVars.get("siteid"); - if(siteName == null) + if (siteName == null) { siteName = templateVars.get("site"); } - if(siteName == null) + if (siteName == null) { siteName = req.getParameter("site"); } - if(siteName == null && json != null) + if (siteName == null && json != null) { - if(json.containsKey("siteid")) + if (json.containsKey("siteid")) { siteName = (String)json.get("siteid"); } - else if(json.containsKey("site")) + else if (json.containsKey("site")) { siteName = (String)json.get("site"); } } - if(siteName == null) + if (siteName == null) { String error = "No site given"; - if(useJSONErrors()) + if (useJSONErrors()) { return buildError("No site given"); } @@ -378,10 +376,10 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript // Grab the requested site SiteInfo site = siteService.getSite(siteName); - if(site == null) + if (site == null) { String error = "Could not find site: " + siteName; - if(useJSONErrors()) + if (useJSONErrors()) { return buildError(error); } @@ -401,5 +399,4 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript protected abstract Map executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache); - } diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java index 2a12c452f9..ce78612562 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java @@ -49,7 +49,8 @@ public class CalendarEntriesListGet extends AbstractCalendarWebScript { @Override protected Map executeImpl(SiteInfo site, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); // Evil... // Get the entries for the list @@ -68,8 +69,8 @@ public class CalendarEntriesListGet extends AbstractCalendarWebScript List ignores = nodeService.getChildAssocs( entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT, - ContentModel.ASSOC_CONTAINS, true - ); + ContentModel.ASSOC_CONTAINS, true); + List ignoreEvents = new ArrayList(); List ignoreEventDates = new ArrayList(); for (ChildAssociationRef ref : ignores) diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryDelete.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryDelete.java index c34aeef3b2..d43daea540 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryDelete.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryDelete.java @@ -39,25 +39,26 @@ public class CalendarEntryDelete extends AbstractCalendarWebScript * This WebScript uses HTTP status codes for errors */ @Override - protected boolean useJSONErrors() { + protected boolean useJSONErrors() + { return false; } @Override protected Map executeImpl(SiteInfo site, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { CalendarEntry entry = calendarService.getCalendarEntry( - site.getShortName(), eventName - ); + site.getShortName(), eventName); - if(entry == null) + if (entry == null) { status.setCode(Status.STATUS_NOT_FOUND); return null; } // Special case for "deleting" an instance of a recurring event - if(req.getParameter("date") != null && entry.getRecurrenceRule() != null) + if (req.getParameter("date") != null && entry.getRecurrenceRule() != null) { // Have an ignored event generated createIgnoreEvent(req, entry); diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java index e73a3b9a01..5cc762d99d 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java @@ -47,12 +47,12 @@ public class CalendarEntryGet extends AbstractCalendarWebScript @Override protected Map executeImpl(SiteInfo site, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { CalendarEntry entry = calendarService.getCalendarEntry( - site.getShortName(), eventName - ); + site.getShortName(), eventName); - if(entry == null) + if (entry == null) { return buildError("Could not find event: " + eventName); } @@ -73,9 +73,9 @@ public class CalendarEntryGet extends AbstractCalendarWebScript result.put("recurrence", buildRecurrenceString(entry)); // Replace nulls with blank strings for the JSON - for(String key : result.keySet()) + for (String key : result.keySet()) { - if(result.get(key) == null) + if (result.get(key) == null) { result.put(key, ""); } @@ -98,7 +98,7 @@ public class CalendarEntryGet extends AbstractCalendarWebScript { // If there's no recurrence rules, then there's nothing to do String recurrence = event.getRecurrenceRule(); - if(recurrence == null || recurrence.trim().length() == 0) + if (recurrence == null || recurrence.trim().length() == 0) { return null; } @@ -114,11 +114,11 @@ public class CalendarEntryGet extends AbstractCalendarWebScript StringBuffer text = new StringBuffer(); // Handle the different frequencies - if(params.containsKey("FREQ")) + if (params.containsKey("FREQ")) { String freq = params.get("FREQ"); String interval = params.get("INTERVAL"); - if(interval == null) + if (interval == null) { interval = "1"; } @@ -134,7 +134,7 @@ public class CalendarEntryGet extends AbstractCalendarWebScript text.append("Occurs every " + interval + " weeks on "); } - for(String day : params.get("BYDAY").split(",")) + for (String day : params.get("BYDAY").split(",")) { text.append(days.get(day)); text.append(", "); @@ -179,11 +179,11 @@ public class CalendarEntryGet extends AbstractCalendarWebScript // And the rest DateFormat dFormat = SimpleDateFormat.getDateInstance( - SimpleDateFormat.MEDIUM, I18NUtil.getLocale() - ); + SimpleDateFormat.MEDIUM, I18NUtil.getLocale()); + DateFormat tFormat = SimpleDateFormat.getTimeInstance( - SimpleDateFormat.SHORT, I18NUtil.getLocale() - ); + SimpleDateFormat.SHORT, I18NUtil.getLocale()); + text.append("effective " + dFormat.format(event.getStart())); if (params.containsKey("COUNT")) diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPost.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPost.java index 21df927ce3..2c0ae80d00 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPost.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPost.java @@ -41,7 +41,8 @@ public class CalendarEntryPost extends AbstractCalendarWebScript { @Override protected Map executeImpl(SiteInfo site, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { CalendarEntry entry = new CalendarEntryDTO(); // TODO Handle All Day events properly, including timezones @@ -59,26 +60,20 @@ public class CalendarEntryPost extends AbstractCalendarWebScript isAllDay = extractDates(entry, json); // Handle tags - if(json.containsKey("tags")) + if (json.containsKey("tags")) { StringTokenizer st = new StringTokenizer((String)json.get("tags"), " "); - while(st.hasMoreTokens()) + while (st.hasMoreTokens()) { entry.getTags().add(st.nextToken()); } } } - catch(JSONException je) + catch (JSONException je) { return buildError("Invalid JSON: " + je.getMessage()); } - if(entry == null) - { - return buildError("Could not find event: " + eventName); - } - - // Have it added entry = calendarService.createCalendarEntry(site.getShortName(), entry); @@ -102,9 +97,9 @@ public class CalendarEntryPost extends AbstractCalendarWebScript result.put("docfolder", entry.getSharePointDocFolder()); // Replace nulls with blank strings for the JSON - for(String key : result.keySet()) + for (String key : result.keySet()) { - if(result.get(key) == null) + if (result.get(key) == null) { result.put(key, ""); } diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPut.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPut.java index 649225e746..fb64ceeb9e 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPut.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryPut.java @@ -41,12 +41,12 @@ public class CalendarEntryPut extends AbstractCalendarWebScript { @Override protected Map executeImpl(SiteInfo site, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { CalendarEntry entry = calendarService.getCalendarEntry( - site.getShortName(), eventName - ); + site.getShortName(), eventName); - if(entry == null) + if (entry == null) { return buildError("Could not find event: " + eventName); } @@ -60,7 +60,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript String docFolder = (String)json.get("docfolder"); // Editing recurring events is special and a little bit odd... - if(entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule")) + if (entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule")) { // Have an ignored event generated // Will allow us to override this one instance @@ -70,7 +70,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript CalendarEntry newEntry = new CalendarEntryDTO(); newEntry.setOutlook(true); - if("*NOT_CHANGE*".equals(docFolder)) + if ("*NOT_CHANGE*".equals(docFolder)) { newEntry.setSharePointDocFolder(entry.getSharePointDocFolder()); } @@ -80,7 +80,7 @@ public class CalendarEntryPut extends AbstractCalendarWebScript } // Doc folder is a bit special - if("*NOT_CHANGE*".equals(docFolder)) + if ("*NOT_CHANGE*".equals(docFolder)) { // Nothing to change } @@ -119,34 +119,27 @@ public class CalendarEntryPut extends AbstractCalendarWebScript else { entry.setLastRecurrence( - parseDate((String)json.get("recurrenceLastMeeting")) - ); + parseDate((String)json.get("recurrenceLastMeeting"))); } } // Handle tags - if(json.containsKey("tags")) + if (json.containsKey("tags")) { entry.getTags().clear(); StringTokenizer st = new StringTokenizer((String)json.get("tags"), " "); - while(st.hasMoreTokens()) + while (st.hasMoreTokens()) { entry.getTags().add(st.nextToken()); } } } - catch(JSONException je) + catch (JSONException je) { return buildError("Invalid JSON: " + je.getMessage()); } - if(entry == null) - { - return buildError("Could not find event: " + eventName); - } - - // Have it edited entry = calendarService.updateCalendarEntry(entry); @@ -170,9 +163,9 @@ public class CalendarEntryPut extends AbstractCalendarWebScript result.put("docfolder", entry.getSharePointDocFolder()); // Replace nulls with blank strings for the JSON - for(String key : result.keySet()) + for (String key : result.keySet()) { - if(result.get(key) == null) + if (result.get(key) == null) { result.put(key, ""); } @@ -192,11 +185,11 @@ public class CalendarEntryPut extends AbstractCalendarWebScript protected String generateTagString(CalendarEntry entry) { StringBuffer sb = new StringBuffer(); - if(entry.getTags() != null) + if (entry.getTags() != null) { - for(String tag : entry.getTags()) + for (String tag : entry.getTags()) { - if(sb.length() > 0) sb.append(' '); + if (sb.length() > 0) sb.append(' '); sb.append(tag); } } diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarRestApiTest.java index 74a3ef5807..277851e437 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarRestApiTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -45,12 +45,13 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * Unit Test to test the Calendaring Web Script API * * @author Nick Burch + * @since 4.0 */ public class CalendarRestApiTest extends BaseWebScriptTest { - @SuppressWarnings("unused") + @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(CalendarRestApiTest.class); - + private MutableAuthenticationService authenticationService; private AuthenticationComponent authenticationComponent; private PersonService personService; @@ -99,7 +100,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest } // Ensure the calendar container is there - if(!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, "calendar")) + if (!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, "calendar")) { siteService.createContainer(SITE_SHORT_NAME_CALENDAR, "calendar", null, null); } @@ -125,13 +126,13 @@ public class CalendarRestApiTest extends BaseWebScriptTest // delete the 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); } @@ -168,13 +169,13 @@ public class CalendarRestApiTest extends BaseWebScriptTest private JSONObject getEntries(String username, String from) throws Exception { String url = URL_EVENTS_LIST + "?site=" + SITE_SHORT_NAME_CALENDAR; - if(username != null) + if (username != null) { url = URL_USER_SITE_EVENTS_LIST; } - if(from != null) + if (from != null) { - if(url.indexOf('/') > 0) + if (url.indexOf('/') > 0) { url += "&"; } @@ -208,8 +209,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest * Creates a 1 hour, non-all day event on the 29th of June */ private JSONObject createEntry(String name, String where, String description, - int expectedStatus) - throws Exception + int expectedStatus) throws Exception { String date = "2011/06/29"; // A wednesday String start = "12:00"; @@ -234,7 +234,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("event")) + if (result.has("event")) { return result.getJSONObject("event"); } @@ -270,7 +270,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest json.put("docfolder", ""); json.put("page", "calendar"); - if(withRecurrence) + if (withRecurrence) { json.put("recurrenceRule", "FREQ=WEEKLY;INTERVAL=2;BYDAY=WE,FR"); json.put("recurrenceLastMeeting", "2011-09-11"); @@ -280,11 +280,11 @@ public class CalendarRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("event")) + if (result.has("event")) { return result.getJSONObject("event"); } - if(result.has("data")) + if (result.has("data")) { return result.getJSONObject("data"); } @@ -301,17 +301,16 @@ public class CalendarRestApiTest extends BaseWebScriptTest */ private String getNameFromEntry(JSONObject entry) throws Exception { - if(! entry.has("uri")) + if (! entry.has("uri")) { throw new IllegalArgumentException("No uri in " + entry.toString()); } String uri = entry.getString("uri"); String name = uri.substring( - uri.indexOf(SITE_SHORT_NAME_CALENDAR) + SITE_SHORT_NAME_CALENDAR.length() + 1 - ); + uri.indexOf(SITE_SHORT_NAME_CALENDAR) + SITE_SHORT_NAME_CALENDAR.length() + 1); - if(name.indexOf('?') > 0) + if (name.indexOf('?') > 0) { return name.substring(0, name.indexOf('?')); } @@ -433,9 +432,7 @@ public class CalendarRestApiTest extends BaseWebScriptTest assertEquals( "Occurs every 2 weeks on Wednesday, Friday, effective " + "28-Jun-2011 until 11-Sep-2011 from 11:30 to 13:30", - entry.getString("recurrence") - ); - + entry.getString("recurrence")); // Delete sendRequest(new DeleteRequest(URL_EVENT_BASE + name), Status.STATUS_NO_CONTENT); diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/UserCalendarEntriesGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/UserCalendarEntriesGet.java index 859442fa32..082cff5da9 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/UserCalendarEntriesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/UserCalendarEntriesGet.java @@ -64,7 +64,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // Site is optional SiteInfo site = null; String siteName = templateVars.get("site"); - if(siteName != null) + if (siteName != null) { site = siteService.getSite(siteName); } @@ -74,7 +74,8 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript @Override protected Map executeImpl(SiteInfo singleSite, String eventName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { // Did they restrict by date? Date fromDate = parseDate(req.getParameter("from")); Date toDate = parseDate(req.getParameter("to")); @@ -82,13 +83,13 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // What should we do about repeating events? First or all? boolean repeatingFirstOnly = true; String repeatingEvents = req.getParameter("repeating"); - if(repeatingEvents != null) + if (repeatingEvents != null) { - if("first".equals(repeatingEvents)) + if ("first".equals(repeatingEvents)) { repeatingFirstOnly = true; } - else if("all".equals(repeatingEvents)) + else if ("all".equals(repeatingEvents)) { repeatingFirstOnly = false; } @@ -97,15 +98,15 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript { // Fall back to the icky old way of guessing it from // the format of the from date, which differs between uses! - if(fromDate != null) + if (fromDate != null) { String fromDateS = req.getParameter("from"); - if(fromDateS.indexOf('-') != -1) + if (fromDateS.indexOf('-') != -1) { // Apparently this is the site calendar dashlet... repeatingFirstOnly = true; } - if(fromDateS.indexOf('/') != -1) + if (fromDateS.indexOf('/') != -1) { // This is something else, wants all events in range repeatingFirstOnly = false; @@ -115,7 +116,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // One site, or all the user's ones? List sites = new ArrayList(); - if(singleSite != null) + if (singleSite != null) { // Just one sites.add(singleSite); @@ -129,7 +130,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // We need to know the Site Names, and the NodeRefs of the calendar containers String[] siteShortNames = new String[sites.size()]; Map containerLookup = new HashMap(); - for(int i=0; i> results = new ArrayList>(); - for(CalendarEntry entry : entries.getPage()) + for (CalendarEntry entry : entries.getPage()) { // Build the object Map result = new HashMap(); @@ -178,9 +178,9 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript result.put("siteTitle", site.getTitle()); // Replace nulls with blank strings for the JSON - for(String key : result.keySet()) + for (String key : result.keySet()) { - if(result.get(key) == null) + if (result.get(key) == null) { result.put(key, ""); } @@ -191,28 +191,30 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // Handle recurring as needed boolean orderChanged = handleRecurring(entry, result, results, fromDate, repeatingFirstOnly); - if(orderChanged) + if (orderChanged) { resortNeeded = true; } } // If the recurring events meant dates changed, re-sort - if(resortNeeded) + if (resortNeeded) { - Collections.sort(results, new Comparator>() { + Collections.sort(results, new Comparator>() + { public int compare(Map resultA, - Map resultB) { + Map resultB) + { Date startA = (Date)resultA.get(RESULT_START); Date startB = (Date)resultB.get(RESULT_START); int cmp = startA.compareTo(startB); - if(cmp == 0) + if (cmp == 0) { Date endA = (Date)resultA.get(RESULT_END); Date endB = (Date)resultB.get(RESULT_END); cmp = endA.compareTo(endB); - if(cmp == 0) + if (cmp == 0) { String nameA = (String)resultA.get(RESULT_NAME); String nameB = (String)resultB.get(RESULT_NAME); @@ -248,7 +250,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript long timeDiff = entry.getEnd().getTime() - entry.getStart().getTime(); int weeks = (int)Math.floor(timeDiff / DURATION_WEEK); - if(weeks > 0) + if (weeks > 0) { duration.append(weeks); duration.append("W"); @@ -256,7 +258,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript } int days = (int)Math.floor(timeDiff / DURATION_DAY); - if(days > 0) + if (days > 0) { duration.append(days); duration.append("D"); @@ -266,7 +268,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript duration.append("T"); int hours = (int)Math.floor(timeDiff / DURATION_HOUR); - if(hours > 0) + if (hours > 0) { duration.append(hours); duration.append("H"); @@ -274,7 +276,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript } int minutes = (int)Math.floor(timeDiff / DURATION_MINUTE); - if(minutes > 0) + if (minutes > 0) { duration.append(minutes); duration.append("M"); @@ -282,7 +284,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript } int seconds = (int)Math.floor(timeDiff / DURATION_SECOND); - if(seconds > 0) + if (seconds > 0) { duration.append(seconds); timeDiff -= minutes * DURATION_MINUTE; @@ -299,21 +301,21 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript private boolean handleRecurring(CalendarEntry entry, Map entryResult, List> allResults, Date from, boolean repeatingFirstOnly) { - if(entry.getRecurrenceRule() == null) + if (entry.getRecurrenceRule() == null) { // Nothing to do return false; } // If no date is given, start looking for occurrences from the event itself - if(from == null) + if (from == null) { from = entry.getStart(); } // Should we limit ourselves? Date until = null; - if(!repeatingFirstOnly) + if (!repeatingFirstOnly) { // Only repeating instances for the next 60 days, to keep the list sane // (It's normally only used for a month view anyway) @@ -329,15 +331,15 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript // Get it's recurring instances List dates = CalendarRecurrenceHelper.getRecurrencesOnOrAfter( entry, from, until, repeatingFirstOnly); - if(dates == null) + if (dates == null) { dates = new ArrayList(); } // Add on the original event time itself if needed - if(entry.getStart().getTime() >= from.getTime()) + if (entry.getStart().getTime() >= from.getTime()) { - if(dates.size() == 0 || dates.get(0).getTime() != entry.getStart().getTime()) + if (dates.size() == 0 || dates.get(0).getTime() != entry.getStart().getTime()) { // Original event is after the start time, and not on the recurring list dates.add(0, entry.getStart()); @@ -345,7 +347,7 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript } // If we got no dates, then no recurrences in the period so zap - if(dates.size() == 0) + if (dates.size() == 0) { allResults.remove(entryResult); return false; // Remains sorted despite delete @@ -355,14 +357,14 @@ public class UserCalendarEntriesGet extends AbstractCalendarWebScript updateRepeatingStartEnd(dates.get(0), duration, entryResult); // If first result only, alter title and finish - if(repeatingFirstOnly) + if (repeatingFirstOnly) { entryResult.put(RESULT_TITLE, entry.getTitle() + " (Repeating)"); return true; // Date has been changed } // Otherwise generate one entry per extra date - for(int i=1; i newResult = new HashMap(entryResult); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/AbstractDiscussionWebScript.java b/source/java/org/alfresco/repo/web/scripts/discussion/AbstractDiscussionWebScript.java index c9b5fe88db..2322de83a4 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/AbstractDiscussionWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/AbstractDiscussionWebScript.java @@ -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 getTags(JSONObject json) { List 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(); JSONArray jsTags = (JSONArray)json.get("tags"); - for(int i=0; i 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> items = new ArrayList>(); - 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 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 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); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java index 289dfd42b4..4af678bcf0 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java @@ -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 diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostDelete.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostDelete.java index 6fdcb70dd4..7c86df3100 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostDelete.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostDelete.java @@ -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); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostGet.java index 372be81341..7184c237dc 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostGet.java @@ -47,11 +47,11 @@ public class ForumPostGet extends AbstractDiscussionWebScript Map 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)); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostPut.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostPut.java index 094e84b976..a79b45d7b8 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostPut.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostPut.java @@ -48,7 +48,7 @@ public class ForumPostPut extends AbstractDiscussionWebScript Map 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 tags = getTags(json); - if(tags != null) + if (tags != null) { topic.getTags().addAll(tags); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesGet.java index bd5e54d626..212aec97b9 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesGet.java @@ -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> r = new ArrayList>(); - for(PostWithReplies child : replies.getReplies()) + for (PostWithReplies child : replies.getReplies()) { r.add(renderReplies(child, site)); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesPost.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesPost.java index 93123fd415..19701d0410 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesPost.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesPost.java @@ -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()); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicPost.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicPost.java index a40bb8aff1..8bbf35e467 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicPost.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicPost.java @@ -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); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsGet.java index cac538f920..ef796cb2e6 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsGet.java @@ -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 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(); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsHotGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsHotGet.java index 49c7b41285..134b62723b 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsHotGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsHotGet.java @@ -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> 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 topics = new ArrayList(); - for(Pair tc : topicsAndCounts.getPage()) + for (Pair 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(); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java index ba553ecab7..980993a8c3 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java @@ -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 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(); } diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java index 5ecf0495c4..7ee6db6f31 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java @@ -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 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(); } diff --git a/source/java/org/alfresco/repo/web/scripts/forms/FormRestApiGet_Test.java b/source/java/org/alfresco/repo/web/scripts/forms/FormRestApiGet_Test.java index 4e7cb023bd..20a8c2e35e 100644 --- a/source/java/org/alfresco/repo/web/scripts/forms/FormRestApiGet_Test.java +++ b/source/java/org/alfresco/repo/web/scripts/forms/FormRestApiGet_Test.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -22,14 +22,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.repository.NodeRef; -import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; -import org.springframework.extensions.webscripts.TestWebScriptServer.Response; -import org.springframework.extensions.webscripts.json.JSONUtils; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; +import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; +import org.springframework.extensions.webscripts.TestWebScriptServer.Response; +import org.springframework.extensions.webscripts.json.JSONUtils; public class FormRestApiGet_Test extends AbstractTestFormRestApi { @@ -58,7 +57,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi public void testGetFormForNonExistentNode() throws Exception { - // Create a NodeRef with all digits changed to an 'x' char - + // Create a NodeRef with all digits changed to an 'x' char - // this should make for a non-existent node. String missingId = this.referencingDocNodeRef.getId().replaceAll("\\d", "x"); NodeRef missingNodeRef = new NodeRef(this.referencingDocNodeRef.getStoreRef(), @@ -130,10 +129,10 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi List keys = new ArrayList(); for (Iterator iter = formDataObject.keys(); iter.hasNext(); ) { - String nextFieldName = (String)iter.next(); + String nextFieldName = (String)iter.next(); assertEquals("Did not expect to find a colon char in " + nextFieldName, - -1, nextFieldName.indexOf(':')); - keys.add(nextFieldName); + -1, nextFieldName.indexOf(':')); + keys.add(nextFieldName); } // Threshold is a rather arbitrary number. I simply want to ensure that there // are *some* entries in the formData hash. @@ -144,7 +143,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi } @SuppressWarnings("unchecked") - public void testJsonDefinitionFields() throws Exception + public void testJsonDefinitionFields() throws Exception { JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef); String jsonPostString = jsonPostData.toString(); diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java index 9f7aa4c390..cd2094625d 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -26,7 +26,6 @@ import org.alfresco.service.cmr.invitation.InvitationExceptionForbidden; import org.alfresco.service.cmr.invitation.InvitationExceptionUserError; import org.alfresco.service.cmr.invitation.InvitationService; import org.alfresco.service.cmr.invitation.NominatedInvitation; -import org.alfresco.service.cmr.workflow.WorkflowService; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; @@ -209,34 +208,34 @@ public class Invite extends DeclarativeWebScript NominatedInvitation newInvite = null; try { - if(inviteeUserName != null) - { - newInvite = invitationService.inviteNominated(inviteeUserName, Invitation.ResourceType.WEB_SITE, siteShortName, inviteeSiteRole, serverPath, acceptUrl, rejectUrl); - } - else - { - newInvite = invitationService.inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, Invitation.ResourceType.WEB_SITE, siteShortName, inviteeSiteRole, serverPath, acceptUrl, rejectUrl); - } - // add model properties for template to render - model.put(MODEL_PROP_KEY_ACTION, ACTION_START); - model.put(MODEL_PROP_KEY_INVITE_ID, newInvite.getInviteId()); - model.put(MODEL_PROP_KEY_INVITE_TICKET, newInvite.getTicket()); - model.put(MODEL_PROP_KEY_INVITEE_USER_NAME, newInvite.getInviteeUserName()); - model.put(MODEL_PROP_KEY_INVITEE_FIRSTNAME, inviteeFirstName); - model.put(MODEL_PROP_KEY_INVITEE_LASTNAME, inviteeLastName); - model.put(MODEL_PROP_KEY_INVITEE_EMAIL, inviteeEmail); - model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); + if (inviteeUserName != null) + { + newInvite = invitationService.inviteNominated(inviteeUserName, Invitation.ResourceType.WEB_SITE, siteShortName, inviteeSiteRole, serverPath, acceptUrl, rejectUrl); + } + else + { + newInvite = invitationService.inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, Invitation.ResourceType.WEB_SITE, siteShortName, inviteeSiteRole, serverPath, acceptUrl, rejectUrl); + } + // add model properties for template to render + model.put(MODEL_PROP_KEY_ACTION, ACTION_START); + model.put(MODEL_PROP_KEY_INVITE_ID, newInvite.getInviteId()); + model.put(MODEL_PROP_KEY_INVITE_TICKET, newInvite.getTicket()); + model.put(MODEL_PROP_KEY_INVITEE_USER_NAME, newInvite.getInviteeUserName()); + model.put(MODEL_PROP_KEY_INVITEE_FIRSTNAME, inviteeFirstName); + model.put(MODEL_PROP_KEY_INVITEE_LASTNAME, inviteeLastName); + model.put(MODEL_PROP_KEY_INVITEE_EMAIL, inviteeEmail); + model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); } catch (InvitationExceptionUserError ie) - { - throw new WebScriptException(Status.STATUS_CONFLICT, + { + throw new WebScriptException(Status.STATUS_CONFLICT, "Cannot proceed with invitation. A person with user name: '" + inviteeUserName + "' and invitee email address: '" + inviteeEmail + "' is already a member of the site: '" + siteShortName + "'."); - } + } catch (InvitationExceptionForbidden fe) { - throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); + throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); } // process action 'start' with provided parameters @@ -259,14 +258,14 @@ public class Invite extends DeclarativeWebScript // process action 'cancel' with provided parameters try { - invitationService.cancel(inviteId); + invitationService.cancel(inviteId); // add model properties for template to render model.put(MODEL_PROP_KEY_ACTION, ACTION_CANCEL); model.put(MODEL_PROP_KEY_INVITE_ID, inviteId); } catch(InvitationExceptionForbidden fe) { - throw new WebScriptException(Status.STATUS_FORBIDDEN, "Unable to cancel workflow" , fe); + throw new WebScriptException(Status.STATUS_FORBIDDEN, "Unable to cancel workflow" , fe); } } // handle action not recognised diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java index a1cb7741f6..b0c91d179f 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -128,27 +128,25 @@ public class InviteByTicket extends DeclarativeWebScript try { - Invitation invitation = invitationService.getInvitation(inviteId); - - if (invitation instanceof NominatedInvitation) - { - NominatedInvitation theInvitation = (NominatedInvitation)invitation; - String ticket = theInvitation.getTicket(); - if (ticket == null || (! ticket.equals(inviteTicket))) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, - "Ticket mismatch"); - } + Invitation invitation = invitationService.getInvitation(inviteId); + + if (invitation instanceof NominatedInvitation) + { + NominatedInvitation theInvitation = (NominatedInvitation)invitation; + String ticket = theInvitation.getTicket(); + if (ticket == null || (! ticket.equals(inviteTicket))) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Ticket mismatch"); + } // return the invite info model.put("invite", toInviteInfo(theInvitation)); return model; - } - else - { - // Not a nominated invitation - throw new WebScriptException(Status.STATUS_FORBIDDEN, - "Not a nominated invitation"); - } + } + else + { + // Not a nominated invitation + throw new WebScriptException(Status.STATUS_FORBIDDEN, "Not a nominated invitation"); + } } catch (InvitationExceptionNotFound nfe) { @@ -177,20 +175,19 @@ public class InviteByTicket extends DeclarativeWebScript TemplateNode inviteePerson = null; if (inviteeRef != null) { - inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null); + inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null); } InviteInfo ret = new InviteInfo(invitationStatus, - invitation.getInviterUserName(), - inviterPerson, - invitation.getInviteeUserName(), - inviteePerson, - invitation.getRoleName(), - invitation.getResourceName(), - siteInfo, - invitation.getSentInviteDate(), - invitation.getInviteId() - ); + invitation.getInviterUserName(), + inviterPerson, + invitation.getInviteeUserName(), + inviteePerson, + invitation.getRoleName(), + invitation.getResourceName(), + siteInfo, + invitation.getSentInviteDate(), + invitation.getInviteId()); return ret; } diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java index 13140ec073..3f5cdad445 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -112,38 +112,38 @@ public class InviteResponse extends DeclarativeWebScript String action = req.getServiceMatch().getTemplateVars().get("action"); if (action.equals("accept")) { - try - { - Invitation invitation = invitationService.accept(inviteId, inviteTicket); + try + { + Invitation invitation = invitationService.accept(inviteId, inviteTicket); // add model properties for template to render model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT); model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, invitation.getResourceName()); - } + } catch (InvitationExceptionForbidden fe) { - throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); + throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); } catch (InvitationExceptionUserError fe) { - throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString()); + throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString()); } } else if (action.equals("reject")) { - try - { - Invitation invitation = invitationService.reject(inviteId, "Rejected"); + try + { + Invitation invitation = invitationService.reject(inviteId, "Rejected"); // add model properties for template to render model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT); model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, invitation.getResourceName()); - } + } catch (InvitationExceptionForbidden fe) { - throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); + throw new WebScriptException(Status.STATUS_FORBIDDEN, fe.toString()); } catch (InvitationExceptionUserError fe) { - throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString()); + throw new WebScriptException(Status.STATUS_CONFLICT, fe.toString()); } } else diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java index 666e70711f..8ce41ab821 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -242,37 +242,37 @@ public class InviteServiceTest extends BaseWebScriptTest */ public static void configureMailExecutorForTestMode(TestWebScriptServer server) { - // This test class depends on a MailActionExecuter bean which sends out emails - // in a live system. We want to prevent these emails from being sent during - // test execution. - // To do that, we need to get at the outboundSMTP-context.xml and change its - // "mail" MailActionExecuter bean to test mode. setTestMode(true) on that object - // will turn off email sending. - // But that bean is defined within a subsystem i.e. a child application context. - - // There are a number of ways we could do this, none of them perfect. - // - // 1. Expose the setTestMode(boolean) method in the subsystem API. - // We could have the "mail" bean implement a "TestModeable" interface and - // expose that through the proxy. - // But that would mean that the setTestMode method would be available in the - // live system too, which is not ideal. - // 2. Replace the "mail" bean in outboundSMTP-context.xml with an alternative in a - // different subsystem context file as described in - // http://wiki.alfresco.com/wiki/Alfresco_Subsystems#Debugging_Alfresco_Subsystems - // But to do that, we'd have to reproduce all the spring config for that bean - // and add a testMode property. Again not ideal. - // 3. Hack into the "mail" bean by programmatically going through the known applicationContext - // and bean structure. This is not ideal either, but it has no effect on product code - // and isolates all the hacking into this test class. - // - // Therefore we've decided to do [3]. - - ChildApplicationContextFactory outboundSmptSubsystem + // This test class depends on a MailActionExecuter bean which sends out emails + // in a live system. We want to prevent these emails from being sent during + // test execution. + // To do that, we need to get at the outboundSMTP-context.xml and change its + // "mail" MailActionExecuter bean to test mode. setTestMode(true) on that object + // will turn off email sending. + // But that bean is defined within a subsystem i.e. a child application context. + + // There are a number of ways we could do this, none of them perfect. + // + // 1. Expose the setTestMode(boolean) method in the subsystem API. + // We could have the "mail" bean implement a "TestModeable" interface and + // expose that through the proxy. + // But that would mean that the setTestMode method would be available in the + // live system too, which is not ideal. + // 2. Replace the "mail" bean in outboundSMTP-context.xml with an alternative in a + // different subsystem context file as described in + // http://wiki.alfresco.com/wiki/Alfresco_Subsystems#Debugging_Alfresco_Subsystems + // But to do that, we'd have to reproduce all the spring config for that bean + // and add a testMode property. Again not ideal. + // 3. Hack into the "mail" bean by programmatically going through the known applicationContext + // and bean structure. This is not ideal either, but it has no effect on product code + // and isolates all the hacking into this test class. + // + // Therefore we've decided to do [3]. + + ChildApplicationContextFactory outboundSmptSubsystem = (ChildApplicationContextFactory)server.getApplicationContext().getBean("OutboundSMTP"); - ApplicationContext childAppCtxt = outboundSmptSubsystem.getApplicationContext(); - MailActionExecuter mailActionExecutor = (MailActionExecuter)childAppCtxt.getBean("mail"); - mailActionExecutor.setTestMode(true); + ApplicationContext childAppCtxt = outboundSmptSubsystem.getApplicationContext(); + MailActionExecuter mailActionExecutor = (MailActionExecuter)childAppCtxt.getBean("mail"); + mailActionExecutor.setTestMode(true); } @Override diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java index 4a2ed022c5..5064430eb8 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java @@ -19,19 +19,16 @@ package org.alfresco.repo.web.scripts.invite; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.alfresco.repo.invitation.InvitationSearchCriteriaImpl; -import org.alfresco.repo.invitation.InviteHelper; -import org.alfresco.service.cmr.invitation.InvitationSearchCriteria; -import org.alfresco.repo.invitation.WorkflowModelNominatedInvitation; import org.alfresco.repo.invitation.site.InviteInfo; import org.alfresco.repo.template.TemplateNode; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.invitation.Invitation; +import org.alfresco.service.cmr.invitation.InvitationSearchCriteria; import org.alfresco.service.cmr.invitation.InvitationService; import org.alfresco.service.cmr.invitation.NominatedInvitation; import org.alfresco.service.cmr.repository.NodeRef; @@ -39,10 +36,6 @@ import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.workflow.WorkflowService; -import org.alfresco.service.cmr.workflow.WorkflowTask; -import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; -import org.alfresco.service.cmr.workflow.WorkflowTaskState; -import org.alfresco.service.namespace.QName; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; @@ -97,23 +90,27 @@ public class Invites extends DeclarativeWebScript this.workflowService = workflowService; } - public void setServiceRegistry(ServiceRegistry serviceRegistry) { - this.serviceRegistry = serviceRegistry; - } - - public void setSiteService(SiteService siteService) { + public void setServiceRegistry(ServiceRegistry serviceRegistry) + { + this.serviceRegistry = serviceRegistry; + } + + public void setSiteService(SiteService siteService) + { this.siteService = siteService; } - public void setInvitationService(InvitationService invitationService) { - this.invitationService = invitationService; - } - - public InvitationService getInvitationService() { - return invitationService; - } + public void setInvitationService(InvitationService invitationService) + { + this.invitationService = invitationService; + } - /* + public InvitationService getInvitationService() + { + return invitationService; + } + + /* * (non-Javadoc) * * @see @@ -181,8 +178,8 @@ public class Invites extends DeclarativeWebScript // query properties if (inviteIdProvided) { - NominatedInvitation invitation = (NominatedInvitation)invitationService.getInvitation(inviteId); - inviteInfoList.add(toInviteInfo(invitation)); + NominatedInvitation invitation = (NominatedInvitation)invitationService.getInvitation(inviteId); + inviteInfoList.add(toInviteInfo(invitation)); } else // 'inviteId' has not been provided, so create the query properties from @@ -194,37 +191,34 @@ public class Invites extends DeclarativeWebScript // properties will be set // at this point { - InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl(); - criteria.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED); - criteria.setResourceType(Invitation.ResourceType.WEB_SITE); + InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl(); + criteria.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED); + criteria.setResourceType(Invitation.ResourceType.WEB_SITE); if (inviterUserNameProvided) { - criteria.setInviter(inviterUserName); - + criteria.setInviter(inviterUserName); } if (inviteeUserNameProvided) { - criteria.setInvitee(inviteeUserName); - + criteria.setInvitee(inviteeUserName); } if (siteShortNameProvided) { - criteria.setResourceName(siteShortName); - + criteria.setResourceName(siteShortName); } - List invitations = invitationService.searchInvitation(criteria); + List invitations = invitationService.searchInvitation(criteria); - // Put InviteInfo objects (containing workflow path properties - // wf:inviterUserName, wf:inviteeUserName, wf:siteShortName, - // and invite id property (from workflow instance id)) - // onto model for each invite workflow task returned by the query - for (Invitation invitation : invitations) - { - inviteInfoList.add(toInviteInfo((NominatedInvitation)invitation)); - } + // Put InviteInfo objects (containing workflow path properties + // wf:inviterUserName, wf:inviteeUserName, wf:siteShortName, + // and invite id property (from workflow instance id)) + // onto model for each invite workflow task returned by the query + for (Invitation invitation : invitations) + { + inviteInfoList.add(toInviteInfo((NominatedInvitation)invitation)); + } } // put the list of invite infos onto model to be passed onto template @@ -256,20 +250,19 @@ public class Invites extends DeclarativeWebScript TemplateNode inviteePerson = null; if (inviteeRef != null) { - inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null); + inviteePerson = new TemplateNode(inviteeRef, serviceRegistry, null); } InviteInfo ret = new InviteInfo(invitationStatus, - invitation.getInviterUserName(), - inviterPerson, - invitation.getInviteeUserName(), - inviteePerson, - invitation.getRoleName(), - invitation.getResourceName(), - siteInfo, - invitation.getSentInviteDate(), - invitation.getInviteId() - ); + invitation.getInviterUserName(), + inviterPerson, + invitation.getInviteeUserName(), + inviteePerson, + invitation.getRoleName(), + invitation.getResourceName(), + siteInfo, + invitation.getSentInviteDate(), + invitation.getInviteId()); return ret; } diff --git a/source/java/org/alfresco/repo/web/scripts/links/AbstractLinksWebScript.java b/source/java/org/alfresco/repo/web/scripts/links/AbstractLinksWebScript.java index 57f95080f8..9e83d7656c 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/AbstractLinksWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/links/AbstractLinksWebScript.java @@ -96,7 +96,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript protected String getOrNull(JSONObject json, String key) { - if(json.containsKey(key)) + if (json.containsKey(key)) { return (String)json.get(key); } @@ -106,14 +106,14 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript protected List getTags(JSONObject json) { List 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; @@ -130,7 +130,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript { tags = new ArrayList(); JSONArray jsTags = (JSONArray)json.get("tags"); - for(int i=0; i templateVars = req.getServiceMatch().getTemplateVars(); - if(templateVars == null) + if (templateVars == null) { String error = "No parameters supplied"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); @@ -267,18 +266,18 @@ public abstract class AbstractLinksWebScript 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()); } @@ -291,22 +290,22 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript // Get the site short name. Try quite hard to do so... String siteName = templateVars.get("site"); - if(siteName == null) + if (siteName == null) { siteName = req.getParameter("site"); } - if(siteName == null && json != null) + if (siteName == null && json != null) { - if(json.containsKey("siteid")) + if (json.containsKey("siteid")) { siteName = (String)json.get("siteid"); } - else if(json.containsKey("site")) + else if (json.containsKey("site")) { siteName = (String)json.get("site"); } } - if(siteName == null) + if (siteName == null) { String error = "No site given"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); @@ -314,7 +313,7 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript // Grab the requested site SiteInfo 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); diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinkDelete.java b/source/java/org/alfresco/repo/web/scripts/links/LinkDelete.java index 139db663a2..04e3f9e50d 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinkDelete.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinkDelete.java @@ -40,12 +40,13 @@ public class LinkDelete extends AbstractLinksWebScript { @Override protected Map executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Try to find the link LinkInfo link = linksService.getLink(site.getShortName(), linkName); - if(link == null) + if (link == null) { String message = "No link found with that name"; throw new WebScriptException(Status.STATUS_NOT_FOUND, message); @@ -56,7 +57,7 @@ public class LinkDelete extends AbstractLinksWebScript { linksService.deleteLink(link); } - catch(AccessDeniedException e) + catch (AccessDeniedException e) { String message = "You don't have permission to delete that link"; throw new WebScriptException(Status.STATUS_FORBIDDEN, message); diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinkGet.java b/source/java/org/alfresco/repo/web/scripts/links/LinkGet.java index d0e4227967..7b84bc0216 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinkGet.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinkGet.java @@ -39,12 +39,13 @@ public class LinkGet extends AbstractLinksWebScript { @Override protected Map executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Try to find the link LinkInfo link = linksService.getLink(site.getShortName(), linkName); - if(link == null) + if (link == null) { String message = "No link found with that name"; throw new WebScriptException(Status.STATUS_NOT_FOUND, message); diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinkPut.java b/source/java/org/alfresco/repo/web/scripts/links/LinkPut.java index 4ce9000bd2..a2cf008504 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinkPut.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinkPut.java @@ -40,12 +40,13 @@ public class LinkPut extends AbstractLinksWebScript { @Override protected Map executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Try to find the link LinkInfo link = linksService.getLink(site.getShortName(), linkName); - if(link == null) + if (link == null) { String message = "No link found with that name"; @@ -63,7 +64,7 @@ public class LinkPut extends AbstractLinksWebScript link.setURL(getOrNull(json, "url")); // Handle internal / not internal - if(json.containsKey("internal")) + if (json.containsKey("internal")) { link.setInternal(true); } @@ -75,7 +76,7 @@ public class LinkPut extends AbstractLinksWebScript // Do the tags link.getTags().clear(); List tags = getTags(json); - if(tags != null && tags.size() > 0) + if (tags != null && tags.size() > 0) { link.getTags().addAll(tags); } @@ -86,7 +87,7 @@ public class LinkPut extends AbstractLinksWebScript { link = linksService.updateLink(link); } - catch(AccessDeniedException e) + catch (AccessDeniedException e) { String message = "You don't have permission to update that link"; diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinksDeletePost.java b/source/java/org/alfresco/repo/web/scripts/links/LinksDeletePost.java index ba526bc3ae..749d3d81ca 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinksDeletePost.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinksDeletePost.java @@ -45,20 +45,21 @@ public class LinksDeletePost extends AbstractLinksWebScript @Override protected Map executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Get the requested nodes from the JSON // Silently skips over any invalid ones specified List links = new ArrayList(); - if(json.containsKey("items")) + if (json.containsKey("items")) { JSONArray items = (JSONArray)json.get("items"); - for(int i=0; i executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { // Decide on what kind of request they wanted String filter = req.getParameter("filter"); // Tagging? boolean tagFiltering = true; String tag = req.getParameter("tag"); - if(tag == null || tag.length() == 0) + if (tag == null || tag.length() == 0) { tagFiltering = false; } @@ -64,7 +65,7 @@ public class LinksListGet extends AbstractLinksWebScript // User? boolean userFiltering = false; String user = null; - if("user".equals(filter)) + if ("user".equals(filter)) { userFiltering = true; user = AuthenticationUtil.getFullyAuthenticatedUser(); @@ -74,7 +75,7 @@ public class LinksListGet extends AbstractLinksWebScript boolean dateFiltering = false; Date from = null; Date to = null; - if("recent".equals(filter)) + if ("recent".equals(filter)) { dateFiltering = true; Date now = new Date(); @@ -86,17 +87,17 @@ public class LinksListGet extends AbstractLinksWebScript // Get the links for the list PagingRequest paging = buildPagingRequest(req); PagingResults links; - if(tagFiltering) + if (tagFiltering) { links = linksService.findLinks(site.getShortName(), user, from, to, tag, paging); } else { - if(userFiltering) + if (userFiltering) { links = linksService.listLinks(site.getShortName(), user, paging); } - else if(dateFiltering) + else if (dateFiltering) { links = linksService.listLinks(site.getShortName(), from, to, paging); } @@ -121,7 +122,7 @@ public class LinksListGet extends AbstractLinksWebScript data.put("itemCount", items.size()); int total = items.size(); - if(links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null) + if (links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null) { total = links.getTotalResultCount().getFirst(); } @@ -129,7 +130,7 @@ public class LinksListGet extends AbstractLinksWebScript // We need the container node for permissions checking NodeRef container; - if(links.getPage().size() > 0) + if (links.getPage().size() > 0) { container = links.getPage().get(0).getContainerNodeRef(); } @@ -137,10 +138,9 @@ public class LinksListGet extends AbstractLinksWebScript { // Find the container (if it's been created yet) container = siteService.getContainer( - site.getShortName(), LinksServiceImpl.LINKS_COMPONENT - ); + site.getShortName(), LinksServiceImpl.LINKS_COMPONENT); - if(container == null) + if (container == null) { // Brand new site, no write operations on links have happened // Fudge it for now with the site itself, the first write call diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinksPost.java b/source/java/org/alfresco/repo/web/scripts/links/LinksPost.java index 780604a31e..7957c87277 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinksPost.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinksPost.java @@ -40,7 +40,8 @@ public class LinksPost extends AbstractLinksWebScript { @Override protected Map executeImpl(SiteInfo site, String linkName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Get the new link details from the JSON @@ -68,7 +69,7 @@ public class LinksPost extends AbstractLinksWebScript { link = linksService.createLink(site.getShortName(), title, description, url, internal); } - catch(AccessDeniedException e) + catch (AccessDeniedException e) { String message = "You don't have permission to create a link"; @@ -79,7 +80,7 @@ public class LinksPost extends AbstractLinksWebScript } // Set the tags if required - if(tags != null && tags.size() > 0) + if (tags != null && tags.size() > 0) { link.getTags().addAll(tags); linksService.updateLink(link); diff --git a/source/java/org/alfresco/repo/web/scripts/links/LinksRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/links/LinksRestApiTest.java index 0681633dcf..4a311e37dd 100644 --- a/source/java/org/alfresco/repo/web/scripts/links/LinksRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/links/LinksRestApiTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -55,12 +55,13 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * Unit Test to test the Links Web Script API * * @author Nick Burch + * @since 4.0 */ public class LinksRestApiTest extends BaseWebScriptTest { - @SuppressWarnings("unused") + @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(LinksRestApiTest.class); - + private MutableAuthenticationService authenticationService; private AuthenticationComponent authenticationComponent; private TransactionService transactionService; @@ -119,7 +120,7 @@ public class LinksRestApiTest extends BaseWebScriptTest } // Ensure the links container is there - if(!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links")) + if (!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links")) { siteService.createContainer(SITE_SHORT_NAME_LINKS, "links", null, null); } @@ -151,7 +152,7 @@ public class LinksRestApiTest extends BaseWebScriptTest } personService.deletePerson(USER_TWO); - if(this.authenticationService.authenticationExists(USER_TWO)) + if (this.authenticationService.authenticationExists(USER_TWO)) { this.authenticationService.deleteAuthentication(USER_TWO); } @@ -188,14 +189,14 @@ public class LinksRestApiTest extends BaseWebScriptTest private JSONObject getLinks(String filter, String username) throws Exception { String origUser = this.authenticationComponent.getCurrentUserName(); - if(username != null) + if (username != null) { this.authenticationComponent.setCurrentUser(username); filter = "user"; } String url = URL_LINKS_LIST; - if(filter == null) + if (filter == null) { filter = "all"; } @@ -205,7 +206,7 @@ public class LinksRestApiTest extends BaseWebScriptTest Response response = sendRequest(new GetRequest(url), 200); JSONObject result = new JSONObject(response.getContentAsString()); - if(username != null) + if (username != null) { this.authenticationComponent.setCurrentUser(origUser); } @@ -219,7 +220,7 @@ public class LinksRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("item")) + if (result.has("item")) { return result.getJSONObject("item"); } @@ -235,8 +236,7 @@ public class LinksRestApiTest extends BaseWebScriptTest * Creates a single link based on the supplied details */ private JSONObject createLink(String title, String description, String url, - boolean internal, int expectedStatus) - throws Exception + boolean internal, int expectedStatus) throws Exception { JSONObject json = new JSONObject(); json.put("site", SITE_SHORT_NAME_LINKS); @@ -244,7 +244,7 @@ public class LinksRestApiTest extends BaseWebScriptTest json.put("description", description); json.put("url", url); json.put("tags", ""); - if(internal) + if (internal) { json.put("internal", "true"); } @@ -254,7 +254,7 @@ public class LinksRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("link")) + if (result.has("link")) { return result.getJSONObject("link"); } @@ -285,7 +285,7 @@ public class LinksRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("links")) + if (result.has("links")) { return result.getJSONObject("links"); } @@ -320,7 +320,7 @@ public class LinksRestApiTest extends BaseWebScriptTest private JSONObject deleteLinks(List names, int expectedStatus) throws Exception { JSONArray items = new JSONArray(); - for(String name : names) + for (String name : names) { items.put(name); } @@ -370,7 +370,7 @@ public class LinksRestApiTest extends BaseWebScriptTest */ private String getNameFromLink(JSONObject link) throws Exception { - if(! link.has("name")) + if (! link.has("name")) { throw new IllegalArgumentException("No name in " + link.toString()); } @@ -442,29 +442,22 @@ public class LinksRestApiTest extends BaseWebScriptTest // Check the comments url assertEquals( "/node/workspace/" + nodeRef.getStoreRef().getIdentifier() + "/" + nodeRef.getId() + "/comments", - link.getString("commentsUrl") - ); + link.getString("commentsUrl")); // Check the created date assertEquals( ISO8601DateFormat.format((Date)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED)), - link.getJSONObject("createdOnDate").getString("iso8601") - ); - - + link.getJSONObject("createdOnDate").getString("iso8601")); // Edit // We should get a simple message link = updateLink(name, LINK_TITLE_ONE, "More Thing 1", LINK_URL_ONE, true, Status.STATUS_OK); assertEquals( "Incorrect JSON: " + link.toString(), - true, link.has("message") - ); + true, link.has("message")); assertEquals( "Incorrect JSON: " + link.toString(), - true, link.getString("message").contains("updated") - ); - + true, link.getString("message").contains("updated")); // Fetch @@ -508,13 +501,12 @@ public class LinksRestApiTest extends BaseWebScriptTest link = deleteLinks(Arrays.asList(new String[]{name}), Status.STATUS_OK); assertEquals( "Incorrect JSON: " + link.toString(), - true, link.has("message") - ); + true, link.has("message")); + assertEquals( "Incorrect JSON: " + link.toString(), - true, link.getString("message").contains("deleted") - ); - + true, link.getString("message").contains("deleted")); + // Fetch, will have gone link = getLink(name, Status.STATUS_NOT_FOUND); diff --git a/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorGet.java b/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorGet.java index 827b00dc09..567ca48f40 100644 --- a/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorGet.java +++ b/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorGet.java @@ -36,7 +36,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 - * */ public class NodeLocatorGet extends DeclarativeWebScript { @@ -66,7 +65,7 @@ public class NodeLocatorGet extends DeclarativeWebScript String storeType = vars.get(STORE_TYPE); String storeId= vars.get(STORE_ID); String nodeId= vars.get(NODE_ID); - if(storeType!=null && storeId != null && nodeId != null) + if (storeType != null && storeId != null && nodeId != null) { source = new NodeRef(storeType, storeId, nodeId); } @@ -83,7 +82,7 @@ public class NodeLocatorGet extends DeclarativeWebScript private Map mapParams(WebScriptRequest req) { Map params = new HashMap(); - for(String key: req.getParameterNames()) + for (String key: req.getParameterNames()) { String value = req.getParameter(key); if (value != null) @@ -103,5 +102,4 @@ public class NodeLocatorGet extends DeclarativeWebScript { this.locatorService = locatorService; } - } diff --git a/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorWebScriptTest.java b/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorWebScriptTest.java index 8751321058..15d469fa71 100644 --- a/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorWebScriptTest.java +++ b/source/java/org/alfresco/repo/web/scripts/nodelocator/NodeLocatorWebScriptTest.java @@ -49,7 +49,6 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; /** * @author Nick Smith * @since 4.0 - * */ public class NodeLocatorWebScriptTest extends BaseWebScriptTest { @@ -108,7 +107,7 @@ public class NodeLocatorWebScriptTest extends BaseWebScriptTest finally { nodeService.deleteNode(companyChild); - if(site != null) + if (site != null) { siteService.deleteSite(site.getShortName()); } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java index 79440ea2f5..dfec785a0b 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/AuthCallbackWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -35,6 +35,10 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; +/** + * @author Brian + * @since 4.0 + */ public class AuthCallbackWebScript extends DeclarativeWebScript { private final static Log log = LogFactory.getLog(AuthCallbackWebScript.class); diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java index ceeb74cf1b..c2940fbaa2 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/AuthFormGetWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -33,6 +33,10 @@ import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; +/** + * @author Brian + * @since 4.0 + */ public class AuthFormGetWebScript extends DeclarativeWebScript { private ChannelService channelService; diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java index 62144075ca..4e6a0684ef 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelAuthHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -26,6 +26,10 @@ import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.util.UrlUtil; +/** + * @author Brian + * @since 4.0 + */ public class ChannelAuthHelper { private String basePath = "/proxy/alfresco/api/publishing/channels/"; diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java index b99ee1028c..24a0c9bf35 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelPut.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -35,7 +35,6 @@ import org.springframework.extensions.webscripts.WebScriptResponse; /** * @author Nick Smith * @since 4.0 - * */ public class ChannelPut extends AbstractWebScript { @@ -54,7 +53,7 @@ public class ChannelPut extends AbstractWebScript Map params = req.getServiceMatch().getTemplateVars(); String channelId = URLDecoder.decode(params.get(CHANNEL_ID)); Channel channel = channelService.getChannelById(channelId); - if(channel == null) + if (channel == null) { String msg = "No channel found for ID: " + channelId; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); @@ -69,7 +68,7 @@ public class ChannelPut extends AbstractWebScript } parser.updateChannel(channel, content, channelService); } - catch(Exception e) + catch (Exception e) { String msg = "Failed to Rename Channel: " + channelId + ". POST body: " + content; throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java index 5569a69350..b9fa5001e0 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelReauthWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -32,6 +32,10 @@ import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; +/** + * @author Brian + * @since 4.0 + */ public class ChannelReauthWebScript extends DeclarativeWebScript { private ChannelService channelService; diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java index b7005e17a5..7f68d002a1 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypeIconGetWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -33,6 +33,10 @@ import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.util.FileCopyUtils; +/** + * @author Brian + * @since 4.0 + */ public class ChannelTypeIconGetWebScript extends AbstractWebScript { private ChannelService channelService; @@ -85,5 +89,4 @@ public class ChannelTypeIconGetWebScript extends AbstractWebScript FileCopyUtils.copy(in, out); in.close(); } - } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java index 9a58086b61..723cbe1fd9 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelTypesGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -33,7 +33,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 - * */ public class ChannelTypesGet extends DeclarativeWebScript { diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java index 9b3982890b..758d6ee533 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsDeleteWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -31,6 +31,10 @@ import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; +/** + * @author Brian + * @since 4.0 + */ public class ChannelsDeleteWebScript extends AbstractWebScript { private ChannelService channelService; diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java index 2084a3b702..2999957d63 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -40,7 +40,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 - * */ public class ChannelsGet extends DeclarativeWebScript { diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java index ec7789c240..3a29a9721d 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/ChannelsPostWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -28,6 +28,10 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; +/** + * @author Brian + * @since 4.0 + */ public class ChannelsPostWebScript extends DeclarativeWebScript { private ChannelService channelService; diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsGet.java b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsGet.java index 70b619eeb8..a5188ae099 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsGet.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PUblishingEventsGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -37,7 +37,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 - * */ public class PUblishingEventsGet extends PublishingWebScript { @@ -49,7 +48,7 @@ public class PUblishingEventsGet extends PublishingWebScript { Map params = req.getServiceMatch().getTemplateVars(); NodeRef node = WebScriptUtil.getNodeRef(params); - if(node == null) + if (node == null) { String msg = "A valid NodeRef must be specified!"; throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg); @@ -60,7 +59,7 @@ public class PUblishingEventsGet extends PublishingWebScript List> model = builder.buildPublishingEventsForNode(events, node, channelService); return WebScriptUtil.createBaseModel(model); } - catch(Exception e) + catch (Exception e) { String msg = "Failed to query for publishing events for node: " + node; throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java index 9373ee9325..c95d622d9c 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingJsonParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -42,14 +42,12 @@ import org.json.JSONTokener; /** * @author Nick Smith * @since 4.0 - * */ public class PublishingJsonParser implements PublishingWebScriptConstants { - public JSONObject getJson(String jsonStr) throws JSONException { - if(jsonStr!=null && jsonStr.isEmpty()==false) + if (jsonStr != null && jsonStr.isEmpty() == false) { return new JSONObject(new JSONTokener(jsonStr)); } @@ -60,7 +58,7 @@ public class PublishingJsonParser implements PublishingWebScriptConstants { JSONObject json = getJson(jsonStr); String newName = json.optString(NAME); - if(newName != null && newName.isEmpty() == false) + if (newName != null && newName.isEmpty() == false) { channelService.renameChannel(channel, newName); } @@ -82,7 +80,7 @@ public class PublishingJsonParser implements PublishingWebScriptConstants public PublishingDetails setStatusUpdate(PublishingDetails details, JSONObject json) { - if(json != null) + if (json != null) { details.setStatusMessage(json.optString(MESSAGE)); String nodeStr = json.optString(NODE_REF); @@ -103,7 +101,7 @@ public class PublishingJsonParser implements PublishingWebScriptConstants private List toStrings(JSONArray json) { - if(json == null || json.length() == 0) + if (json == null || json.length() == 0) { return Collections.emptyList(); } @@ -114,5 +112,4 @@ public class PublishingJsonParser implements PublishingWebScriptConstants } return results; } - } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java index 7ed388ef29..9a9274d734 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingModelBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -46,7 +46,6 @@ import org.springframework.extensions.surf.util.URLEncoder; /** * @author Nick Smith * @since 4.0 - * */ public class PublishingModelBuilder implements PublishingWebScriptConstants { @@ -87,7 +86,7 @@ public class PublishingModelBuilder implements PublishingWebScriptConstants String channelId = event.getChannelId(); Channel channel = channelService.getChannelById(channelId); - if(channel!= null) + if (channel!= null) { model.put(CHANNEL, buildChannel(channel)); } @@ -224,16 +223,15 @@ public class PublishingModelBuilder implements PublishingWebScriptConstants NodeSnapshot snapshot = entry.getSnapshot(); model.put(NODEREF, entry.getNodeRef().toString()); String version = snapshot.getVersion(); - if(version!=null && version.isEmpty()==false) + if (version != null && version.isEmpty() == false) { model.put(VERSION, version); } String name = (String) snapshot.getProperties().get(ContentModel.PROP_NAME); - if(name != null && name.isEmpty() == false) + if (name != null && name.isEmpty() == false) { model.put(NAME, name); } return model; } - } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java index 069169fad5..f6589da9e9 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingQueuePost.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -33,7 +33,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Smith * @since 4.0 - * */ public class PublishingQueuePost extends PublishingWebScript { @@ -47,7 +46,7 @@ public class PublishingQueuePost extends PublishingWebScript try { content = WebScriptUtil.getContent(req); - if(content == null || content.isEmpty()) + if (content == null || content.isEmpty()) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "No publishing event was posted!"); } @@ -56,15 +55,14 @@ public class PublishingQueuePost extends PublishingWebScript Map eventModel = builder.buildPublishingEvent(event, channelService); return WebScriptUtil.createBaseModel(eventModel); } - catch(WebScriptException we) + catch (WebScriptException we) { throw we; } - catch(Exception e) + catch (Exception e) { String msg = "Failed to schedule publishing event. POST body: " + content; throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } } - } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java index fb97e6814c..51734b1194 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingRestApiTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -118,7 +118,6 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; /** * @author Nick Smith * @since 4.0 - * */ public class PublishingRestApiTest extends BaseWebScriptTest { @@ -481,7 +480,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest for (int i = 0; i < data.length(); i++) { JSONObject json = data.optJSONObject(i); - if(typeId.equals(json.optString(ID))) + if (typeId.equals(json.optString(ID))) { checkChannelType(json, type); return; @@ -504,7 +503,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest for (int i = 0; i < data.length(); i++) { JSONObject json = data.optJSONObject(i); - if(eventId.equals(json.optString(ID))) + if (eventId.equals(json.optString(ID))) { PublishingEvent event = publishingService.getPublishingEvent(eventId); checkJsonEvent(event, json); @@ -555,7 +554,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); - if(nodeId.equals(json.getString(NODE_REF))) + if (nodeId.equals(json.getString(NODE_REF))) { checkNode(entry, json); return; @@ -568,12 +567,12 @@ public class PublishingRestApiTest extends BaseWebScriptTest { NodeSnapshot snapshot = entry.getSnapshot(); String version = snapshot.getVersion(); - if(version != null && version.isEmpty() == false) + if (version != null && version.isEmpty() == false) { assertEquals(version, json.getString(VERSION)); } String name = (String) snapshot.getProperties().get(ContentModel.PROP_NAME); - if(name != null && name.isEmpty() == false) + if (name != null && name.isEmpty() == false) { assertEquals(name, json.getString(NAME)); } @@ -602,7 +601,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest json.put(CHANNEL_ID, publishChannel.getId()); json.put(COMMENT, comment); Collection publishNodes = Collections.singleton(node.toString()); - if(publish) + if (publish) { json.put(PUBLISH_NODES, publishNodes); } @@ -610,7 +609,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest { json.put(UNPUBLISH_NODES, publishNodes); } - if(statusMessage != null) + if (statusMessage != null) { json.put(STATUS_UPDATE, buildStatusUpdate(statusMessage, node, statusChannels)); } @@ -649,7 +648,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest { JSONObject jsonChannel = json.getJSONObject(i); String name = jsonChannel.getString(NAME); - if(channel.getName().equals(name)) + if (channel.getName().equals(name)) { checkChannel(jsonChannel, channel); return; @@ -719,7 +718,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest { for (int i = 0; i < json.length(); i++) { - if(string.equals(json.getString(i))) + if (string.equals(json.getString(i))) { return; } diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java index 3fbee83c9c..829ce0cde5 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -27,7 +27,6 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript; /** * @author Nick Smith * @since 4.0 - * */ public abstract class PublishingWebScript extends DeclarativeWebScript { diff --git a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java index dc374c95dc..f81aff874b 100644 --- a/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java +++ b/source/java/org/alfresco/repo/web/scripts/publishing/PublishingWebScriptConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -22,7 +22,6 @@ package org.alfresco.repo.web.scripts.publishing; /** * @author Nick Smith * @since 4.0 - * */ public interface PublishingWebScriptConstants { @@ -74,5 +73,4 @@ public interface PublishingWebScriptConstants public static final String URL_LENGTH = "urlLength"; public static final String PUBLISHING_CHANNELS = "publishChannels"; public static final String STATUS_UPDATE_CHANNELS = "statusUpdateChannels"; - } diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/AbstractWikiWebScript.java b/source/java/org/alfresco/repo/web/scripts/wiki/AbstractWikiWebScript.java index 7d441df482..4ef27194fc 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/AbstractWikiWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/AbstractWikiWebScript.java @@ -95,7 +95,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript protected String getOrNull(JSONObject json, String key) { - if(json.containsKey(key)) + if (json.containsKey(key)) { return (String)json.get(key); } @@ -112,26 +112,26 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript int pageNumber = 1; 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 pageNumberS = req.getParameter("page"); - if(pageNumberS != null) + if (pageNumberS != null) { try { pageNumber = Integer.parseInt(pageNumberS); } - catch(NumberFormatException e) + catch (NumberFormatException e) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid"); } @@ -150,14 +150,14 @@ public abstract class AbstractWikiWebScript 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 = "wiki"; @@ -176,10 +176,9 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript "org.alfresco.wiki.page-" + event, site.getShortName(), WIKI_SERVICE_ACTIVITY_APP_NAME, - activityJson.toString() - ); + activityJson.toString()); } - catch(Exception e) + catch (Exception e) { // Warn, but carry on logger.warn("Error adding wiki page " + event + " to activities feed", e); @@ -188,7 +187,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript protected Object buildPerson(String username) { - if(username == null || username.length() == 0) + if (username == null || username.length() == 0) { // Empty string needed return ""; @@ -220,9 +219,9 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript res.put("modifiedBY", buildPerson(page.getModifier())); // We want blank instead of null - for(String key : res.keySet()) + for (String key : res.keySet()) { - if(res.get(key) == null) + if (res.get(key) == null) { res.put(key, ""); } @@ -236,7 +235,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript Status status, Cache cache) { Map templateVars = req.getServiceMatch().getTemplateVars(); - if(templateVars == null) + if (templateVars == null) { String error = "No parameters supplied"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); @@ -246,22 +245,22 @@ public abstract class AbstractWikiWebScript 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()); } @@ -270,17 +269,17 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript // Get the site short name. Try quite hard to do so... String siteName = templateVars.get("siteId"); - if(siteName == null) + if (siteName == null) { siteName = req.getParameter("site"); } - if(siteName == null && json != null) + if (siteName == null && json != null) { - if(json.containsKey("siteid")) + if (json.containsKey("siteid")) { siteName = (String)json.get("siteid"); } - else if(json.containsKey("siteId")) + else if (json.containsKey("siteId")) { siteName = (String)json.get("siteId"); } @@ -289,7 +288,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript siteName = (String)json.get("site"); } } - if(siteName == null) + if (siteName == null) { String error = "No site given"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); @@ -297,7 +296,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript // Grab the requested site SiteInfo 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); @@ -314,5 +313,4 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript protected abstract Map executeImpl(SiteInfo site, String pageName, WebScriptRequest req, JSONObject json, Status status, Cache cache); - } diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageDelete.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageDelete.java index aa90b43559..c4d7147b43 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageDelete.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageDelete.java @@ -39,12 +39,13 @@ public class WikiPageDelete extends AbstractWikiWebScript { @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Try to find the page WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName); - if(page == null) + if (page == null) { String message = "The Wiki Page could not be found"; throw new WebScriptException(Status.STATUS_NOT_FOUND, message); diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageGet.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageGet.java index 275a005c67..9599351125 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageGet.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageGet.java @@ -49,12 +49,13 @@ public class WikiPageGet extends AbstractWikiWebScript @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Try to find the page WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName); - if(page == null) + if (page == null) { String message = "The Wiki Page could not be found"; status.setCode(Status.STATUS_NOT_FOUND); @@ -63,10 +64,10 @@ public class WikiPageGet extends AbstractWikiWebScript // Grab the container, used in permissions checking NodeRef container = siteService.getContainer( - site.getShortName(), WikiServiceImpl.WIKI_COMPONENT - ); + site.getShortName(), WikiServiceImpl.WIKI_COMPONENT); + // If there's no container yet, the site will do for permissions - if(container == null) + if (container == null) { container = site.getNodeRef(); } @@ -83,13 +84,13 @@ public class WikiPageGet extends AbstractWikiWebScript // Identify all the internal page links, valid and not // TODO This may be a candidate for the service in future List links = new ArrayList(); - if(page.getContents() != null) + if (page.getContents() != null) { Matcher m = LINK_PATTERN.matcher(page.getContents()); - while(m.find()) + while (m.find()) { String link = m.group(1); - if(! links.contains(link)) + if (! links.contains(link)) { links.add(link); } diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageListGet.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageListGet.java index d2230a17b9..b93c46d11f 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageListGet.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageListGet.java @@ -49,14 +49,15 @@ public class WikiPageListGet extends AbstractWikiWebScript @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { // Decide on what kind of request they wanted String filter = req.getParameter("filter"); // User? boolean userFiltering = false; String user = null; - if("user".equals(filter) || "myPages".equals(filter)) + if ("user".equals(filter) || "myPages".equals(filter)) { userFiltering = true; user = AuthenticationUtil.getFullyAuthenticatedUser(); @@ -67,19 +68,19 @@ public class WikiPageListGet extends AbstractWikiWebScript boolean dateIsCreated = true; Date from = null; Date to = null; - if("recentlyAdded".equals(filter) || - "recentlyCreated".equals(filter) || - "recentlyModified".equals(filter)) + if ("recentlyAdded".equals(filter) || + "recentlyCreated".equals(filter) || + "recentlyModified".equals(filter)) { dateFiltering = true; - if("recentlyModified".equals(filter)) + if ("recentlyModified".equals(filter)) { dateIsCreated = false; } int days = RECENT_SEARCH_PERIOD_DAYS; String daysS = req.getParameter("days"); - if(daysS != null && daysS.length() > 0) + if (daysS != null && daysS.length() > 0) { days = Integer.parseInt(daysS); } @@ -93,13 +94,13 @@ public class WikiPageListGet extends AbstractWikiWebScript // Get the links for the list PagingRequest paging = buildPagingRequest(req); PagingResults pages; - if(userFiltering) + if (userFiltering) { pages = wikiService.listWikiPages(site.getShortName(), user, paging); } - else if(dateFiltering) + else if (dateFiltering) { - if(dateIsCreated) + if (dateIsCreated) { pages = wikiService.listWikiPagesByCreated(site.getShortName(), from, to, paging); } @@ -128,7 +129,7 @@ public class WikiPageListGet extends AbstractWikiWebScript data.put("itemCount", items.size()); int total = items.size(); - if(pages.getTotalResultCount() != null && pages.getTotalResultCount().getFirst() != null) + if (pages.getTotalResultCount() != null && pages.getTotalResultCount().getFirst() != null) { total = pages.getTotalResultCount().getFirst(); } @@ -136,7 +137,7 @@ public class WikiPageListGet extends AbstractWikiWebScript // We need the container node for permissions checking NodeRef container; - if(pages.getPage().size() > 0) + if (pages.getPage().size() > 0) { container = pages.getPage().get(0).getContainerNodeRef(); } @@ -144,10 +145,9 @@ public class WikiPageListGet extends AbstractWikiWebScript { // Find the container (if it's been created yet) container = siteService.getContainer( - site.getShortName(), WikiServiceImpl.WIKI_COMPONENT - ); + site.getShortName(), WikiServiceImpl.WIKI_COMPONENT); - if(container == null) + if (container == null) { // Brand new site, no write operations on links have happened // Fudge it for now with the site itself, the first write call diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageMovePost.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageMovePost.java index 58b76257c6..7b4aa2c58f 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageMovePost.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageMovePost.java @@ -25,7 +25,6 @@ import java.util.ResourceBundle; import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.wiki.WikiPageInfo; -import org.json.JSONException; import org.json.simple.JSONObject; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; @@ -48,13 +47,14 @@ public class WikiPageMovePost extends AbstractWikiWebScript @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { final Map model = new HashMap(); final ResourceBundle rb = getResources(); // Try to find the page we're renaming WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName); - if(page == null) + if (page == null) { String message = "The Wiki Page could not be found"; status.setCode(Status.STATUS_NOT_FOUND); @@ -80,7 +80,7 @@ public class WikiPageMovePost extends AbstractWikiWebScript page.setTitle(newTitle); page = wikiService.updateWikiPage(page); } - catch(FileExistsException e) + catch (FileExistsException e) { throw new WebScriptException(Status.STATUS_CONFLICT, "Duplicate page name"); } diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPagePut.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPagePut.java index 258a0a3266..fe942809bd 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPagePut.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPagePut.java @@ -55,7 +55,8 @@ public class WikiPagePut extends AbstractWikiWebScript @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Grab the details of the change @@ -64,7 +65,7 @@ public class WikiPagePut extends AbstractWikiWebScript // Fetch the title, used only when creating String title; - if(json.containsKey("title")) + if (json.containsKey("title")) { title = (String)json.get("title"); } @@ -76,17 +77,17 @@ public class WikiPagePut extends AbstractWikiWebScript // Fetch the versioning details boolean forceSave = json.containsKey("forceSave"); String currentVersion = null; - if(json.containsKey("currentVersion")) + if (json.containsKey("currentVersion")) { currentVersion = (String)json.get("currentVersion"); } // Fetch the tags, if given List tags = null; - if(json.containsKey("tags")) + if (json.containsKey("tags")) { tags = new ArrayList(); - if(json.get("tags").equals("")) + if (json.get("tags").equals("")) { // Empty list given as a string, eg "tags":"" } @@ -94,7 +95,7 @@ public class WikiPagePut extends AbstractWikiWebScript { // Array of tags JSONArray tagsA = (JSONArray)json.get("tags"); - for(int i=0; i 0) + if (tags != null && tags.size() > 0) { page.getTags().addAll(tags); wikiService.updateWikiPage(page); @@ -124,11 +125,11 @@ public class WikiPagePut extends AbstractWikiWebScript else { // Updating, check about versioning first - if(forceSave || pageVersionMatchesSubmitted(page, currentVersion)) + if (forceSave || pageVersionMatchesSubmitted(page, currentVersion)) { // Update the page page.setContents(contents); - if(tags != null && tags.size() > 0) + if (tags != null && tags.size() > 0) { page.getTags().clear(); page.getTags().addAll(tags); @@ -161,14 +162,14 @@ public class WikiPagePut extends AbstractWikiWebScript private boolean pageVersionMatchesSubmitted(WikiPageInfo page, String currentVersion) { // If they didn't give version, it can't be right - if(currentVersion == null) + if (currentVersion == null) { return false; } // Grab the current version Version version = versionService.getCurrentVersion(page.getNodeRef()); - if(version == null) + if (version == null) { // It should be versioned already, fix that makeVersioned(page); @@ -178,7 +179,7 @@ public class WikiPagePut extends AbstractWikiWebScript } // Check the label - if(version.getVersionLabel().equals(currentVersion)) + if (version.getVersionLabel().equals(currentVersion)) { // Match, no changes return true; diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageVersionGet.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageVersionGet.java index badf48a44b..d66a028dce 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageVersionGet.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiPageVersionGet.java @@ -54,25 +54,27 @@ public class WikiPageVersionGet extends AbstractWikiWebScript private ContentService contentService; private VersionService versionService; + public void setVersionService(VersionService versionService) { this.versionService = versionService; } + public void setContentService(ContentService contentService) { this.contentService = contentService; } - @Override protected Map executeImpl(SiteInfo site, String pageName, - WebScriptRequest req, JSONObject json, Status status, Cache cache) { + WebScriptRequest req, JSONObject json, Status status, Cache cache) + { Map model = new HashMap(); // Grab the version string Map templateVars = req.getServiceMatch().getTemplateVars(); String versionId = templateVars.get("versionId"); - if(versionId == null) + if (versionId == null) { String error = "No versionId supplied"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); @@ -80,7 +82,7 @@ public class WikiPageVersionGet extends AbstractWikiWebScript // Try to find the page WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName); - if(page == null) + if (page == null) { String message = "The Wiki Page could not be found"; status.setCode(Status.STATUS_NOT_FOUND); @@ -99,9 +101,9 @@ public class WikiPageVersionGet extends AbstractWikiWebScript { versionHistory = versionService.getVersionHistory(page.getNodeRef()); } - catch(AspectMissingException e) {} + catch (AspectMissingException e) {} - if(versionHistory == null) + if (versionHistory == null) { // Not been versioned, return an empty string model.put(PARAM_CONTENT, ""); @@ -111,23 +113,23 @@ public class WikiPageVersionGet extends AbstractWikiWebScript // Fetch the version by either ID or Label Matcher m = LABEL_PATTERN.matcher(versionId); - if(m.matches()) + if (m.matches()) { // It's a version label like 2.3 try { version = versionHistory.getVersion(versionId); } - catch(VersionDoesNotExistException e) {} + catch (VersionDoesNotExistException e) {} } else { // It's a version ID like ed00bac1-f0da-4042-8598-45a0d39cb74d // (The ID is usually part of the NodeRef of the frozen node, but we // don't assume to be able to just generate the full NodeRef) - for(Version v : versionHistory.getAllVersions()) + for (Version v : versionHistory.getAllVersions()) { - if(v.getFrozenStateNodeRef().getId().equals(versionId)) + if (v.getFrozenStateNodeRef().getId().equals(versionId)) { version = v; } @@ -137,10 +139,10 @@ public class WikiPageVersionGet extends AbstractWikiWebScript // Did we find the right version in the end? String contents; - if(version != null) + if (version != null) { ContentReader reader = contentService.getReader(version.getFrozenStateNodeRef(), ContentModel.PROP_CONTENT); - if(reader != null) + if (reader != null) { contents = reader.getContentString(); } diff --git a/source/java/org/alfresco/repo/web/scripts/wiki/WikiRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/wiki/WikiRestApiTest.java index 47d107f763..74fafb3c22 100644 --- a/source/java/org/alfresco/repo/web/scripts/wiki/WikiRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/wiki/WikiRestApiTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -54,12 +54,13 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; * Unit Test to test the Wiki Web Script API * * @author Nick Burch + * @since 4.0 */ public class WikiRestApiTest extends BaseWebScriptTest { - @SuppressWarnings("unused") + @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(WikiRestApiTest.class); - + private MutableAuthenticationService authenticationService; private AuthenticationComponent authenticationComponent; private TransactionService transactionService; @@ -191,14 +192,14 @@ public class WikiRestApiTest extends BaseWebScriptTest private JSONObject getPages(String filter, String username) throws Exception { String origUser = this.authenticationComponent.getCurrentUserName(); - if(username != null) + if (username != null) { this.authenticationComponent.setCurrentUser(username); filter = "myPages"; } String url = URL_WIKI_LIST; - if(filter == null) + if (filter == null) { filter = "all"; } @@ -208,7 +209,7 @@ public class WikiRestApiTest extends BaseWebScriptTest Response response = sendRequest(new GetRequest(url), 200); JSONObject result = new JSONObject(response.getContentAsString()); - if(username != null) + if (username != null) { this.authenticationComponent.setCurrentUser(origUser); } @@ -222,13 +223,13 @@ public class WikiRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("page")) + if (result.has("page")) { return result.getJSONObject("page"); } return result; } - else if(expectedStatus == Status.STATUS_NOT_FOUND) + else if (expectedStatus == Status.STATUS_NOT_FOUND) { JSONObject result = new JSONObject(response.getContentAsString()); return result; @@ -250,7 +251,7 @@ public class WikiRestApiTest extends BaseWebScriptTest { return response.getContentAsString(); } - else if(expectedStatus == Status.STATUS_NOT_FOUND) + else if (expectedStatus == Status.STATUS_NOT_FOUND) { return response.getContentAsString(); } @@ -275,14 +276,14 @@ public class WikiRestApiTest extends BaseWebScriptTest json.put("tags", ""); json.put("page", "wiki-page"); // TODO Is this really needed? - if(version == null || "force".equals(version)) + if (version == null || "force".equals(version)) { // Allow the save as-is, no versioning check json.put("forceSave", "true"); // Allow the save as-is } else { - if("none".equals(version)) + if ("none".equals(version)) { // No versioning } @@ -296,7 +297,7 @@ public class WikiRestApiTest extends BaseWebScriptTest if (expectedStatus == Status.STATUS_OK) { JSONObject result = new JSONObject(response.getContentAsString()); - if(result.has("page")) + if (result.has("page")) { return result.getJSONObject("page"); } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java index 2554e5f837..f9583ce2be 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowRestApiTest.java @@ -93,9 +93,9 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest protected static final String COMPANY_HOME = "/app:company_home"; protected static final String TEST_CONTENT = "TestContent"; - protected static final String ADHOC_START_TASK_TYPE = "wf:submitAdhocTask"; - protected static final String ADHOC_TASK_TYPE = "wf:adhocTask"; - protected static final String ADHOC_TASK_COMPLETED_TYPE = "wf:completedAdhocTask"; + protected static final String ADHOC_START_TASK_TYPE = "wf:submitAdhocTask"; + protected static final String ADHOC_TASK_TYPE = "wf:adhocTask"; + protected static final String ADHOC_TASK_COMPLETED_TYPE = "wf:completedAdhocTask"; private TestPersonManager personManager; @@ -106,10 +106,10 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest private NamespaceService namespaceService; private NodeRef packageRef; private NodeRef contentNodeRef; - private AuthenticationComponent authenticationComponent; + private AuthenticationComponent authenticationComponent; + + private List workflows = new LinkedList(); - private List workflows = new LinkedList(); - public void testTaskInstancesGet() throws Exception { // Check USER2 starts with no tasks. @@ -385,7 +385,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest // Finish the start-task, and fetch it again workflowService.endTask(startTask.getId(), null); startTask = workflowService.getTaskById(startTask.getId()); - + response = sendRequest(new GetRequest(URL_TASKS + "/" + startTask.getId()), Status.STATUS_OK); jsonStr = response.getContentAsString(); json = new JSONObject(jsonStr); @@ -464,44 +464,44 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest checkWorkflowTaskDefinition(firstTask.getDefinition(), result.getJSONObject("definition")); } - private void checkWorkflowTaskPropertiesPresent(JSONObject taskJson) throws Exception - { - JSONObject properties = taskJson.getJSONObject("properties"); + private void checkWorkflowTaskPropertiesPresent(JSONObject taskJson) throws Exception + { + JSONObject properties = taskJson.getJSONObject("properties"); assertNotNull(properties); assertTrue(properties.has("bpm_priority")); assertTrue(properties.has("bpm_description")); assertTrue(properties.has("bpm_reassignable")); - } - - private void checkWorkflowTaskReadOnly(JSONObject taskJson) throws Exception - { - // Task shouldn't be editable and reassignable, since it's completed + } + + private void checkWorkflowTaskReadOnly(JSONObject taskJson) throws Exception + { + // Task shouldn't be editable and reassignable, since it's completed assertFalse(taskJson.getBoolean("isPooled")); assertFalse(taskJson.getBoolean("isEditable")); assertFalse(taskJson.getBoolean("isReassignable")); assertFalse(taskJson.getBoolean("isClaimable")); assertFalse(taskJson.getBoolean("isReleasable")); - } + } - private void checkWorkflowTaskOwner(JSONObject taskJson, String user) throws Exception - { - JSONObject owner = taskJson.getJSONObject("owner"); + private void checkWorkflowTaskOwner(JSONObject taskJson, String user) throws Exception + { + JSONObject owner = taskJson.getJSONObject("owner"); assertEquals(user, owner.getString("userName")); assertEquals(personManager.getFirstName(user), owner.getString("firstName")); assertEquals(personManager.getLastName(user), owner.getString("lastName")); - } + } - private void checkWorkflowTaskEditable(JSONObject taskJson) throws Exception - { - assertFalse(taskJson.getBoolean("isPooled")); + private void checkWorkflowTaskEditable(JSONObject taskJson) throws Exception + { + assertFalse(taskJson.getBoolean("isPooled")); assertTrue(taskJson.getBoolean("isEditable")); assertTrue(taskJson.getBoolean("isReassignable")); assertFalse(taskJson.getBoolean("isClaimable")); assertFalse(taskJson.getBoolean("isReleasable")); - } + } - private void checkWorkflowInstance(WorkflowInstance wfInstance, JSONObject instance) throws Exception - { + private void checkWorkflowInstance(WorkflowInstance wfInstance, JSONObject instance) throws Exception + { assertNotNull(instance); assertEquals(wfInstance.getId(), instance.getString("id")); assertTrue(instance.has("url")); @@ -516,17 +516,17 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest assertEquals(USER1, initiator.getString("userName")); assertEquals(personManager.getFirstName(USER1), initiator.getString("firstName")); assertEquals(personManager.getLastName(USER1), initiator.getString("lastName")); - } + } - private void checkWorkflowTaskDefinition(WorkflowTaskDefinition wfDefinition, JSONObject definition) throws Exception - { + private void checkWorkflowTaskDefinition(WorkflowTaskDefinition wfDefinition, JSONObject definition) throws Exception + { assertNotNull(definition); - assertEquals(wfDefinition.getId(), definition.getString("id")); + assertEquals(wfDefinition.getId(), definition.getString("id")); assertTrue(definition.has("url")); JSONObject type = definition.getJSONObject("type"); - TypeDefinition startType = (wfDefinition).getMetadata(); + TypeDefinition startType = (wfDefinition).getMetadata(); assertNotNull(type); @@ -536,7 +536,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest assertTrue(type.has("url")); JSONObject node = definition.getJSONObject("node"); - WorkflowNode startNode = wfDefinition.getNode(); + WorkflowNode startNode = wfDefinition.getNode(); assertNotNull(node); @@ -559,7 +559,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest assertNotNull(transition); - if(startTransition.getId() == null) + if (startTransition.getId() == null) { assertEquals("", transition.getString("id")); } @@ -678,7 +678,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest public void testTaskInstancePutCompletedTask() throws Exception { - // Start workflow as USER1 and assign to self + // Start workflow as USER1 and assign to self personManager.setUser(USER1); WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName()); Map params = new HashMap(); @@ -746,7 +746,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest { assertEquals(getAdhocWorkflowDefinitionTitle(), title); assertEquals(getAdhocWorkflowDefinitionDescription(), description); - adhocWorkflowPresent = true; + adhocWorkflowPresent = true; } } @@ -806,13 +806,11 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest public void testWorkflowDefinitionGet() throws Exception { - - // Get the latest definition for the adhoc-workflow - WorkflowDefinition wDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName()); - - String responseUrl = MessageFormat.format( - URL_WORKFLOW_DEFINITION, wDef.getId()); - + // Get the latest definition for the adhoc-workflow + WorkflowDefinition wDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName()); + + String responseUrl = MessageFormat.format(URL_WORKFLOW_DEFINITION, wDef.getId()); + Response response = sendRequest(new GetRequest(responseUrl), Status.STATUS_OK); JSONObject json = new JSONObject(response.getContentAsString()); JSONObject workflowDefinitionJSON = json.getJSONObject("data"); @@ -839,8 +837,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest assertTrue(workflowDefinitionJSON.has("startTaskDefinitionUrl")); String startTaskDefUrl = workflowDefinitionJSON.getString("startTaskDefinitionUrl"); - assertEquals(startTaskDefUrl, "api/classes/" - + getSafeDefinitionName(ADHOC_START_TASK_TYPE)); + assertEquals(startTaskDefUrl, "api/classes/" + getSafeDefinitionName(ADHOC_START_TASK_TYPE)); assertTrue(workflowDefinitionJSON.has("startTaskDefinitionType")); assertEquals(ADHOC_START_TASK_TYPE, workflowDefinitionJSON.getString("startTaskDefinitionType")); @@ -863,20 +860,20 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest private void checkTaskDefinitionTypeAndUrl(String expectedTaskType, JSONObject taskDefinition) throws Exception { - // Check type + // Check type assertTrue(taskDefinition.has("type")); assertEquals(expectedTaskType, taskDefinition.getString("type")); // Check URL assertTrue(taskDefinition.has("url")); - assertEquals("api/classes/" - + getSafeDefinitionName(expectedTaskType), taskDefinition.getString("url")); + assertEquals("api/classes/" + + getSafeDefinitionName(expectedTaskType), taskDefinition.getString("url")); } - private String getSafeDefinitionName(String definitionName) { - return definitionName.replace(":", "_"); - } - + private String getSafeDefinitionName(String definitionName) + { + return definitionName.replace(":", "_"); + } public void testWorkflowInstanceGet() throws Exception { @@ -1010,7 +1007,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest checkFiltering(URL_WORKFLOW_INSTANCES + "?startedAfter=" + ISO8601DateFormat.format(anHourAgo)); // filter by startedBefore - checkFiltering(URL_WORKFLOW_INSTANCES + "?startedBefore=" + ISO8601DateFormat.format(anHourLater)); + checkFiltering(URL_WORKFLOW_INSTANCES + "?startedBefore=" + ISO8601DateFormat.format(anHourLater)); // filter by dueAfter checkFiltering(URL_WORKFLOW_INSTANCES + "?dueAfter=" + ISO8601DateFormat.format(anHourAgo)); @@ -1064,7 +1061,8 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest break; } } - assertFalse("Found adhoc workflows when they were supposed to be excluded", adhocWorkflowPresent); + + assertFalse("Found adhoc workflows when they were supposed to be excluded", adhocWorkflowPresent); } public void testWorkflowInstancesForNodeGet() throws Exception @@ -1141,7 +1139,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + instanceId), Status.STATUS_OK); WorkflowInstance instance = workflowService.getWorkflowById(instanceId); - if(instance!=null) + if (instance != null) { assertFalse("The deleted workflow is still active!", instance.isActive()); } @@ -1158,26 +1156,26 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest public void testReviewProcessFlow() throws Exception { - // Approve path - runReviewFlow(true); - - // Create package again, since WF is deleteds - packageRef = workflowService.createPackage(null); - - // Reject path - runReviewFlow(false); + // Approve path + runReviewFlow(true); + + // Create package again, since WF is deleteds + packageRef = workflowService.createPackage(null); + + // Reject path + runReviewFlow(false); } public void testReviewPooledProcessFlow() throws Exception { - // Approve path - runReviewPooledFlow(true); - - // Create package again, since WF is deleteds - packageRef = workflowService.createPackage(null); - - // Reject path - runReviewPooledFlow(false); + // Approve path + runReviewPooledFlow(true); + + // Create package again, since WF is deleteds + packageRef = workflowService.createPackage(null); + + // Reject path + runReviewPooledFlow(false); } protected void runReviewFlow(boolean approve) throws Exception @@ -1416,7 +1414,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest { workflowService.cancelWorkflow(id); } - catch(Throwable t) + catch (Throwable t) { // Do nothing } @@ -1493,42 +1491,41 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest private void checkPriorityFiltering(String url) throws Exception { - JSONObject json = getDataFromRequest(url); - JSONArray result = json.getJSONArray("data"); - assertNotNull(result); - assertTrue(result.length() > 0); - - for(int i=0; i 0); + + for (int i=0; i taskIds = Arrays.asList(ids); - JSONObject json = getDataFromRequest(url); - JSONArray result = json.getJSONArray("data"); - assertNotNull(result); - - ArrayList resultIds = new ArrayList(result.length()); - for(int i=0; i resultIds = new ArrayList(result.length()); + for (int i=0; i resultIds = new ArrayList(result.length()); - for(int i=0; i expectedProperties) throws Exception { - JSONObject data = getDataFromRequest(MessageFormat.format(URL_USER_TASKS_PROPERTIES, USER2, propertiesParamValue)); - JSONArray taskArray = data.getJSONArray("data"); - assertEquals(1, taskArray.length()); - - JSONObject taskProperties = taskArray.getJSONObject(0).getJSONObject("properties"); - assertNotNull(taskProperties); - - int expectedNumberOfProperties = 0; - if(expectedProperties != null) - { - expectedNumberOfProperties = expectedProperties.size(); - } - // Check right number of properties - assertEquals(expectedNumberOfProperties, taskProperties.length()); + JSONObject data = getDataFromRequest(MessageFormat.format(URL_USER_TASKS_PROPERTIES, USER2, propertiesParamValue)); + JSONArray taskArray = data.getJSONArray("data"); + assertEquals(1, taskArray.length()); - // Check if all properties are present - if(expectedProperties != null) - { - for(String prop : expectedProperties) - { - assertTrue(taskProperties.has(prop)); - } - } + JSONObject taskProperties = taskArray.getJSONObject(0).getJSONObject("properties"); + assertNotNull(taskProperties); + + int expectedNumberOfProperties = 0; + if(expectedProperties != null) + { + expectedNumberOfProperties = expectedProperties.size(); + } + // Check right number of properties + assertEquals(expectedNumberOfProperties, taskProperties.length()); + + // Check if all properties are present + if (expectedProperties != null) + { + for (String prop : expectedProperties) + { + assertTrue(taskProperties.has(prop)); + } + } } private void checkFiltering(String url) throws Exception diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowWebscript.java b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowWebscript.java index c666fe49a3..aaeace423e 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowWebscript.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/AbstractWorkflowWebscript.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/ActivitiWorkflowRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/workflow/ActivitiWorkflowRestApiTest.java index 5a1bd1ea16..fd06472f71 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/ActivitiWorkflowRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/ActivitiWorkflowRestApiTest.java @@ -24,59 +24,64 @@ import java.util.HashMap; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +/** + * @author Nick Smith + * @author Frederik Heremans + * @since 3.4.e + */ public class ActivitiWorkflowRestApiTest extends AbstractWorkflowRestApiTest { + private static final String ADHOC_WORKFLOW_DEFINITION_NAME = "activiti$activitiAdhoc"; + private static final String ADHOC_WORKFLOW_DEFINITION_TITLE = "Adhoc Workflow"; + private static final String ADHOC_WORKFLOW_DEFINITION_DESCRIPTION = "Assign arbitrary task to colleague using Activiti workflow engine"; + private static final String REVIEW_WORKFLOW_DEFINITION_NAME = "activiti$activitiReview"; + private static final String REVIEW_POOLED_WORKFLOW_DEFINITION_NAME = "activiti$activitiReviewPooled"; + + @Override + protected String getAdhocWorkflowDefinitionName() + { + return ADHOC_WORKFLOW_DEFINITION_NAME; + } + + @Override + protected String getAdhocWorkflowDefinitionTitle() + { + return ADHOC_WORKFLOW_DEFINITION_TITLE; + } + + @Override + protected String getAdhocWorkflowDefinitionDescription() + { + return ADHOC_WORKFLOW_DEFINITION_DESCRIPTION; + } + + @Override + protected String getReviewWorkflowDefinitionName() + { + return REVIEW_WORKFLOW_DEFINITION_NAME; + } + + @Override + protected String getReviewPooledWorkflowDefinitionName() + { + return REVIEW_POOLED_WORKFLOW_DEFINITION_NAME; + } - private static final String ADHOC_WORKFLOW_DEFINITION_NAME = "activiti$activitiAdhoc"; - private static final String ADHOC_WORKFLOW_DEFINITION_TITLE = "Adhoc Workflow"; - private static final String ADHOC_WORKFLOW_DEFINITION_DESCRIPTION = "Assign arbitrary task to colleague using Activiti workflow engine"; - private static final String REVIEW_WORKFLOW_DEFINITION_NAME = "activiti$activitiReview"; - private static final String REVIEW_POOLED_WORKFLOW_DEFINITION_NAME = "activiti$activitiReviewPooled"; - - @Override - protected String getAdhocWorkflowDefinitionName() - { - return ADHOC_WORKFLOW_DEFINITION_NAME; - } + @Override + protected void approveTask(String taskId) + { + HashMap params = new HashMap(); + params.put(QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "reviewOutcome"), "Approve"); + workflowService.updateTask(taskId, params, null, null); + workflowService.endTask(taskId, null); + } - @Override - protected String getAdhocWorkflowDefinitionTitle() - { - return ADHOC_WORKFLOW_DEFINITION_TITLE; - } - - @Override - protected String getAdhocWorkflowDefinitionDescription() - { - return ADHOC_WORKFLOW_DEFINITION_DESCRIPTION; - } - - @Override - protected String getReviewWorkflowDefinitionName() { - return REVIEW_WORKFLOW_DEFINITION_NAME; - } - - @Override - protected String getReviewPooledWorkflowDefinitionName() { - return REVIEW_POOLED_WORKFLOW_DEFINITION_NAME; - } - - @Override - protected void approveTask(String taskId) - { - HashMap params = new HashMap(); - params.put(QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "reviewOutcome"), "Approve"); - workflowService.updateTask(taskId, params, null, null); - workflowService.endTask(taskId, null); - } - - @Override - protected void rejectTask(String taskId) - { - HashMap params = new HashMap(); + @Override + protected void rejectTask(String taskId) + { + HashMap params = new HashMap(); params.put(QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "reviewOutcome"), "Reject"); workflowService.updateTask(taskId, params, null, null); workflowService.endTask(taskId, null); - } - + } } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/JBPMWorkflowRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/workflow/JBPMWorkflowRestApiTest.java index 6b136f27e4..0e8f713990 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/JBPMWorkflowRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/JBPMWorkflowRestApiTest.java @@ -24,66 +24,73 @@ import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.Response; +/** + * @author Nick Smith + * @author Frederik Heremans + * @since 3.4.e + */ public class JBPMWorkflowRestApiTest extends AbstractWorkflowRestApiTest { - private static final String ADHOC_WORKFLOW_DEFINITION_NAME = "jbpm$wf:adhoc"; - private static final String ADHOC_WORKFLOW_DEFINITION_TITLE = "Adhoc Workflow (JBPM)"; - private static final String ADHOC_WORKFLOW_DEFINITION_DESCRIPTION = "Assign arbitrary task to colleague using JBPM workflow engine"; - private static final String REVIEW_WORKFLOW_DEFINITION_NAME = "jbpm$wf:review"; - private static final String REVIEW_POOLED_WORKFLOW_DEFINITION_NAME = "jbpm$wf:reviewpooled"; + private static final String ADHOC_WORKFLOW_DEFINITION_NAME = "jbpm$wf:adhoc"; + private static final String ADHOC_WORKFLOW_DEFINITION_TITLE = "Adhoc Workflow (JBPM)"; + private static final String ADHOC_WORKFLOW_DEFINITION_DESCRIPTION = "Assign arbitrary task to colleague using JBPM workflow engine"; + private static final String REVIEW_WORKFLOW_DEFINITION_NAME = "jbpm$wf:review"; + private static final String REVIEW_POOLED_WORKFLOW_DEFINITION_NAME = "jbpm$wf:reviewpooled"; + + @Override + protected String getAdhocWorkflowDefinitionName() + { + return ADHOC_WORKFLOW_DEFINITION_NAME; + } + + @Override + protected String getAdhocWorkflowDefinitionTitle() + { + return ADHOC_WORKFLOW_DEFINITION_TITLE; + } + + @Override + protected String getAdhocWorkflowDefinitionDescription() + { + return ADHOC_WORKFLOW_DEFINITION_DESCRIPTION; + } + + @Override + protected String getReviewWorkflowDefinitionName() + { + return REVIEW_WORKFLOW_DEFINITION_NAME; + } + + @Override + protected String getReviewPooledWorkflowDefinitionName() + { + return REVIEW_POOLED_WORKFLOW_DEFINITION_NAME; + } + + @Override + protected void approveTask(String taskId) throws Exception + { + String transition = "approve"; + checkTransitionExists(transition, taskId); - @Override - protected String getAdhocWorkflowDefinitionName() - { - return ADHOC_WORKFLOW_DEFINITION_NAME; - } + // Take transition + workflowService.endTask(taskId, transition); + } + + @Override + protected void rejectTask(String taskId) throws Exception + { + String transition = "reject"; + checkTransitionExists(transition, taskId); - @Override - protected String getAdhocWorkflowDefinitionTitle() - { - return ADHOC_WORKFLOW_DEFINITION_TITLE; - } - - @Override - protected String getAdhocWorkflowDefinitionDescription() - { - return ADHOC_WORKFLOW_DEFINITION_DESCRIPTION; - } - - @Override - protected String getReviewWorkflowDefinitionName() { - return REVIEW_WORKFLOW_DEFINITION_NAME; - } - - @Override - protected String getReviewPooledWorkflowDefinitionName() { - return REVIEW_POOLED_WORKFLOW_DEFINITION_NAME; - } - - @Override - protected void approveTask(String taskId) throws Exception - { - String transition = "approve"; - checkTransitionExists(transition, taskId); - - // Take transition - workflowService.endTask(taskId, transition); - } - - @Override - protected void rejectTask(String taskId) throws Exception - { - String transition = "reject"; - checkTransitionExists(transition, taskId); - - // Take transition - workflowService.endTask(taskId, transition); - } - - private void checkTransitionExists(String transitionName, String taskId) throws Exception - { - // Transition to "Approve", check if transition is available - Response response = sendRequest(new GetRequest(URL_TASKS + "/" + taskId), Status.STATUS_OK); + // Take transition + workflowService.endTask(taskId, transition); + } + + private void checkTransitionExists(String transitionName, String taskId) throws Exception + { + // Transition to "Approve", check if transition is available + Response response = sendRequest(new GetRequest(URL_TASKS + "/" + taskId), Status.STATUS_OK); String jsonStr = response.getContentAsString(); JSONObject json = new JSONObject(jsonStr); JSONObject result = json.getJSONObject("data"); @@ -98,16 +105,15 @@ public class JBPMWorkflowRestApiTest extends AbstractWorkflowRestApiTest boolean found = false; // Find approve transition - for(int i=0; i < transitions.length(); i++) + for (int i=0; i < transitions.length(); i++) { - String name = transitions.getJSONObject(i).getString("id"); - if(name.equals("approve")) - { - found = true; - break; - } + String name = transitions.getJSONObject(i).getString("id"); + if (name.equals("approve")) + { + found = true; + break; + } } - assertTrue("Transition 'Approve' not found", found); - } - + assertTrue("Transition 'Approve' not found", found); + } } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstanceGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstanceGet.java index 31c5972985..631c31028d 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstanceGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstanceGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancePut.java b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancePut.java index b305d1fe31..6681fe45bf 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancePut.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancePut.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -147,35 +147,35 @@ public class TaskInstancePut extends AbstractWorkflowWebscript } else { - // If the JSON returns an Object which is not a String, we use that type. - // Otherwise, we try to convert the string - if(jsonValue instanceof String) - { - // Check if the task already has the property, use that type. - Serializable existingValue = workflowTask.getProperties().get(key); - if(existingValue != null) - { - try - { - value = DefaultTypeConverter.INSTANCE.convert(existingValue.getClass(), jsonValue); - } - catch(TypeConversionException tce) - { - // TODO: is this the right approach, ignoring exception? - // Ignore the exception, revert to using String-value - } - } - else - { - // Revert to using string-value - value = (String) jsonValue; - } - } - else - { - // Use the value provided by JSON - value = (Serializable) jsonValue; - } + // If the JSON returns an Object which is not a String, we use that type. + // Otherwise, we try to convert the string + if (jsonValue instanceof String) + { + // Check if the task already has the property, use that type. + Serializable existingValue = workflowTask.getProperties().get(key); + if (existingValue != null) + { + try + { + value = DefaultTypeConverter.INSTANCE.convert(existingValue.getClass(), jsonValue); + } + catch(TypeConversionException tce) + { + // TODO: is this the right approach, ignoring exception? + // Ignore the exception, revert to using String-value + } + } + else + { + // Revert to using string-value + value = (String) jsonValue; + } + } + else + { + // Use the value provided by JSON + value = (Serializable) jsonValue; + } } } } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancesGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancesGet.java index 724167962d..d80279d2c5 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/TaskInstancesGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionGet.java index 971fb1570f..c235e92fd1 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionGet.java @@ -38,23 +38,23 @@ import org.springframework.extensions.webscripts.WebScriptRequest; */ public class WorkflowDefinitionGet extends AbstractWorkflowWebscript { - private static final String PARAM_WORKFLOW_DEFINITION_ID = "workflowDefinitionId"; - + private static final String PARAM_WORKFLOW_DEFINITION_ID = "workflowDefinitionId"; + @Override protected Map buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { - Map params = req.getServiceMatch().getTemplateVars(); + Map params = req.getServiceMatch().getTemplateVars(); // Get the definition id from the params String workflowDefinitionId = params.get(PARAM_WORKFLOW_DEFINITION_ID); - WorkflowDefinition workflowDefinition = workflowService.getDefinitionById(workflowDefinitionId); - - // Workflow definition is not found, 404 + WorkflowDefinition workflowDefinition = workflowService.getDefinitionById(workflowDefinitionId); + + // Workflow definition is not found, 404 if (workflowDefinition == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, - "Unable to find workflow definition with id: " + workflowDefinitionId); + "Unable to find workflow definition with id: " + workflowDefinitionId); } Map model = new HashMap(); diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionsGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionsGet.java index 5a4cb14780..932a8f1341 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionsGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowDefinitionsGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDelete.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDelete.java index f79924ba82..cdfef64f35 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDelete.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDelete.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -38,7 +38,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; */ public class WorkflowInstanceDelete extends AbstractWorkflowWebscript { - public static final String PARAM_FORCED = "forced"; @Override @@ -106,10 +105,10 @@ public class WorkflowInstanceDelete extends AbstractWorkflowWebscript // get the initiator WorkflowInstance wi = workflowService.getWorkflowById(instanceId); - if(wi == null) + if (wi == null) { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, - "The workflow instance to delete/cancel with id " + instanceId + " doesn't exist: "); + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, + "The workflow instance to delete/cancel with id " + instanceId + " doesn't exist: "); } NodeRef initiator = wi.getInitiator(); @@ -117,7 +116,7 @@ public class WorkflowInstanceDelete extends AbstractWorkflowWebscript { // determine if the current user is the initiator of the workflow String currentUserName = authenticationService.getCurrentUserName(); - + // get the username of the initiator String userName = (String)nodeService.getProperty(initiator, ContentModel.PROP_USERNAME); diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDiagramGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDiagramGet.java index 955fb270fd..717e2e9543 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDiagramGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceDiagramGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceGet.java index a216836a78..2f2be7fe90 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstanceGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -32,11 +32,9 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author unknown * @since 3.4 - * */ public class WorkflowInstanceGet extends AbstractWorkflowWebscript { - public static final String PARAM_INCLUDE_TASKS = "includeTasks"; @Override diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesForNodeGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesForNodeGet.java index 6ba082b4ca..049ec2d527 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesForNodeGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesForNodeGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -32,7 +32,6 @@ import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author unknown * @since 3.4 - * */ public class WorkflowInstancesForNodeGet extends AbstractWorkflowWebscript { @@ -65,5 +64,4 @@ public class WorkflowInstancesForNodeGet extends AbstractWorkflowWebscript return model; } - } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesGet.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesGet.java index 065f353789..e83892889b 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowInstancesGet.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilder.java index 7c9d3dd19c..14c8dcda54 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -57,7 +57,7 @@ import org.springframework.extensions.surf.util.ISO8601DateFormat; /** * @author Nick Smith - * + * @since 3.4 */ public class WorkflowModelBuilder { @@ -403,7 +403,9 @@ public class WorkflowModelBuilder keys.addAll(propKeys); } else + { keys = buildQNameKeys(propertyFilters); + } return buildQNameProperties(properties, keys); } @@ -592,10 +594,10 @@ public class WorkflowModelBuilder break; } } - if(outcomeLabel == null) + if (outcomeLabel == null) { - // TODO: is this okay -> no real transitions exist for activiti - outcomeLabel = outcomeId; + // TODO: is this okay -> no real transitions exist for activiti + outcomeLabel = outcomeId; } } } diff --git a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilderTest.java b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilderTest.java index 924c25e4d2..c218901980 100644 --- a/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilderTest.java +++ b/source/java/org/alfresco/repo/web/scripts/workflow/WorkflowModelBuilderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2011 Alfresco Software Limited. * * This file is part of Alfresco * @@ -53,8 +53,8 @@ import org.alfresco.service.namespace.QName; import org.alfresco.util.ISO8601DateFormat; /** - * @since 3.4 * @author Nick Smith + * @since 3.4 */ public class WorkflowModelBuilderTest extends TestCase {