Skip to content

Commit 475ebfe

Browse files
committed
feat: support new maintenance endpoint
1 parent 3759723 commit 475ebfe

File tree

4 files changed

+233
-1
lines changed

4 files changed

+233
-1
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog - FOSSology.REST.dotnet
22

3+
## NEXT
4+
5+
* support new maintenance endpoint.
6+
37
## 1.3.0 (2022-12-30)
48

59
* all dependencies updates to the latest version.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="CreateMaintenanceInfo.cs" company="Tethys">
3+
// Copyright (C) 2023 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 System.Collections.Generic;
18+
19+
using Newtonsoft.Json;
20+
21+
/// <summary>
22+
/// Information to start maintenance.
23+
/// </summary>
24+
public class CreateMaintenanceInfo
25+
{
26+
/// <summary>
27+
/// No documentation on option 'a' available yet.
28+
/// </summary>
29+
public const string Optiona = "a";
30+
31+
/// <summary>
32+
/// No documentation on option 'A' available yet.
33+
/// </summary>
34+
public const string OptionA = "A";
35+
36+
/// <summary>
37+
/// No documentation on option 'F' available yet.
38+
/// </summary>
39+
public const string OptionF = "F";
40+
41+
/// <summary>
42+
/// No documentation on option 'g' available yet.
43+
/// </summary>
44+
public const string Optiong = "g";
45+
46+
/// <summary>
47+
/// No documentation on option 'E' available yet.
48+
/// </summary>
49+
public const string OptionE = "E";
50+
51+
/// <summary>
52+
/// No documentation on option 'L' available yet.
53+
/// </summary>
54+
public const string OptionL = "L";
55+
56+
/// <summary>
57+
/// No documentation on option 'N' available yet.
58+
/// </summary>
59+
public const string OptionN = "N";
60+
61+
/// <summary>
62+
/// No documentation on option 'R' available yet.
63+
/// </summary>
64+
public const string OptionR = "R";
65+
66+
/// <summary>
67+
/// No documentation on option 't' available yet.
68+
/// </summary>
69+
public const string Optiont = "t";
70+
71+
/// <summary>
72+
/// No documentation on option 'T' available yet.
73+
/// </summary>
74+
public const string OptionT = "T";
75+
76+
/// <summary>
77+
/// No documentation on option 'D' available yet.
78+
/// </summary>
79+
public const string OptionD = "D";
80+
81+
/// <summary>
82+
/// No documentation on option 'Z' available yet.
83+
/// </summary>
84+
public const string OptionZ = "Z";
85+
86+
/// <summary>
87+
/// No documentation on option 'I' available yet.
88+
/// </summary>
89+
public const string OptionI = "I";
90+
91+
/// <summary>
92+
/// No documentation on option 'v' available yet.
93+
/// </summary>
94+
public const string Optionv = "v";
95+
96+
/// <summary>
97+
/// No documentation on option 'o' available yet.
98+
/// </summary>
99+
public const string Optiono = "o";
100+
101+
/// <summary>
102+
/// No documentation on option 'l' available yet.
103+
/// </summary>
104+
public const string Optionl = "l";
105+
106+
/// <summary>
107+
/// Gets or sets the maintenance options.
108+
/// </summary>
109+
[JsonProperty("options")]
110+
public List<string> Options { get; set; }
111+
112+
/// <summary>
113+
/// Gets or sets the logs date.
114+
/// </summary>
115+
[JsonProperty("logsDate")]
116+
public string LogsDate { get; set; }
117+
118+
/// <summary>
119+
/// Gets or sets gold date.
120+
/// </summary>
121+
[JsonProperty("goldDate")]
122+
public string GoldDate { get; set; }
123+
124+
/// <summary>
125+
/// Initializes a new instance of the <see cref="CreateMaintenanceInfo"/> class.
126+
/// </summary>
127+
public CreateMaintenanceInfo()
128+
{
129+
this.Options = new List<string>();
130+
} // CreateMaintenance()
131+
132+
/// <inheritdoc />
133+
public override string ToString()
134+
{
135+
return $"{this.Options}: {this.LogsDate}, {this.GoldDate}";
136+
} // ToString()
137+
} // CreateMaintenance
138+
}

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class FossologyClientTest
4545
/// <summary>
4646
/// The access token.
4747
/// </summary>
48-
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzI2MTc1OTksIm5iZiI6MTY3MjM1ODQwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.zivhU2CiTDI2_PqWvPejifhs6d6HohVOW6w1XG3GUSQ";
48+
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Nzk3MDIzOTksIm5iZiI6MTY3OTM1NjgwMCwianRpIjoiTXk0eiIsInNjb3BlIjoid3JpdGUifQ.LAM8QI2o1zry1PbyxHCqmNYr45jDPFzadH7FNm1L-CQ";
4949

5050
/// <summary>
5151
/// The filename of a test package.
@@ -1067,6 +1067,25 @@ public void TestFileSearch()
10671067
// ]"
10681068
}
10691069

1070+
/// <summary>
1071+
/// Unit test.
1072+
/// </summary>
1073+
[TestMethod]
1074+
public void TestInitiateMaintenance()
1075+
{
1076+
var client = new FossologyClient(LocalUrl, Token);
1077+
var info = new CreateMaintenanceInfo();
1078+
info.Options.Add(CreateMaintenanceInfo.Optiona);
1079+
info.LogsDate = "2023-01-01";
1080+
info.GoldDate = "2023-04-01";
1081+
1082+
var result = client.InitiateMaintenance(info);
1083+
Assert.IsNotNull(result);
1084+
Assert.AreEqual("INFO", result.Type);
1085+
Assert.AreEqual(201, result.Code);
1086+
Debug.WriteLine($"Initiate maintenance = {result.Message}");
1087+
}
1088+
10701089
//// ---------------------------------------------------------------------
10711090

10721091
#region TESTS THAT REQUIRE MANUAL PREPARATION
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FossologyClientMaintenance.cs" company="Tethys">
3+
// Copyright (C) 2023 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 Fossology.Rest.Dotnet.Model;
18+
19+
using Newtonsoft.Json;
20+
using RestSharp;
21+
22+
/// <summary>
23+
/// Client for the SW360 REST API.
24+
/// </summary>
25+
public partial class FossologyClient
26+
{
27+
/// <summary>
28+
/// Initiates maintenance.
29+
/// </summary>
30+
/// <param name="info">The information.</param>
31+
/// <returns>
32+
/// <see cref="Result" />.
33+
/// </returns>
34+
public Result InitiateMaintenance(CreateMaintenanceInfo info)
35+
{
36+
Log.Debug("Initiating maintenance...");
37+
38+
var json = JsonConvert.SerializeObject(info);
39+
var request = new RestRequest(this.Url + "/maintenance", Method.Post);
40+
request.RequestFormat = DataFormat.Json;
41+
42+
request.AddJsonBody(json);
43+
request.AddHeader("Content-Type", "application/json");
44+
45+
var response = this.api.Execute(request);
46+
if (response?.Content == null)
47+
{
48+
throw new FossologyApiException(ErrorCode.NoValidAnswer);
49+
} // if
50+
51+
var result = JsonConvert.DeserializeObject<Result>(response.Content);
52+
if (result == null)
53+
{
54+
Log.Error("Got empty response!");
55+
}
56+
else
57+
{
58+
if (result.Code == 201)
59+
{
60+
Log.Debug($"Maintenance initiated: {result.Message}");
61+
}
62+
else
63+
{
64+
Log.Error($"Error initiating maintenance: {result.Message}");
65+
} // if
66+
} // if
67+
68+
return result;
69+
} // InitiateMaintenance()
70+
} // FossologyClient
71+
}

0 commit comments

Comments
 (0)