Search in sources :

Example 86 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method createRuleNodeRef.

private NodeRef createRuleNodeRef(NodeRef folder, String title) throws Exception {
    JSONObject jsonRule = createRule(folder, title);
    String id = jsonRule.getJSONObject("data").getString("id");
    return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, id);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject)

Example 87 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class DiscussionRestApiTest method testDeleteToplevelPost.

public void testDeleteToplevelPost() throws Exception {
    // Create two posts
    JSONObject item1 = createSitePost("test1", "test1", Status.STATUS_OK);
    JSONObject item2 = createSitePost("test2", "test2", Status.STATUS_OK);
    String name1 = item1.getString("name");
    NodeRef nodeRef1 = new NodeRef(item1.getString("nodeRef"));
    NodeRef nodeRef2 = new NodeRef(item2.getString("nodeRef"));
    // The node references returned correspond to the topics
    assertEquals(ForumModel.TYPE_TOPIC, nodeService.getType(nodeRef1));
    assertEquals(ForumModel.TYPE_TOPIC, nodeService.getType(nodeRef2));
    // Delete one post by name
    deletePost(name1, Status.STATUS_OK);
    // Check it went
    getPost(name1, Status.STATUS_NOT_FOUND);
    // Delete the other post by noderef
    deletePost(nodeRef2, Status.STATUS_OK);
    // Check it went
    getPost(nodeRef2, Status.STATUS_NOT_FOUND);
    // Check all the nodes have gone
    assertEquals(false, nodeService.exists(nodeRef1));
    assertEquals(false, nodeService.exists(nodeRef2));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject)

Example 88 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class DiscussionRestApiTest method testListings.

/**
 * Test for the various listings:
 *  All, New, Hot (Most Active), Mine
 */
public void testListings() throws Exception {
    JSONObject result;
    JSONObject item;
    // Check all of the listings, none should have anything yet
    result = getPosts(null, Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts("hot", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts("mine", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts("new?numdays=100", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    // Check with a noderef too
    result = getPosts(FORUM_NODE, null, Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts(FORUM_NODE, "hot", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts(FORUM_NODE, "mine", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    result = getPosts(FORUM_NODE, "new?numdays=100", Status.STATUS_OK);
    assertEquals(0, result.getInt("total"));
    assertEquals(0, result.getInt("itemCount"));
    assertEquals(0, result.getJSONArray("items").length());
    // Now add a few topics with replies
    // Some of these will be created as different users
    item = createSitePost("SiteTitle1", "Content", Status.STATUS_OK);
    NodeRef siteTopic1 = new NodeRef(item.getString("nodeRef"));
    this.authenticationComponent.setCurrentUser(USER_TWO);
    item = createSitePost("SiteTitle2", "Content", Status.STATUS_OK);
    NodeRef siteTopic2 = new NodeRef(item.getString("nodeRef"));
    item = createNodePost(FORUM_NODE, "NodeTitle1", "Content", Status.STATUS_OK);
    NodeRef nodeTopic1 = new NodeRef(item.getString("nodeRef"));
    this.authenticationComponent.setCurrentUser(USER_ONE);
    item = createNodePost(FORUM_NODE, "NodeTitle2", "Content", Status.STATUS_OK);
    NodeRef nodeTopic2 = new NodeRef(item.getString("nodeRef"));
    item = createNodePost(FORUM_NODE, "NodeTitle3", "Content", Status.STATUS_OK);
    NodeRef nodeTopic3 = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteTopic1, "Reply1a", "Content", Status.STATUS_OK);
    NodeRef siteReply1A = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteTopic1, "Reply1b", "Content", Status.STATUS_OK);
    NodeRef siteReply1B = new NodeRef(item.getString("nodeRef"));
    this.authenticationComponent.setCurrentUser(USER_TWO);
    item = createReply(siteTopic2, "Reply2a", "Content", Status.STATUS_OK);
    NodeRef siteReply2A = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteTopic2, "Reply2b", "Content", Status.STATUS_OK);
    NodeRef siteReply2B = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteTopic2, "Reply2c", "Content", Status.STATUS_OK);
    NodeRef siteReply2C = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteReply2A, "Reply2aa", "Content", Status.STATUS_OK);
    NodeRef siteReply2AA = new NodeRef(item.getString("nodeRef"));
    item = createReply(siteReply2A, "Reply2ab", "Content", Status.STATUS_OK);
    NodeRef siteReply2AB = new NodeRef(item.getString("nodeRef"));
    this.authenticationComponent.setCurrentUser(USER_ONE);
    item = createReply(siteReply2AA, "Reply2aaa", "Content", Status.STATUS_OK);
    NodeRef siteReply2AAA = new NodeRef(item.getString("nodeRef"));
    item = createReply(nodeTopic1, "ReplyN1a", "Content", Status.STATUS_OK);
    NodeRef nodeReply1A = new NodeRef(item.getString("nodeRef"));
    item = createReply(nodeReply1A, "ReplyN1aa", "Content", Status.STATUS_OK);
    NodeRef nodeReply1AA = new NodeRef(item.getString("nodeRef"));
    item = createReply(nodeReply1AA, "ReplyN1aaa", "Content", Status.STATUS_OK);
    NodeRef nodeReply1AAA = new NodeRef(item.getString("nodeRef"));
    // Check for totals
    // We should get all the topics
    result = getPosts(null, Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, null, Status.STATUS_OK);
    assertEquals(3, result.getInt("total"));
    assertEquals(3, result.getInt("itemCount"));
    assertEquals(3, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(2).getString("title"));
    assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    // Check for "mine"
    // User 1 has Site 1, and Nodes 2 + 3
    result = getPosts("mine", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "mine", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    // Check for recent (new)
    // We should get all the topics, with the newest one first (rather than last as with others)
    result = getPosts("new?numdays=2", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "new?numdays=2", Status.STATUS_OK);
    assertEquals(3, result.getInt("total"));
    assertEquals(3, result.getInt("itemCount"));
    assertEquals(3, result.getJSONArray("items").length());
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(2).getString("title"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
    // Check for hot
    // Will only show topics with replies. Sorting is by replies, not date
    result = getPosts("hot", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "hot", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    // Shift some of the posts into the past
    // (Update the created and published dates)
    pushCreatedDateBack(siteTopic1, 10);
    // Make it newer
    pushCreatedDateBack(siteReply1B, -2);
    pushCreatedDateBack(nodeTopic2, 10);
    pushCreatedDateBack(nodeTopic3, 4);
    // Make it newer
    pushCreatedDateBack(nodeReply1AAA, -1);
    // Re-check totals, only ordering changes
    result = getPosts(null, Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, null, Status.STATUS_OK);
    assertEquals(3, result.getInt("total"));
    assertEquals(3, result.getInt("itemCount"));
    assertEquals(3, result.getJSONArray("items").length());
    assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(2).getString("title"));
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    // Re-check recent, old ones vanish
    result = getPosts("new?numdays=2", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "new?numdays=6", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "new?numdays=2", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    // Re-check "mine", no change except ordering
    result = getPosts("mine", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "mine", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    // Re-check hot, some old ones vanish
    result = getPosts("hot", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(2, result.getInt("itemCount"));
    assertEquals(2, result.getJSONArray("items").length());
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "hot", Status.STATUS_OK);
    assertEquals(1, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    // Check paging
    result = getPosts("limit", Status.STATUS_OK);
    assertEquals(2, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
    result = getPosts(FORUM_NODE, "limit", Status.STATUS_OK);
    assertEquals(3, result.getInt("total"));
    assertEquals(1, result.getInt("itemCount"));
    assertEquals(1, result.getJSONArray("items").length());
    assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
    assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject)

Example 89 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class DownloadRestApiTest method createNodeWithTextContent.

public NodeRef createNodeWithTextContent(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName, String content) {
    NodeRef nodeRef = createNode(parentNode, nodeCmName, nodeType, ownerUserName);
    // If there is any content, add it.
    if (content != null) {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        writer.setEncoding("UTF-8");
        writer.putContent(content);
    }
    return nodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter)

Example 90 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class DownloadRestApiTest method testCreateAndGetDownload.

@Test
public void testCreateAndGetDownload() throws UnsupportedEncodingException, IOException, JSONException {
    // CReate the download
    String postData = "[{ \"nodeRef\": \"" + rootFile + "\"}, { \"nodeRef\": \"" + rootFolder + "\"}]";
    Response response = sendRequest(new PostRequest(URL_DOWNLOADS, postData, "application/json"), 200);
    // Parse the response
    JSONObject result = new JSONObject(response.getContentAsString());
    NodeRef downloadNodeRef = new NodeRef(result.getString("nodeRef"));
    // Get the status
    String statusUrl = MessageFormat.format(URL_DOWNLOAD_STATUS, downloadNodeRef.getStoreRef().getProtocol(), downloadNodeRef.getStoreRef().getIdentifier(), downloadNodeRef.getId());
    Response statusResponse = sendRequest(new GetRequest(statusUrl), 200);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) BaseWebScriptTest(org.alfresco.repo.web.scripts.BaseWebScriptTest) Test(org.junit.Test)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51