Skip to content

Commit 4076a73

Browse files
committed
feat: support for groups added
1 parent 5b14638 commit 4076a73

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* supports FOSSology REST API v1.4.3 (FOSSology 4.0.0 built @ 2023/03/09).
66
* new method GetHealth().
77
* have `FossologyClient` to be a partial class for better overview.
8+
* new method GetGroupList().
89

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

Fossology.Rest.Dotnet.Model/Group.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="Group.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// Fossology Group information.
21+
/// </summary>
22+
public class Group
23+
{
24+
/// <summary>
25+
/// Gets or sets the id.
26+
/// </summary>
27+
[JsonProperty("id")]
28+
public int Id { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the name.
32+
/// </summary>
33+
[JsonProperty("name")]
34+
public string Name { get; set; }
35+
36+
/// <inheritdoc />
37+
public override string ToString()
38+
{
39+
return $"{this.Id}: {this.Name}";
40+
}
41+
} // Group
42+
}

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,37 @@ public void TestGetHealth()
708708
Assert.AreEqual("OK", actual.Database.Status);
709709
}
710710

711+
/// <summary>
712+
/// Unit test.
713+
/// </summary>
714+
[TestMethod]
715+
public void TestGetGroupList()
716+
{
717+
var client = new FossologyClient(LocalUrl, Token);
718+
var actual = client.GetGroupList();
719+
Assert.IsNotNull(actual);
720+
Assert.IsTrue(actual.Count > 0);
721+
}
722+
723+
#if false // not yet supported by Fossology
724+
/// <summary>
725+
/// Unit test.
726+
/// </summary>
727+
[TestMethod]
728+
public void TestCreateGroup()
729+
{
730+
const string GroupName = "TestGroup";
731+
732+
var client = new FossologyClient(LocalUrl, Token);
733+
var actual = client.CreateGroup(GroupName);
734+
Assert.IsNotNull(actual);
735+
//Assert.AreEqual("OK", actual.Status);
736+
}
737+
#endif
738+
739+
//// ---------------------------------------------------------------------
740+
741+
#region SUPPORT METHODS
711742
private static void WaitUntilUploadIsDone(FossologyClient client, int id)
712743
{
713744
while (!client.IsUploadUnpacked(id))
@@ -755,5 +786,6 @@ private static int FindFolder(IEnumerable<Folder> folderList, string folderName)
755786

756787
return -1;
757788
} // FindFolder()
789+
#endregion SUPPORT METHODS
758790
}
759791
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FossologyClientGroup.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet
16+
{
17+
using System.Collections.Generic;
18+
using Fossology.Rest.Dotnet.Model;
19+
20+
using Newtonsoft.Json;
21+
22+
using RestSharp;
23+
24+
using JsonSerializer = RestSharp.Serialization.Json.JsonSerializer;
25+
26+
/// <summary>
27+
/// Client for the SW360 REST API.
28+
/// </summary>
29+
public partial class FossologyClient
30+
{
31+
/// <summary>
32+
/// Gets the list of all groups.
33+
/// </summary>
34+
/// <returns>A list of <see cref="Group"/> objects.</returns>
35+
public IReadOnlyList<Group> GetGroupList()
36+
{
37+
Log.Debug("Getting list of folder...");
38+
39+
var request = new RestRequest(this.Url + $"/groups", Method.GET);
40+
request.RequestFormat = DataFormat.Json;
41+
request.JsonSerializer = new JsonSerializer();
42+
request.Parameters.Clear();
43+
44+
var response = this.api.Execute(request);
45+
var list = JsonConvert.DeserializeObject<List<Group>>(
46+
response.Content,
47+
new JsonSerializerSettings
48+
{
49+
NullValueHandling = NullValueHandling.Ignore,
50+
});
51+
return list;
52+
} // GetGroupList()
53+
54+
#if false // not yet supported by Fossology
55+
/// <summary>
56+
/// Creates a new group.
57+
/// </summary>
58+
/// <param name="groupName">Name of the group.</param>
59+
/// <returns>An <see cref="Result"/> object.</returns>
60+
/// <remarks>
61+
/// The message property of the result contains the group id
62+
/// which is needed for further operations.
63+
/// </remarks>>
64+
public Result CreateGroup(string groupName)
65+
{
66+
var request = new RestRequest(this.Url + "/groups", Method.POST);
67+
request.RequestFormat = DataFormat.Json;
68+
request.AddHeader("groupName", groupName);
69+
70+
var resultRaw = this.api.Execute(request);
71+
var result = JsonConvert.DeserializeObject<Result>(resultRaw.Content);
72+
Log.Debug($"Group {result.Message} created.");
73+
74+
return result;
75+
} // CreateGroup()
76+
#endif
77+
} // FossologyClient
78+
}

0 commit comments

Comments
 (0)