Created
June 1, 2012 13:55
-
-
Save bobbychopra/2852338 to your computer and use it in GitHub Desktop.
Confluence (XML-RPC) Client code to access and create new page with permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public const string SECTION_OWNER_TEXT = "I AM A PARENT PAGE"; | |
public static IEnumerable<RemotePage> getWeeklyParentPages(this ConfluenceClient client, string token, RemotePageSummary[] pages) | |
{ | |
var pageContent = pages.Select(p => client.getPage(token, p.id)); | |
var weeklyParentPages = pageContent.Where(p => p.content.Contains(SECTION_OWNER_TEXT)); | |
return weeklyParentPages; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NOTE: You need to do the following for the Xml-RPC client code wrap | |
// Open VS 2010 Command prompt and run wsdl <url-to-confluence-xml-rpc-api> | |
// add the file as ConfluenceClient. | |
// Using svcutil.exe or adding it as a SOAP service to WCF did not work | |
// for Confluence 4.2 | |
var client = new ConfluenceClient(); | |
var token = client.login(username, password); | |
Console.WriteLine("Received Token: {0}", token); | |
var pages = client.getPages(token, SPACE_KEY); | |
var weeklyParentPages = client.getWeeklyParentPages(token, pages); | |
var mapPageToChildren = from parent in weeklyParentPages | |
let children = pages.Where(p => p.parentId == parent.id) | |
select new {Page = parent, Children = children}; | |
foreach (var parentPage in weeklyParentPages) | |
{ | |
try | |
{ | |
//Create the new child page | |
var newpage = new RemotePage { | |
parentId = parentPage.id, | |
space = parentPage.space, | |
title = pageTitle, | |
content = content, | |
permissions = parentPage.permissions | |
}; | |
client.storePage(token, newpage); | |
newpage = client.getPage(token, newpage.space, newpage.title); | |
//Create the permissions on child | |
var parentPermissions = client.getContentPermissionSets(token, parentPage.id); | |
parentPermissions.ToList().ForEach( | |
ss => client.setContentPermissions(token, newpage.id, ss.type, ss.contentPermissions)); | |
} | |
catch (Exception) | |
{ | |
//Need logging here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment