Skip to content

Commit

Permalink
Updated requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ragavareddychalapala committed Feb 6, 2025
1 parent 90d2aa8 commit 50e50bb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface ISw360ApiCommunication
string AttachComponentSourceToSW360(AttachReport attachReport);
void DownloadAttachmentUsingWebClient(string attachmentDownloadLink, string fileName);
Task<HttpResponseMessage> GetComponentDetailsByUrl(string componentLink);
Task<HttpResponseMessage> GetAllReleasesWithAllData(string page, string pageEntries);
Task<HttpResponseMessage> GetAllReleasesWithAllData(int page, int pageEntries);
}
}
5 changes: 2 additions & 3 deletions src/LCT.APICommunications/SW360Apicommunication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,9 @@ public async Task<HttpResponseMessage> GetComponentUsingName(string componentNam
string url = $"{sw360ComponentApi}{ApiConstant.ComponentNameUrl}{componentName}";
return await httpClient.GetAsync(url);
}
public async Task<HttpResponseMessage> GetAllReleasesWithAllData(string page, string pageEntries)
public async Task<HttpResponseMessage> GetAllReleasesWithAllData(int page, int pageEntries)
{
HttpClient httpClient = GetHttpClient();
HttpResponseMessage httpResponseMessage=new HttpResponseMessage();
HttpClient httpClient = GetHttpClient();
string url = $"{sw360ReleaseApi}?page={page}&allDetails=true&page_entries={pageEntries}";
return await httpClient.GetAsync(url);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.Facade/Interfaces/ISW360ApicommunicationFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public interface ISW360ApicommunicationFacade
Task<HttpResponseMessage> UpdateLinkedRelease(string projectId, string releaseId, UpdateLinkedRelease updateLinkedRelease);
Task<HttpResponseMessage> GetReleaseByExternalId(string purlId,string externalIdKey = "");
Task<HttpResponseMessage> GetComponentByExternalId(string purlId, string externalIdKey = "");
Task<HttpResponseMessage> GetAllReleasesWithAllData(string page, string pageEntries);
Task<HttpResponseMessage> GetAllReleasesWithAllData(int page, int pageEntries);
}
}
2 changes: 1 addition & 1 deletion src/LCT.Facade/SW360ApicommunicationFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Task<HttpResponseMessage> GetComponentByExternalId(string purlId, string
{
return m_sw360ApiCommunication.GetComponentByExternalId(purlId, externalIdKey);
}
public Task<HttpResponseMessage> GetAllReleasesWithAllData(string page,string pageEntries)
public Task<HttpResponseMessage> GetAllReleasesWithAllData(int page, int pageEntries)
{
return m_sw360ApiCommunication.GetAllReleasesWithAllData(page, pageEntries);
}
Expand Down
24 changes: 12 additions & 12 deletions src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task ValidateAppSettings_TestPositive()
{
//Arrange
string projectName = "Test";
ProjectReleases projectReleases=new ProjectReleases();
ProjectReleases projectReleases = new ProjectReleases();
var CommonAppSettings = new CommonAppSettings()
{
SW360 = new SW360()
Expand All @@ -64,7 +64,7 @@ public async Task ValidateAppSettings_TestPositive()
.ReturnsAsync(projectName);

//Act
await CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object,projectReleases);
await CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases);

//Assert
mockISw360ProjectService.Verify(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<string>(), It.IsAny<string>(), projectReleases), Times.AtLeastOnce);
Expand All @@ -81,10 +81,10 @@ public async Task ValidateAppSettings_OnClosedProject_EndsTheApplication()
{
SW360 = new SW360()
{
ProjectName= "Test"
ProjectName = "Test"
}
};

mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<String>(), It.IsAny<string>(), projectReleases))
.ReturnsAsync(projectName);

Expand All @@ -104,9 +104,9 @@ public void ValidateAppSettings_TestNegative()
ProjectReleases projectReleases = new ProjectReleases();
var CommonAppSettings = new CommonAppSettings()
{
SW360=new SW360()
SW360 = new SW360()
};
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<string>(), It.IsAny<string>(),projectReleases))
mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny<string>(), It.IsAny<string>(), projectReleases))
.ReturnsAsync(projectName);

//Act
Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task TriggerFossologyValidation_TestPositive()

var triggerStatusResponse = JsonConvert.SerializeObject(fossTriggerStatus);

mockISW360ApicommunicationFacade.Setup(x => x.GetAllReleasesWithAllData(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(new HttpResponseMessage
mockISW360ApicommunicationFacade.Setup(x => x.GetAllReleasesWithAllData(It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(new HttpResponseMessage
{
Content = new StringContent(responseBody)
});
Expand All @@ -160,14 +160,14 @@ public async Task TriggerFossologyValidation_TestPositive()
await CreatorValidator.TriggerFossologyValidation(appSettings, mockISW360ApicommunicationFacade.Object);

// Assert
mockISW360ApicommunicationFacade.Verify(x => x.GetAllReleasesWithAllData(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
mockISW360ApicommunicationFacade.Verify(x => x.TriggerFossologyProcess(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
mockISW360ApicommunicationFacade.Verify(x => x.GetAllReleasesWithAllData(It.IsAny<int>(), It.IsAny<int>()), Times.Once);
mockISW360ApicommunicationFacade.Verify(x => x.TriggerFossologyProcess(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
public async Task FossologyUrlValidation_ValidUrl_ReturnsTrue()
{
// Arrange


var appSettings = new CommonAppSettings()
{
Expand Down Expand Up @@ -228,7 +228,7 @@ public async Task FossologyUrlValidation_InvalidUrl_ReturnsFalse()
// Assert
Assert.IsFalse(result);
}


[Test]
public async Task FossologyUrlValidation_InvalidUri_ThrowsException()
Expand Down Expand Up @@ -282,7 +282,7 @@ public async Task FossologyUrlValidation_HttpRequestException_ReturnsFalse()
Assert.IsFalse(result);
}



}
}
41 changes: 22 additions & 19 deletions src/LCT.SW360PackageCreator/CreatorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting

try
{
string page = "0";
string pageEntries = "20";
int page = 0;
int pageEntries = 40;
bool validReleaseFound = false;
ReleasesAllDetails.Sw360Release validRelease = null;
int pageCount = 0;
Expand All @@ -74,37 +74,40 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting
string response = responseData?.Content?.ReadAsStringAsync()?.Result ?? string.Empty;
ReleasesAllDetails releaseResponse = JsonConvert.DeserializeObject<ReleasesAllDetails>(response);

validRelease = releaseResponse.Embedded.Sw360releases
if (releaseResponse != null)
{
validRelease = releaseResponse?.Embedded?.Sw360releases?
.FirstOrDefault(release => release.ClearingState == "APPROVED" &&
release.AllReleasesEmbedded?.Sw360attachments != null &&
release.AllReleasesEmbedded.Sw360attachments.Any(attachments => attachments.Count != 0));

if (validRelease != null)
{
validReleaseFound = true;
}
else
{
// Check if there are more pages
int currentPage = int.Parse(page);
int totalPages = releaseResponse.Page.TotalPages;
if (currentPage < totalPages - 1)
if (validRelease != null)
{
page = (currentPage + 1).ToString();
pageCount++;
validReleaseFound = true;
}
else
{
break; // No more pages to check
int currentPage = page;
int totalPages = (int)(releaseResponse?.Page?.TotalPages);
if (currentPage < totalPages - 1)
{
page = currentPage + 1;
pageCount++;
}
else
{
break;
}
}
}

}

if (validReleaseFound)
{
var releaseUrl = validRelease.Links.Self.Href;
var releaseUrl = validRelease?.Links?.Self?.Href;
var releaseId = CommonHelper.GetSubstringOfLastOccurance(releaseUrl, "/");
string sw360link = $"{validRelease.Name}:{validRelease.Version}:{appSettings.SW360.URL}{ApiConstant.Sw360ReleaseUrlApiSuffix}" +
string sw360link = $"{validRelease?.Name}:{validRelease?.Version}:{appSettings?.SW360?.URL}{ApiConstant.Sw360ReleaseUrlApiSuffix}" +
$"{releaseId}#/tab-Summary";
FossTriggerStatus fossResult = await sw360CreatorService.TriggerFossologyProcessForValidation(releaseId, sw360link);
if (!string.IsNullOrEmpty(fossResult?.Links?.Self?.Href))
Expand All @@ -116,7 +119,7 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting
}
catch (AggregateException ex)
{
Logger.Debug($"\tError in TriggerFossologyProcess--{ex}");
Logger.Debug($"\tError in TriggerFossologyValidation--{ex}");
Logger.Error($"Trigger Fossology Process failed.Please check fossology configuration in sw360");
environmentHelper.CallEnvironmentExit(-1);
}
Expand Down

0 comments on commit 50e50bb

Please sign in to comment.