Skip to content

Commit 64ce1c0

Browse files
committed
feat: enhance folders to support groups
1 parent 4076a73 commit 64ce1c0

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* new method GetHealth().
77
* have `FossologyClient` to be a partial class for better overview.
88
* new method GetGroupList().
9+
* add support for groups for all methods where it did not yet exist.
910

1011
## 1.1.0 (2020-06-25)
1112
* supports FOSSology REST API v1.0.16 (FOSSology 3.8.0 built @ 2020/06/19).

Fossology.Rest.Dotnet/FossologyClientFolder.cs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace Fossology.Rest.Dotnet
2121

2222
using RestSharp;
2323

24+
using JsonSerializer = RestSharp.Serialization.Json.JsonSerializer;
25+
2426
/// <summary>
2527
/// Client for the SW360 REST API.
2628
/// </summary>
@@ -30,14 +32,24 @@ public partial class FossologyClient
3032
/// Gets the folder with the specified id.
3133
/// </summary>
3234
/// <param name="id">The identifier.</param>
35+
/// <param name="groupName">The group name to choose.</param>
3336
/// <returns>A <see cref="Folder"/> object.</returns>
34-
public Folder GetFolder(int id)
37+
public Folder GetFolder(int id, string groupName = "")
3538
{
3639
Log.Debug($"Getting folder {id}...");
3740

38-
var result = this.api.Get(this.Url + $"/folders/{id}");
41+
var request = new RestRequest(this.Url + $"/folders/{id}", Method.GET);
42+
request.RequestFormat = DataFormat.Json;
43+
request.JsonSerializer = new JsonSerializer();
44+
request.Parameters.Clear();
45+
if (!string.IsNullOrEmpty(groupName))
46+
{
47+
request.AddHeader("groupName", groupName);
48+
} // if
49+
50+
var response = this.api.Execute(request);
3951
var folder = JsonConvert.DeserializeObject<Folder>(
40-
result.Content,
52+
response.Content,
4153
new JsonSerializerSettings
4254
{
4355
NullValueHandling = NullValueHandling.Ignore,
@@ -48,14 +60,24 @@ public Folder GetFolder(int id)
4860
/// <summary>
4961
/// Gets the list of all folders.
5062
/// </summary>
63+
/// <param name="groupName">The group name to choose.</param>
5164
/// <returns>A list of <see cref="Folder"/> objects.</returns>
52-
public IReadOnlyList<Folder> GetFolderList()
65+
public IReadOnlyList<Folder> GetFolderList(string groupName = "")
5366
{
5467
Log.Debug("Getting list of folder...");
5568

56-
var result = this.api.Get(this.Url + "/folders");
69+
var request = new RestRequest(this.Url + $"/folders", Method.GET);
70+
request.RequestFormat = DataFormat.Json;
71+
request.JsonSerializer = new JsonSerializer();
72+
request.Parameters.Clear();
73+
if (!string.IsNullOrEmpty(groupName))
74+
{
75+
request.AddHeader("groupName", groupName);
76+
} // if
77+
78+
var response = this.api.Execute(request);
5779
var list = JsonConvert.DeserializeObject<List<Folder>>(
58-
result.Content,
80+
response.Content,
5981
new JsonSerializerSettings
6082
{
6183
NullValueHandling = NullValueHandling.Ignore,
@@ -68,17 +90,28 @@ public IReadOnlyList<Folder> GetFolderList()
6890
/// </summary>
6991
/// <param name="folderName">Name of the folder.</param>
7092
/// <param name="parentFolder">The parent folder.</param>
93+
/// <param name="description">The folder description (optional).</param>
94+
/// <param name="groupName">The group name to choose (optional).</param>
7195
/// <returns>An <see cref="Result"/> object.</returns>
7296
/// <remarks>
7397
/// The message property of the result contains the folder id
7498
/// which is needed for further operations.
7599
/// </remarks>>
76-
public Result CreateFolder(string folderName, int parentFolder)
100+
public Result CreateFolder(string folderName, int parentFolder, string description = "", string groupName = "")
77101
{
78102
var request = new RestRequest(this.Url + "/folders", Method.POST);
79103
request.RequestFormat = DataFormat.Json;
80104
request.AddHeader("parentFolder", parentFolder.ToString());
81105
request.AddHeader("folderName", folderName);
106+
if (!string.IsNullOrEmpty(description))
107+
{
108+
request.AddHeader("description", description);
109+
} // if
110+
111+
if (!string.IsNullOrEmpty(groupName))
112+
{
113+
request.AddHeader("groupName", groupName);
114+
} // if
82115

83116
var resultRaw = this.api.Execute(request);
84117
var result = JsonConvert.DeserializeObject<Result>(resultRaw.Content);
@@ -91,12 +124,22 @@ public Result CreateFolder(string folderName, int parentFolder)
91124
/// Deletes the folder with the specified id.
92125
/// </summary>
93126
/// <param name="id">The identifier.</param>
127+
/// <param name="groupName">The group name to choose.</param>
94128
/// <returns>An <see cref="Result"/> object.</returns>
95-
public Result DeleteFolder(int id)
129+
public Result DeleteFolder(int id, string groupName = "")
96130
{
97131
Log.Debug($"Deleting folder {id}...");
98132

99-
var response = this.api.Delete(this.Url + $"/folders/{id}");
133+
var request = new RestRequest(this.Url + $"/folders/{id}", Method.DELETE);
134+
request.RequestFormat = DataFormat.Json;
135+
request.JsonSerializer = new JsonSerializer();
136+
request.Parameters.Clear();
137+
if (!string.IsNullOrEmpty(groupName))
138+
{
139+
request.AddHeader("groupName", groupName);
140+
} // if
141+
142+
var response = this.api.Execute(request);
100143
var result = JsonConvert.DeserializeObject<Result>(response.Content);
101144
return result;
102145
} // DeleteFolder()

0 commit comments

Comments
 (0)