diff --git a/IntegrationConnectors/src/IntegrationConnectors.Confluence/ConfluenceConnector.cs b/IntegrationConnectors/src/IntegrationConnectors.Confluence/ConfluenceConnector.cs index a3d7808..be29db8 100644 --- a/IntegrationConnectors/src/IntegrationConnectors.Confluence/ConfluenceConnector.cs +++ b/IntegrationConnectors/src/IntegrationConnectors.Confluence/ConfluenceConnector.cs @@ -48,19 +48,14 @@ public async Task UpdatePage(string pageId, string htmlContent, string comment) var result = await PutAsync($"{_url}/wiki/rest/api/content/{pageId}", requestJson); } - public async Task> SearchContentByLabelAsync(string label) - { - //&expand=history - //expand=metadata.labels - var response = await GetAsync($"{_url}/wiki/rest/api/content/search?limit=10000&cql=type=page%20AND%20label='{label}'&expand=metadata.labels"); - var wikiPageSearchResults = JsonSerializer.Deserialize(response, _jsonSerializerOptions); - return wikiPageSearchResults.Results.Where(r => r.Type.Equals("page")).ToList(); - } - public async Task> SearchContentAsync(string contributorAccountId, string spaceKey) + public async Task> SearchContentAsync(string contributorAccountId, string spaceKey, string label, string lastModifiedYear, string createdYear) { string contributorClause = string.Empty; string spaceClause = string.Empty; + string labelClause = string.Empty; + string lastModifiedClause = string.Empty; + string createdYearClause = string.Empty; if (!string.IsNullOrEmpty(contributorAccountId)) { @@ -72,8 +67,23 @@ public async Task> SearchContentAsync(string co spaceClause = $" and space.key='{spaceKey}'"; } + if (!string.IsNullOrEmpty(label)) + { + spaceClause = $" and label='{label}'"; + } + + if (!string.IsNullOrEmpty(lastModifiedYear)) + { + lastModifiedClause = $" and lastModified <= '{lastModifiedYear}-12-31'"; + } + + if (!string.IsNullOrEmpty(createdYear)) + { + createdYearClause = $" and created <= '{createdYear}-12-31'"; + } + var results = new List(); - var response = await GetAsync($"{_url}/wiki/rest/api/content/search?limit=10000&cql=type=page{contributorClause}{spaceClause}&expand=history,history.lastUpdated"); + var response = await GetAsync($"{_url}/wiki/rest/api/content/search?limit=10000&cql=type=page{contributorClause}{spaceClause}{labelClause}{lastModifiedClause}{createdYearClause}&expand=history,history.lastUpdated,metadata.labels"); var wikiPageSearchResults = JsonSerializer.Deserialize(response, _jsonSerializerOptions); results.AddRange(wikiPageSearchResults.Results); while (wikiPageSearchResults.Links.Next != null) diff --git a/Tools/src/ConfluenceKB/Options.cs b/Tools/src/ConfluenceKB/Options.cs index b4c10c2..ce7da3d 100644 --- a/Tools/src/ConfluenceKB/Options.cs +++ b/Tools/src/ConfluenceKB/Options.cs @@ -19,5 +19,14 @@ public class Options [Option("SpaceKey", Required = false, HelpText = "Space Key")] public string SpaceKey { get; set; } + [Option("Label", Required = false, HelpText = "Labels")] + public string Label { get; set; } + + [Option("LastModifiedYear", Required = false, HelpText = "Last Modified Year")] + public string LastModifiedYear { get; set; } + + [Option("CreatedYear", Required = false, HelpText = "Created Year")] + public string CreatedYear { get; set; } + } } \ No newline at end of file diff --git a/Tools/src/ConfluenceKB/Program.cs b/Tools/src/ConfluenceKB/Program.cs index b6ec153..fc78795 100644 --- a/Tools/src/ConfluenceKB/Program.cs +++ b/Tools/src/ConfluenceKB/Program.cs @@ -8,17 +8,17 @@ Parser.Default.ParseArguments(args) .WithParsed(o => { - ExecuteJob(o.ConfluenceEndpoint, o.ConfluenceUsername, o.ConfluenceAuthenticationToken, o.UserAccountId, o.SpaceKey); + ExecuteJob(o.ConfluenceEndpoint, o.ConfluenceUsername, o.ConfluenceAuthenticationToken, o.UserAccountId, o.SpaceKey, o.Label, o.LastModifiedYear, o.CreatedYear); }); -void ExecuteJob(string confluenceEndpoint, string confluenceUsername, string confluenceAuthenticationToken, string userAccountId, string spaceKey) +void ExecuteJob(string confluenceEndpoint, string confluenceUsername, string confluenceAuthenticationToken, string userAccountId, string spaceKey, string label, string lastModifiedYear, string createdYear) { var key = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{confluenceUsername}:{confluenceAuthenticationToken}")); var confluenceConnector = new ConfluenceConnector(confluenceEndpoint, key, AuthenticationType.Basic); - var results = confluenceConnector.SearchContentAsync(userAccountId, spaceKey).Result; + var results = confluenceConnector.SearchContentAsync(userAccountId, spaceKey, label, lastModifiedYear, createdYear).Result; foreach (var result in results) { - Console.WriteLine($"https://{confluenceEndpoint}/wiki{result.Links.WebUi}"); + Console.WriteLine($"{confluenceEndpoint}/wiki{result.Links.WebUi}"); } }