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

Skipping of CATool when Sw360 project is in Closed state #187

Closed
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion 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 Down
10 changes: 10 additions & 0 deletions src/LCT.PackageIdentifier/BomValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
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 @@ -17,6 +20,7 @@ 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, ProjectReleases projectReleases)
{
string sw360ProjectName = await bomService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName,projectReleases);
Expand All @@ -25,6 +29,12 @@ public static async Task ValidateAppSettings(CommonAppSettings appSettings, ISw3
{
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;
Expand Down
10 changes: 10 additions & 0 deletions src/LCT.SW360PackageCreator/CreatorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using System.Threading.Tasks;
using LCT.Common;
using LCT.APICommunications.Model;
using System;
using log4net;
using System.Reflection;


namespace LCT.SW360PackageCreator
Expand All @@ -18,6 +21,7 @@ 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, ProjectReleases projectReleases)
{
string sw360ProjectName = await sw360ProjectService.GetProjectNameByProjectIDFromSW360(appSettings.SW360ProjectID, appSettings.SW360ProjectName,projectReleases);
Expand All @@ -26,6 +30,12 @@ public static async Task ValidateAppSettings(CommonAppSettings appSettings, ISw3
{
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;
Expand Down
21 changes: 11 additions & 10 deletions src/LCT.Services/Sw360CommonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ private async Task<IList<Sw360Components>> GetCompListFromExternalIDCombinations
public async Task<Releasestatus> GetReleaseDataByExternalId(string releaseName, string releaseVersion, string releaseExternalId)
{
Logger.Debug($"GetReleaseDataByExternalId(): Release name - {releaseName}@{releaseVersion}");
string externalIdUriString;
if (releaseExternalId.Contains(Dataconstant.PurlCheck()["NPM"]))
{
externalIdUriString = Uri.EscapeDataString(releaseExternalId);
}
else
{
externalIdUriString = releaseExternalId;
}
Releasestatus releasestatus = new Releasestatus();

releasestatus.isReleaseExist = false;
Expand All @@ -138,11 +129,21 @@ public async Task<Releasestatus> GetReleaseDataByExternalId(string releaseName,
{
foreach (string externalIdKey in externalIdKeyList)
{
HttpResponseMessage httpResponseComponent = await m_SW360ApiCommunicationFacade.GetReleaseByExternalId(externalIdUriString, externalIdKey);
HttpResponseMessage httpResponseComponent = await m_SW360ApiCommunicationFacade.GetReleaseByExternalId(releaseExternalId, externalIdKey);
var responseContent = httpResponseComponent?.Content?.ReadAsStringAsync()?.Result ?? string.Empty;
var componentsRelease = JsonConvert.DeserializeObject<ComponentsRelease>(responseContent);
var sw360releasesdata = componentsRelease?.Embedded?.Sw360Releases ?? new List<Sw360Releases>();

//It's for Local Sw360 servers,making an API call with EscapeDataString..
if (sw360releasesdata.Count == 0 && releaseExternalId.Contains(Dataconstant.PurlCheck()["NPM"]))
{
releaseExternalId = Uri.EscapeDataString(releaseExternalId);
httpResponseComponent = await m_SW360ApiCommunicationFacade.GetReleaseByExternalId(releaseExternalId, externalIdKey);
responseContent = httpResponseComponent?.Content?.ReadAsStringAsync()?.Result ?? string.Empty;
componentsRelease = JsonConvert.DeserializeObject<ComponentsRelease>(responseContent);
sw360releasesdata = componentsRelease?.Embedded?.Sw360Releases ?? new List<Sw360Releases>();
}

if (sw360releasesdata.Count > 0)
{
Releasestatus releaseStatus = GetReleaseExistStatus(releaseName, externalIdKey, sw360releasesdata);
Expand Down
3 changes: 2 additions & 1 deletion src/LCT.Services/Sw360ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public async Task<string> GetProjectNameByProjectIDFromSW360(string projectId, s
sw360ProjectName = projectInfo?.Name;
projectReleases.Name=projectInfo?.Name;
projectReleases.Version=projectInfo?.Version;

projectReleases.state = projectInfo?.state;
projectReleases.clearingState = projectInfo?.clearingState;
}
}
catch (HttpRequestException ex)
Expand Down
Loading