Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stops the CATool execution when provided Sw360 project is in closed state #185

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/LCT.APICommunications/Model/ProjectReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class ProjectReleases
[JsonProperty("version")]
public string Version { get; set; }

[JsonProperty("state")]
public string state { get; set; }

[JsonProperty("clearingState")]
public string clearingState { get; set; }

[JsonProperty("_embedded")]
public ReleaseEmbedded Embedded { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/LCT.Common/ExceptionHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void HttpException(HttpRequestException ex, HttpResponseMessage re
Logger.Logger.Log(null, Level.Error, $"The exception may be caused by an incorrect projectid or missing token for {exceptionSource} , Please ensure that a valid token is provided and try again:{ex.Message}", null);

}
else if (500 <= Convert.ToInt32(ex.StatusCode) && Convert.ToInt32(ex.StatusCode) <= 599)
else if ((500 <= Convert.ToInt32(ex.StatusCode) && Convert.ToInt32(ex.StatusCode) <= 599) || ex.StatusCode == null)
{
Logger.Logger.Log(null, Level.Error, $"The exception may arise because {exceptionSource} is currently unresponsive:{ex.Message} Please try again later", null);
}
Expand All @@ -43,7 +43,7 @@ public static void FossologyException(HttpRequestException ex)
}
}

public static void ArgumentException( string message)
public static void ArgumentException(string message)
{
Logger.Logger.Log(null, Level.Error, $"Missing Arguments: Please provide the below arguments via inline or in the appSettings.json file to proceed.", null);
Logger.Logger.Log(null, Level.Warn, $"{message}", null);
Expand Down
11 changes: 7 additions & 4 deletions src/LCT.PackageIdentifier.UTest/BomValidatorUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.IO;
using System.Threading.Tasks;
using LCT.Common;
using LCT.APICommunications.Model;

namespace PackageIdentifier.UTest
{
Expand All @@ -27,13 +28,14 @@ public class BomValidatorUnitTests
public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName()
{
//Arrange
string projectName = "Test";
ProjectReleases projectReleases = new ProjectReleases();
projectReleases.Name = "Test";
var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object)
{
SW360ProjectName = "Test"
};
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<String>(), It.IsAny<string>()))
.ReturnsAsync(projectName);
.ReturnsAsync(projectReleases);

mockIFileOperations.Setup(x => x.ValidateFilePath(It.IsAny<string>()))
.Callback((string message) => { })
Expand All @@ -55,13 +57,14 @@ public async Task ValidateAppSettings_ProvidedProjectID_ReturnsProjectName()
public Task ValidateAppSettings_ProvidedProjectID_ReturnsInvalidDataException()
{
//Arrange
string projectName = null;
ProjectReleases projectReleases = new ProjectReleases();
projectReleases.Name = "";
var CommonAppSettings = new CommonAppSettings(mockIFolderAction.Object)
{
SW360ProjectName = "Test"
};
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(projectName);
.ReturnsAsync(projectReleases);

mockIFileOperations.Setup(x => x.ValidateFilePath(It.IsAny<string>()))
.Callback((string message) => { })
Expand Down
17 changes: 14 additions & 3 deletions src/LCT.PackageIdentifier/BomValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
// SPDX-License-Identifier: MIT
// --------------------------------------------------------------------------------------------------------------------

using LCT.APICommunications.Model;
using LCT.Common;
using LCT.Services.Interface;
using System;
using System.IO;
using System.Threading.Tasks;
using log4net;
using System.Reflection;

namespace LCT.PackageIdentifier
{
Expand All @@ -16,17 +20,24 @@ namespace LCT.PackageIdentifier
/// </summary>
public static class BomValidator
{
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static async Task ValidateAppSettings(CommonAppSettings appSettings, ISw360ProjectService bomService)
{
string sw360ProjectName = await bomService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName);
ProjectReleases projectReleases = await bomService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName);

if (string.IsNullOrEmpty(sw360ProjectName))
if (projectReleases == null || string.IsNullOrEmpty(projectReleases.Name))
{
throw new InvalidDataException($"Invalid Project Id - {appSettings.SW360ProjectID}");
}
else if (projectReleases.clearingState == "CLOSED")
{
Logger.Error($"Provided Sw360 project is not in active state ,Please make sure you added the correct project details that is in active state..");
Logger.Debug($"ValidateAppSettings() : Sw360 project "+ projectReleases.Name +" is in " + projectReleases.clearingState +" state.");
Environment.Exit(-1);
}
else
{
appSettings.SW360ProjectName = sw360ProjectName;
appSettings.SW360ProjectName = projectReleases.Name;
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.IO;
using LCT.Common;
using System.Threading.Tasks;
using LCT.APICommunications.Model;

namespace SW360ComponentCreator.UTest
{
Expand All @@ -28,11 +29,12 @@ public CreatorValidatorTest()
public async Task ValidateAppSettings_TestPositive()
{
//Arrange
string projectName = "Test";
ProjectReleases projectReleases = new ProjectReleases();
projectReleases.Name = "Test";
var CommonAppSettings = new CommonAppSettings();
CommonAppSettings.SW360ProjectName = "Test";
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<String>(), It.IsAny<string>()))
.ReturnsAsync(projectName);
.ReturnsAsync(projectReleases);

//Act
await CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object);
Expand All @@ -45,12 +47,11 @@ public async Task ValidateAppSettings_TestPositive()
public void ValidateAppSettings_TestNegative()
{
//Arrange
string projectName = null;
ProjectReleases projectReleases = new ProjectReleases();
projectReleases.Name = null;
var CommonAppSettings = new CommonAppSettings();
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<string>(), It.IsAny<string>()))
.ReturnsAsync(projectName);

//Act
.ReturnsAsync(projectReleases);

//Assert
Assert.ThrowsAsync<InvalidDataException>(() => CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object));
Expand Down
9 changes: 2 additions & 7 deletions src/LCT.SW360PackageCreator/CreatorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,11 @@ private static async Task<string> GetAttachmentUrlList(ComparisonBomData compone
public async Task<List<ComparisonBomData>> SetContentsForComparisonBOM(List<Components> lstComponentForBOM, ISW360Service sw360Service)
{
Logger.Debug($"SetContentsForComparisonBOM():Start");
List<ComparisonBomData> comparisonBomData = new List<ComparisonBomData>();
List<ComparisonBomData> comparisonBomData;
Logger.Logger.Log(null, Level.Notice, $"Collecting comparison BOM Data...", null);
componentsAvailableInSw360 = await sw360Service.GetAvailableReleasesInSw360(lstComponentForBOM);

//Checking components count before getting status of individual comp details
if (componentsAvailableInSw360?.Count > 0)
{
comparisonBomData = await GetComparisionBomItems(lstComponentForBOM, sw360Service);
}

comparisonBomData = await GetComparisionBomItems(lstComponentForBOM, sw360Service);
Logger.Debug($"SetContentsForComparisonBOM():End");
return comparisonBomData;
}
Expand Down
18 changes: 14 additions & 4 deletions src/LCT.SW360PackageCreator/CreatorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
using System.IO;
using System.Threading.Tasks;
using LCT.Common;

using LCT.APICommunications.Model;
using System;
using log4net;
using System.Reflection;

namespace LCT.SW360PackageCreator
{
Expand All @@ -17,17 +20,24 @@ namespace LCT.SW360PackageCreator
/// </summary>
public static class CreatorValidator
{
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static async Task ValidateAppSettings(CommonAppSettings appSettings, ISw360ProjectService sw360ProjectService)
{
string sw360ProjectName = await sw360ProjectService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName);
ProjectReleases projectReleases = await sw360ProjectService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName);

if (string.IsNullOrEmpty(sw360ProjectName))
if (projectReleases == null || string.IsNullOrEmpty(projectReleases.Name))
{
throw new InvalidDataException($"Invalid Project Id - {appSettings.SW360ProjectID}");
}
else if (projectReleases.clearingState == "CLOSED")
{
Logger.Error($"Provided Sw360 project is not in active state ,Please make sure you added the correct project details that is in active state.");
Logger.Debug($"ValidateAppSettings() : Sw360 project " + projectReleases.Name + " is in " + projectReleases.clearingState + " state.");
Environment.Exit(-1);
}
else
{
appSettings.SW360ProjectName = sw360ProjectName;
appSettings.SW360ProjectName = projectReleases.Name;
}
}
}
Expand Down
Loading
Loading