Skip to content

Commit 1921c75

Browse files
committed
chores: disable GetUploadScanCodeCopyrights()
1 parent b90df77 commit 1921c75

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ public void TestInitiateMaintenance()
11721172

11731173
//// ---------------------------------------------------------------------
11741174

1175-
#region TESTS THAT REQUIRE MANUAL PREPARATION
1175+
#region TESTS THAT REQUIRE MANUAL PREPARATION
11761176
#if false
11771177
/// <summary>
11781178
/// Unit test.
@@ -1191,6 +1191,7 @@ public void TestDeleteUserSuccess()
11911191
}
11921192
#endif
11931193

1194+
#if false // NOT YET SUPPORTED
11941195
/// <summary>
11951196
/// Unit test.
11961197
/// </summary>
@@ -1205,7 +1206,8 @@ public void TestGetScanCodeResults()
12051206
var result = client.GetUploadScanCodeCopyrights(UploadId, itemId, "active", 100, 1);
12061207
Assert.IsNotNull(result);
12071208
}
1208-
#endregion TESTS THAT REQUIRE MANUAL PREPARATION
1209+
#endif
1210+
#endregion TESTS THAT REQUIRE MANUAL PREPARATION
12091211

12101212
//// ---------------------------------------------------------------------
12111213

Fossology.Rest.Dotnet/FossologyClientUpload.cs

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="FossologyClientUpload.cs" company="Tethys">
3-
// Copyright (C) 2019-2022 T. Graf
3+
// Copyright (C) 2019-2025 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -18,14 +18,11 @@ namespace Fossology.Rest.Dotnet
1818
using System.Collections.Generic;
1919
using System.Linq;
2020
using System.Net;
21-
using System.Runtime.InteropServices.ComTypes;
22-
using System.Threading.Tasks;
2321
using Fossology.Rest.Dotnet.Model;
2422

2523
using Newtonsoft.Json;
2624

2725
using RestSharp;
28-
using RestSharp.Extensions;
2926

3027
/// <summary>
3128
/// Client for the SW360 REST API.
@@ -514,14 +511,15 @@ public Result GetUploadFileById(int id, string filename)
514511
{
515512
Log.Debug($"Downloading upload {id}...");
516513

514+
// ReSharper disable once RedundantArgumentDefaultValue
517515
var request = new RestRequest(this.Url + $"/uploads/{id}/download", Method.Get);
518516
var response = this.api.Execute(request);
519517
if (response?.Content == null)
520518
{
521519
throw new FossologyApiException(ErrorCode.NoValidAnswer);
522520
} // if
523521

524-
if (response.StatusCode == HttpStatusCode.OK)
522+
if ((response.StatusCode == HttpStatusCode.OK) && (response.RawBytes != null))
525523
{
526524
System.IO.File.WriteAllBytes(filename, response.RawBytes);
527525
var res = new Result();
@@ -547,7 +545,7 @@ public Result GetUploadFileById(int id, string filename)
547545
} // GetUploadFileById()
548546

549547
/// <summary>
550-
/// Gets the coüpyright for an upload.
548+
/// Gets the copyright for an upload.
551549
/// </summary>
552550
/// <param name="id">The identifier.</param>
553551
/// <returns>A list of <see cref="CopyrightEntry" /> objects.</returns>
@@ -572,5 +570,78 @@ public List<CopyrightEntry> GetUploadCopyrights(int id)
572570

573571
return summary;
574572
} // GetUploadCopyrights()
573+
574+
/// <summary>
575+
/// Get the item id for the top level item in a given upload.
576+
/// </summary>
577+
/// <param name="id">The upload identifier.</param>
578+
/// <returns>System.Int32.</returns>
579+
public int GetTopItem(int id)
580+
{
581+
Log.Debug($"Getting upload top item upload {id}...");
582+
583+
var request = new RestRequest(this.Url + $"/uploads/{id}/topitem");
584+
request.RequestFormat = DataFormat.Json;
585+
var response = this.api.Execute(request);
586+
if (response?.Content == null)
587+
{
588+
throw new FossologyApiException(ErrorCode.NoValidAnswer);
589+
} // if
590+
591+
var result = JsonConvert.DeserializeObject<Result>(response.Content);
592+
if (result == null)
593+
{
594+
Log.Error("Got empty response!");
595+
return -1;
596+
}
597+
else
598+
{
599+
if (result.Code != (int)HttpStatusCode.OK)
600+
{
601+
Log.Error($"Error getting top-item: {result.Message}");
602+
} // if
603+
} // if
604+
605+
return int.Parse(result.Message);
606+
} // GetTopItem()
607+
608+
#if false // NOT YET SUPPORTED
609+
/// <summary>
610+
/// Gets the copyright found by ScanCode for an upload.
611+
/// </summary>
612+
/// <param name="uploadId">The upload id.</param>
613+
/// <param name="itemId">The upload tree id.</param>
614+
/// <param name="status">Status of the CX.</param>
615+
/// <param name="limit">Limits of responses per request.</param>
616+
/// <param name="page">Page number for responses.</param>
617+
/// <returns>A list of <see cref="CopyrightEntry" /> objects.</returns>
618+
public List<CopyrightEntry> GetUploadScanCodeCopyrights(
619+
int uploadId,
620+
int itemId,
621+
string status,
622+
int limit,
623+
int page)
624+
{
625+
Log.Debug($"Getting upload copyrights for upload {uploadId}, {itemId}...");
626+
627+
////var request = new RestRequest(this.Url + $"/uploads/{uploadId}/item/{itemId}/scancode-copyrights?status={status}");
628+
var request = new RestRequest("http://localhost:8081/repo/api/v2" + $"/uploads/{uploadId}/item/{itemId}/scancode-copyrights?status={status}");
629+
request.RequestFormat = DataFormat.Json;
630+
var response = this.api.Execute(request);
631+
if (response?.Content == null)
632+
{
633+
throw new FossologyApiException(ErrorCode.NoValidAnswer);
634+
} // if
635+
636+
var summary = JsonConvert.DeserializeObject<List<CopyrightEntry>>(
637+
response.Content,
638+
new JsonSerializerSettings
639+
{
640+
NullValueHandling = NullValueHandling.Ignore,
641+
});
642+
643+
return summary;
644+
} // GetUploadScanCodeCopyrights()
645+
#endif
575646
} // FossologyClient
576647
}

0 commit comments

Comments
 (0)